|
@@ -1,13 +1,7 @@
|
|
|
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.model.ProductBom;
|
|
|
|
|
import easydo.technology.model.ProductMaterial;
|
|
import easydo.technology.model.ProductMaterial;
|
|
|
-import easydo.technology.service.FlowNoService;
|
|
|
|
|
-import easydo.technology.utils.SecurityUtils;
|
|
|
|
|
-import easydo.technology.utils.StringUtil;
|
|
|
|
|
|
|
+import easydo.technology.service.ProductMaterialService;
|
|
|
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;
|
|
@@ -15,127 +9,42 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import javax.sql.DataSource;
|
|
|
|
|
-import java.sql.Connection;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/processMaterial")
|
|
@RequestMapping("/processMaterial")
|
|
|
public class ProductMaterialController {
|
|
public class ProductMaterialController {
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
- JdbcClient jdbcClient;
|
|
|
|
|
- @Resource
|
|
|
|
|
- DataSource dataSource;
|
|
|
|
|
- @Resource
|
|
|
|
|
- FlowNoService flowNoService;
|
|
|
|
|
|
|
+ ProductMaterialService productMaterialService;
|
|
|
|
|
|
|
|
@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<ProductMaterial> list = jdbcClient.getJdbcList(map, ProductMaterial.class);
|
|
|
|
|
|
|
+ Object list = productMaterialService.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, ProductMaterial.class, connection);
|
|
|
|
|
- return new ResponseEntity<>(recordsPage, HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Object page = productMaterialService.getPage(map);
|
|
|
|
|
+ return new ResponseEntity<>(page, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/save")
|
|
@RequestMapping(value = "/save")
|
|
|
public Object save(@RequestBody ProductMaterial model) throws Exception {
|
|
public Object save(@RequestBody ProductMaterial model) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
- connection.setAutoCommit(false);
|
|
|
|
|
- model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
|
|
|
|
|
- model.setCreateId(SecurityUtils.getCurrentUserId());
|
|
|
|
|
- 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();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Object result = productMaterialService.save(model);
|
|
|
|
|
+ return new ResponseEntity<>(result, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/update")
|
|
@RequestMapping(value = "/update")
|
|
|
public Object update(@RequestBody ProductMaterial model) throws Exception {
|
|
public Object update(@RequestBody ProductMaterial model) throws Exception {
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
- connection.setAutoCommit(false);
|
|
|
|
|
-
|
|
|
|
|
- jdbcClient.jdbcUpdateById(model, connection);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
- paramMap.put("materialCode", model.getCode());
|
|
|
|
|
- ProductBom bom = new ProductBom();
|
|
|
|
|
- bom.setMaterialName(model.getName());
|
|
|
|
|
- jdbcClient.jdbcUpdate(bom, paramMap, connection);
|
|
|
|
|
-
|
|
|
|
|
- connection.commit();
|
|
|
|
|
- return new ResponseEntity<>(HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- connection.rollback();
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Object result = productMaterialService.update(model);
|
|
|
|
|
+ return new ResponseEntity<>(result, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/remove")
|
|
@RequestMapping(value = "/remove")
|
|
|
- public Object deleteProgram(@RequestBody ProductMaterial model) throws Exception {
|
|
|
|
|
- Connection connection = dataSource.getConnection();
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- model = jdbcClient.getJdbcModelById(model, connection);
|
|
|
|
|
- ProductBom bom = new ProductBom();
|
|
|
|
|
- bom.setMaterialCode(model.getCode());
|
|
|
|
|
- int count = jdbcClient.getJdbcCount(bom, connection);
|
|
|
|
|
- if (count > 0) {
|
|
|
|
|
- throw new BizException("该物料在bom管理中存在,无法删除");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- jdbcClient.jdbcRemoveById(model, connection);
|
|
|
|
|
-
|
|
|
|
|
- return new ResponseEntity<>(HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new BizException(e.getMessage());
|
|
|
|
|
- } finally {
|
|
|
|
|
- connection.close();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private synchronized void generateCode(ProductMaterial model, Connection connection) throws Exception {
|
|
|
|
|
- if (StringUtil.isEmpty(model.getCode())) {
|
|
|
|
|
- while (true) {
|
|
|
|
|
- String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_PRODUCT_MATERIAL.getValue(), connection);
|
|
|
|
|
- ProductMaterial productMaterialParam = new ProductMaterial();
|
|
|
|
|
- productMaterialParam.setCode(flowNo);
|
|
|
|
|
- int count = jdbcClient.getJdbcCount(productMaterialParam, connection);
|
|
|
|
|
- if (count == 0) {
|
|
|
|
|
- model.setCode(flowNo);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- ProductMaterial productMaterialParam = new ProductMaterial();
|
|
|
|
|
- productMaterialParam.setCode(model.getCode());
|
|
|
|
|
- int count = jdbcClient.getJdbcCount(productMaterialParam, connection);
|
|
|
|
|
- if (count > 0) {
|
|
|
|
|
- throw new BizException("编号已存在,请重新填写");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public Object remove(@RequestBody ProductMaterial model) throws Exception {
|
|
|
|
|
+ Object result = productMaterialService.remove(model);
|
|
|
|
|
+ return new ResponseEntity<>(result, HttpStatus.OK);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|