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<Batt_electricity> list=dao.serchByCondition(obj);
|
List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
|
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<ServiceModel> last=new ArrayList<ServiceModel>();
|
for (int i=0;i<listmodel.size();i++) {
|
time=listmodel.get(i).getMsgN();
|
dev_id=listmodel.get(i).getNewsum();
|
numCA+=listmodel.get(i).getLowCA();
|
numCH+=listmodel.get(i).getLowCH();
|
numRA+=listmodel.get(i).getLowRA();
|
if((i+1)<listmodel.size()){
|
if(listmodel.get(i+1).getNewsum()==dev_id){
|
if(!listmodel.get(i+1).getMsgN().equals(time)){
|
ServiceModel newModel=new ServiceModel();
|
newModel.setCode(listmodel.get(i).getCode());
|
newModel.setMsgN(listmodel.get(i).getMsgN());
|
newModel.setMsg(listmodel.get(i).getMsg());
|
newModel.setNewsum(listmodel.get(i).getNewsum());
|
newModel.setSum(listmodel.get(i).getSum());
|
newModel.setLowCA(numCA);
|
newModel.setLowCH(numCH);
|
newModel.setLowRA(numRA);
|
numCA=0f;
|
numCH=0f;
|
numRA=0f;
|
last.add(newModel);
|
}
|
}else{
|
ServiceModel newModel=new ServiceModel();
|
newModel.setCode(listmodel.get(i).getCode());
|
newModel.setMsgN(listmodel.get(i).getMsgN());
|
newModel.setMsg(listmodel.get(i).getMsg());
|
newModel.setNewsum(listmodel.get(i).getNewsum());
|
newModel.setSum(listmodel.get(i).getSum());
|
newModel.setLowCA(numCA);
|
newModel.setLowCH(numCH);
|
newModel.setLowRA(numRA);
|
numCA=0f;
|
numCH=0f;
|
numRA=0f;
|
last.add(newModel);
|
}
|
|
}
|
|
}
|
/*for (ServiceModel s : last) {
|
System.out.println(s);
|
}*/
|
//System.out.println(last.size());
|
return last;
|
}
|
public static void main(String[] args) throws ParseException {
|
Batt_electricityImpl bimpl=new Batt_electricityImpl();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date date1 = sdf.parse("2015-01-01");
|
Date date2 = sdf.parse("2017-12-01");
|
BattInf binf=new BattInf();
|
binf.setStationName("");
|
binf.setStationName1("");
|
binf.setSignalName("1");
|
binf.setBattProductDate(ActionUtil.getSimpDate(date1));
|
binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
|
Batt_electricityService bservice=new Batt_electricityService();
|
bservice.serchByCondition(binf);
|
|
|
//binf.setStationId("42070218");
|
//bservice.serchByInfo(binf);
|
}
|
}
|