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 map) throws Exception { List list = jdbcClient.getJdbcList(map, ProcessRoute.class); return new ResponseEntity<>(list, HttpStatus.OK); } @RequestMapping(value = "/getPage") public Object getPage(@RequestBody Map map) throws Exception { Connection connection = dataSource.getConnection(); try { Map recordsPage = jdbcClient.getJdbcPage(map, ProcessRoute.class, connection); List records = (List) recordsPage.get("records"); for (ProcessRoute model : records) { ProcessRouteRef routeRef = new ProcessRouteRef(); routeRef.setRouteId(model.getId()); List 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 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(); } } }