| | |
| | | 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; |
| | | @Autowired |
| | | @Resource |
| | | private User_battmaint_check_processMapper processMapper; |
| | | @Autowired |
| | | @Resource |
| | | private User_infMapper userInfMapper; |
| | | @Autowired |
| | | @Resource |
| | | private BattInfMapper battInfMapper; |
| | | |
| | | //4.10作业抽查管理(新建) |
| | | public ServiceModel add(Object obj) { |
| | | public ServiceModel add(User_battmaint_check obj) { |
| | | ServiceModel model=new ServiceModel(); |
| | | Boolean bl=mapper.add(obj); |
| | | Boolean bl=mapper.add(obj)>0; |
| | | if(bl){ |
| | | model.setCode(1); |
| | | model.setMsg("添加成功!"); |
| | |
| | | |
| | | } |
| | | //4.10作业抽查管理(编辑记录) |
| | | public ServiceModel update(Object obj) { |
| | | public ServiceModel update(User_battmaint_check obj) { |
| | | ServiceModel model=new ServiceModel(); |
| | | Boolean bl=mapper.update(obj); |
| | | Boolean bl=mapper.update(obj)>0; |
| | | if(bl){ |
| | | model.setCode(1); |
| | | model.setMsg("修改成功!"); |
| | |
| | | return model; |
| | | } |
| | | //4.10作业抽查管理(编辑记录)(user_battmaint_check表修改时User_battmaint_check_process表就新增一条记录) |
| | | public ServiceModel updatePro(Object obj1,Object obj2) { |
| | | ServiceModel model=new ServiceModel(); |
| | | User_battmaint_check ucheck=(User_battmaint_check) obj1; |
| | | List<User_battmaint_check_process> list=(List<User_battmaint_check_process>) obj2; |
| | | ArrayList<String> str_sql=new ArrayList<String>();//存放所有的sql语句 |
| | | //修改User_battmaint_check表 |
| | | String sqlCheck=mapper.updatePro(ucheck); |
| | | str_sql.add(sqlCheck); |
| | | if(list!=null && list.size()>0){ |
| | | for (int i = 0; i < list.size(); i++) { |
| | | //Date caption_time=new Date(); |
| | | //System.out.println("caption_time:"+caption_time); |
| | | //list.get(i).setWork_caption_time(caption_time); |
| | | //新增User_battmaint_check_process表 |
| | | String sqlProcess=processMapper.addPro(list.get(i)); |
| | | str_sql.add(sqlProcess); |
| | | } |
| | | } |
| | | //System.out.println(str_sql); |
| | | public ServiceModel updatePro(User_battmaint_check ucheck,List<User_battmaint_check_process> list) { |
| | | ServiceModel model = new ServiceModel(); |
| | | //TODO perry待查 |
| | | boolean bl=true; |
| | | //Boolean bl=DateUtil.makeManualCommit(DBUtil.getConn(), str_sql); |
| | | if(bl){ |
| | | 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{ |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | model.setMsg("修改失败!"); |
| | | } |
| | | return model; |
| | | } |
| | | return model; |
| | | } |
| | | //4.10作业抽查管理(删除记录) |
| | | public ServiceModel delete(Object obj) { |
| | | public ServiceModel delete(User_battmaint_check obj) { |
| | | ServiceModel model=new ServiceModel(); |
| | | Boolean bl=mapper.del(obj); |
| | | Boolean bl=mapper.del(obj)>0; |
| | | if(bl){ |
| | | model.setCode(1); |
| | | model.setMsg("删除成功!"); |
| | |
| | | return model; |
| | | } |
| | | //4.10作业抽查管理(删除记录) |
| | | public ServiceModel deletePro(Object obj) { |
| | | ServiceModel model=new ServiceModel(); |
| | | User_battmaint_check ucheck=(User_battmaint_check) obj; |
| | | //删除对应的User_battmaint_check_process |
| | | User_battmaint_check_process uprocess=new User_battmaint_check_process(); |
| | | uprocess.setTask_rec_id(ucheck.getNum()); |
| | | ArrayList<String> str_sql=new ArrayList<String>();//存放所有的sql语句 |
| | | //删除User_battmaint_check表 |
| | | String sqlCheck=mapper.delPro(ucheck); |
| | | str_sql.add(sqlCheck); |
| | | //删除User_battmaint_check_process表中task_rec_id对应的记录 |
| | | String sqlProcess=processMapper.delPro(uprocess); |
| | | str_sql.add(sqlProcess); |
| | | //TODO perry待查 |
| | | boolean bl=true; |
| | | //Boolean bl= DateUtil.makeManualCommit(DBUtil.getConn(), str_sql); |
| | | if(bl){ |
| | | 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{ |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | model.setMsg("修改失败!"); |
| | | } |
| | | return model; |
| | | return model; |
| | | } |
| | | |
| | | //TODO 数据不足待测试 |
| | | //4.10作业抽查管理 |
| | | public ServiceModel serchByCondition(Object obj){ |
| | | public ServiceModel serchByCondition(Task_Batt_Test tbt){ |
| | | System.out.println("tbt = " + tbt); |
| | | ServiceModel model=new ServiceModel(); |
| | | List<Task_Batt_Test> list=mapper.serchByCondition(obj); |
| | | |
| | | //分页 |
| | | 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 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); |
| | | usr_name=((User_inf)userInfMapper.serchUname(uinf).get(0)).getUName(); |
| | | 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); |
| | | master_name=((User_inf)userInfMapper.serchUname(uinf).get(0)).getUName(); |
| | | 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); |
| | | appoint_name=((User_inf)userInfMapper.serchUname(uinf).get(0)).getUName(); |
| | | 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(","); |
| | | for(int j=0;j<copy_names.length;j++){ |
| | | copy_id=Integer.parseInt(copy_names[j]); |
| | | uinf.setUId(copy_id); |
| | | copy_name+=","; |
| | | copy_name+=((User_inf)userInfMapper.serchUname(uinf).get(0)).getUName(); |
| | | 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()); |
| | |
| | | } |
| | | if(list!=null && list.size()>0){ |
| | | model.setCode(1); |
| | | model.setData(list); |
| | | PageInfo<Task_Batt_Test> pageInfo = new PageInfo<>(list); |
| | | model.setData(pageInfo); |
| | | } |
| | | List<Task_Batt_Test> listt=(List<Task_Batt_Test>)model.getData(); |
| | | // for (Task_Batt_Test t : listt) { |
| | | // System.out.println(t.getBinf().getStationName9()+" "+t.getMcheck().getCopy_uids()); |
| | | // } |
| | | |
| | | return model; |
| | | } |
| | | |