|
@@ -1,11 +1,8 @@
|
|
|
package easydo.technology.controller;
|
|
package easydo.technology.controller;
|
|
|
|
|
|
|
|
-import easydo.technology.components.JdbcClient;
|
|
|
|
|
-import easydo.technology.enums.MESEnum;
|
|
|
|
|
import easydo.technology.exception.BizException;
|
|
import easydo.technology.exception.BizException;
|
|
|
import easydo.technology.model.SalePlan;
|
|
import easydo.technology.model.SalePlan;
|
|
|
-import easydo.technology.service.FlowNoService;
|
|
|
|
|
-import easydo.technology.utils.StringUtil;
|
|
|
|
|
|
|
+import easydo.technology.service.SalePlanService;
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -22,105 +19,35 @@ import java.util.Map;
|
|
|
@RequestMapping("/salePlan")
|
|
@RequestMapping("/salePlan")
|
|
|
public class SalePlanController {
|
|
public class SalePlanController {
|
|
|
@Resource
|
|
@Resource
|
|
|
- JdbcClient jdbcClient;
|
|
|
|
|
- @Resource
|
|
|
|
|
- DataSource dataSource;
|
|
|
|
|
- @Resource
|
|
|
|
|
- FlowNoService flowNoService;
|
|
|
|
|
|
|
+ SalePlanService salePlanService;
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getList")
|
|
@RequestMapping(value = "/getList")
|
|
|
public Object getList(@RequestBody Map<String, Object> map) throws Exception {
|
|
public Object getList(@RequestBody Map<String, Object> map) throws Exception {
|
|
|
- List<SalePlan> list = jdbcClient.getJdbcList(map, SalePlan.class);
|
|
|
|
|
|
|
+ List<SalePlan> list = salePlanService.getList(map);
|
|
|
return new ResponseEntity<>(list, HttpStatus.OK);
|
|
return new ResponseEntity<>(list, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getPage")
|
|
@RequestMapping(value = "/getPage")
|
|
|
public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
|
|
public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
- Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, SalePlan.class, connection);
|
|
|
|
|
- List<SalePlan> records = (List<SalePlan>) recordsPage.get("records");
|
|
|
|
|
-
|
|
|
|
|
- return new ResponseEntity<>(recordsPage, HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Map<String, Object> recordsPage = salePlanService.getPage(map);
|
|
|
|
|
+ return new ResponseEntity<>(recordsPage, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/save")
|
|
@RequestMapping(value = "/save")
|
|
|
public Object save(@RequestBody SalePlan model) throws Exception {
|
|
public Object save(@RequestBody SalePlan model) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
- connection.setAutoCommit(false);
|
|
|
|
|
- generateCode(model, connection);
|
|
|
|
|
- jdbcClient.jdbcInsert(model, connection);
|
|
|
|
|
-
|
|
|
|
|
- connection.commit();
|
|
|
|
|
- return new ResponseEntity<>(model, HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- connection.rollback();
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return new ResponseEntity<>(salePlanService.save(model), HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/update")
|
|
@RequestMapping(value = "/update")
|
|
|
public Object update(@RequestBody SalePlan model) throws Exception {
|
|
public Object update(@RequestBody SalePlan model) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
- connection.setAutoCommit(false);
|
|
|
|
|
-
|
|
|
|
|
- jdbcClient.jdbcUpdateById(model, connection);
|
|
|
|
|
-
|
|
|
|
|
- connection.commit();
|
|
|
|
|
- return new ResponseEntity<>(HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- connection.rollback();
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ salePlanService.update(model);
|
|
|
|
|
+ return new ResponseEntity<>(HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/remove")
|
|
@RequestMapping(value = "/remove")
|
|
|
public Object deleteProgram(@RequestBody SalePlan model) throws Exception {
|
|
public Object deleteProgram(@RequestBody SalePlan model) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- jdbcClient.jdbcRemoveById(model, connection);
|
|
|
|
|
-
|
|
|
|
|
- return new ResponseEntity<>(HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- private synchronized void generateCode(SalePlan model, Connection connection) throws Exception {
|
|
|
|
|
- if (StringUtil.isEmpty(model.getCode())) {
|
|
|
|
|
- while (true) {
|
|
|
|
|
- String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_SALE_PLAN.getValue(), connection);
|
|
|
|
|
- SalePlan param = new SalePlan();
|
|
|
|
|
- param.setCode(flowNo);
|
|
|
|
|
- int count = jdbcClient.getJdbcCount(param, connection);
|
|
|
|
|
- if (count == 0) {
|
|
|
|
|
- model.setCode(flowNo);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- SalePlan param = new SalePlan();
|
|
|
|
|
- param.setCode(model.getCode());
|
|
|
|
|
- int count = jdbcClient.getJdbcCount(param, connection);
|
|
|
|
|
- if (count > 0) {
|
|
|
|
|
- throw new BizException("编号已存在,请重新填写");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ salePlanService.remove(model);
|
|
|
|
|
+ return new ResponseEntity<>(HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|