ProcessRouteController.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.ProcessRoute;
  6. import easydo.technology.model.ProcessRouteRef;
  7. import easydo.technology.service.FlowNoService;
  8. import easydo.technology.utils.SecurityUtils;
  9. import easydo.technology.utils.StringUtil;
  10. import org.springframework.http.HttpStatus;
  11. import org.springframework.http.ResponseEntity;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import javax.annotation.Resource;
  16. import javax.sql.DataSource;
  17. import java.sql.Connection;
  18. import java.util.List;
  19. import java.util.Map;
  20. @RestController
  21. @RequestMapping("/processRoute")
  22. public class ProcessRouteController {
  23. @Resource
  24. JdbcClient jdbcClient;
  25. @Resource
  26. DataSource dataSource;
  27. @Resource
  28. FlowNoService flowNoService;
  29. @RequestMapping(value = "/getList")
  30. public Object getList(@RequestBody Map<String, Object> map) throws Exception {
  31. List<ProcessRoute> list = jdbcClient.getJdbcList(map, ProcessRoute.class);
  32. return new ResponseEntity<>(list, HttpStatus.OK);
  33. }
  34. @RequestMapping(value = "/getPage")
  35. public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
  36. Connection connection = dataSource.getConnection();
  37. try {
  38. Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessRoute.class, connection);
  39. List<ProcessRoute> records = (List<ProcessRoute>) recordsPage.get("records");
  40. for (ProcessRoute model : records) {
  41. ProcessRouteRef routeRef = new ProcessRouteRef();
  42. routeRef.setRouteId(model.getId());
  43. List<ProcessRouteRef> routeRefList = jdbcClient.getJdbcList(routeRef, connection);
  44. model.setRefList(routeRefList);
  45. jdbcClient.getMinioFile(model, connection);
  46. }
  47. return new ResponseEntity<>(recordsPage, HttpStatus.OK);
  48. } catch (Exception e) {
  49. throw new BizException(e.getMessage());
  50. } finally {
  51. connection.close();
  52. }
  53. }
  54. @RequestMapping(value = "/save")
  55. public Object add(@RequestBody ProcessRoute model) throws Exception {
  56. Connection connection = dataSource.getConnection();
  57. try {
  58. connection.setAutoCommit(false);
  59. model.setCreateId(SecurityUtils.getCurrentUserId());
  60. if (StringUtil.isEmpty(model.getCode())) {
  61. model.setCode(flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_PROCESS_ROUTE.getValue(), connection));
  62. }
  63. jdbcClient.jdbcInsert(model, connection);
  64. List<ProcessRouteRef> refList = model.getRefList();
  65. for (ProcessRouteRef ref : refList) {
  66. ref.setRouteId(model.getId());
  67. jdbcClient.jdbcInsert(ref, connection);
  68. }
  69. connection.commit();
  70. return new ResponseEntity<>(model, HttpStatus.OK);
  71. } catch (Exception e) {
  72. connection.rollback();
  73. throw new BizException(e.getMessage());
  74. } finally {
  75. connection.close();
  76. }
  77. }
  78. }