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 sun.print.SunMinMaxPage;
|
|
import com.fgkj.actions.ActionUtil;
|
import com.fgkj.dao.BaseDAO;
|
import com.fgkj.dao.BaseDAOFactory;
|
import com.fgkj.dao.impl.BattInfImpl;
|
import com.fgkj.dao.impl.User_task_batt_testImpl;
|
import com.fgkj.dto.BattInf;
|
import com.fgkj.dto.Batt_maint_inf;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.Task_Batt_Test;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.dto.User_task_batt_test;
|
import com.fgkj.dto.User_task_param;
|
|
public class User_task_batt_testService {
|
|
private ServiceModel model;
|
private BaseDAO dao;
|
|
public User_task_batt_testService() {
|
model=new ServiceModel();
|
dao=BaseDAOFactory.getBaseDAO(BaseDAO.USER_TASK_BATT_TEST);
|
}
|
public ServiceModel add(Object obj) {
|
Boolean bl=dao.add(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
//4.1作业管理(修改执行人)
|
public ServiceModel updateTask(Object obj) {
|
Boolean bl=((User_task_batt_testImpl)dao).updateTask(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else{
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
//4.1作业管理(作业删除)
|
public ServiceModel delete(Object obj) {
|
Boolean bl=dao.del(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}
|
else{
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
//4.6作业报表(根据电池组信息以及统计方式查询user_task_batt_test信息)
|
public List serchByInfo(Object obj){
|
Task_Batt_Test tbt=(Task_Batt_Test) obj;
|
System.out.println(tbt);
|
// 总作业数
|
List<Task_Batt_Test> list=dao.serchByInfo(tbt);
|
//System.out.println(list.size());
|
int allTask=list.size();
|
//已完成作业总数
|
tbt.getUtest().setTest_complete(1);
|
//System.out.println(tbt.getUtest().getTest_complete());
|
List<Task_Batt_Test> listCompelete = dao.serchByInfo(tbt);
|
int compeleteTask=listCompelete.size();
|
//及时完成作业数
|
tbt.getUtest().setTest_complete(2);
|
//System.out.println(tbt.getUtest().getTest_complete());
|
List<Task_Batt_Test> listRightNow = dao.serchByInfo(tbt);
|
int rightNowTask=listRightNow.size();
|
// System.out.println(allTask+" "+compeleteTask+" "+rightNowTask);
|
// System.out.println(allTask+" "+compeleteTask+" "+uncompeleteTask);
|
List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
|
|
if (list != null && list.size() > 0) {
|
for (int i = 0; i < list.size(); i++) {
|
// 时间段
|
String perid_Time = "";
|
Date Task_exe_date = list.get(i).getUtest().getTask_exe_date();
|
Date Task_exe_date1 = list.get(i).getUtest().getTask_exe_date1();
|
// System.out.println(maint_time_limit);
|
// System.out.println(maint_done_time.getTime());
|
// System.out.println(maint_time_limit.getTime());
|
|
// 获取具体年份,月份和该月的总天数
|
int year = Task_exe_date.getYear() + 1900;
|
int month = Task_exe_date.getMonth() + 1;
|
int day=ActionUtil.getDaysByYearMonth(year, month);
|
//System.out.println(day);
|
// 获取统计方式
|
String method = list.get(i).getUtest().getNote();
|
if (method.equals("1")) {// 按月份
|
perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1);
|
perid_Time += " ";
|
perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1);
|
// System.out.println(method+":"+perid_Time);
|
} else if (method.equals("2")) {// 按季度
|
if (month < 3) {
|
month = 1;
|
} else {
|
if (month % 3 == 0) {
|
month = month / 3;
|
} else {
|
month = month / 3 + 1;
|
}
|
}
|
//System.out.println(month);
|
|
perid_Time = ActionUtil.getFirstDayOfMonth(year,
|
(month - 1) * 3);
|
perid_Time += " ";
|
perid_Time += ActionUtil.getLastDayOfMonth(year,
|
month * 3 - 1);
|
// System.out.println(method+":"+perid_Time);
|
} else if (method.equals("3")) {// 按年份
|
perid_Time = ActionUtil.getFirstDayOfMonth(year, 0);
|
perid_Time += " ";
|
perid_Time += ActionUtil.getLastDayOfMonth(year, 11);
|
// System.out.println(method+":"+perid_Time);
|
}
|
model = new ServiceModel();
|
|
model.setMsgN(perid_Time); // 时间段
|
model.setSum(allTask); //总数
|
Float percentTask=0f;
|
if(allTask!=0){
|
percentTask= (float) (compeleteTask/ allTask);
|
}
|
model.setLowCH(percentTask);//完成率
|
model.setNewsum(compeleteTask); // 完成次数
|
model.setLowCA((float)rightNowTask);//及时完成数
|
model.setLowRA((float)(compeleteTask-rightNowTask));//未及时完成数
|
Float percentRightTask=0f;
|
if(compeleteTask!=0){
|
percentRightTask= (float) (rightNowTask/ compeleteTask);
|
}
|
model.setLowRH(percentRightTask);//及时完成率
|
|
model.setMsg(list.get(i).getBinf().getSignalName());//执行人
|
model.setMsgO(list.get(i).getBinf().getStationName1()); //维护区
|
model.setMsgV(list.get(i).getBinf().getStationName());//机房站点
|
model.setMsgT(list.get(i).getBinf().getBattGroupName());//电池组名称
|
listmodel.add(model);
|
}
|
} else {
|
model.setMsg("查询失败!");
|
model.setCode(0);
|
listmodel.add(model);
|
}
|
ServiceModel lastModel=new ServiceModel();
|
lastModel.setMsgN("0");
|
lastModel.setCode(model.getCode());
|
lastModel.setMsg(model.getMsg());
|
lastModel.setLowCA(model.getLowCA());
|
lastModel.setLowCH(model.getLowCH());
|
lastModel.setLowRA(model.getLowRA());
|
lastModel.setLowRH(model.getLowRH());
|
|
lastModel.setMsgV(model.getMsgV());
|
lastModel.setMsgO(model.getMsgO());
|
lastModel.setMsgT(model.getMsgT());
|
listmodel.add(lastModel);//补全最后一次时间改变
|
int num=0;//存放下发作业数
|
String time="";
|
ServiceModel sumModel=null;
|
List<ServiceModel> last=new ArrayList<ServiceModel>();
|
//System.out.println(listmodel.size()+"***");
|
if(listmodel.size()>2){
|
for (int i=0;i<listmodel.size();i++) {
|
//System.out.println(listmodel.get(i).getMsgN());
|
if(listmodel.get(i).getMsgN().equals(time)){
|
num++;
|
}else{
|
if(i!=0){
|
sumModel=new ServiceModel();
|
sumModel.setSum(num+1);
|
sumModel.setMsg(listmodel.get(i).getMsg());//执行人
|
sumModel.setNewsum(listmodel.get(i).getNewsum());// 完成次数
|
//未完成数
|
int uncompeleteTask=sumModel.getSum()-sumModel.getNewsum();
|
sumModel.setCode(uncompeleteTask);//未完成数
|
sumModel.setLowCH(listmodel.get(i).getLowCH());//完成率
|
sumModel.setLowCA(listmodel.get(i).getLowCA());//及时完成数
|
sumModel.setLowRA(listmodel.get(i).getLowRA());//未及时完成数
|
sumModel.setLowRH(listmodel.get(i).getLowRH());//及时完成率
|
sumModel.setMsgN(time);//时间段
|
sumModel.setMsgV(listmodel.get(i).getMsgV());//机房站点
|
sumModel.setMsgO(listmodel.get(i).getMsgO()); //维护区
|
sumModel.setMsgT(listmodel.get(i).getMsgT());//电池组名称
|
|
last.add(sumModel);
|
}
|
num=0;
|
time=listmodel.get(i).getMsgN();
|
}
|
}
|
}
|
/*for (ServiceModel s : last) {
|
System.out.println(s);
|
}*/
|
//System.out.println(last.size());
|
return last;
|
}
|
|
public ServiceModel serchByCondition(Object obj){
|
List list=dao.serchByCondition(obj);
|
// for (Object object : list) {
|
// System.out.println(object);
|
// }
|
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
//System.out.println(model);
|
return model;
|
}
|
public ServiceModel searchAll(){
|
List list=dao.searchAll();
|
// for (Object object : list) {
|
// System.out.println(object);
|
// }
|
//System.out.println(list);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
public static void main(String[] args) throws ParseException {
|
User_task_batt_testService us = new User_task_batt_testService();
|
/*User_task_batt_test u=new User_task_batt_test();
|
u.setNum(10578);
|
us.serchByCondition(u);
|
//us.searchAll();*/
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date date1 = sdf.parse("2000-01-01");
|
Date date2 = sdf.parse("2016-11-30");
|
Date date3 = sdf.parse("2000-01-01");
|
Date date4 = sdf.parse("2016-11-30");
|
|
User_task_batt_test utest=new User_task_batt_test();
|
utest.setTask_usr_ids("0");
|
utest.setTest_complete(100);//已完成:1 未完成:0 全部:100
|
utest.setTask_exe_date(date3);
|
utest.setTask_exe_date1(date4);
|
utest.setNote("1");//1:按月份 2:按季度 3:按年份
|
|
BattInf binf = new BattInf();
|
binf.setStationName("");
|
binf.setStationName1("");
|
binf.setBattGroupName(""); //电池组名
|
binf.setSignalName(""); //执行人
|
binf.setBattGroupId(0);
|
binf.setBattGroupName1("");
|
binf.setBattProducer("");
|
binf.setMonCapStd(0f);
|
binf.setMonVolStd(0f);
|
binf.setBattProductDate(ActionUtil.getSimpDate(date1));
|
binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
|
binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
|
binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
|
|
User_inf uinf=new User_inf();
|
uinf.setUId(0);
|
|
Task_Batt_Test tbt=new Task_Batt_Test();
|
tbt.setBinf(binf);
|
tbt.setUtest(utest);
|
tbt.setUinf(uinf);
|
us.serchByInfo(tbt);
|
}
|
}
|