| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package easydo.technology.controller;
- import easydo.technology.components.JdbcClient;
- import easydo.technology.enums.MESEnum;
- import easydo.technology.exception.BizException;
- import easydo.technology.model.ProcessRoute;
- import easydo.technology.model.ProcessRouteRef;
- import easydo.technology.service.FlowNoService;
- import easydo.technology.utils.SecurityUtils;
- import easydo.technology.utils.StringUtil;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import javax.sql.DataSource;
- import java.sql.Connection;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("/processRoute")
- public class ProcessRouteController {
- @Resource
- JdbcClient jdbcClient;
- @Resource
- DataSource dataSource;
- @Resource
- FlowNoService flowNoService;
- @RequestMapping(value = "/getList")
- public Object getList(@RequestBody Map<String, Object> map) throws Exception {
- List<ProcessRoute> list = jdbcClient.getJdbcList(map, ProcessRoute.class);
- return new ResponseEntity<>(list, HttpStatus.OK);
- }
- @RequestMapping(value = "/getPage")
- public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
- Connection connection = dataSource.getConnection();
- try {
- Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessRoute.class, connection);
- List<ProcessRoute> records = (List<ProcessRoute>) recordsPage.get("records");
- for (ProcessRoute model : records) {
- ProcessRouteRef routeRef = new ProcessRouteRef();
- routeRef.setRouteId(model.getId());
- List<ProcessRouteRef> routeRefList = jdbcClient.getJdbcList(routeRef, connection);
- model.setRefList(routeRefList);
- jdbcClient.getMinioFile(model, connection);
- }
- return new ResponseEntity<>(recordsPage, HttpStatus.OK);
- } catch (Exception e) {
- throw new BizException(e.getMessage());
- } finally {
- connection.close();
- }
- }
- @RequestMapping(value = "/save")
- public Object add(@RequestBody ProcessRoute model) throws Exception {
- Connection connection = dataSource.getConnection();
- try {
- connection.setAutoCommit(false);
- model.setCreateId(SecurityUtils.getCurrentUserId());
- if (StringUtil.isEmpty(model.getCode())) {
- model.setCode(flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_PROCESS_ROUTE.getValue(), connection));
- }
- jdbcClient.jdbcInsert(model, connection);
- List<ProcessRouteRef> refList = model.getRefList();
- for (ProcessRouteRef ref : refList) {
- ref.setRouteId(model.getId());
- jdbcClient.jdbcInsert(ref, connection);
- }
- connection.commit();
- return new ResponseEntity<>(model, HttpStatus.OK);
- } catch (Exception e) {
- connection.rollback();
- throw new BizException(e.getMessage());
- } finally {
- connection.close();
- }
- }
- }
|