D10011Service.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.miniframe.bisiness.system;
  2. import java.util.Map;
  3. import com.miniframe.core.ExecProcessFlow;
  4. import com.miniframe.core.exception.BusinessException;
  5. import com.miniframe.core.ext.UtilTools;
  6. import com.miniframe.generate.business.system.model.D10011BaseModel;
  7. import com.miniframe.model.system.DPipe;
  8. import com.miniframe.model.system.DSensor;
  9. import com.miniframe.model.system.DSensorSQLBuilder;
  10. import com.miniframe.model.system.dao.DPipeMapper;
  11. import com.miniframe.model.system.dao.DSensorMapper;
  12. /**
  13. * 基础系统,“传感器数据添加修改”逻辑处理(重新生成不覆盖)。
  14. */
  15. public class D10011Service extends D10011BaseModel implements ExecProcessFlow {
  16. private static final long serialVersionUID = -7051358269847459502L;
  17. /**
  18. * 基础系统,“传感器数据添加修改”业务核心处理
  19. */
  20. public void transExecute() throws Exception {
  21. Integer seid =this.getA_d10011().getSeid();
  22. Integer pid =this.getA_d10011().getPid();
  23. double site =this.getA_d10011().getSite();
  24. String type =this.getA_d10011().getType();
  25. DPipeMapper pipeMapper =UtilTools.getBean(DPipeMapper.class);
  26. DPipe pipe = pipeMapper.selectByPrimaryKey(pid);
  27. if(pipe==null){
  28. throw new BusinessException("EB3100015");
  29. }
  30. String pname =pipe.getName();
  31. DSensorMapper sensorMapper = UtilTools.getBean(DSensorMapper.class);
  32. if(seid==null||seid<=0){//添加
  33. pdPidSiteType(pid, (float) site, type, sensorMapper);
  34. DSensor s =new DSensor();
  35. s.setPid(pid);
  36. s.setSite((float)site);
  37. s.setType(type);
  38. s.setPname(pname);
  39. sensorMapper.insertSelective(s);
  40. }else{
  41. DSensor s = sensorMapper.selectByPrimaryKey(seid);
  42. if (s == null) {
  43. throw new BusinessException("EB3100008");
  44. }
  45. pdPidSiteTypeBySeid(pid, (float) site, type,seid, sensorMapper);
  46. s.setPid(pid);
  47. s.setSite((float)site);
  48. s.setType(type);
  49. s.setPname(pname);
  50. sensorMapper.updateByPrimaryKey(s);
  51. }
  52. }
  53. private void pdPidSiteTypeBySeid(Integer pid, float site, String type,Integer seid, DSensorMapper sensorMapper) throws BusinessException {
  54. DSensorSQLBuilder sb =new DSensorSQLBuilder();
  55. DSensorSQLBuilder.Criteria sc =sb.createCriteria();
  56. sc.andPidEqualTo(pid);
  57. sc.andSiteEqualTo(site);
  58. sc.andTypeEqualTo(type);
  59. sc.andIdNotEqualTo(seid);
  60. int count = sensorMapper.selectCountByExample(sb);
  61. if(count>0){
  62. throw new BusinessException("EB3100007");
  63. }
  64. }
  65. private void pdPidSiteType(Integer pid, float site, String type, DSensorMapper sensorMapper) throws BusinessException {
  66. DSensorSQLBuilder sb =new DSensorSQLBuilder();
  67. DSensorSQLBuilder.Criteria sc =sb.createCriteria();
  68. sc.andPidEqualTo(pid);
  69. sc.andSiteEqualTo(site);
  70. sc.andTypeEqualTo(type);
  71. int count = sensorMapper.selectCountByExample(sb);
  72. if(count>0){
  73. throw new BusinessException("EB3100007");
  74. }
  75. }
  76. /**
  77. * 基础系统,“传感器数据添加修改”业务前处理
  78. */
  79. public void preTransFlow() throws Exception {
  80. this.validater();
  81. }
  82. /**
  83. * 基础系统,“传感器数据添加修改”业务后处理
  84. */
  85. public void afterTransFlow() throws Exception {
  86. }
  87. /**
  88. * 基础系统,“传感器数据添加修改”逻辑入口处理方法
  89. */
  90. @SuppressWarnings("rawtypes")
  91. @Override
  92. public Map execute(Map vars) throws Exception {
  93. this.setTransMap(vars);
  94. preTransFlow();// 执行业务开始的规则检查和校验
  95. transExecute();// 执行核心业务段
  96. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  97. return this.getTransMap();
  98. }
  99. }