QualityInspectProgramController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package easydo.technology.controller;
  2. import easydo.technology.components.JdbcClient;
  3. import easydo.technology.enums.MESEnum;
  4. import easydo.technology.exception.BizException;
  5. import easydo.technology.model.QualityInspectProgram;
  6. import easydo.technology.service.FlowNoService;
  7. import easydo.technology.system.model.SysUser;
  8. import easydo.technology.utils.StringUtil;
  9. import org.springframework.http.HttpStatus;
  10. import org.springframework.http.ResponseEntity;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import javax.annotation.Resource;
  15. import javax.sql.DataSource;
  16. import java.sql.Connection;
  17. import java.util.List;
  18. import java.util.Map;
  19. @RestController
  20. @RequestMapping("/qualityInspectProgram")
  21. public class QualityInspectProgramController {
  22. @Resource
  23. JdbcClient jdbcClient;
  24. @Resource
  25. DataSource dataSource;
  26. @Resource
  27. FlowNoService flowNoService;
  28. @RequestMapping(value = "/getList")
  29. public Object getList(@RequestBody Map<String, Object> map) throws Exception {
  30. List<QualityInspectProgram> list = jdbcClient.getJdbcList(map, QualityInspectProgram.class);
  31. return new ResponseEntity<>(list, HttpStatus.OK);
  32. }
  33. @RequestMapping(value = "/getPage")
  34. public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
  35. Connection connection = dataSource.getConnection();
  36. try {
  37. Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, QualityInspectProgram.class, connection);
  38. List<QualityInspectProgram> records = (List<QualityInspectProgram>) recordsPage.get("records");
  39. for (QualityInspectProgram model : records) {
  40. jdbcClient.getMinioFile(model, connection);
  41. SysUser inspectUser = new SysUser();
  42. inspectUser.setId(model.getInspectUserId());
  43. inspectUser = jdbcClient.getJdbcModelById(inspectUser,connection);
  44. model.setInspectUserName(inspectUser.getNickName());
  45. SysUser reviewUser = new SysUser();
  46. reviewUser.setId(model.getReviewUserId());
  47. reviewUser = jdbcClient.getJdbcModelById(reviewUser, connection);
  48. model.setReviewUserName(reviewUser.getNickName());
  49. }
  50. return new ResponseEntity<>(recordsPage, HttpStatus.OK);
  51. } catch (Exception e) {
  52. throw new BizException(e.getMessage());
  53. } finally {
  54. connection.close();
  55. }
  56. }
  57. @RequestMapping(value = "/save")
  58. public Object add(@RequestBody QualityInspectProgram model) throws Exception {
  59. Connection connection = dataSource.getConnection();
  60. try {
  61. connection.setAutoCommit(false);
  62. generateCode(model, connection);
  63. jdbcClient.jdbcInsert(model, connection);
  64. connection.commit();
  65. return new ResponseEntity<>(model, HttpStatus.OK);
  66. } catch (Exception e) {
  67. connection.rollback();
  68. throw new BizException(e.getMessage());
  69. } finally {
  70. connection.close();
  71. }
  72. }
  73. @RequestMapping(value = "/update")
  74. public Object update(@RequestBody QualityInspectProgram model) throws Exception {
  75. jdbcClient.jdbcUpdateById(model);
  76. return new ResponseEntity<>(HttpStatus.OK);
  77. }
  78. @RequestMapping(value = "/remove")
  79. public Object remove(@RequestBody QualityInspectProgram model) throws Exception {
  80. jdbcClient.jdbcRemoveById(model);
  81. return new ResponseEntity<>(HttpStatus.OK);
  82. }
  83. private synchronized void generateCode(QualityInspectProgram model, Connection connection) throws Exception {
  84. if (StringUtil.isEmpty(model.getCode())) {
  85. while (true) {
  86. String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_QUALITY_INSPECT_PROGRAM.getValue(), connection);
  87. QualityInspectProgram param = new QualityInspectProgram();
  88. param.setCode(flowNo);
  89. int count = jdbcClient.getJdbcCount(param, connection);
  90. if (count == 0) {
  91. model.setCode(flowNo);
  92. break;
  93. }
  94. }
  95. } else {
  96. QualityInspectProgram param = new QualityInspectProgram();
  97. param.setCode(model.getCode());
  98. int count = jdbcClient.getJdbcCount(param, connection);
  99. if (count > 0) {
  100. throw new BizException("编号已存在,请重新填写");
  101. }
  102. }
  103. }
  104. }