package com.fgkj.services;
|
|
import com.fgkj.dto.*;
|
import com.fgkj.mapper.impl.BattInfMapper;
|
import com.fgkj.mapper.impl.User_battmaint_checkMapper;
|
import com.fgkj.mapper.impl.User_battmaint_check_processMapper;
|
import com.fgkj.mapper.impl.User_infMapper;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionStatus;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
@Service
|
public class User_battmaint_checkService {
|
|
@Autowired
|
DataSourceTransactionManager dataSourceTransactionManager;
|
@Autowired
|
TransactionDefinition transactionDefinition;
|
@Resource
|
private User_battmaint_checkMapper mapper;
|
@Resource
|
private User_battmaint_check_processMapper processMapper;
|
@Resource
|
private User_infMapper userInfMapper;
|
@Resource
|
private BattInfMapper battInfMapper;
|
|
//4.10作业抽查管理(新建)
|
public ServiceModel add(User_battmaint_check obj) {
|
ServiceModel model=new ServiceModel();
|
Boolean bl=mapper.add(obj)>0;
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
//4.10作业抽查管理(编辑记录)
|
public ServiceModel update(User_battmaint_check obj) {
|
ServiceModel model=new ServiceModel();
|
Boolean bl=mapper.update(obj)>0;
|
if(bl){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else{
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
//4.10作业抽查管理(编辑记录)(user_battmaint_check表修改时User_battmaint_check_process表就新增一条记录)
|
public ServiceModel updatePro(User_battmaint_check ucheck,List<User_battmaint_check_process> list) {
|
ServiceModel model = new ServiceModel();
|
//TODO perry待查
|
boolean bl = true;
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
// ArrayList<String> str_sql = new ArrayList<String>();//存放所有的sql语句
|
//修改User_battmaint_check表
|
if (!(mapper.updatePro(ucheck) > 0)) {
|
bl = false;
|
}
|
if (list != null && list.size() > 0) {
|
for (int i = 0; i < list.size(); i++) {
|
if (!(processMapper.addPro(list.get(i)) > 0)) {
|
bl = false;
|
}
|
}
|
}
|
//System.out.println(str_sql);
|
//Boolean bl=DateUtil.makeManualCommit(DBUtil.getConn(), str_sql);
|
if (bl) {
|
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
dataSourceTransactionManager.rollback(transactionStatus); //事务回滚
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
//4.10作业抽查管理(删除记录)
|
public ServiceModel delete(User_battmaint_check obj) {
|
ServiceModel model=new ServiceModel();
|
Boolean bl=mapper.del(obj)>0;
|
if(bl){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}
|
else{
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
//4.10作业抽查管理(删除记录)
|
public ServiceModel deletePro(User_battmaint_check ucheck) {
|
ServiceModel model = new ServiceModel();
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
boolean bl = true;
|
//删除对应的User_battmaint_check_process
|
User_battmaint_check_process uprocess = new User_battmaint_check_process();
|
uprocess.setTask_rec_id(ucheck.getNum());
|
//删除User_battmaint_check表
|
bl = mapper.delPro(ucheck) > 0;
|
//删除User_battmaint_check_process表中task_rec_id对应的记录
|
if (bl) {
|
bl = processMapper.delPro(uprocess) > 0;
|
}
|
if (bl) {
|
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
} else {
|
dataSourceTransactionManager.rollback(transactionStatus); //事务回滚
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
//TODO 数据不足待测试
|
//4.10作业抽查管理
|
public ServiceModel serchByCondition(Task_Batt_Test tbt){
|
System.out.println("tbt = " + tbt);
|
ServiceModel model=new ServiceModel();
|
//分页
|
PageBean pageBean = tbt.getPageBean();
|
PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize(),true);
|
List<Task_Batt_Test> list=mapper.serchByCondition(tbt);
|
User_inf uinf=new User_inf();
|
int usr_id=0;//责任人
|
String usr_name="";
|
int master_id=0;//创建人
|
String master_name="";
|
int appoint_uid=0;//指派人
|
String appoint_name="";
|
String copy_ids="";//抄送人
|
int copy_id=0;
|
String copy_name="";
|
String[] copy_names;
|
System.out.println(" list.size = " + list.size());
|
for(int i=0;i<list.size();i++){
|
System.out.println("list.get("+i+") = " + list.get(i));
|
BattInf binf=new BattInf();
|
//电池组组数
|
binf.setStationName(list.get(i).getMcheck().getRemark());
|
// binf.setStationName("湖北省-武汉市-东西湖区-我的测试机房-BTS");
|
binf.setStationName1("");
|
List listbinf=battInfMapper.serchByBattGroupName(binf);
|
list.get(i).getMcheck().setStationId(listbinf.size());
|
//责任人/创建人/指派人/抄送人
|
usr_id=list.get(i).getMcheck().getUsr_id();
|
uinf.setuId(usr_id);
|
// System.out.println("usr_id = " + usr_id);
|
List<User_inf> listuser_inf = userInfMapper.serchUname(uinf);
|
if (listuser_inf.size() > 0) {
|
usr_name = listuser_inf.get(0).getuName();
|
}
|
binf.setStationName6(usr_name);
|
|
master_id=list.get(i).getMcheck().getMaster_id();
|
uinf.setuId(master_id);
|
List<User_inf> user_infs = userInfMapper.serchUname(uinf);
|
if (user_infs.size() > 0) {
|
master_name = user_infs.get(0).getuName();
|
}
|
binf.setStationName7(master_name);
|
|
appoint_uid=list.get(i).getMcheck().getAppoint_uid();
|
uinf.setuId(appoint_uid);
|
List<User_inf> user_infs1 = userInfMapper.serchUname(uinf);
|
if (user_infs1.size() > 0) {
|
appoint_name = user_infs1.get(0).getuName();
|
}
|
binf.setStationName8(appoint_name);
|
//System.out.println(usr_name+" "+master_name+" "+appoint_name);
|
copy_ids=list.get(i).getMcheck().getCopy_uids();
|
System.out.println("copy_ids = " + copy_ids); //1001,1002,1003,1004,1008
|
copy_names=copy_ids.split(",");
|
if (copy_names.length>0) {
|
System.out.println("copy_names = " + copy_names.toString());
|
for (int j = 0; j < copy_names.length; j++) {
|
String copy_name1 = copy_names[j];
|
if (copy_name1.length() > 0) {
|
copy_id = Integer.parseInt(copy_name1);
|
uinf.setuId(copy_id);
|
}
|
copy_name += ",";
|
List<User_inf> user_infs2 = userInfMapper.serchUname(uinf);
|
if (user_infs2.size() > 0) {
|
copy_name += user_infs2.get(0).getuName();
|
}
|
}
|
}
|
binf.setStationName9(copy_name.substring(1, copy_name.length()));
|
//System.out.println(binf.getStationName9());
|
list.get(i).setBinf(binf);
|
copy_name="";
|
}
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
PageInfo<Task_Batt_Test> pageInfo = new PageInfo<>(list);
|
model.setData(pageInfo);
|
}
|
|
return model;
|
}
|
|
|
public ServiceModel searchAll() {
|
ServiceModel model=new ServiceModel();
|
List<User_battmaint_check> list = mapper.searchAll();
|
//System.out.println(list.size());
|
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
|
}
|