D10021Service.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package com.miniframe.bisiness.system;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileReader;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Map;
  8. import com.miniframe.constant.MFConstant;
  9. import com.miniframe.core.ExecProcessFlow;
  10. import com.miniframe.core.exception.BusinessException;
  11. import com.miniframe.core.ext.UtilTools;
  12. import com.miniframe.generate.business.system.model.D10021BaseModel;
  13. import com.miniframe.generate.comm.system.D_D10016_CHVALS_RECODE;
  14. import com.miniframe.generate.comm.system.D_D10016_COCODES_RECODE;
  15. import com.miniframe.model.system.*;
  16. import com.miniframe.model.system.dao.DAccidentMapper;
  17. import com.miniframe.model.system.dao.DGasGatherAreaMapper;
  18. import com.miniframe.model.system.dao.DGasMapper;
  19. import com.miniframe.model.system.dao.SysFileMapper;
  20. import com.miniframe.tools.XIFileUtils;
  21. import javax.rmi.CORBA.Util;
  22. /**
  23. * 基础系统,“瓦斯灾源添加修改”逻辑处理(重新生成不覆盖)。
  24. */
  25. public class D10021Service extends D10021BaseModel implements ExecProcessFlow {
  26. private static final long serialVersionUID = -7051358269847459502L;
  27. /**
  28. * 基础系统,“瓦斯灾源添加修改”业务核心处理
  29. */
  30. public void transExecute() throws Exception {
  31. Integer gid = this.getA_d10021().getGid();
  32. String gfid = this.getA_d10021().getGfid();
  33. String bfid = this.getA_d10021().getBfid();
  34. Integer aid = this.getA_d10021().getAid();
  35. SysFileMapper sysFileMapper = UtilTools.getBean(SysFileMapper.class);
  36. SysFile gf = sysFileMapper.selectByPrimaryKey(gfid);
  37. if (gf == null) {
  38. throw new BusinessException("EB3100020");
  39. }
  40. SysFile bf = sysFileMapper.selectByPrimaryKey(bfid);
  41. if (bf == null) {
  42. throw new BusinessException("EB3100021");
  43. }
  44. List<String> blockNames = readBFile(bf);
  45. System.out.println(blockNames);
  46. DAccidentMapper accidentMapper = UtilTools.getBean(DAccidentMapper.class);
  47. DAccident accident = accidentMapper.selectByPrimaryKey(aid);
  48. if (accident == null) {
  49. throw new BusinessException("EB3000002");
  50. }
  51. DGasGatherAreaMapper areaMapper = UtilTools.getBean(DGasGatherAreaMapper.class);
  52. DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
  53. if (gid == null || gid <= 0) {//添加
  54. DGas gas = new DGas();
  55. gas.setAid(aid);
  56. gas.setBfid(bfid);
  57. gas.setBfname(bf.getFilename());
  58. gas.setGfid(gfid);
  59. gas.setGfname(gf.getFilename());
  60. gasMapper.insertSelective(gas);
  61. DGasSQLBuilder sb = new DGasSQLBuilder();
  62. DGasSQLBuilder.Criteria sc = sb.createCriteria();
  63. sc.andAidEqualTo(aid);
  64. sc.andBfidEqualTo(bfid);
  65. sc.andGfidEqualTo(gfid);
  66. sb.setOrderByClause("id DESC");
  67. gas = gasMapper.selectByExample(sb).get(0);
  68. for (String blockName : blockNames) {
  69. DGasGatherArea area =new DGasGatherArea();
  70. area.setGasdensity(0f);
  71. area.setType("0");
  72. area.setAid(aid);
  73. area.setGid(gas.getId());
  74. area.setName(blockName);
  75. areaMapper.insertSelective(area);
  76. }
  77. } else {//修改
  78. DGas gas = gasMapper.selectByPrimaryKey(gid);
  79. if (gas == null) {
  80. throw new BusinessException("EB3100022");
  81. }
  82. if(gas.getBfid()!=bfid){
  83. DGasGatherAreaSQLBuilder ggsb = new DGasGatherAreaSQLBuilder();
  84. DGasGatherAreaSQLBuilder.Criteria ggsc = ggsb.createCriteria();
  85. ggsc.andGidEqualTo(gid);
  86. areaMapper.deleteByExample(ggsb);
  87. for (String blockName : blockNames) {
  88. DGasGatherArea area =new DGasGatherArea();
  89. area.setGasdensity(0f);
  90. area.setType("0");
  91. area.setAid(aid);
  92. area.setGid(gid);
  93. area.setName(blockName);
  94. areaMapper.insertSelective(area);
  95. }
  96. }
  97. gas.setAid(aid);
  98. gas.setBfid(bfid);
  99. gas.setBfname(bf.getFilename());
  100. gas.setGfid(gfid);
  101. gas.setGfname(gf.getFilename());
  102. gasMapper.updateByPrimaryKey(gas);
  103. }
  104. }
  105. private List<String> readBFile(SysFile bf) throws BusinessException {
  106. //TODO 解析 边界文件 生成瓦斯积聚区数据
  107. File bfFile = new File(XIFileUtils.getRootPathStr() + MFConstant.separator + bf.getFilepath());
  108. List<String> fileStrs = new ArrayList<>();
  109. try {
  110. FileReader fileReader = new FileReader(bfFile);
  111. BufferedReader reader = new BufferedReader(fileReader);
  112. String line;
  113. int linNum = 1;
  114. while ((line = reader.readLine()) != null) {
  115. fileStrs.add(line);
  116. }
  117. fileReader.close();
  118. reader.close();
  119. if (fileStrs.size() <= 3) {
  120. throw new BusinessException("EB3100025");
  121. }
  122. boolean isBlockStart = false;
  123. boolean isBlockNumStart = false;
  124. int blockNum = 0;
  125. List<String> blockNames = new ArrayList<>();
  126. for (int i = 3; i < fileStrs.size(); i++) {
  127. if (!isBlockStart) {
  128. isBlockStart = true;
  129. blockNames.add(fileStrs.get(i));
  130. continue;
  131. }
  132. if (!isBlockNumStart) {
  133. blockNum = Integer.valueOf(fileStrs.get(i));
  134. isBlockNumStart = true;
  135. continue;
  136. }
  137. int dyhang = 0;
  138. for (int j = 0; j < blockNum; j++) {
  139. String linet = fileStrs.get(i + dyhang + j);
  140. String[] t = linet.trim().split(" ");
  141. int last = Integer.valueOf(t[t.length - 1]);
  142. if (last == -1) {
  143. ++dyhang;
  144. }
  145. }
  146. i = i + dyhang + blockNum;
  147. isBlockStart = false;
  148. isBlockNumStart = false;
  149. }
  150. return blockNames;
  151. } catch (Exception e) {
  152. System.out.println(e);
  153. throw new BusinessException("EB3100025");
  154. }
  155. }
  156. /**
  157. * 基础系统,“瓦斯灾源添加修改”业务前处理
  158. */
  159. public void preTransFlow() throws Exception {
  160. this.validater();
  161. }
  162. /**
  163. * 基础系统,“瓦斯灾源添加修改”业务后处理
  164. */
  165. public void afterTransFlow() throws Exception {
  166. }
  167. /**
  168. * 基础系统,“瓦斯灾源添加修改”逻辑入口处理方法
  169. */
  170. @SuppressWarnings("rawtypes")
  171. @Override
  172. public Map execute(Map vars) throws Exception {
  173. this.setTransMap(vars);
  174. preTransFlow();// 执行业务开始的规则检查和校验
  175. transExecute();// 执行核心业务段
  176. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  177. return this.getTransMap();
  178. }
  179. }