package com.fgkj.services;
|
|
import com.fgkj.dto.BattInf;
|
import com.fgkj.dto.Battresdata;
|
import com.fgkj.dto.Battresdata_inf;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.mapper.impl.BattInfMapper;
|
import com.fgkj.mapper.impl.BattresdataMapper;
|
import com.fgkj.mapper.impl.Battresdata_infMapper;
|
import com.fgkj.util.ActionUtil;
|
import com.fgkj.util.DateUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.text.ParseException;
|
import java.util.List;
|
@Service
|
public class Battresdata_infService {
|
|
ServiceModel model = new ServiceModel();
|
|
@Resource
|
private Battresdata_infMapper mapper;
|
@Resource
|
private BattInfMapper battInfMapper;
|
@Resource
|
private BattresdataMapper battResDataMapper;
|
|
|
public ServiceModel add(Battresdata_inf dataInf) {
|
Boolean bl = mapper.add(dataInf);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
} else {
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
|
public ServiceModel update(Battresdata_inf dataInf) {
|
Boolean bl = mapper.update(dataInf);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
public ServiceModel delete(int num) {
|
Boolean bl = mapper.del(num);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
} else {
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
|
//筛选存在battresdata_inf表中的数据
|
public ServiceModel serchByCondition(Battresdata_inf dataInf){
|
model=new ServiceModel();
|
List list=mapper.serchByCondition(dataInf);
|
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(Battresdata_inf dataInf){
|
model=new ServiceModel();
|
List<String> list=mapper.judge(dataInf);
|
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 = mapper.searchAll();
|
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(Battresdata_inf dataInf){
|
int level=dataInf.getData_available();
|
int year=dataInf.getTest_type();//获取年份
|
int firstMonth=0;//获取起始月份
|
int lastMonth=0;//获取结束月份
|
String dateFirst=""; //起始时间
|
String dateLast=""; //结束时间
|
//做时间判断
|
if(dataInf.getTest_record_count()==0){
|
firstMonth=0;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}else if(dataInf.getTest_record_count()==1){
|
if(dataInf.getTest_record_count_ex()==1){
|
firstMonth=0;//获取起始月份
|
lastMonth=2;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==2){
|
firstMonth=3;//获取起始月份
|
lastMonth=5;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==3){
|
firstMonth=6;//获取起始月份
|
lastMonth=8;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==4){
|
firstMonth=9;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}
|
}
|
dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
|
try {
|
dataInf.setTest_starttime(DateUtil.sdf.parse(dateFirst));
|
dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
|
dataInf.setTest_starttime_ex(DateUtil.sdf.parse(dateLast));
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
List<BattInf> listB=battInfMapper.serchBylevel(level);
|
if(listB!=null&&listB.size()>0){
|
for(int i=0;i<listB.size();i++){
|
if(level==1){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2("");
|
dataInf.setStationname3("");
|
dataInf.setStationname4("");
|
}else if(level==2){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3("");
|
dataInf.setStationname4("");
|
}else if(level==3){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3(listB.get(i).getStationName3());
|
dataInf.setStationname4("");
|
}else if(level==4){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3(listB.get(i).getStationName3());
|
dataInf.setStationname4(listB.get(i).getStationName4());
|
}
|
List<Integer> list=mapper.serchComplete(dataInf);
|
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(Battresdata_inf dataInf) {
|
int level=dataInf.getData_available();
|
int year=dataInf.getTest_type();//获取年份
|
int firstMonth=0;//获取起始月份
|
int lastMonth=0;//获取结束月份
|
String dateFirst=""; //起始时间
|
String dateLast=""; //结束时间
|
//做时间判断
|
if(dataInf.getTest_record_count()==0){
|
firstMonth=0;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}else if(dataInf.getTest_record_count()==1){
|
if(dataInf.getTest_record_count_ex()==1){
|
firstMonth=0;//获取起始月份
|
lastMonth=2;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==2){
|
firstMonth=3;//获取起始月份
|
lastMonth=5;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==3){
|
firstMonth=6;//获取起始月份
|
lastMonth=8;//获取结束月份
|
}else if(dataInf.getTest_record_count_ex()==4){
|
firstMonth=9;//获取起始月份
|
lastMonth=11;//获取结束月份
|
}
|
}
|
dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
|
try {
|
dataInf.setTest_starttime(DateUtil.sdf.parse(dateFirst));
|
//System.out.println(dateFirst.substring(0,10));
|
dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
|
dataInf.setTest_starttime_ex(DateUtil.sdf.parse(dateLast));
|
} catch (ParseException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
List<BattInf> listB=battInfMapper.serchBylevel(level);
|
if(listB!=null&&listB.size()>0){
|
for(int i=0;i<listB.size();i++){
|
if(level==1){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2("");
|
dataInf.setStationname3("");
|
dataInf.setStationname4("");
|
}else if(level==2){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3("");
|
dataInf.setStationname4("");
|
}else if(level==3){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3(listB.get(i).getStationName3());
|
dataInf.setStationname4("");
|
}else if(level==4){
|
dataInf.setStationname1(listB.get(i).getStationName1());
|
dataInf.setStationname2(listB.get(i).getStationName2());
|
dataInf.setStationname3(listB.get(i).getStationName3());
|
dataInf.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=mapper.serchSer(dataInf);
|
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=battResDataMapper.serchSer(rdata);//已测试
|
numC+=listC.size();
|
BattInf binf=new BattInf();//求battgroupid标存电导
|
binf.setBattGroupId(list.get(j).getBattGroupId());
|
List<BattInf> listS=battInfMapper.serchByCondition(binf);
|
if(list!=null&&list.size()>0){
|
monSerStd=listS.get(list.size()-1).getMonSerStd();
|
}
|
rdata.setMon_ser((float) 0.8*monSerStd);
|
List listQ=battResDataMapper.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;
|
}
|
|
}
|