f8b451f9e8216a0b627fbd9178ba35b95d0b22a0.svn-base 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. package cn.com.goldenwater.dcproj.service.impl.importex;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.constValue.SplitValue;
  4. import cn.com.goldenwater.dcproj.controller.rsvr.AttRsBaseController;
  5. import cn.com.goldenwater.dcproj.dao.AttRsBaseCrrctDao;
  6. import cn.com.goldenwater.dcproj.dao.BisInspRsvrRgstrDao;
  7. import cn.com.goldenwater.dcproj.dao.ImpExcelDao;
  8. import cn.com.goldenwater.dcproj.dto.BisInspRsvrRgstrPcDto;
  9. import cn.com.goldenwater.dcproj.model.*;
  10. import cn.com.goldenwater.dcproj.param.*;
  11. import cn.com.goldenwater.dcproj.service.*;
  12. import cn.com.goldenwater.dcproj.service.impl.rsvr.BisInspRsvrRgstrServiceImpl;
  13. import cn.com.goldenwater.dcproj.socket.WebSocketServer;
  14. import cn.com.goldenwater.dcproj.utils.export.TableEnum;
  15. import cn.com.goldenwater.dcproj.utils.export.template.CreateSkExcelTemplate;
  16. import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel;
  17. import cn.com.goldenwater.id.util.UuidUtil;
  18. import com.github.pagehelper.PageInfo;
  19. import org.apache.commons.lang.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.io.ByteArrayOutputStream;
  27. import java.io.File;
  28. import java.io.IOException;
  29. import java.text.ParseException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.*;
  32. import java.util.concurrent.ConcurrentHashMap;
  33. import java.util.stream.Collectors;
  34. import static cn.com.goldenwater.dcproj.controller.rsvr.AttRsBaseController.isNumeric;
  35. import static cn.com.goldenwater.dcproj.utils.export.FieldFormatDispatch.getFormatValue;
  36. import static cn.com.goldenwater.dcproj.utils.impexcel.ExportExcel.downloadExcelFile;
  37. import static cn.com.goldenwater.dcproj.utils.impexcel.ImpUtil.checkIsDate;
  38. import static cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel.convertMapToBean;
  39. /**
  40. * <p>
  41. * 导入业务
  42. * </p>
  43. *
  44. * @author liyz
  45. * @date 2019/4/9 19:22
  46. **/
  47. @Service
  48. @Transactional(rollbackFor = Exception.class)
  49. public class ImpExcelServiceImpl extends AbstractCrudService<Object, Object> implements ImpExcelService {
  50. private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  51. private static ConcurrentHashMap<String, List<LinkedHashMap>> concurrentHashMap = new ConcurrentHashMap<>();
  52. @Autowired
  53. private ImpExcelDao impExcelDao;
  54. @Autowired
  55. private CreateSkExcelTemplate createSkExcelTemplate;
  56. @Autowired
  57. private BisInspBaseExtService bisInspBaseExtService;
  58. @Autowired
  59. private BisInspBasePresExtService bisInspBasePresExtService;
  60. @Autowired
  61. private BisInspRsvrRgstrService bisInspRsvrRgstrService;
  62. @Autowired
  63. private BisInspSafeExtManageService bisInspSafeExtManageService;
  64. @Autowired
  65. private BisInspBaseViewService bisInspBaseViewService;
  66. @Autowired
  67. private BisInspPreListService bisInspPreListService;
  68. @Autowired
  69. private BisInspRsvrRgstrDao bisInspRsvrRgstrDao;
  70. @Autowired
  71. private BisInspRsvrProjectService bisInspRsvrProjectService;
  72. @Autowired
  73. private BisInspRsvrBenefitsService bisInspRsvrBenefitsService;
  74. @Autowired
  75. private AttRsBaseCrrctDao attRsBaseCrrctDao;
  76. @Value("${impExcel.basePath}")
  77. private String path;
  78. @Autowired
  79. private GwComFileService gwComFileService;
  80. private static final String FILE_EXTS = "xls";
  81. public ImpExcelServiceImpl(ImpExcelDao impExcelDao) {
  82. super(impExcelDao);
  83. this.impExcelDao = impExcelDao;
  84. }
  85. @Override
  86. public boolean parseAndInsert(String tid, String filePath, String sid, String userId) {
  87. // 确定是哪一张表的Excel
  88. TableEnum tableEnum = TableEnum.getTypeByValue(tid);
  89. if (tableEnum != null) {
  90. switch (tableEnum) {
  91. case T8:
  92. List<LinkedHashMap> listSkTable = parseSkTables(filePath, sid);
  93. return this.insertSkTables(listSkTable, sid, userId);
  94. default:
  95. break;
  96. }
  97. }
  98. return false;
  99. }
  100. @Override
  101. public int downloadSkExcelTemplate(HttpServletResponse response, TypeExportParam tep) {
  102. //不需要的逻辑
  103. ByteArrayOutputStream os = new ByteArrayOutputStream();
  104. int i = createSkExcelTemplate.createBisInspRsvrRgstrPcDtoExcel(tep, os);
  105. if (i != 0) {
  106. String fileName = TableEnum.getNameByValue(tep.getTableIds()) + ".xls";
  107. downloadExcelFile(response, os, fileName);
  108. }
  109. return i;
  110. }
  111. @Override
  112. public String uploadExcel(String userId, String sid, MultipartFile file, String tid) {
  113. // 上传文件
  114. String id = tid + "-" + UUID.randomUUID().toString();
  115. if (file != null) {
  116. String fileName = file.getOriginalFilename();
  117. // 获取扩展名称
  118. String ext = fileName.substring(1 + fileName.lastIndexOf("."));
  119. if (!ext.endsWith(FILE_EXTS)) {
  120. WebSocketServer.sendInfo(sdf.format(new Date()) + "-文件类型不对", sid);
  121. return "";
  122. }
  123. }
  124. //按时间日期存文件
  125. Calendar dat = Calendar.getInstance();
  126. String filePath = this.path + File.separator + dat.get(Calendar.YEAR)
  127. + File.separator + (dat.get(Calendar.MONTH) + 1)
  128. + File.separator + dat.get(Calendar.DAY_OF_MONTH);
  129. boolean boo = gwComFileService.writeFile(id, FILE_EXTS, file, filePath);
  130. WebSocketServer.sendInfo(sdf.format(new Date()) + "-①开始上传", sid);
  131. if (boo) {
  132. WebSocketServer.sendInfo(sdf.format(new Date()) + "-上传成功√", sid);
  133. return filePath + File.separator + id + "." + FILE_EXTS;
  134. } else {
  135. WebSocketServer.sendInfo(sdf.format(new Date()) + "-上传失败×", sid);
  136. return "";
  137. }
  138. }
  139. @Override
  140. public List<LinkedHashMap> parseExcel(String userId, String sid, String filePath, String tid, String pid) {
  141. TableEnum tableEnum = TableEnum.getTypeByValue(tid);
  142. if (tableEnum != null) {
  143. switch (tableEnum) {
  144. case T8:
  145. // 得到解析出来的原始数据
  146. List<LinkedHashMap> listSkTable = parseSkTables(filePath, sid);
  147. // 得到过滤后的数据
  148. listSkTable = this.filterNotTreeIdData(listSkTable, pid, userId);
  149. // websocket 发送信息到前台
  150. WebSocketServer.sendInfo(sdf.format(new Date()) + "-读取完成,自动过滤无督查表id的行数据,过滤后共" + listSkTable.size() + "行√", sid);
  151. // listResult的作用是把字典数据转为汉字后展示到前台
  152. List<LinkedHashMap> listResult = new ArrayList<>();
  153. for (LinkedHashMap lhm : listSkTable) {
  154. LinkedHashMap<String, String> map = new LinkedHashMap<>();
  155. for (Object o : lhm.keySet()) {
  156. String key = o.toString();
  157. String value = lhm.get(key).toString();
  158. // 转化为汉字,并检查是否有错误,有的话加上错误标识
  159. Object formatValue = getFormatValue("sk", key, value, false);
  160. map.put(key, formatValue.toString());
  161. }
  162. listResult.add(map);
  163. }
  164. // websocket 发送信息到前台
  165. WebSocketServer.sendInfo(sdf.format(new Date()) + "-完成数据校验√", sid);
  166. // 如果有数据,就放入缓存中
  167. if (listSkTable.size() > 0) {
  168. concurrentHashMap.put(sid, listSkTable);
  169. }
  170. // 返回前端的数据
  171. return listResult;
  172. default:
  173. return null;
  174. }
  175. }
  176. return null;
  177. }
  178. public List<LinkedHashMap> showErrData(List<LinkedHashMap> listResult){
  179. // 给前端返回数据,如果没有数据
  180. if(listResult.size() == 0){
  181. return new ArrayList<LinkedHashMap>(){{
  182. add(new LinkedHashMap<String,String>(){{
  183. put("Message","empty");
  184. }});
  185. }} ;
  186. }else{// 如果有数据
  187. // 得到错误的数据
  188. listResult = this.getErrData(listResult);
  189. if(listResult.size() == 0){
  190. return new ArrayList<LinkedHashMap>(){{
  191. add(new LinkedHashMap<String,String>(){{
  192. put("Message","success");
  193. }});
  194. }} ;
  195. }else {
  196. return listResult;
  197. }
  198. }
  199. }
  200. public List<LinkedHashMap> getErrData(List<LinkedHashMap> listResult){
  201. List<LinkedHashMap> list = new ArrayList<>();
  202. for(LinkedHashMap map : listResult){
  203. Iterator it = map.keySet().iterator();
  204. while (it.hasNext()){
  205. String key = it.next().toString();
  206. String value = map.get(key).toString();
  207. if(value.contains("$E$")){
  208. list.add(map);
  209. }
  210. }
  211. }
  212. return list;
  213. }
  214. @Override
  215. public Boolean insertExcel(String userId, String sid, String tid) {
  216. TableEnum tableEnum = TableEnum.getTypeByValue(tid);
  217. if (tableEnum != null) {
  218. switch (tableEnum) {
  219. case T8:
  220. // 从缓存里取出数据
  221. List<LinkedHashMap> listSkTable = concurrentHashMap.get(sid);
  222. boolean aBoolean = false;
  223. if (listSkTable != null) {
  224. // 执行入库操作
  225. aBoolean = insertSkTables(listSkTable, sid, userId);
  226. // 执行完成,删除缓存里的数据
  227. concurrentHashMap.remove(sid);
  228. }
  229. return aBoolean;
  230. default:
  231. return false;
  232. }
  233. }
  234. return false;
  235. }
  236. /**
  237. * 从水库Excel里把数据解析出来
  238. */
  239. public List<LinkedHashMap> parseSkTables(String filePath, String sid) {
  240. List<LinkedHashMap> listSkTable = null;
  241. int startRow = 4;
  242. int endRow = 0;
  243. try {
  244. // 获取到从Excel里提取到的数据,并已格式化
  245. listSkTable = (List<LinkedHashMap>) ImportExcel.importExcel(filePath, startRow, endRow, LinkedHashMap.class, sid, "sk");
  246. } catch (IOException e) {
  247. e.printStackTrace();
  248. }
  249. return listSkTable;
  250. }
  251. /**
  252. * 过滤掉findList不是此用户下的此节点的数据
  253. *
  254. * @see BisInspRsvrRgstrServiceImpl#findPcPage(TypeParam)
  255. */
  256. private List<LinkedHashMap> filterNotTreeIdData(List<LinkedHashMap> listSkTable, String pid, String userId) {
  257. TypeExportParam tep = new TypeExportParam();
  258. tep.setType("rsvr");
  259. tep.setPresId(userId);
  260. // 水库
  261. tep.setpType("1");
  262. tep.setTableIds("08");
  263. // 0未督查 1督查中 2已督查
  264. tep.setState("1,0");
  265. tep.setId(pid);
  266. List<BisInspRsvrRgstrPcDto> list = bisInspRsvrRgstrDao.findPcPage(tep);
  267. List<String> rgstrIds = list.stream().map(BisInspRsvrRgstrPcDto::getRgstrId).collect(Collectors.toList());
  268. if (listSkTable == null) {
  269. return new ArrayList<>();
  270. } else {
  271. listSkTable = listSkTable.stream().filter(x -> x.get("rgstrId") != null && !"".equals(x.get("rgstrId")) && rgstrIds.toString().contains(x.get("rgstrId").toString())).collect(Collectors.toList());
  272. }
  273. return listSkTable;
  274. }
  275. /**
  276. * 真正的添加数据入库
  277. */
  278. private boolean insertSkTables(List<LinkedHashMap> listSkTable, String sid, String userId) {
  279. // websocket 向前台发送信息,开始进行批量填报
  280. WebSocketServer.sendInfo(sdf.format(new Date()) + "-③开始批量填报", sid);
  281. int i = 0;
  282. for (LinkedHashMap lhp : listSkTable) {
  283. i++;
  284. try {
  285. String rgstrId = lhp.get("rgstrId").toString();
  286. if (rgstrId == null || StringUtils.isBlank(rgstrId) || rgstrId.length() != 32) {
  287. WebSocketServer.sendInfo(sdf.format(new Date()) + "-数据校验失败:表格第" + i + 5 + "行的<督查填报代码>列填写有误,请从导出模板里编辑填项后上传填报!", sid);
  288. return false;
  289. }
  290. // 1.修改基础信息表和基础信息纠错表
  291. insertOrUpdateBaseCrrct(lhp, userId);
  292. // 2.重点环节落实情况
  293. insertOrUpdateBaseExt(lhp, userId);
  294. // 3.责任人落实情况
  295. insertOrUpdateBasePresExt(lhp, userId);
  296. // 4.水库工程实体和运行管理情况
  297. insertOrUpdateSafeExtManage(lhp, userId);
  298. // 5 走访情况
  299. insertOrUpdatePreList(lhp, userId);
  300. // 6.水库工程实体(新表)
  301. insertOrUpdateRsvrProject(lhp, userId);
  302. // 7.效益发挥情况
  303. insertOrUpdateRsvrBenefits(lhp, userId);
  304. WebSocketServer.sendInfo(sdf.format(new Date()) + "-第" + i + "条:" + lhp.get("rsName") + "填报完成√", sid);
  305. } catch (Exception e) {
  306. e.printStackTrace();
  307. }
  308. }
  309. WebSocketServer.sendInfo(sdf.format(new Date()) + "-批量填报完成,共" + i + "条。√", sid);
  310. return true;
  311. }
  312. /**
  313. * 添加或修改重点落实环节
  314. *
  315. * 说明:填报的字段
  316. * emerPlanSameAppr: "2"
  317. * emerPlanSameEme: "1"
  318. * emerPlanSameExta: "1"
  319. * emerPlanSameSpeed: "2"
  320. * rainForc: "1"
  321. * recPersId: "89E69B31FE1344A98316A0153BA7386C"
  322. * rgstrId: "0bdb496bc27c4fd48bb17708a2dd895d"
  323. * schPlanSameAppr: "1"
  324. * schPlanSameExta: "1"
  325. * schPlanSameSpeed: "1"
  326. *
  327. */
  328. public void insertOrUpdateBaseExt(LinkedHashMap lhp, String userId) {
  329. try {
  330. String rgstrId = lhp.get("rgstrId").toString();
  331. // 先判断一下是否已经填报
  332. BisInspBaseExtParam bisInspBaseExtParam = new BisInspBaseExtParam();
  333. bisInspBaseExtParam.setRgstrId(rgstrId);
  334. List<BisInspBaseExt> inspBaseExtList = bisInspBaseExtService.findList(bisInspBaseExtParam);
  335. BisInspBaseExt inspBaseExt = null;
  336. if(inspBaseExtList.size() > 0){
  337. inspBaseExt = inspBaseExtList.get(0);
  338. }
  339. BisInspBaseExt bisInspBaseExt = new BisInspBaseExt();
  340. // 从导入的Excel里的字段赋值
  341. bisInspBaseExt = (BisInspBaseExt) convertMapToBean(bisInspBaseExt.getClass(), lhp);
  342. // 添加时必填项 用户id
  343. bisInspBaseExt.setRecPersId(userId);
  344. // 添加时必填项 督查登记表id
  345. bisInspBaseExt.setRgstrId(rgstrId);
  346. // 如果没有填报
  347. if (inspBaseExt == null || StringUtils.isBlank(inspBaseExt.getThrqId())) {
  348. // 入库
  349. this.insertBaseExt(bisInspBaseExt);
  350. } else {
  351. // 修改
  352. Date date = new Date();
  353. bisInspBaseExt.setUpdateTime(date);
  354. bisInspBaseExt.setUpdateTime(date);
  355. // 这个是重点情况表的id,必填项
  356. bisInspBaseExt.setThrqId(inspBaseExt.getThrqId());
  357. int i = bisInspBaseExtService.update(bisInspBaseExt);
  358. }
  359. if(!"0".equals(bisInspBaseExt.getRainForc()) && !"0".equals(bisInspBaseExt.getRainForcNote())
  360. && !"0".equals(bisInspBaseExt.getSchPlanSameExta()) && !"0".equals(bisInspBaseExt.getEmerPlanSameExta())){
  361. bisInspRsvrRgstrService.updateRsvr(bisInspBaseExt.getRgstrId(), "2", "ext");
  362. }else {
  363. // 未完成
  364. bisInspRsvrRgstrService.updateRsvr(bisInspBaseExt.getRgstrId(), "1", "ext");
  365. }
  366. } catch (Exception e) {
  367. e.printStackTrace();
  368. }
  369. }
  370. private void insertBaseExt(BisInspBaseExt bisInspBaseExt) {
  371. Date date = new Date();
  372. String uuid = UuidUtil.uuid();
  373. bisInspBaseExt.setThrqId(uuid);
  374. bisInspBaseExt.setStatus("1");
  375. bisInspBaseExt.setCreateTime(date);
  376. bisInspBaseExt.setUpdateTime(date);
  377. int ret = bisInspBaseExtService.insert(bisInspBaseExt);
  378. BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr();
  379. inspRsvrRgstr.setRgstrId(bisInspBaseExt.getRgstrId());
  380. inspRsvrRgstr.setBaseStat("1");
  381. inspRsvrRgstr.setState("1");
  382. bisInspRsvrRgstrService.update(inspRsvrRgstr);
  383. }
  384. /**
  385. * 添加或修改责任人落实情况
  386. *
  387. */
  388. public void insertOrUpdateBasePresExt(LinkedHashMap lhp, String userId) {
  389. try {
  390. String rgstrId = lhp.get("rgstrId").toString();
  391. // 先判断一下是否已经填报
  392. BisInspBasePresExtParam bisInspBasePresExtParam = new BisInspBasePresExtParam();
  393. bisInspBasePresExtParam.setRgstrId(rgstrId);
  394. BisInspBasePresExt inspBasePresExt = bisInspBasePresExtService.getBy(bisInspBasePresExtParam);
  395. BisInspBasePresExt bisInspBasePresExt = new BisInspBasePresExt();
  396. // 从Excel里获取的数据设置
  397. bisInspBasePresExt = (BisInspBasePresExt) convertMapToBean(bisInspBasePresExt.getClass(), lhp);
  398. // 必填项数据设置
  399. bisInspBasePresExt.setRecPersId(userId);
  400. bisInspBasePresExt.setRgstrId(rgstrId);
  401. if (inspBasePresExt == null || StringUtils.isBlank(inspBasePresExt.getDutyId())) {
  402. this.insertBasePresExt(bisInspBasePresExt);
  403. } else {
  404. // 修改
  405. bisInspBasePresExt.setUpdateTime(new Date());
  406. bisInspBasePresExt.setDutyId(inspBasePresExt.getDutyId());
  407. int ret = bisInspBasePresExtService.update(bisInspBasePresExt);
  408. }
  409. if(!"0".equals(bisInspBasePresExt.getHasWiunWaoLegPers()) && !"0".equals(bisInspBasePresExt.getHasPatrolPers())
  410. && !"0".equals(bisInspBasePresExt.getHasTechPers()) ){
  411. bisInspRsvrRgstrService.updateRsvr(bisInspBasePresExt.getRgstrId(), "2", "pres");
  412. }else {
  413. // 未完成
  414. bisInspRsvrRgstrService.updateRsvr(bisInspBasePresExt.getRgstrId(), "1", "pres");
  415. }
  416. } catch (Exception e) {
  417. e.printStackTrace();
  418. }
  419. }
  420. /**
  421. *
  422. * 添加的字段
  423. * hasAttendTrain: "1"
  424. * hasPatrolPers: "1"
  425. * hasTechPers: "1"
  426. * hasWiunWaoLegPers: "1"
  427. * patrolPersDuty: "1"
  428. * patrolPersResu: "1"
  429. * recPersId: "89E69B31FE1344A98316A0153BA7386C" 用户id 必填项
  430. * rgstrId: "138122c2a35c4e90bfddf7a57481d5b3" 督查表id 必填项
  431. * techPersResu: "1"
  432. * wiunWaoLegPersResu: "1"
  433. *
  434. * 修改的字段
  435. * createTime: 1555468322000
  436. * dangReportObj: null
  437. * dtyprsnId: "0"
  438. * dutyId: "5cc1a3ad0d1747ffad9f990907c7a496"
  439. * fundSour: null
  440. * fundSourCount: 0
  441. * hasAttendTrain: "1"
  442. * hasAttendTrainNote: null
  443. * hasExtPatrol: "0"
  444. * hasFlLowLimLev: null
  445. * hasKnowEmerPlanSame: null
  446. * hasPatrolPers: "1"
  447. * hasRepDangReal: null
  448. * hasReport: null
  449. * hasTechPers: "1"
  450. * hasWiunWaoLegPers: "1"
  451. * isPatrolMsgComp: null
  452. * manaOrg: null
  453. * noManHasPres: "0"
  454. * orgProp: null
  455. * otherReasonNote: null
  456. * patrolFundSour: null
  457. * patrolPers: null
  458. * patrolPersDuty: "2"
  459. * patrolPersId: null
  460. * patrolPersNote: null
  461. * patrolPersResu: "3"
  462. * patrolPersResuNote: null
  463. * patrolPersTel: null
  464. * patrolReward: 0
  465. * protalRate: 0
  466. * recPers2: "许伟"
  467. * recPersId: "89E69B31FE1344A98316A0153BA7386C"
  468. * recPersTel: null
  469. * rgstrId: "cab2ec01a2864169bc95e789b38d630c"
  470. * specialManage: "0"
  471. * status: "0"
  472. * techPers: null
  473. * techPersDuty: null
  474. * techPersId: null
  475. * techPersResu: "1"
  476. * techPersResuNote: null
  477. * techPersTel: null
  478. * techPresNote: null
  479. * updateTime: 1555468366000
  480. * wiunWaoLegPers: null
  481. * wiunWaoLegPersDuty: null
  482. * wiunWaoLegPersId: null
  483. * wiunWaoLegPersResu: "1"
  484. * wiunWaoLegPersTel: null
  485. */
  486. public void insertBasePresExt(BisInspBasePresExt bisInspBasePresExt) throws InstantiationException, IllegalAccessException {
  487. String uuid = UuidUtil.uuid();
  488. bisInspBasePresExt.setDutyId(uuid);
  489. bisInspBasePresExt.setStatus("0");
  490. bisInspBasePresExt.setCreateTime(new Date());
  491. bisInspBasePresExt.setUpdateTime(new Date());
  492. int ret = bisInspBasePresExtService.insert(bisInspBasePresExt);
  493. BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr();
  494. inspRsvrRgstr.setRgstrId(bisInspBasePresExt.getRgstrId());
  495. inspRsvrRgstr.setPresStat("1");
  496. inspRsvrRgstr.setState("1");
  497. bisInspRsvrRgstrService.update(inspRsvrRgstr);
  498. }
  499. /**
  500. * 添加或修改水库工程实体和运行管理情况
  501. *
  502. */
  503. public void insertOrUpdateSafeExtManage(LinkedHashMap lhp, String userId) {
  504. try {
  505. String rgstrId = lhp.get("rgstrId").toString();
  506. // 先判断一下是否已经填报
  507. BisInspSafeExtManageParam bisInspSafeExtManageParam = new BisInspSafeExtManageParam();
  508. bisInspSafeExtManageParam.setRgstrId(rgstrId);
  509. BisInspSafeExtManage inspSafeExtManage = bisInspSafeExtManageService.getBy(bisInspSafeExtManageParam);
  510. BisInspSafeExtManage bisInspSafeExtManage = new BisInspSafeExtManage();
  511. bisInspSafeExtManage = (BisInspSafeExtManage) convertMapToBean(bisInspSafeExtManage.getClass(), lhp);
  512. // 必填项数据设置
  513. bisInspSafeExtManage.setRecPersId(userId);
  514. bisInspSafeExtManage.setRgstrId(rgstrId);
  515. if (inspSafeExtManage == null || StringUtils.isBlank(inspSafeExtManage.getMngrnId())) {
  516. this.insertSafeExtManage(bisInspSafeExtManage);
  517. } else {
  518. bisInspSafeExtManage.setUpdateTime(new Date());
  519. bisInspSafeExtManage.setMngrnId(inspSafeExtManage.getMngrnId());
  520. int ret = bisInspSafeExtManageService.update(bisInspSafeExtManage);
  521. }
  522. if(!"0".equals(bisInspSafeExtManage.getHasSpeManage()) && !"0".equals(bisInspSafeExtManage.getHasWdEmnic())
  523. && !"0".equals(bisInspSafeExtManage.getIfDamWarnLogo()) && !"0".equals(bisInspSafeExtManage.getSafeComment())){
  524. bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "2", "safe");
  525. }else {
  526. // 未完成
  527. bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "1", "safe");
  528. }
  529. if (StringUtils.isNotBlank(bisInspSafeExtManage.getSafeComment())) {
  530. bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "2", "dam");
  531. }
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. }
  536. public void insertSafeExtManage(BisInspSafeExtManage bisInspSafeExtManage) {
  537. String uuid = UuidUtil.uuid();
  538. bisInspSafeExtManage.setMngrnId(uuid);
  539. bisInspSafeExtManage.setStatus("0");
  540. bisInspSafeExtManage.setCreateTime(new Date());
  541. bisInspSafeExtManage.setUpdateTime(new Date());
  542. int ret = bisInspSafeExtManageService.insert(bisInspSafeExtManage);
  543. BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr();
  544. inspRsvrRgstr.setRgstrId(bisInspSafeExtManage.getRgstrId());
  545. inspRsvrRgstr.setResRunStat("1");
  546. inspRsvrRgstr.setState("1");
  547. bisInspRsvrRgstrService.update(inspRsvrRgstr);
  548. }
  549. /**
  550. * 添加或修改走访情况
  551. *
  552. */
  553. public void insertOrUpdatePreList(LinkedHashMap lhp, String userId) {
  554. try {
  555. String rgstrId = lhp.get("rgstrId").toString();
  556. // 先获取viewId 判断是否先添加,其实在前端已经判断过了,直接会走update
  557. BisInspBaseViewParam bisInspBaseViewParam = new BisInspBaseViewParam();
  558. bisInspBaseViewParam.setRgstrId(rgstrId);
  559. BisInspBaseView inspBaseView = bisInspBaseViewService.getBy(bisInspBaseViewParam);
  560. BisInspBaseView bisInspBaseView = new BisInspBaseView();
  561. bisInspBaseView.setRecPersId(userId);
  562. bisInspBaseView.setRgstrId(rgstrId);
  563. if (inspBaseView == null || StringUtils.isBlank(inspBaseView.getViewId())) {
  564. this.insertPreList(bisInspBaseView);
  565. } else {
  566. // 所有的添加其实都是修改
  567. String viewId = inspBaseView.getViewId();
  568. this.updatePreList(bisInspBaseView, viewId, lhp);
  569. }
  570. } catch (Exception e) {
  571. e.printStackTrace();
  572. }
  573. }
  574. public void insertPreList(BisInspBaseView bisInspBaseView) {
  575. try {
  576. // 添加
  577. String uuid = UuidUtil.uuid();
  578. bisInspBaseView.setViewId(uuid);
  579. bisInspBaseView.setCreateTime(new Date());
  580. bisInspBaseView.setStatus("0");
  581. bisInspBaseView.setUpdateTime(new Date());
  582. bisInspBaseViewService.insertBaseView(bisInspBaseView);
  583. } catch (Exception e) {
  584. e.printStackTrace();
  585. }
  586. }
  587. public void updatePreList(BisInspBaseView bisInspBaseView, String viewId, LinkedHashMap lhp) throws InstantiationException, IllegalAccessException {
  588. bisInspBaseView.setUpdateTime(new Date());
  589. // 必填项
  590. bisInspBaseView.setViewId(viewId);
  591. BisInspPreList bisInspPreList = new BisInspPreList();
  592. // 获取Excel里填报的人员信息
  593. bisInspPreList = (BisInspPreList) convertMapToBean(bisInspPreList.getClass(), lhp);
  594. // 获取原来的人员列表
  595. List<BisInspPreList> inspPreLists = this.getInspPreLists(viewId);
  596. if (inspPreLists == null) {
  597. inspPreLists = new ArrayList<>();
  598. }
  599. // 把新增的人员加进去
  600. String preNameNew = bisInspPreList.getViewPreName();
  601. // 名字为空字符串,不添加
  602. if(StringUtils.isNotBlank(preNameNew)){
  603. if(inspPreLists.size() == 0){
  604. // 如果原来没有人员,直接添加
  605. inspPreLists.add(bisInspPreList);
  606. }else {
  607. int count = 0;
  608. for(BisInspPreList pre : inspPreLists){
  609. if(preNameNew.equals(pre.getViewPreName())){
  610. // 如果有相同的名字,count + 1
  611. count ++ ;
  612. }
  613. }
  614. if(count == 0){
  615. inspPreLists.add(bisInspPreList);
  616. }
  617. }
  618. }
  619. bisInspBaseView.setInspPreLists(inspPreLists);
  620. int ret = bisInspBaseViewService.updateBaseView(bisInspBaseView);
  621. BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr();
  622. if (org.apache.commons.lang3.StringUtils.isBlank(bisInspBaseView.getRgstrId())) {
  623. bisInspBaseView = bisInspBaseViewService.get(bisInspBaseView.getViewId());
  624. }
  625. inspRsvrRgstr.setRgstrId(bisInspBaseView.getRgstrId());
  626. inspRsvrRgstr.setViewStat("1");
  627. inspRsvrRgstr.setState("1");
  628. bisInspRsvrRgstrService.update(inspRsvrRgstr);
  629. }
  630. /**
  631. * 获取人员列表
  632. *
  633. */
  634. private List<BisInspPreList> getInspPreLists(String viewId) {
  635. List<BisInspPreList> inspPreLists;
  636. BisInspPreListParam inspPreListParam = new BisInspPreListParam();
  637. inspPreListParam.setViewId(viewId);
  638. // 按照原来前端的逻辑来写
  639. inspPreListParam.setPageSize(50);
  640. PageInfo<BisInspPreList> bisInspPreList = bisInspPreListService.findPageInfo(inspPreListParam);
  641. inspPreLists = bisInspPreList.getList();
  642. return inspPreLists;
  643. }
  644. /**
  645. * 添加或修改工程实体
  646. *
  647. */
  648. public void insertOrUpdateRsvrProject(LinkedHashMap lhp, String userId){
  649. try{
  650. String rgstrId = lhp.get("rgstrId").toString();
  651. // 先判断一下是否已经填报
  652. BisInspRsvrProjectParam bisInspRsvrProjectParam = new BisInspRsvrProjectParam();
  653. bisInspRsvrProjectParam.setRgstrId(rgstrId);
  654. BisInspRsvrProject inspRsvrProject = bisInspRsvrProjectService.getBy(bisInspRsvrProjectParam);
  655. BisInspRsvrProject bisInspRsvrProject = new BisInspRsvrProject();
  656. bisInspRsvrProject = (BisInspRsvrProject) convertMapToBean(bisInspRsvrProject.getClass(), lhp);
  657. // 必填项数据设置
  658. bisInspRsvrProject.setRecPersId(userId);
  659. bisInspRsvrProject.setRgstrId(rgstrId);
  660. if(inspRsvrProject != null && org.apache.commons.lang3.StringUtils.isNotBlank(inspRsvrProject.getId())){
  661. bisInspRsvrProject.setId(inspRsvrProject.getId());
  662. bisInspRsvrProjectService.update(bisInspRsvrProject);
  663. }else{
  664. String uuid = UuidUtil.uuid();
  665. bisInspRsvrProject.setId(uuid);
  666. bisInspRsvrProjectService.insert(bisInspRsvrProject);
  667. }
  668. if(!"0".equals(bisInspRsvrProject.getPoorCountry()) && !"0".equals(bisInspRsvrProject.getWaterRunInfo())
  669. && !"0".equals(bisInspRsvrProject.getFsltdzInfo()) && !"0".equals(bisInspRsvrProject.getDiskRunInfo())
  670. && !"0".equals(bisInspRsvrProject.getHasSetMainFl()) && !"0".equals(bisInspRsvrProject.getHasSetPourFl())
  671. && !"0".equals(bisInspRsvrProject.getHasExtDamSafeAppr()) && !"0".equals(bisInspRsvrProject.getIfReinForce())
  672. ){
  673. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "2", "project");
  674. }else {
  675. // 未完成
  676. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "1", "project");
  677. }
  678. if (StringUtils.isNotBlank(bisInspRsvrProject.getIfDamSafe()) && StringUtils.isNotBlank(bisInspRsvrProject.getIfReinForce())) {
  679. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "2", "rein");
  680. }else {
  681. // 未完成
  682. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "1", "rein");
  683. }
  684. }catch (Exception e){
  685. e.printStackTrace();
  686. }
  687. }
  688. /**
  689. * 添加或修改效益发挥情况
  690. *
  691. */
  692. public void insertOrUpdateRsvrBenefits(LinkedHashMap lhp, String userId){
  693. try{
  694. String rgstrId = lhp.get("rgstrId").toString();
  695. // 先判断一下是否已经填报
  696. BisInspRsvrBenefitsParam bisInspRsvrBenefitsParam = new BisInspRsvrBenefitsParam();
  697. bisInspRsvrBenefitsParam.setRgstrId(rgstrId);
  698. BisInspRsvrBenefits inspRsvrBenefits = bisInspRsvrBenefitsService.getBy(bisInspRsvrBenefitsParam);
  699. BisInspRsvrBenefits bisInspRsvrBenefits = new BisInspRsvrBenefits();
  700. bisInspRsvrBenefits = (BisInspRsvrBenefits) convertMapToBean(bisInspRsvrBenefits.getClass(), lhp);
  701. // diskRunInfo 和 hasSetMainFl 字段 与工程实体里的重复,单独处理
  702. String diskRunInfo = "diskRunInfo2";
  703. String hasSetMainFl = "hasSetMainFl2";
  704. if(lhp.get(diskRunInfo) != null){
  705. bisInspRsvrBenefits.setDiskRunInfo(lhp.get(diskRunInfo).toString());
  706. }else {
  707. bisInspRsvrBenefits.setDiskRunInfo("");
  708. }
  709. if(lhp.get(hasSetMainFl) != null){
  710. bisInspRsvrBenefits.setHasSetMainFl(lhp.get(hasSetMainFl).toString());
  711. }else {
  712. bisInspRsvrBenefits.setHasSetMainFl("");
  713. }
  714. // 必填项数据设置
  715. bisInspRsvrBenefits.setRecPersId(userId);
  716. bisInspRsvrBenefits.setRgstrId(rgstrId);
  717. if(inspRsvrBenefits != null && org.apache.commons.lang3.StringUtils.isNotBlank(inspRsvrBenefits.getId())){
  718. bisInspRsvrBenefits.setId(inspRsvrBenefits.getId());
  719. bisInspRsvrBenefitsService.update(bisInspRsvrBenefits);
  720. }else{
  721. String uuid = UuidUtil.uuid();
  722. bisInspRsvrBenefits.setId(uuid);
  723. bisInspRsvrBenefits.setCreateTime(new Date());
  724. bisInspRsvrBenefitsService.insert(bisInspRsvrBenefits);
  725. }
  726. if(!"0".equals(bisInspRsvrBenefits.getIfEffective()) && !"0".equals(bisInspRsvrBenefits.getIfWaterS())
  727. && !"0".equals(bisInspRsvrBenefits.getDiskRunInfo())
  728. ){
  729. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrBenefits.getRgstrId(), "2", "fits");
  730. }else {
  731. // 未完成
  732. bisInspRsvrRgstrService.updateRsvr(bisInspRsvrBenefits.getRgstrId(), "1", "fits");
  733. }
  734. }catch (Exception e){
  735. e.printStackTrace();
  736. }
  737. }
  738. /**
  739. * 添加或修改水库基础信息(主要是修改)
  740. *
  741. * @see AttRsBaseController#update(AttRsBaseCrrct)
  742. */
  743. public void insertOrUpdateBaseCrrct(LinkedHashMap lhp, String userId){
  744. try {
  745. String rgstrId = lhp.get("rgstrId").toString();
  746. // 1.修改纠错表
  747. AttRsBaseCrrct attRsBase = new AttRsBaseCrrct();
  748. // 这里把Excel里的字段转成实体类字段
  749. attRsBase = (AttRsBaseCrrct) convertMapToBean(attRsBase.getClass(), lhp);
  750. // userId放在下面,不然会被上一步冲掉
  751. attRsBase.setPersId(userId);
  752. // 设置建成时间
  753. if(org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getCompDateStr())) {
  754. try {
  755. // 不是时间格式会报错,判断一下,不是时间格式就不赋给它了
  756. if(checkIsDate(attRsBase.getCompDateStr())){
  757. attRsBase.setCompDate(new SimpleDateFormat(SplitValue.TIME_SPLIT).parse(attRsBase.getCompDateStr()));
  758. }
  759. } catch (ParseException e) {
  760. e.printStackTrace();
  761. }
  762. }
  763. // 设置经纬度
  764. attRsBase.setCenterX(attRsBase.getCenterXGd());
  765. attRsBase.setCenterY(attRsBase.getCenterYGd());
  766. AttRsBaseCrrct baseCrrct=attRsBaseCrrctDao.get(attRsBase.getRsCode(),attRsBase.getPersId());
  767. // 需要新增吗?只是修改就够了吧。 不不,需要新增,否则原来为空的进不去。
  768. if(baseCrrct==null){
  769. attRsBaseCrrctDao.insert(attRsBase);
  770. }else {
  771. attRsBaseCrrctDao.update(attRsBase);
  772. }
  773. // 2.修改登记表
  774. BisInspRsvrRgstrParam bisInspRsvrRgstrParam=new BisInspRsvrRgstrParam();
  775. // 不能用objId 和 rsCode 因为objId我这里获取不到,所以我直接用rgstrId获取
  776. bisInspRsvrRgstrParam.setRgstrId(rgstrId);
  777. // 防止有冗余数据,用rgstrId查出来的数据不是唯一的,其实是数据的问题,这里只是保证不出错
  778. List<BisInspRsvrRgstr> bisInspRsvrRgstrList=bisInspRsvrRgstrService.findList(bisInspRsvrRgstrParam);
  779. BisInspRsvrRgstr bisInspRsvrRgstr = null;
  780. if(bisInspRsvrRgstrList.size() > 0){
  781. bisInspRsvrRgstr = bisInspRsvrRgstrList.get(0);
  782. }
  783. if(bisInspRsvrRgstr!=null){
  784. bisInspRsvrRgstr.setDamType(attRsBase.getDamType());
  785. bisInspRsvrRgstr.setDamRegCode(attRsBase.getRegCode());
  786. bisInspRsvrRgstr.setEngScal(attRsBase.getEngScal());
  787. bisInspRsvrRgstr.setAdCode(attRsBase.getAdmDiv());
  788. bisInspRsvrRgstr.setObjId(attRsBase.getObjId());
  789. //详细地址
  790. bisInspRsvrRgstr.setHystSite(attRsBase.getRsLoc());
  791. if(org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getLocation()) && !isNumeric(attRsBase.getLocation())){
  792. bisInspRsvrRgstr.setLocation(attRsBase.getLocation());
  793. }
  794. bisInspRsvrRgstr.setRsvrAdmName(attRsBase.getRsAdmName());
  795. if(attRsBase.getDamSizeHig()==null){
  796. bisInspRsvrRgstr.setDamMaxHigh(null);
  797. }else {
  798. bisInspRsvrRgstr.setDamMaxHigh(Double.toString(attRsBase.getDamSizeHig()));
  799. }
  800. bisInspRsvrRgstr.setRsCode(attRsBase.getRsCode());
  801. bisInspRsvrRgstr.setTotCap(attRsBase.getTotCap());
  802. if(attRsBase.getCenterYGd()!=null && !"".equals(attRsBase.getCenterYGd())){
  803. bisInspRsvrRgstr.setRsvrLat(Double.parseDouble(attRsBase.getCenterYGd()));
  804. }
  805. if(attRsBase.getCenterXGd()!=null && !"".equals(attRsBase.getCenterXGd())){
  806. bisInspRsvrRgstr.setRsvrLong(Double.parseDouble(attRsBase.getCenterXGd()));
  807. }
  808. bisInspRsvrRgstr.setResCreateTime(attRsBase.getCompDate());
  809. bisInspRsvrRgstr.setCompDateStr(attRsBase.getCompDateStr());
  810. Date date=new Date();
  811. bisInspRsvrRgstr.setUptm(date);
  812. bisInspRsvrRgstr.setHasDamRegCode("1");
  813. bisInspRsvrRgstr.setRsvrNm(attRsBase.getRsName());
  814. bisInspRsvrRgstrService.update(bisInspRsvrRgstr);
  815. }
  816. } catch (Exception e) {
  817. e.printStackTrace();
  818. }
  819. }
  820. }