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.DAOHelper;
|
import com.fgkj.dao.impl.BattInfImpl;
|
import com.fgkj.dao.impl.Batt_maint_infImpl;
|
import com.fgkj.dao.impl.Batt_maint_processImpl;
|
import com.fgkj.db.DBUtil;
|
import com.fgkj.db.IDatabaseName;
|
import com.fgkj.dto.AllModel;
|
import com.fgkj.dto.BattInf;
|
import com.fgkj.dto.Batt_Maint_Dealarm;
|
import com.fgkj.dto.Batt_User_Permit;
|
import com.fgkj.dto.Batt_maint_inf;
|
import com.fgkj.dto.Batt_maint_process;
|
import com.fgkj.dto.Batt_maintenance_inf;
|
import com.fgkj.dto.Batttestdata_inf;
|
import com.fgkj.dto.Page;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User_inf;
|
|
public class Batt_maint_infService {
|
private ServiceModel model;
|
private BaseDAO dao;
|
private BaseDAO daoAgain;
|
private BaseDAO daoProcess;
|
private User_infService uservice;
|
private Batt_maint_processService pservice;
|
|
public Batt_maint_infService() {
|
model=new ServiceModel();
|
dao=BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_INF);
|
daoAgain = BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_INFAGAIN);
|
daoProcess=BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_PROCESS);
|
uservice=new User_infService();
|
pservice=new Batt_maint_processService();
|
}
|
|
|
//2.1电池故障维护记录查询
|
public ServiceModel serchMaint(Object obj){
|
Batt_Maint_Dealarm bmd = (Batt_Maint_Dealarm) obj;
|
User_inf uinf=new User_inf();
|
Batt_maint_process pinf=new Batt_maint_process();
|
List<Batt_Maint_Dealarm> list =dao.serchByCondition(bmd);
|
for(int i=0;i<list.size();i++){
|
|
Batt_maint_inf mainf=list.get(i).getMainf();
|
if(list.get(i).getMainf().getUsr_id()!=null){
|
uinf.setUId(list.get(i).getMainf().getUsr_id());
|
mainf.setUname(((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName());
|
// System.out.println(mainf.getUname());
|
|
}
|
|
if(list.get(i).getMainf().getCopy_uids()!=null&&list.get(i).getMainf().getCopy_uids().length()>0){
|
//System.out.println(list.get(i).getMainf().getCopy_uids());
|
String[] names=list.get(i).getMainf().getCopy_uids().split(",");
|
String copyname=new String();
|
for (String string : names) {
|
uinf.setUId(Integer.parseInt(string));
|
copyname+=((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName()+",";
|
}
|
|
copyname=copyname.substring(0, copyname.length()-1);
|
mainf.setCopy_name(copyname);
|
//System.out.println(mainf.getCopy_name());
|
}
|
|
if(list.get(i).getMainf().getAppoint_uid()!=null){
|
uinf.setUId(list.get(i).getMainf().getAppoint_uid());
|
mainf.setAppoint_name(((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName());
|
// System.out.println(mainf.getAppoint_name());
|
}
|
list.get(i).setMainf(mainf);
|
//System.out.println(list.size());
|
}
|
if(list!=null&&list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
model.setMsg("查询成功!");
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
// 2.2电池故障处理统计查询
|
/*
|
* maint_result存放统计方式
|
* fault_caption存放维护区
|
* master_check存放包机人
|
* remark存放品牌
|
*/
|
public List serchByCondition(Object obj) {
|
//System.out.println(obj+"&&&&&&&&&&&&");
|
Batt_User_Permit bup = (Batt_User_Permit) obj;
|
BattInf binf=bup.getBinf();
|
List<Batt_maint_inf> list = daoAgain.serchByCondition(binf);
|
List<BattInf> listb=(new BattInfImpl()).searchAll();
|
// 总电池数
|
int allBatt=listb.size();
|
// 超时次数
|
List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
|
|
//System.out.println(list.get(1));
|
if (list != null && list.size() > 0) {
|
for (int i = 0; i < list.size(); i++) {
|
//System.out.println(list.size()+"lll");
|
int overTime = 0;
|
// 未完成次数
|
int lastNum = 0;
|
// 时间段
|
String perid_Time = "";
|
|
//System.out.println(i);
|
Date maint_time_limit = list.get(i).getMaint_time_limit();
|
Date maint_done_time = list.get(i).getMaint_done_time();
|
// System.out.println(maint_time_limit);
|
// System.out.println(maint_done_time.getTime());
|
// System.out.println(maint_time_limit.getTime());
|
|
// 获取具体年份,月份和该月的总天数
|
int year = maint_time_limit.getYear() + 1900;
|
int month = maint_time_limit.getMonth() + 1;
|
// int day=ActionUtil.getDaysByYearMonth(year, month);
|
// System.out.println(day);
|
|
// 获取统计方式
|
String method = list.get(i).getMaint_result();
|
|
if (method.equals("1")) {// 按月份
|
perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1);
|
perid_Time += " ";
|
perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1);
|
// System.out.println(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(perid_Time);
|
} else if (method.equals("3")) {// 按年份
|
perid_Time = ActionUtil.getFirstDayOfMonth(year, 0);
|
perid_Time += " ";
|
perid_Time += ActionUtil.getLastDayOfMonth(year, 11);
|
// System.out.println(perid_Time);
|
}
|
if (maint_done_time.getTime() > maint_time_limit.getTime()) {
|
overTime++;
|
}
|
if (list.get(i).getMaint_done() == 0) {
|
lastNum++;
|
}
|
model = new ServiceModel();
|
model.setCode(1);
|
model.setMsgN(perid_Time); // 时间段
|
model.setSum(list.size()); // 故障次数
|
Float percentBatt=0f;
|
if(allBatt!=0){
|
percentBatt= (float) (list.size()/ allBatt);
|
}
|
//System.out.println(list.size());
|
//System.out.println(allBatt);
|
//System.out.println(percentBatt);
|
model.setLowCH(percentBatt);//电池故障率
|
|
model.setNewsum(lastNum); // 未完成次数
|
Float percent = (float) (overTime / list.size());
|
model.setLowCA(percent); // 超时率
|
model.setMsg(list.get(i).getFault_caption());//维护区
|
model.setMsgO(list.get(i).getMaster_check()); //责任人
|
model.setMsgV(list.get(i).getRemark());//电池品牌
|
listmodel.add(model);
|
}
|
} else {
|
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(model.getLowCH());
|
lastModel.setLowCA(model.getLowCA());
|
lastModel.setMsgO(model.getMsgO());
|
lastModel.setMsgV(model.getMsgV());
|
listmodel.add(lastModel);//补全最后一次时间改变
|
// System.out.println(listmodel.size());
|
int num=0;//存放下发作业数
|
String time="";
|
ServiceModel sumModel=null;
|
List<ServiceModel> last=new ArrayList<ServiceModel>();
|
for (int i=0;i<listmodel.size();i++) {
|
//System.out.println(listmodel.get(i));
|
if(listmodel.get(i).getMsgN().equals(time)){
|
num++;
|
}else{
|
if(i!=0){
|
sumModel=new ServiceModel();
|
sumModel.setSum(num+1);// 故障次数
|
sumModel.setNewsum(listmodel.get(i).getNewsum());// 未完成次数
|
sumModel.setCode(listmodel.get(i).getCode());
|
sumModel.setLowCH(listmodel.get(i).getLowCH());//故障率
|
sumModel.setLowCA(listmodel.get(i).getLowCA());// 超时率
|
sumModel.setMsgN(time);//时间段
|
sumModel.setMsgV(listmodel.get(i).getMsgV());//电池平拍
|
sumModel.setMsgO(listmodel.get(i).getMsgO()); //责任人
|
sumModel.setMsg(listmodel.get(i).getMsg());//维护区
|
last.add(sumModel);
|
}
|
num=0;
|
time=listmodel.get(i).getMsgN();
|
}
|
|
}
|
// for (ServiceModel s : last) {
|
// System.out.println(s);
|
// }
|
|
|
List<ServiceModel> listd=new ArrayList();
|
for(int i=(bup.getPage().getPageCurr()-1)*bup.getPage().getPageSize();i<bup.getPage().getPageSize()*bup.getPage().getPageCurr()&&i<last.size();i++){
|
last.get(i).setLowRA((float)last.size());
|
listd.add(last.get(i));
|
}
|
return listd;
|
|
}
|
|
public ServiceModel add(Object obj) {
|
Boolean bl=dao.add(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
//2.1 电池维护记录查询(编辑记录)
|
public ServiceModel update(Object obj1,Object obj2) {
|
Batt_maint_inf mainf=(Batt_maint_inf) obj1;
|
Boolean bl = dao.update(mainf);
|
//System.out.println(bl);
|
List<Batt_maint_process> process = (List<Batt_maint_process>)obj2;
|
ArrayList<String> sql_str = new ArrayList<String>();//存放所有的sql语句
|
if (bl) {
|
for(int i=0;i<process.size();i++){
|
Batt_maint_process bprocess=process.get(i);
|
bprocess.setBatt_maint_rec_id(mainf.getNum());
|
sql_str.add(((Batt_maint_processImpl)daoProcess).addPro(bprocess));
|
//System.out.println("sql_str:"+sql_str);
|
|
}
|
Boolean blP= DAOHelper.makeManualCommit(DBUtil.getConn(),sql_str);
|
if(blP){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else {
|
model.setCode(0);
|
model.setMsg("修改失败!");
|
}
|
|
} else {
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
//2.1 电池维护记录查询(删除记录)
|
public ServiceModel delete(Object obj) {
|
Batt_maint_inf mainf=(Batt_maint_inf) obj;
|
Batt_maint_process bprocess=new Batt_maint_process();
|
bprocess.setBatt_maint_rec_id(mainf.getNum()); //通过Batt_maint_rec_id属性删除
|
Boolean bl = dao.del(mainf);
|
if (bl) {
|
Boolean blp=daoProcess.del(bprocess);
|
if(blp){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}else{
|
model.setCode(0);
|
model.setMsg("删除失败!");
|
}
|
|
} else {
|
model.setCode(0);
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
|
|
//1.1,1.2根据battgroupid查时间
|
public ServiceModel serchByInfo(Object obj) {
|
model=new ServiceModel();
|
Batt_maint_inf mainf =(Batt_maint_inf) obj;
|
List<Batt_maint_inf> list = dao.serchByInfo(mainf);
|
/*for (Batt_maint_inf u : list) {
|
System.out.println(u);
|
}*/
|
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
model.setSum(list.size());
|
}
|
return model;
|
}
|
|
//0.3查询所有的维护记录(只传page对象)
|
public ServiceModel search(){
|
//Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
|
List<Batt_Maint_Dealarm> list=((Batt_maint_infImpl)dao).search();
|
if(list!=null&&list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
//0.4电池组故障率
|
public ServiceModel searchAll() {
|
List<Batt_maint_inf> list = dao.searchAll();
|
List<BattInf> listb=new BattInfImpl().searchAll();
|
if(list!=null && listb!=null){
|
model.setCode(1);
|
model.setNewsum(list.size());
|
model.setSum(listb.size());
|
}
|
//System.out.println(model);
|
return model;
|
}
|
|
//0.4/0.8电池组故障率/维护率(最新)
|
public ServiceModel searchByStationName(Object obj) {
|
Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
|
BattInf binf=bmd.getBinf();
|
Batt_maint_inf mainf=bmd.getMainf();
|
List<Batt_maint_inf> list = ((Batt_maint_infImpl)dao).searchByStationName(bmd); //故障数
|
mainf.setMaint_done(1);
|
List<Batt_maint_inf> listD = ((Batt_maint_infImpl)dao).searchByStationName(bmd); //故障维护数
|
|
List<BattInf> listB=new BattInfImpl().search(binf);//
|
model.setCode(listD.size()); ////故障维护数
|
model.setNewsum(listB.size()); //电池组数
|
model.setSum(list.size()); //故障数
|
//System.out.println(model);
|
return model;
|
}
|
|
//根据电池组id查询电池的故障记录
|
public ServiceModel searchByBattgroupId(Object obj) {
|
model=new ServiceModel();
|
List<Batt_maint_inf> list = ((Batt_maint_infImpl)dao).searchByBattgroupId(obj);
|
User_inf uinf=new User_inf();
|
if(list!=null && list.size()>0){
|
for (int i = 0; i < list.size(); i++) {
|
uinf.setUId(list.get(i).getUsr_id());
|
List<User_inf> users=(List<User_inf>) uservice.serchuName(uinf).getData();
|
//System.out.println(users);
|
if(users.size()>0){
|
list.get(i).setUname(users.get(0).getUName());
|
}
|
//System.out.println(list.get(i));
|
}
|
model.setCode(1);
|
model.setData(list);
|
model.setMsg("查询成功");
|
}else{
|
model.setMsg("查询失败");
|
}
|
return model;
|
}
|
|
public static void main(String[] args) throws ParseException {
|
Batt_maint_infService us = new Batt_maint_infService();
|
|
BattInf binf = new BattInf();
|
/*
|
* 维护区:stationname1 包机人:stationname 电池品牌:battproducer 统计方式:devicename
|
* 统计开始时间:battproductdate 统计结束时间:battproductdata1
|
*/
|
binf.setStationName("");
|
binf.setStationName1("");
|
binf.setBattGroupName("");
|
binf.setBattGroupName1("");
|
binf.setBattProducer("");
|
binf.setBattGroupId(0);
|
|
binf.setDeviceName("2");
|
binf.setMonCapStd(0f);
|
binf.setMonVolStd(0f);
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date date1 = sdf.parse("2000-01-01");
|
Date date2 = sdf.parse("2016-12-30");
|
binf.setBattProductDate(ActionUtil.getSimpDate(date1));
|
binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
|
binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
|
binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
|
|
/*
|
* binf.getStationName1(), binf.getStationName(),
|
* binf.getBattGroupName(), binf.getBattProducer(),
|
* binf.getBattGroupName1(), binf.getBattProductDate(),
|
* binf.getBattProductDate1(), binf.getBattInUseDate(),
|
* binf.getBattInUseDate1(),uinf.getuName()
|
*/
|
|
Batt_maint_inf mainf = new Batt_maint_inf();
|
mainf.setRemark("100");
|
mainf.setMaint_done_time(ActionUtil.getSimpDate(date1));
|
mainf.setMaint_done_time1(ActionUtil.getSimpDate(date2));
|
mainf.setMaint_done(100);
|
|
Batttestdata_inf tdata = new Batttestdata_inf();
|
tdata.setTest_type(0);
|
tdata.setTest_starttype(0);
|
tdata.setRecord_time(ActionUtil.getSimpDate(date1));
|
tdata.setRecord_time1(ActionUtil.getSimpDate(date2));
|
|
User_inf uinf = new User_inf();
|
uinf.setUName("0");
|
|
Page p = new Page();
|
p.setPageCurr(1);
|
p.setPageSize(1);
|
|
Batt_User_Permit bup=new Batt_User_Permit();
|
bup.setBinf(binf);
|
bup.setPage(p);
|
bup.setUinf(uinf);
|
|
Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
|
bmd.setBinf(binf);
|
bmd.setMainf(mainf);
|
bmd.setTdata(tdata);
|
bmd.setPage(p);
|
bmd.setUinf(uinf);
|
|
|
//us.searchByStationName(bmd);
|
// us.serchMaint(bmd);
|
//us.serchByCondition(bup);
|
//us.search();
|
//us.searchAll();
|
mainf.setBattGroupId(1000001);
|
us.searchByBattgroupId(mainf);
|
}
|
}
|