TRestrictedSpacePermitController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package com.ruoyi.project.ticket.controller;
  2. import java.io.IOException;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.deepoove.poi.data.TextRenderData;
  7. import com.deepoove.poi.data.Texts;
  8. import com.deepoove.poi.data.style.Style;
  9. import com.ruoyi.common.utils.DateUtils;
  10. import com.ruoyi.framework.config.RuoYiConfig;
  11. import com.ruoyi.project.common.controller.WordController;
  12. import com.ruoyi.project.configuration.domain.TMatter;
  13. import com.ruoyi.project.configuration.mapper.TMatterMapper;
  14. import com.ruoyi.project.configuration.service.ITMatterProtectService;
  15. import com.ruoyi.project.system.service.ISysDeptService;
  16. import com.ruoyi.project.ticket.domain.PermitRelation;
  17. import com.ruoyi.project.ticket.domain.TRestrictedSpacePermit;
  18. import com.ruoyi.project.ticket.domain.TTicketId;
  19. import com.ruoyi.project.ticket.service.ITPermitRelationService;
  20. import com.ruoyi.project.ticket.service.ITRestrictedSpacePermitService;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.GetMapping;
  23. import org.springframework.web.bind.annotation.PostMapping;
  24. import org.springframework.web.bind.annotation.PutMapping;
  25. import org.springframework.web.bind.annotation.DeleteMapping;
  26. import org.springframework.web.bind.annotation.PathVariable;
  27. import org.springframework.web.bind.annotation.RequestBody;
  28. import org.springframework.web.bind.annotation.RequestMapping;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  31. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  32. import com.ruoyi.framework.web.controller.BaseController;
  33. import com.ruoyi.framework.web.domain.AjaxResult;
  34. import com.ruoyi.common.utils.poi.ExcelUtil;
  35. import com.ruoyi.framework.web.page.TableDataInfo;
  36. import javax.annotation.Resource;
  37. /**
  38. * 限制性空间进入开票Controller
  39. *
  40. * @author ruoyi
  41. * @date 2023-05-05
  42. */
  43. @RestController
  44. @RequestMapping("/ticket/restrictedspace")
  45. public class TRestrictedSpacePermitController extends BaseController
  46. {
  47. @Autowired
  48. private ITRestrictedSpacePermitService tRestrictedSpacePermitService;
  49. @Autowired
  50. private TTicketIdController tTicketIdController;
  51. @Autowired
  52. private ITPermitRelationService itPermitRelationService;
  53. @Resource
  54. private TMatterMapper tMatterMapper;
  55. @Autowired
  56. private WordController wordController;
  57. @Autowired
  58. private ITMatterProtectService matterProtectService;
  59. @Autowired
  60. private ISysDeptService deptService;
  61. /**
  62. * 查询限制性空间进入开票列表
  63. */
  64. @GetMapping("/list")
  65. public TableDataInfo list(TRestrictedSpacePermit tRestrictedSpacePermit)
  66. {
  67. startPage();
  68. List<TRestrictedSpacePermit> list = tRestrictedSpacePermitService.selectTRestrictedSpacePermitList(tRestrictedSpacePermit);
  69. return getDataTable(list);
  70. }
  71. /**
  72. * 导出限制性空间进入开票列表
  73. */
  74. @Log(title = "限制性空间进入开票", businessType = BusinessType.EXPORT)
  75. @GetMapping("/export")
  76. public AjaxResult export(TRestrictedSpacePermit tRestrictedSpacePermit)
  77. {
  78. List<TRestrictedSpacePermit> list = tRestrictedSpacePermitService.selectTRestrictedSpacePermitList(tRestrictedSpacePermit);
  79. ExcelUtil<TRestrictedSpacePermit> util = new ExcelUtil<TRestrictedSpacePermit>(TRestrictedSpacePermit.class);
  80. return util.exportExcel(list, "permit");
  81. }
  82. /**
  83. * 获取限制性空间进入开票详细信息
  84. */
  85. @GetMapping(value = "/{cId}")
  86. public AjaxResult getInfo(@PathVariable("cId") Long cId)
  87. {
  88. return AjaxResult.success(tRestrictedSpacePermitService.selectTRestrictedSpacePermitById(cId));
  89. }
  90. /**
  91. * 新增限制性空间进入开票
  92. */
  93. @Log(title = "限制性空间进入开票", businessType = BusinessType.INSERT)
  94. @PostMapping
  95. public AjaxResult add(@RequestBody TRestrictedSpacePermit tRestrictedSpacePermit) throws IOException {
  96. //生成票号
  97. TTicketId tTicketId = new TTicketId();
  98. tTicketId.setId(1l);
  99. Long ticketId = tTicketIdController.createId(tTicketId);
  100. //保存限制空间许可证
  101. tRestrictedSpacePermit.setcId(ticketId);
  102. //生成word
  103. //渲染文本
  104. Map<String, Object> params = getWordData(tRestrictedSpacePermit);
  105. // 模板路径
  106. String templatePath = "static/word/restrictedSpaceTicket.docx";
  107. // 生成word的路径
  108. String fileDir = RuoYiConfig.getProfile() + "/" + "ticketWord";;
  109. // 生成word的文件
  110. String fileName = "C" + ticketId + ".docx";
  111. String wordPath = this.wordController.createWord(templatePath, fileDir, fileName, params);
  112. tRestrictedSpacePermit.setWordUrl(wordPath);
  113. //使用流的方式转换PDF
  114. String fileName2 = "C" + tRestrictedSpacePermit.getcId() + ".pdf";
  115. String pdfPath = this.wordController.createPDF(fileDir, fileName, fileName2, params);
  116. tRestrictedSpacePermit.setPdfUrl(pdfPath);
  117. tRestrictedSpacePermitService.insertTRestrictedSpacePermit(tRestrictedSpacePermit);
  118. //返回票号
  119. return AjaxResult.success(tRestrictedSpacePermit.getcId());
  120. }
  121. /**
  122. * 修改限制性空间进入开票
  123. */
  124. @Log(title = "限制性空间进入开票", businessType = BusinessType.UPDATE)
  125. @PutMapping
  126. public AjaxResult edit(@RequestBody TRestrictedSpacePermit tRestrictedSpacePermit) throws IOException {
  127. //生成word
  128. //渲染文本
  129. Map<String, Object> params = getWordData(tRestrictedSpacePermit);
  130. // 模板路径
  131. String templatePath = "static/word/restrictedSpaceTicket.docx";
  132. // 生成word的路径
  133. String fileDir = RuoYiConfig.getProfile() + "/" + "ticketWord";
  134. // 生成word的文件
  135. String fileName = "C" + tRestrictedSpacePermit.getcId() + ".docx";
  136. String wordPath = this.wordController.createWord(templatePath, fileDir, fileName, params);
  137. tRestrictedSpacePermit.setWordUrl(wordPath);
  138. //使用流的方式转换PDF
  139. String fileName2 = "C" + tRestrictedSpacePermit.getcId() + ".pdf";
  140. String pdfPath = this.wordController.createPDF(fileDir, fileName, fileName2, params);
  141. tRestrictedSpacePermit.setPdfUrl(pdfPath);
  142. return toAjax(tRestrictedSpacePermitService.updateTRestrictedSpacePermit(tRestrictedSpacePermit));
  143. }
  144. /**
  145. * 删除限制性空间进入开票
  146. */
  147. @Log(title = "限制性空间进入开票", businessType = BusinessType.DELETE)
  148. @DeleteMapping("/{cIds}")
  149. public AjaxResult remove(@PathVariable Long[] cIds)
  150. {
  151. return toAjax(tRestrictedSpacePermitService.deleteTRestrictedSpacePermitByIds(cIds));
  152. }
  153. public Map<String, Object> getWordData(TRestrictedSpacePermit tRestrictedSpacePermit) {
  154. Map<String, Object> params = new HashMap<>();
  155. // 渲染文本
  156. params.put("cId", Texts.of(tRestrictedSpacePermit.getcId().toString()).fontSize(7).bold().create());
  157. // A栏
  158. params.put("aEquipmentName", Texts.of(tRestrictedSpacePermit.getaEquipmentName()).fontSize(7).bold().create());
  159. params.put("aEquipmentLeader", Texts.of(tRestrictedSpacePermit.getaEquipmentLeader()).fontSize(7).bold().create());
  160. params.put("aEquipmentTel", Texts.of(tRestrictedSpacePermit.getaEquipmentTel()).fontSize(7).bold().create());
  161. params.put("aEquipmentOffice", Texts.of(tRestrictedSpacePermit.getaEquipmentOffice()).fontSize(7).bold().create());
  162. params.put("aConstructionName", Texts.of(deptService.selectDeptById(Long.parseLong(tRestrictedSpacePermit.getaConstructionName())).getDeptName()).fontSize(7).bold().create());
  163. params.put("aConstructionLeader", Texts.of(tRestrictedSpacePermit.getaConstructionLeader()).fontSize(7).bold().create());
  164. params.put("aConstructionTel", Texts.of(tRestrictedSpacePermit.getaConstructionTel()).fontSize(7).bold().create());
  165. params.put("aConstructionOffice", Texts.of(tRestrictedSpacePermit.getaConstructionOffice()).fontSize(7).bold().create());
  166. params.put("aContractorName", Texts.of(tRestrictedSpacePermit.getaContractorName()).fontSize(7).bold().create());
  167. params.put("aContractorLeader", Texts.of(tRestrictedSpacePermit.getaContractorLeader()).fontSize(7).bold().create());
  168. params.put("aContractorTel", Texts.of(tRestrictedSpacePermit.getaContractorTel()).fontSize(7).bold().create());
  169. params.put("aContractorOffice", Texts.of(tRestrictedSpacePermit.getaContractorOffice()).fontSize(7).bold().create());
  170. getCheck(params, tRestrictedSpacePermit.getaIsNeedSafeLiaison().toString(), "aIsNSL1", "aIsNSL2");
  171. params.put("aSafeLiaisonName", Texts.of(tRestrictedSpacePermit.getaSafeLiaisonName()).fontSize(7).bold().create());
  172. params.put("aSafeLiaisonSign", Texts.of(tRestrictedSpacePermit.getaSafeLiaisonSign()).fontSize(7).bold().create());
  173. params.put("aSafeLiaisonTel", Texts.of(tRestrictedSpacePermit.getaSafeLiaisonTel()).fontSize(7).bold().create());
  174. params.put("aSafeLiaisonOffice", Texts.of(tRestrictedSpacePermit.getaSafeLiaisonOffice()).fontSize(7).bold().create());
  175. // B栏
  176. params.put("bDeviceName", Texts.of(tRestrictedSpacePermit.getbDeviceName()).fontSize(7).bold().create());
  177. params.put("bAreaNo", Texts.of(tRestrictedSpacePermit.getbAreaNo()).fontSize(7).bold().create());
  178. params.put("bWorkContent", Texts.of(tRestrictedSpacePermit.getbWorkContent()).fontSize(7).bold().create());
  179. if (tRestrictedSpacePermit.getbValidityStartTime() != null) {
  180. params.put("bValidityStartTime", Texts.of(DateUtils.parseDateToStr("yyyy年MM月dd日HH时mm分", tRestrictedSpacePermit.getbValidityStartTime())).fontSize(7).bold().create());
  181. }
  182. if (tRestrictedSpacePermit.getbValidityEndTime() != null) {
  183. params.put("bValidityEndTime", Texts.of(DateUtils.parseDateToStr("yyyy年MM月dd日HH时mm分", tRestrictedSpacePermit.getbValidityEndTime())).fontSize(7).bold().create());
  184. }
  185. // C 栏
  186. getCheck(params, tRestrictedSpacePermit.getcIsYesDanger(), "cIsYesDanger");
  187. List<TMatter> tMatters = tMatterMapper.selectTMatterList(new TMatter());
  188. for (TMatter t : tMatters
  189. ) {
  190. if (t.getId().toString().equals(tRestrictedSpacePermit.getcHarmMatterName())) {
  191. params.put("cHarmMatterName", Texts.of(t.getMatterName()).fontSize(7).bold().create());
  192. }
  193. }
  194. getCheck(params, tRestrictedSpacePermit.getcIsGhs(), "cIsGhs");
  195. getCheck(params, tRestrictedSpacePermit.getcIsToxic(), "cIsToxic");
  196. getCheck(params, tRestrictedSpacePermit.getcIsFlammable(), "cIsFlammable");
  197. getCheck(params, tRestrictedSpacePermit.getcIsOxidizing(), "cIsOxidizing");
  198. getCheck(params, tRestrictedSpacePermit.getcIsExplosive(), "cIsExplosive");
  199. getCheck(params, tRestrictedSpacePermit.getcIsCorrosive(), "cIsCorrosive");
  200. getCheck(params, tRestrictedSpacePermit.getcIsIrritantToxic(), "cIsIrritantToxic");
  201. getCheck(params, tRestrictedSpacePermit.getcIsHealthHazard(), "cIsHealthHazard");
  202. getCheck(params, tRestrictedSpacePermit.getcIsCompressedGas(), "cIsCompressedGas");
  203. getCheck(params, tRestrictedSpacePermit.getcIsEnvironmentalHazard(), "cIsEnvironmentalHazard");
  204. //设备内物质处于危险状态({{cIsHighTemp}}高温/{{cIsLowTemp}}低温;{{cIsPosPressure}}正压/{{cIsNegPressure}}负压
  205. getCheck(params, tRestrictedSpacePermit.getcIsHighTemp(), "cIsHighTemp");
  206. getCheck(params, tRestrictedSpacePermit.getcIsLowTemp(), "cIsLowTemp");
  207. getCheck(params, tRestrictedSpacePermit.getcIsPosPressure(), "cIsPosPressure");
  208. getCheck(params, tRestrictedSpacePermit.getcIsNegPressure(), "cIsNegPressure");
  209. if ("1".equals(tRestrictedSpacePermit.getcIsHighTemp()) || "1".equals(tRestrictedSpacePermit.getcIsLowTemp()) || "1".equals(tRestrictedSpacePermit.getcIsPosPressure()) || "1".equals(tRestrictedSpacePermit.getcIsHighTemp())) {
  210. getCheck(params, "1", "isFacilityHazards");
  211. } else {
  212. getCheck(params, "2", "isFacilityHazards");
  213. }
  214. //来自设备/设施的危害({{cIsMovingParts}}移动部件,{{cIsHotSurfaces}}热表面/ {{cIsColdSurfaces}}冷表面,{{cIsVoltages}}电压)
  215. getCheck(params, tRestrictedSpacePermit.getcIsMovingParts(), "cIsMovingParts");
  216. getCheck(params, tRestrictedSpacePermit.getcIsHotSurfaces(), "cIsHotSurfaces");
  217. getCheck(params, tRestrictedSpacePermit.getcIsColdSurfaces(), "cIsColdSurfaces");
  218. getCheck(params, tRestrictedSpacePermit.getcIsVoltages(), "cIsVoltages");
  219. if ("1".equals(tRestrictedSpacePermit.getcIsMovingParts()) || "1".equals(tRestrictedSpacePermit.getcIsHotSurfaces()) || "1".equals(tRestrictedSpacePermit.getcIsColdSurfaces()) || "1".equals(tRestrictedSpacePermit.getcIsVoltages())) {
  220. getCheck(params, "1", "isEquipmentHazards");
  221. } else {
  222. getCheck(params, "2", "isEquipmentHazards");
  223. }
  224. //{{cIsOtherDanger}} 其它危害:{{cOtherDangerContent}}
  225. getCheck(params, tRestrictedSpacePermit.getcIsOtherDanger(), "cIsOtherDanger");
  226. params.put("cOtherDangerContent", Texts.of(tRestrictedSpacePermit.getcOtherDangerContent()).fontSize(7).bold().create());
  227. //{{cIsHazardsProd}} 施工对生产单位的危害:{{cIsHazardsProdContent}}
  228. getCheck(params, tRestrictedSpacePermit.getcIsHazardsProd(), "cIsHazardsProd");
  229. params.put("cIsHazardsProdContent", Texts.of(tRestrictedSpacePermit.getcIsHazardsProdContent()).fontSize(7).bold().create());
  230. //E 栏
  231. //1.是否可能有残留物料
  232. getCheck(params, tRestrictedSpacePermit.geteIsPresent(), "eIsPresent", "eIsPresent2");
  233. getCheck(params, tRestrictedSpacePermit.geteIsRequiredPpe(), "eIsRequiredPpe", "eIsRequiredPpe2");
  234. //2.项目内容"
  235. params.put("ePpeContent", Texts.of(tRestrictedSpacePermit.getePpeContent()).fontSize(7).bold().create());
  236. params.put("ePpeContent2", Texts.of(tRestrictedSpacePermit.getePpeContent2()).fontSize(7).bold().create());
  237. getCheck(params, tRestrictedSpacePermit.geteIsSafeGoggles(), "eIsSafeGoggles", "eIsSafeGoggles2");
  238. getCheck(params, tRestrictedSpacePermit.geteIsFaceShield(), "eIsFaceShield", "eIsFaceShield2");
  239. getCheck(params, tRestrictedSpacePermit.geteIsProtectGloves(), "eIsProtectGloves", "eIsProtectGloves2");
  240. if (tRestrictedSpacePermit.geteProtectGlovesContent() != null && !"0".equals(tRestrictedSpacePermit.geteProtectGlovesContent())) {
  241. params.put("eProtectGlovesContent", Texts.of(matterProtectService.selectTMatterProtectById(Long.parseLong(tRestrictedSpacePermit.geteProtectGlovesContent())).getConservatoryMeasureName()).fontSize(7).bold().create());
  242. }
  243. getCheck(params, tRestrictedSpacePermit.geteIsRubberBoots(), "eIsRubberBoots", "eIsRubberBoots2");
  244. getCheck(params, tRestrictedSpacePermit.geteIsRubberApron(), "eIsRubberApron", "eIsRubberApron2");
  245. getCheck(params, tRestrictedSpacePermit.geteIsProtectSuit(), "eIsProtectSuit", "eIsProtectSuit2");
  246. if (tRestrictedSpacePermit.geteProtectSuitContent() != null && !"0".equals(tRestrictedSpacePermit.geteProtectSuitContent())) {
  247. params.put("eProtectSuitContent", Texts.of(matterProtectService.selectTMatterProtectById(Long.parseLong(tRestrictedSpacePermit.geteProtectSuitContent())).getConservatoryMeasureName()).fontSize(7).bold().create());
  248. }
  249. //2.7是否呼吸保护用品
  250. getCheck(params, tRestrictedSpacePermit.geteIsResProtect(), "eIsResProtect", "eIsResProtect2");
  251. if (tRestrictedSpacePermit.geteResProtectContent() != null && !"0".equals(tRestrictedSpacePermit.geteResProtectContent())) {
  252. params.put("eResProtectContent", Texts.of(matterProtectService.selectTMatterProtectById(Long.parseLong(tRestrictedSpacePermit.geteResProtectContent())).getConservatoryMeasureName()).fontSize(7).bold().create());
  253. }
  254. getCheck(params, tRestrictedSpacePermit.geteIsFallArrest(), "eIsFallArrest", "eIsFallArrest2");
  255. params.put("eFallArrestContent", Texts.of(tRestrictedSpacePermit.geteFallArrestContent()).fontSize(7).bold().create());
  256. //2.9
  257. getCheck(params, tRestrictedSpacePermit.geteIsOtherProtect(), "eIsOtherProtect", "eIsOtherProtect2");
  258. params.put("eOtherProtectContent", Texts.of(tRestrictedSpacePermit.geteOtherProtectContent()).fontSize(7).bold().create());
  259. //3.是否连续监控
  260. getCheck(params, tRestrictedSpacePermit.geteIsContinueMonitoring(), "eIsContinueMonitoring", "eIsContinueMonitoring2");
  261. params.put("eMonitor", Texts.of(tRestrictedSpacePermit.geteMonitor()).fontSize(7).bold().create());
  262. params.put("eSafeAttendant", Texts.of(tRestrictedSpacePermit.geteSafeAttendant()).fontSize(7).bold().create());
  263. //4.通风措施
  264. params.put("eNaturalVenContent", Texts.of(tRestrictedSpacePermit.geteNaturalVenContent()).fontSize(7).bold().create());
  265. params.put("eMecVenContent", Texts.of(tRestrictedSpacePermit.geteMecVenContent()).fontSize(7).bold().create());
  266. params.put("eAnalyzeAirContent", Texts.of(tRestrictedSpacePermit.geteAnalyzeAirContent()).fontSize(7).bold().create());
  267. params.put("eAnalyzeAirInterval", Texts.of(tRestrictedSpacePermit.geteAnalyzeAirInterval()).fontSize(7).bold().create());
  268. params.put("eOtherVenContent", Texts.of(tRestrictedSpacePermit.geteOtherVenContent()).fontSize(7).bold().create());
  269. getCheck(params, tRestrictedSpacePermit.geteIsNaturalVen(), "eIsNaturalVen", "eIsNaturalVen2");
  270. getCheck(params, tRestrictedSpacePermit.geteIsMecVen(), "eIsMecVen", "eIsMecVen2");
  271. getCheck(params, tRestrictedSpacePermit.geteIsExxtractDust(), "eIsExxtractDust", "eIsExxtractDust2");
  272. getCheck(params, tRestrictedSpacePermit.geteIsAnalyzeAir(), "eIsAnalyzeAir", "eIsAnalyzeAir2");
  273. getCheck(params, tRestrictedSpacePermit.geteIsOtherVen(), "eIsOtherVen", "eIsOtherVen2");
  274. return params;
  275. }
  276. // 勾选框判断渲染
  277. public void getCheck(Map<String, Object> params, String ticketWord, String check1) {
  278. if ("1".equals(ticketWord)) {
  279. params.put(check1, new TextRenderData("\u00FE", new Style("Wingdings", 7)));
  280. } else if ("2".equals(ticketWord)) {
  281. params.put(check1, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  282. } else {
  283. params.put(check1, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  284. }
  285. }
  286. // 勾选框判断渲染
  287. public void getCheck(Map<String, Object> params, String ticketWord, String check1, String check2) {
  288. if ("1".equals(ticketWord)) {
  289. params.put(check1, new TextRenderData("\u00FE", new Style("Wingdings", 7)));
  290. params.put(check2, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  291. } else if ("0".equals(ticketWord)) {
  292. params.put(check1, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  293. params.put(check2, new TextRenderData("\u00FE", new Style("Wingdings", 7)));
  294. } else {
  295. params.put(check1, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  296. params.put(check2, new TextRenderData("\u006F", new Style("Wingdings", 7)));
  297. }
  298. }
  299. }