package com.fgkj.services; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.fgkj.actions.ActionUtil; import com.fgkj.dao.BaseDAO; import com.fgkj.dao.BaseDAOFactory; import com.fgkj.dao.impl.Batt_electricityImpl; import com.fgkj.dto.BattInf; import com.fgkj.dto.Batt_electricity; import com.fgkj.dto.ServiceModel; public class Batt_electricityService { private BaseDAO dao; private ServiceModel model; public Batt_electricityService() { dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATT_ELECTRICITY); model = new ServiceModel();; } public ServiceModel add(Object obj){ Boolean bl=dao.add(obj); if(bl){ model.setCode(1); model.setMsg("添加成功!"); }else{ model.setCode(0); model.setMsg("添加失败!"); } return model; } public ServiceModel update(Object obj){ Boolean bl=dao.update(obj); if(bl){ model.setCode(1); model.setMsg("修改成功!"); }else{ model.setCode(0); model.setMsg("修改失败!"); } return model; } public ServiceModel del(Object obj){ Boolean bl=dao.del(obj); if(bl){ model.setCode(1); model.setMsg("删除成功!"); }else{ model.setCode(0); model.setMsg("删除失败!"); } return model; } public ServiceModel searchAll(){ List list=dao.searchAll(); if(list!=null&&list.size()>0){ model.setCode(1); model.setMsg("查询成功!"); model.setData(list); }else{ model.setCode(0); model.setMsg("查询失败!"); } return model; } //9.1机房主控中用电量的统计的折线图 public ServiceModel serchByInfo(Object obj){ List list=dao.serchByInfo(obj); if(list!=null&&list.size()>0){ model.setCode(1); model.setMsg("查询成功!"); //System.out.println(list.size()); model.setData(list); }else{ model.setCode(0); model.setMsg("查询失败!"); } //System.out.println(model); return model; } //10.1根据设备id连battinf和batt_devdischarge表 /* * 统计方式放在battinf的signalname中*/ public List serchByCondition(Object obj){ List list=dao.serchByCondition(obj); List listmodel=new ArrayList(); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { // 时间段 String perid_Time = ""; // 年份,季度,月份 Date dev_recordtime = list.get(i).getDev_recordtime(); // 获取具体年份,月份和该月的总天数 int year = dev_recordtime.getYear() + 1900; int month = dev_recordtime.getMonth() + 1; // 获取统计方式 String method = list.get(i).getNote(); if (method.equals("1")) {// 按月份 perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1); perid_Time += " "; perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1); } else if (method.equals("2")) {// 按季度 if (month < 3) { month = 1; } else { if (month % 3 == 0) { month = month / 3; } else { month = month / 3 + 1; } } perid_Time = ActionUtil.getFirstDayOfMonth(year, (month - 1) * 3); perid_Time += " "; perid_Time += ActionUtil.getLastDayOfMonth(year, month * 3 - 1); } else if (method.equals("3")) {// 按年份 perid_Time = ActionUtil.getFirstDayOfMonth(year, 0); perid_Time += " "; perid_Time += ActionUtil.getLastDayOfMonth(year, 11); month=0; } model = new ServiceModel(); model.setCode(year); model.setMsgN(perid_Time); // 时间段 model.setSum(month); // 所有的电度统计次数 model.setNewsum(list.get(i).getDev_id());//设备id model.setMsg(list.get(i).getDev_name());//设备名称 model.setLowCA(list.get(i).getDev_electricity_CM()); model.setLowCH(list.get(i).getDev_electricity_CT()); model.setLowRA(list.get(i).getDev_electricity_CU()); model.setMsgO("");// model.setMsgV("");// listmodel.add(model); } } else { model.setLowCA(0f); model.setLowCH(0f); model.setLowRA(0f); model.setCode(0); model.setMsgN("0"); listmodel.add(model); } ServiceModel lastModel=new ServiceModel(); lastModel.setMsgN("0"); lastModel.setCode(model.getCode()); lastModel.setMsg(model.getMsg()); lastModel.setLowCH(0f); lastModel.setLowCA(0f); lastModel.setLowRA(0f); lastModel.setMsgO(model.getMsgO()); lastModel.setMsgV(model.getMsgV()); listmodel.add(lastModel);//补全第一次一次时间改变 float numCA=0f;//移动电度 float numCH=0f;//联通电度 float numRA=0f;//电信电度 String time="";//时间段统计 int dev_id=0;//设备id ServiceModel sumModel=null; // for (ServiceModel m : listmodel) { // System.out.println(m.getMsgN()+" "+m.getNewsum()+" "+m.getLowCA()+" "+m.getLowCH()+" "+m.getLowRA()); // } List last=new ArrayList(); for (int i=0;i