package com.fgkj.services;
|
|
import java.text.ParseException;
|
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.BattresdataDAOImpl;
|
import com.fgkj.dao.impl.Battresdata_infDAOImpl;
|
import com.fgkj.dto.BattInf;
|
import com.fgkj.dto.Battresdata;
|
import com.fgkj.dto.Battresdata_inf;
|
import com.fgkj.dto.ServiceModel;
|
|
public class Battresdata_infService {
|
private ServiceModel model;
|
private BaseDAO dao;
|
private BaseDAO daoB;
|
private BaseDAO daoR;
|
public Battresdata_infService() {
|
model = new ServiceModel();
|
dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATTRESDATA_INF);
|
daoB= BaseDAOFactory.getBaseDAO(BaseDAO.BATTINF);
|
daoR= BaseDAOFactory.getBaseDAO(BaseDAO.BATTRESDATA);
|
}
|
|
public ServiceModel add(Object obj) {
|
Boolean bl = dao.add(obj);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
} else {
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
|
public ServiceModel update(Object obj) {
|
Boolean bl = dao.update(obj);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
public ServiceModel delete(Object obj) {
|
Boolean bl = dao.del(obj);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
} else {
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
|
//筛选存在battresdata_inf表中的数据
|
public ServiceModel serchByCondition(Object obj){
|
model=new ServiceModel();
|
List list=dao.serchByCondition(obj);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}else{
|
model.setCode(0);
|
}
|
//System.out.println(list.size());
|
|
return model;
|
}
|
//测试battgroupid在battresdata_inf中是否存在
|
public ServiceModel judge(Object obj){
|
model=new ServiceModel();
|
List<String> list=((Battresdata_infDAOImpl)dao).judge(obj);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
/*for (String u :list) {
|
System.out.println(u);
|
}*/
|
return model;
|
}
|
//查询所有
|
public ServiceModel searchAll() {
|
List<Battresdata_inf> list = dao.searchAll();
|
// for (Battresdata_inf u : list) {
|
// System.out.println(u);
|
// }
|
// System.out.println(list);
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
//6.4.1根据条件查询符合条件的测试完成的电池组(蓄电池电导测试完成率)
|
/*
|
* data_available中存放层次
|
* test_record_count 中存放统计方式:年度统计为0 季度统计为1
|
* test_record_count_ex中存放统计季度:一季度为1 以此类推
|
* test_type 中存放年份
|
* upload_usr_id 中存上传方式 100:全部 0:自动上传 用户ID对应手动上传*/
|
public ServiceModel serchComplete(Object obj){
|
Battresdata_inf rinf=(Battresdata_inf) obj;
|
int level=rinf.getData_available();
|
int year=rinf.getTest_type();//获取年份
|
int firstMonth=0;//获取起始月份
|
int lastMonth=0;//获取结束月份
|
String dateFirst=""; //起始时间
|
String dateLast=""; //结束时间
|
//做时间判断
|
if(rinf.getTest_record_count()==0){
|
firstMonth=0;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}else if(rinf.getTest_record_count()==1){
|
if(rinf.getTest_record_count_ex()==1){
|
firstMonth=0;//获取起始月份
|
lastMonth=2;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==2){
|
firstMonth=3;//获取起始月份
|
lastMonth=5;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==3){
|
firstMonth=6;//获取起始月份
|
lastMonth=8;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==4){
|
firstMonth=9;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}
|
}
|
dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
|
try {
|
rinf.setTest_starttime(DAOHelper.sdf.parse(dateFirst));
|
//System.out.println(dateFirst.substring(0,10));
|
dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
|
rinf.setTest_starttime_ex(DAOHelper.sdf.parse(dateLast));
|
} catch (ParseException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//System.out.println(dateLast.substring(0,10));
|
//System.out.println(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
|
|
List<BattInf> listB=((BattInfImpl)daoB).serchBylevel(level);
|
if(listB!=null&&listB.size()>0){
|
for(int i=0;i<listB.size();i++){
|
if(level==1){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2("");
|
rinf.setStationname3("");
|
rinf.setStationname4("");
|
}else if(level==2){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3("");
|
rinf.setStationname4("");
|
}else if(level==3){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3(listB.get(i).getStationName3());
|
rinf.setStationname4("");
|
}else if(level==4){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3(listB.get(i).getStationName3());
|
rinf.setStationname4(listB.get(i).getStationName4());
|
}
|
List<Battresdata_inf> list=((Battresdata_infDAOImpl)(dao)).serchComplete(rinf);
|
listB.get(i).setMonCount(list.size());//完成数
|
listB.get(i).setStationName9(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
|
if(listB.get(i).getMonNum()!=0){
|
int numC=listB.get(i).getMonCount();
|
int numM=listB.get(i).getMonNum();
|
Float percent=(float) (((numC*1.0)/numM)*100);
|
//System.out.println(percent);
|
listB.get(i).setMonVolLowToAvg(percent);//完成率
|
}
|
}
|
/* for (BattInf binf : listB) {
|
System.out.println(binf);
|
}*/
|
model.setCode(1);
|
model.setData(listB);
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
//6.4.3根据条件查询符合条件的测试完成的电池组(蓄电池电导合格率)
|
/*
|
* data_available中存放层次
|
* test_record_count 中存放统计方式:年度统计为0 季度统计为1
|
* test_record_count_ex中存放统计季度:一季度为1 以此类推
|
* test_type 中存放年份*/
|
public ServiceModel serchSer(Object obj) {
|
Battresdata_inf rinf=(Battresdata_inf) obj;
|
int level=rinf.getData_available();
|
int year=rinf.getTest_type();//获取年份
|
int firstMonth=0;//获取起始月份
|
int lastMonth=0;//获取结束月份
|
String dateFirst=""; //起始时间
|
String dateLast=""; //结束时间
|
//做时间判断
|
if(rinf.getTest_record_count()==0){
|
firstMonth=0;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}else if(rinf.getTest_record_count()==1){
|
if(rinf.getTest_record_count_ex()==1){
|
firstMonth=0;//获取起始月份
|
lastMonth=2;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==2){
|
firstMonth=3;//获取起始月份
|
lastMonth=5;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==3){
|
firstMonth=6;//获取起始月份
|
lastMonth=8;//获取结束月份
|
}else if(rinf.getTest_record_count_ex()==4){
|
firstMonth=9;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}
|
}
|
dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
|
try {
|
rinf.setTest_starttime(DAOHelper.sdf.parse(dateFirst));
|
//System.out.println(dateFirst.substring(0,10));
|
dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
|
rinf.setTest_starttime_ex(DAOHelper.sdf.parse(dateLast));
|
} catch (ParseException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
List<BattInf> listB=((BattInfImpl)daoB).serchBylevel(level);
|
if(listB!=null&&listB.size()>0){
|
for(int i=0;i<listB.size();i++){
|
if(level==1){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2("");
|
rinf.setStationname3("");
|
rinf.setStationname4("");
|
}else if(level==2){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3("");
|
rinf.setStationname4("");
|
}else if(level==3){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3(listB.get(i).getStationName3());
|
rinf.setStationname4("");
|
}else if(level==4){
|
rinf.setStationname1(listB.get(i).getStationName1());
|
rinf.setStationname2(listB.get(i).getStationName2());
|
rinf.setStationname3(listB.get(i).getStationName3());
|
rinf.setStationname4(listB.get(i).getStationName4());
|
}
|
listB.get(i).setStationName9(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
|
Float monSerStd=0f;//标存电导
|
List<Battresdata_inf> list=((Battresdata_infDAOImpl)(dao)).serchSer(rinf);
|
int numC=0;//已完成个数总数
|
int numQ=0;//80%合格个数总数
|
if(list!=null&&list.size()>0){
|
Battresdata rdata=new Battresdata();
|
for(int j=0;j<list.size();j++){
|
rdata.setBattGroupId(list.get(j).getBattGroupId());
|
rdata.setTest_starttime(list.get(j).getTest_starttime());
|
rdata.setTest_record_count(list.get(j).getTest_record_count());
|
rdata.setMon_ser(0f);
|
List listC=((BattresdataDAOImpl)(daoR)).serchSer(rdata);//已测试
|
numC+=listC.size();
|
BattInf binf=new BattInf();//求battgroupid标存电导
|
binf.setBattGroupId(list.get(j).getBattGroupId());
|
List<BattInf> listS=(new BattInfImpl()).serchByCondition(binf);
|
if(list!=null&&list.size()>0){
|
monSerStd=listS.get(list.size()-1).getMonSerStd();
|
}
|
rdata.setMon_ser((float) 0.8*monSerStd);
|
List listQ=((BattresdataDAOImpl)(daoR)).serchSer(rdata);//80%合格测试
|
numQ+=listQ.size();
|
// System.out.println("1:"+numC+" "+numQ);
|
}
|
|
}
|
|
listB.get(i).setStationId(list.size()+"");//已经测试电池组数 monnum中存放的所有的电池组数(某个分组)
|
listB.get(i).setGroupIndexInFBSDevice(numC);//已经测试的电池单体总数
|
listB.get(i).setBattGroupNum(numQ);//大于80%容量的电池单体总数
|
}
|
// for(BattInf binf : listB) {
|
// System.out.println(binf.getGroupIndexInFBSDevice()+" "+binf.getBattGroupNum());
|
// }
|
model.setCode(1);
|
model.setData(listB);
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
|
public static void main(String[] args) {
|
Battresdata_infService brids = new Battresdata_infService();
|
Battresdata_inf brid = new Battresdata_inf();
|
brid.setTest_record_count(1);
|
// brids.serchByCondition(brid);
|
//brids.searchAll();
|
Battresdata_inf brsdata=new Battresdata_inf();
|
brsdata.setBattGroupId(1002561);
|
brids.serchByCondition(brsdata);
|
}
|
}
|