TJobticketController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. package com.ruoyi.project.ehs.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ruoyi.common.utils.DateUtils;
  4. import com.ruoyi.common.utils.SpringContextUtils;
  5. import com.ruoyi.common.utils.file.ExcelUtils;
  6. import com.ruoyi.common.utils.poi.ExcelUtil;
  7. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  8. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  9. import com.ruoyi.framework.web.controller.BaseController;
  10. import com.ruoyi.framework.web.domain.AjaxResult;
  11. import com.ruoyi.framework.web.page.TableDataInfo;
  12. import com.ruoyi.project.common.domain.DataEntity;
  13. import com.ruoyi.project.ehs.domain.TJobticket;
  14. import com.ruoyi.project.ehs.mapper.TJobticketMapper;
  15. import com.ruoyi.project.ehs.service.ITJobticketService;
  16. import com.ruoyi.project.invoice.domain.TInvoiceWorkcontent;
  17. import com.ruoyi.project.invoice.mapper.TInvoiceWorkcontentMapper;
  18. import com.ruoyi.project.system.domain.SysDept;
  19. import com.ruoyi.project.system.domain.SysDictData;
  20. import com.ruoyi.project.system.domain.SysUser;
  21. import com.ruoyi.project.system.service.ISysDeptService;
  22. import com.ruoyi.project.system.service.ISysDictTypeService;
  23. import com.ruoyi.project.system.service.ISysUserService;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.apache.poi.ss.usermodel.Cell;
  26. import org.apache.poi.ss.usermodel.Row;
  27. import org.apache.poi.ss.usermodel.Sheet;
  28. import org.apache.poi.ss.usermodel.Workbook;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.security.access.prepost.PreAuthorize;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import javax.annotation.Resource;
  34. import java.io.IOException;
  35. import java.text.SimpleDateFormat;
  36. import java.util.*;
  37. import java.util.concurrent.CountDownLatch;
  38. import java.util.concurrent.ExecutorService;
  39. import java.util.concurrent.Executors;
  40. import java.util.concurrent.Future;
  41. /**
  42. * 工作票Controller
  43. *
  44. * @author ruoyi
  45. * @date 2020-12-01
  46. */
  47. @RestController
  48. @RequestMapping("/ehs/jobticket")
  49. public class TJobticketController extends BaseController {
  50. @Autowired
  51. private ITJobticketService tJobticketService;
  52. @Autowired
  53. private ISysDictTypeService iSysDictTypeService;
  54. @Autowired
  55. private ISysDeptService iSysDeptService;
  56. @Resource
  57. private TJobticketMapper tJobticketMapper;
  58. @Resource
  59. private TInvoiceWorkcontentMapper invoiceWorkcontentMapper;
  60. /**
  61. * 查询工作票列表
  62. */
  63. @PreAuthorize("@ss.hasPermi('ehs:jobticket:list')")
  64. @GetMapping("/list")
  65. public TableDataInfo list(TJobticket tJobticket) {
  66. startPage();
  67. if (tJobticket.getTableType() == 1) {
  68. List<TJobticket> list = tJobticketService.selectTJobticketList(tJobticket);
  69. //查询续票
  70. if (list.size() > 0) {
  71. //线程池
  72. ExecutorService executorService = Executors.newFixedThreadPool(20);
  73. final CountDownLatch latch = new CountDownLatch(list.size()); //相同线程数量的计数
  74. for (TJobticket t : list
  75. ) {
  76. executorService.submit(() -> {
  77. try {
  78. //续票列表 -- 业务模块
  79. if ("10".equals(t.getXpxp())) {
  80. List<TJobticket> cList = tJobticketMapper.selectTJobticketChildren(t);
  81. t.setChildren(cList);
  82. }
  83. } catch (Exception e) {
  84. logger.error("e:", e);
  85. } finally {
  86. latch.countDown(); //线程计数
  87. }
  88. });
  89. }
  90. try {
  91. latch.await(); //线程计数完毕后继续执行
  92. } catch (InterruptedException e) {
  93. logger.error("e" ,e);
  94. }
  95. executorService.shutdown();
  96. }
  97. return getDataTable(list);
  98. } else {
  99. List<TJobticket> list = tJobticketService.selectTJobticketList(tJobticket);
  100. return getDataTable(list);
  101. }
  102. }
  103. //情况统计
  104. @GetMapping("/fireData")
  105. public List<DataEntity> fireData(Map param) {
  106. param.put("params", new HashMap<>());
  107. List<DataEntity> list = tJobticketMapper.selectFireData(param);
  108. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("HPJB");
  109. for (DataEntity d : list
  110. ) {
  111. for (SysDictData s : dictList
  112. ) {
  113. if (StringUtils.isBlank(d.getDataName())) {
  114. d.setDataName("未知");
  115. break;
  116. }
  117. if (s.getDictValue().equals(d.getDataName())) {
  118. d.setDataName(s.getDictLabel());
  119. break;
  120. }
  121. }
  122. }
  123. return list;
  124. }
  125. //情况统计
  126. @GetMapping("/statusData")
  127. public List<DataEntity> statusData(Map param) {
  128. param.put("params", new HashMap<>());
  129. List<DataEntity> list = tJobticketMapper.selectStatusData(param);
  130. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("ZYPZT");
  131. for (DataEntity d : list
  132. ) {
  133. for (SysDictData s : dictList
  134. ) {
  135. if (StringUtils.isBlank(d.getDataName())) {
  136. d.setDataName("未知");
  137. break;
  138. }
  139. if (s.getDictValue().equals(d.getDataName())) {
  140. d.setDataName(s.getDictLabel());
  141. break;
  142. }
  143. }
  144. }
  145. return list;
  146. }
  147. /**
  148. * 导出工作票列表
  149. */
  150. @PreAuthorize("@ss.hasPermi('ehs:jobticket:export')")
  151. @Log(title = "工作票", businessType = BusinessType.EXPORT)
  152. @GetMapping("/export")
  153. public AjaxResult export(TJobticket tJobticket) {
  154. List<TJobticket> list = tJobticketService.selectTJobticketList(tJobticket);
  155. List<TJobticket> exportList = new ArrayList<>();
  156. //查询续票
  157. for (TJobticket t : list
  158. ) {
  159. exportList.add(t);
  160. List<TJobticket> cList = tJobticketMapper.selectTJobticketChildren(t);
  161. if (cList.size() > 0) {
  162. exportList.addAll(cList);
  163. }
  164. }
  165. ExcelUtil<TJobticket> util = new ExcelUtil<TJobticket>(TJobticket.class);
  166. return util.exportExcel(exportList, "jobticket");
  167. }
  168. /**
  169. * 获取工作票详细信息
  170. */
  171. @PreAuthorize("@ss.hasPermi('ehs:jobticket:query')")
  172. @GetMapping(value = "/{id}")
  173. public AjaxResult getInfo(@PathVariable("id") Long id) {
  174. return AjaxResult.success(tJobticketService.selectTJobticketById(id));
  175. }
  176. /**
  177. * 新增工作票
  178. */
  179. @PreAuthorize("@ss.hasPermi('ehs:jobticket:add')")
  180. @Log(title = "工作票", businessType = BusinessType.INSERT)
  181. @PostMapping
  182. public AjaxResult add(@RequestBody TJobticket tJobticket) {
  183. if (StringUtils.isEmpty(tJobticket.getWhgzxkzh()) && StringUtils.isEmpty(tJobticket.getDhzyxkzh()) && StringUtils.isEmpty(tJobticket.getXzkjxkzh()) && StringUtils.isEmpty(tJobticket.getMbzyxkzh()) && StringUtils.isEmpty(tJobticket.getGczyxkzh())) {
  184. return AjaxResult.error("票号不能为空");
  185. }
  186. if (tJobticket.getXpxp() != null && tJobticket.getXpxp().equals("12")) {
  187. int i = tJobticketMapper.countXp(tJobticket);
  188. logger.info("预约票数量:" + i);
  189. if (i >= 10) {
  190. return AjaxResult.error("超过预约票数量上限10");
  191. }
  192. }
  193. ISysUserService sysUserService = (ISysUserService) SpringContextUtils.getBean("sysUserService");
  194. StringBuilder contentUserUnit = new StringBuilder();
  195. if (tJobticket.getUserUnit() != null) {
  196. contentUserUnit.append(tJobticket.getUserUnit());//用户单位
  197. }
  198. if (tJobticket.getUserMg() != null) {
  199. SysUser sysUser = sysUserService.selectUserById(tJobticket.getUserMg());
  200. contentUserUnit.append(sysUser.getNickName());
  201. }
  202. tJobticket.setByclxr(contentUserUnit.toString());
  203. tJobticket.setCreaterCode(getUserId().toString());
  204. return toAjax(tJobticketService.insertTJobticket(tJobticket));
  205. }
  206. /**
  207. * 批量新增工作票
  208. */
  209. @Log(title = "工作票", businessType = BusinessType.INSERT)
  210. @RequestMapping("/batchAddJobticket")
  211. public AjaxResult batchEdit(@RequestBody List<TInvoiceWorkcontent> dto) {
  212. ISysUserService sysUserService = (ISysUserService) SpringContextUtils.getBean("sysUserService");
  213. StringBuilder contentUserUnit = new StringBuilder();
  214. int sameCount = 0;
  215. int nosanmeCount = 0;
  216. int noCount = 0;
  217. //批量插入时 需要查询数据库是否有重复数据 若果有 就不新增
  218. for (int i = 0; i < dto.size(); i++) {
  219. if (StringUtils.isEmpty(dto.get(i).getGczyxkzh()) && StringUtils.isEmpty(dto.get(i).getDhzyxkzh()) && StringUtils.isEmpty(dto.get(i).getXzkjxkzh()) && StringUtils.isEmpty(dto.get(i).getMbzyxkzh()) && StringUtils.isEmpty(dto.get(i).getWhgzxkzh())) {
  220. noCount++;
  221. continue;
  222. }
  223. TJobticket tJobticket = new TJobticket();
  224. TInvoiceWorkcontent tInvoiceWorkcontent = dto.get(i);
  225. //部门应该是CBP/C 写死
  226. tJobticket.setDeptId(103l);
  227. tJobticket.setContent(tInvoiceWorkcontent.getBookingworkticket().getWorkArea() + tInvoiceWorkcontent.getWorkDescription());
  228. //byc 联系人 用户主管+用户单位
  229. if (tInvoiceWorkcontent.getBookingworkticket().getUserUnit() != null) {
  230. contentUserUnit.append(tInvoiceWorkcontent.getBookingworkticket().getUserUnit());//用户单位
  231. }
  232. if (tInvoiceWorkcontent.getBookingworkticket().getUserMg() != null) {
  233. SysUser sysUser = sysUserService.selectUserById(tInvoiceWorkcontent.getBookingworkticket().getUserMg());
  234. contentUserUnit.append(sysUser.getNickName());
  235. }
  236. tJobticket.setByclxr(contentUserUnit.toString());
  237. tJobticket.setSgdw(tInvoiceWorkcontent.getBookingworkticket().getWorkUnit());
  238. tJobticket.setLxr(tInvoiceWorkcontent.getBookingworkticket().getContact());
  239. tJobticket.setLxdh(tInvoiceWorkcontent.getBookingworkticket().getPhonenumber());
  240. //各项票号
  241. tJobticket.setYqxkzh(tInvoiceWorkcontent.getYqxkzh());
  242. tJobticket.setXzkjxkzh(tInvoiceWorkcontent.getXzkjxkzh());
  243. tJobticket.setMbzyxkzh(tInvoiceWorkcontent.getMbzyxkzh());
  244. tJobticket.setWhgzxkzh(tInvoiceWorkcontent.getWhgzxkzh());
  245. tJobticket.setHpjb(tInvoiceWorkcontent.getHpjb());
  246. tJobticket.setGczyxkzh(tInvoiceWorkcontent.getGczyxkzh());
  247. tJobticket.setGczyjb(tInvoiceWorkcontent.getGczyjb());
  248. tJobticket.setDhzyxkzh(tInvoiceWorkcontent.getDhzyxkzh());
  249. tJobticket.setUserMg(tInvoiceWorkcontent.getBookingworkticket().getUserMg());
  250. tJobticket.setUserUnit(tInvoiceWorkcontent.getBookingworkticket().getUserUnit());
  251. tJobticket.setTag(tInvoiceWorkcontent.getTag());
  252. tJobticket.setZypzt("10");
  253. tJobticket.setQfsj("8:30");
  254. tJobticket.setKprq(tInvoiceWorkcontent.getBookingworkticket().getWorkStartTime());
  255. tJobticket.setXpxp(tInvoiceWorkcontent.getXpxp());
  256. //先查询是否重复
  257. int same = tJobticketService.selectTJobticketSameData(tJobticket);
  258. if (same > 0) {
  259. sameCount++;
  260. tInvoiceWorkcontent.setAddStatus(1);
  261. invoiceWorkcontentMapper.updateTInvoiceWorkcontent(tInvoiceWorkcontent);
  262. } else {
  263. tJobticketService.insertTJobticket(tJobticket);
  264. nosanmeCount++;
  265. tInvoiceWorkcontent.setAddStatus(1);
  266. invoiceWorkcontentMapper.updateTInvoiceWorkcontent(tInvoiceWorkcontent);
  267. }
  268. contentUserUnit.delete(0, contentUserUnit.length());
  269. }
  270. return AjaxResult.success("成功导入" + nosanmeCount + "条数据," + "\n" + "未导入重复" + sameCount + "条数据!" + "\n" + "未填写票号" + noCount + "条数据!");
  271. }
  272. /**
  273. * 修改工作票
  274. */
  275. @PreAuthorize("@ss.hasPermi('ehs:jobticket:edit')")
  276. @Log(title = "工作票", businessType = BusinessType.UPDATE)
  277. @PutMapping
  278. public AjaxResult edit(@RequestBody TJobticket tJobticket) {
  279. if (StringUtils.isEmpty(tJobticket.getWhgzxkzh()) && StringUtils.isEmpty(tJobticket.getDhzyxkzh()) && StringUtils.isEmpty(tJobticket.getXzkjxkzh()) && StringUtils.isEmpty(tJobticket.getMbzyxkzh()) && StringUtils.isEmpty(tJobticket.getGczyxkzh())) {
  280. return AjaxResult.error("票号不能为空");
  281. }
  282. ISysUserService sysUserService = (ISysUserService) SpringContextUtils.getBean("sysUserService");
  283. StringBuilder contentUserUnit = new StringBuilder();
  284. if (tJobticket.getUserUnit() != null) {
  285. contentUserUnit.append(tJobticket.getUserUnit());//用户单位
  286. }
  287. if (tJobticket.getUserMg() != null) {
  288. SysUser sysUser = sysUserService.selectUserById(tJobticket.getUserMg());
  289. contentUserUnit.append(sysUser.getNickName());
  290. }
  291. tJobticket.setByclxr(contentUserUnit.toString());
  292. tJobticket.setUpdaterCode(getUserId().toString());
  293. tJobticket.setUpdatedate(new Date());
  294. return toAjax(tJobticketService.updateTJobticket(tJobticket));
  295. }
  296. /**
  297. * 修改工作票状态
  298. */
  299. @PreAuthorize("@ss.hasPermi('ehs:jobticket:edit')")
  300. @Log(title = "工作票状态", businessType = BusinessType.UPDATE)
  301. @PutMapping("/status")
  302. public AjaxResult editStatus(@RequestBody TJobticket tJobticket) {
  303. if ("18".equals(tJobticket.getZypzt())) {
  304. if (StringUtils.isEmpty(tJobticket.getWhgzxkzh()) && StringUtils.isEmpty(tJobticket.getDhzyxkzh()) && StringUtils.isEmpty(tJobticket.getXzkjxkzh()) && StringUtils.isEmpty(tJobticket.getMbzyxkzh()) && StringUtils.isEmpty(tJobticket.getGczyxkzh())) {
  305. return AjaxResult.error("票号不能为空");
  306. }
  307. //批量
  308. return toAjax(tJobticketMapper.updateTJobticketStatus(tJobticket));
  309. } else {
  310. //单个
  311. return toAjax(tJobticketService.updateTJobticket(tJobticket));
  312. }
  313. }
  314. /**
  315. * 删除工作票
  316. */
  317. @PreAuthorize("@ss.hasPermi('ehs:jobticket:remove')")
  318. @Log(title = "工作票", businessType = BusinessType.DELETE)
  319. @DeleteMapping("/{ids}")
  320. public AjaxResult remove(@PathVariable Long[] ids) {
  321. return toAjax(tJobticketService.deleteTJobticketByIds(ids));
  322. }
  323. /**
  324. * 批量导入工作票
  325. */
  326. @PreAuthorize("@ss.hasPermi('ehs:jobticket:add')")
  327. @Log(title = "工作票", businessType = BusinessType.INSERT)
  328. @PostMapping("/importData")
  329. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  330. //获取操作人员ID
  331. Long userId = getUserId();
  332. //报错行数统计
  333. List<Integer> failRow = new ArrayList<Integer>();
  334. Workbook workbook = ExcelUtils.getWorkBook(file);
  335. Sheet sheet = workbook.getSheetAt(0);
  336. List<TJobticket> list = new ArrayList<TJobticket>();
  337. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  338. //字典查询
  339. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  340. List<SysDictData> qfbz = iSysDictTypeService.selectDictDataByType("QFBZ");
  341. List<SysDictData> xpxp = iSysDictTypeService.selectDictDataByType("XPXP");
  342. List<SysDictData> hpjb = iSysDictTypeService.selectDictDataByType("HPJB");
  343. List<SysDictData> zypzt = iSysDictTypeService.selectDictDataByType("ZYPZT");
  344. //部门查询
  345. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  346. int rowNum = sheet.getPhysicalNumberOfRows();
  347. int failNumber = 0;
  348. for (int i = 1; i < rowNum; i++) {
  349. try {
  350. logger.info("读取行数:" + i);
  351. Row row = sheet.getRow(i);
  352. int cellNum = row.getPhysicalNumberOfCells();
  353. TJobticket entity = new TJobticket();
  354. for (int j = 0; j < cellNum; j++) {
  355. Cell cell = row.getCell(j);
  356. // cell.setCellType(CellType.STRING);
  357. String cellValue = ExcelUtils.getCellValue(cell);
  358. logger.info("cellValue:" + cellValue);
  359. if (j == 0) {
  360. for (SysDictData p : plant) {
  361. if (p.getDictLabel().equals(cellValue.trim())) {
  362. entity.setPlantCode(p.getDictValue());//装置名称
  363. }
  364. }
  365. } else if (j == 1) {
  366. if (cellValue.length() > 3) {
  367. entity.setKprq(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//开票日期
  368. }
  369. } else if (j == 2) {
  370. entity.setQfsj(cellValue);//签发时间
  371. } else if (j == 3) {
  372. for (SysDictData p : qfbz) {
  373. if (p.getDictLabel().equals(cellValue.trim())) {
  374. entity.setQfbz(p.getDictValue());//签发班组
  375. }
  376. }
  377. } else if (j == 4) {
  378. entity.setQfr(cellValue);//签发人
  379. } else if (j == 5) {
  380. for (SysDictData p : xpxp) {
  381. if (p.getDictLabel().equals(cellValue.trim())) {
  382. entity.setXpxp(p.getDictValue());//新票/续票
  383. }
  384. }
  385. } else if (j == 6) {
  386. entity.setYqxkzh(cellValue);//延期许可证号
  387. } else if (j == 7) {
  388. entity.setWhgzxkzh(cellValue);//危害工作许可证号
  389. } else if (j == 8) {
  390. entity.setDhzyxkzh(cellValue);//未撤销项编号
  391. } else if (j == 9) {
  392. for (SysDictData p : hpjb) {
  393. if (p.getDictLabel().equals(cellValue.trim())) {
  394. entity.setHpjb(p.getDictValue());//火票级别
  395. }
  396. }
  397. } else if (j == 10) {
  398. entity.setXzkjxkzh(cellValue);//限制空间许可证号
  399. } else if (j == 11) {
  400. entity.setContent(cellValue);//工作内容
  401. } else if (j == 12) {
  402. entity.setByclxr(cellValue);//BYC负责单位/联系人
  403. } else if (j == 13) {
  404. entity.setSgdw(cellValue);//施工单位
  405. } else if (j == 14) {
  406. entity.setLxr(cellValue);//联系人
  407. } else if (j == 15) {
  408. entity.setLxdh(cellValue);//联系电话
  409. } else if (j == 16) {
  410. if (cellValue.length() > 3) {
  411. entity.setXpsj(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//销票时间
  412. }
  413. } else if (j == 17) {
  414. for (SysDictData p : zypzt) {
  415. if (p.getDictLabel().equals(cellValue.trim())) {
  416. entity.setZypzt(p.getDictValue());//作业票状态
  417. }
  418. }
  419. } else if (j == 18) {
  420. entity.setJccdr(cellValue);//检查/存档人
  421. } else if (j == 19) {
  422. entity.setWcxxbh(cellValue);//未撤销项编号
  423. } else if (j == 20) {
  424. entity.setWcxzt(cellValue);//未撤销状态
  425. } else if (j == 21) {
  426. if (cellValue.length() > 3) {
  427. entity.setCxsj(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//撤销时间
  428. }
  429. } else if (j == 22) {
  430. for (SysDept d : dept) {
  431. if (d.getDeptName().equals(cellValue.trim())) {
  432. entity.setDeptId(d.getDeptId());//部门编号
  433. }
  434. }
  435. } else if (j == 23) {
  436. entity.setRemarks(cellValue);//备注
  437. }
  438. }
  439. entity.setCreaterCode(userId.toString());
  440. logger.info("entity:" + entity);
  441. list.add(entity);
  442. } catch (Exception e) {
  443. failNumber++;
  444. failRow.add(i + 1);
  445. }
  446. }
  447. int successNumber = 0;
  448. int failNum = 0;
  449. for (TJobticket t : list
  450. ) {
  451. failNum++;
  452. try {
  453. tJobticketService.insertTJobticket(t);
  454. successNumber++;
  455. } catch (Exception e) {
  456. failNumber++;
  457. failRow.add(failNum + 1);
  458. }
  459. }
  460. logger.info("list:" + JSON.toJSONString(list));
  461. logger.info("successNumber:" + String.valueOf(successNumber));
  462. logger.info("failNumber:" + String.valueOf(failNumber));
  463. logger.info("failRow:" + String.valueOf(failRow));
  464. return AjaxResult.success(String.valueOf(successNumber), failRow);
  465. }
  466. }