| | |
| | | import com.fgkj.mapper.impl.BattDischarge_planMapper; |
| | | import com.fgkj.mapper.impl.BattInfMapper; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | |
| | | @Resource |
| | | private User_logService userLogService; |
| | | @Autowired |
| | | DataSourceTransactionManager dataSourceTransactionManager; |
| | | @Autowired |
| | | TransactionDefinition transactionDefinition; |
| | | |
| | | ServiceModel model = new ServiceModel(); |
| | | |
| | |
| | | return model; |
| | | } |
| | | public ServiceModel update(BattDischarge_plan obj){ |
| | | ServiceModel model = new ServiceModel(); |
| | | Boolean bl=mapper.update(obj)>0; |
| | | if(bl){ |
| | | model.setCode(1); |
| | |
| | | return model; |
| | | } |
| | | //8.1批量添加电池计划 |
| | | public ServiceModel addPro(Object obj){ |
| | | Boolean bl=mapper.addPro(obj); |
| | | if(bl){ |
| | | public ServiceModel addPro(@RequestBody List<BattDischarge_plan> list) { |
| | | ServiceModel model = new ServiceModel(); |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | Boolean bl = true; |
| | | if (list != null && list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (!bl)continue; |
| | | BattDischarge_plan bdp = list.get(i); |
| | | try { |
| | | bl = mapper.addPro(bdp) > 0; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | model.setCode(0); |
| | | model.setMsg("添加失败!"); |
| | | return model; |
| | | } |
| | | String msg = "添加" + bdp.getNote() + "电池组在" + bdp.getDischarge_starttime() + "的放电计划"; |
| | | User_log ulog = UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg); |
| | | userLogService.add(ulog); |
| | | } |
| | | }else{ |
| | | bl = false; |
| | | } |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | model.setCode(1); |
| | | model.setMsg("添加成功!"); |
| | | }else{ |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | model.setCode(0); |
| | | model.setMsg("添加失败!"); |
| | | } |
| | | return model; |
| | | } |
| | | //8.1批量修改放电计划的开始时间 |
| | | public ServiceModel updatePro(List<BattDischarge_plan> list){ |
| | | public ServiceModel updatePro(List<BattDischarge_plan> list) { |
| | | ServiceModel model = new ServiceModel(); |
| | | List<User_log> listU=new ArrayList<User_log>();//存放user_log |
| | | List<BattDischarge_plan> listlast= new ArrayList<>(); |
| | | for(int i=0;i<list.size();i++){ |
| | | BattDischarge_plan ddata=list.get(i); |
| | | String formattime = DateUtil.sdf.format(ddata.getDischarge_starttime()); |
| | | list.get(i).setFormattime(formattime); |
| | | { |
| | | String msg="批量修改放电计划的开始时间"+formattime+" "+ddata.getBattgroupid()+"组 "+ddata.getNote()+""; |
| | | User_log ulog= UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg); |
| | | listU.add(ulog); |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | Boolean bl = true; |
| | | if (list != null && list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (!bl) continue; |
| | | BattDischarge_plan bdp = list.get(i); |
| | | try { |
| | | bl = mapper.updatePro(bdp) > 0; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | model.setCode(0); |
| | | model.setMsg("添加失败!"); |
| | | return model; |
| | | } |
| | | { |
| | | String msg = "批量修改放电计划的开始时间" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(bdp.getDischarge_starttime())+ " " + bdp.getBattgroupid() + "组 " + bdp.getNote(); |
| | | User_log ulog = UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg); |
| | | userLogService.add(ulog); |
| | | } |
| | | } |
| | | }else{ |
| | | bl = false; |
| | | } |
| | | System.out.println("list = " + list); |
| | | Boolean bl = mapper.updatePro(list)>0; |
| | | userLogService.addPro(listU);//将用户的操作记录下来 |
| | | if(bl){ |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | model.setCode(1); |
| | | model.setMsg("修改成功!"); |
| | | }else{ |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | model.setCode(0); |
| | | model.setMsg("修改失败!"); |
| | | } |