|
@@ -1,6 +1,7 @@
|
|
|
package cn.fastfun.controller.api;
|
|
|
|
|
|
|
|
|
+import cn.fastfun.service.AppDeviceService;
|
|
|
import cn.fastfun.service.ProductService;
|
|
|
import cn.fastfun.service.entity.IdParamForStatus;
|
|
|
import cn.fastfun.service.entity.Product;
|
|
@@ -10,10 +11,12 @@ import com.bridge.dto.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Api(tags = "设备类型记录(典表)")
|
|
|
@RestController
|
|
@@ -22,48 +25,78 @@ public class ProductController {
|
|
|
|
|
|
@Resource
|
|
|
ProductService productService;
|
|
|
+ @Resource
|
|
|
+ AppDeviceService appDeviceService;
|
|
|
|
|
|
@ApiOperation(value = "保存SN规则信息")
|
|
|
@PostMapping("/save")
|
|
|
public ApiDTO save(@RequestBody @ApiParam(name = "SN规则对象", value = "传入json格式", required = true) Product product) {
|
|
|
+ //已经使用过的imei对应的值不可以更改 M GM CL N 7 50 M 214L028,未被使用过的可以随便改
|
|
|
+ String sql = "select id from app_device where imei is not null ";
|
|
|
+ String condition = "";
|
|
|
+ if (product.getId() != null) {
|
|
|
+ Product p = productService.getOne(QueryParamExp.eq("id", product.getId()));
|
|
|
+ if (product.getSnTypeEn() != null) {
|
|
|
+ switch (product.getSnTypeEn()) {
|
|
|
+ //(1位)=产品类型代码
|
|
|
+ case 1:
|
|
|
+ condition = "and substring(imei,1,1)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(2-3位)=PACK制造商简称
|
|
|
+ case 2:
|
|
|
+ condition = "and substring(imei,2,2)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(4-5位)=电芯厂家名称
|
|
|
+ case 3:
|
|
|
+ condition = "and substring(imei,4,2)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(6位)=产品规格代码 L化学成分
|
|
|
+ case 4:
|
|
|
+ condition = "and substring(imei,6,1)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(7位)=电压
|
|
|
+ case 5:
|
|
|
+ condition = "and substring(imei,7,1)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(8-9位)=电量
|
|
|
+ case 6:
|
|
|
+ condition = "and substring(imei,8,2)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ //(10位)=产品扩展代码
|
|
|
+ case 7:
|
|
|
+ condition = "and substring(imei,10,1)='" + p.getSnTypeCode() + "'";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ condition = "";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(condition)) {
|
|
|
+ sql = sql.concat(condition);
|
|
|
+ }
|
|
|
|
|
|
-// // 针对产品规格这一项进行操作
|
|
|
-// if(product.getSnType().equals("产品规格")){
|
|
|
-// String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
|
|
|
-// if(!(checkSnTypeCodeResult.equals("passed"))){
|
|
|
-// return ApiDTO.error(500,checkSnTypeCodeResult);
|
|
|
-// }
|
|
|
-// List<Product> productSpecificationResults = ResolveUtil.resolveProductSpecification(product);
|
|
|
-// List<List<Product>> checkDuplicatedResults = new ArrayList<>();
|
|
|
-//
|
|
|
-// for(Product productSpecificationResult:productSpecificationResults) {
|
|
|
-// List<Product> checkDuplicatedResult = productService.findAll(
|
|
|
-// Arrays.asList(QueryParamExp.eq("snTypeCode", productSpecificationResult.getSnTypeCode()),
|
|
|
-// QueryParamExp.eq("snType", productSpecificationResult.getSnType())));
|
|
|
-//
|
|
|
-// checkDuplicatedResults.add(checkDuplicatedResult);
|
|
|
-//
|
|
|
-// String checkSnTypeCodeResultForEach = VerifyUtil.checkSnTypeCode(productSpecificationResult);
|
|
|
-// if((checkSnTypeCodeResultForEach.equals("passed"))&(checkDuplicatedResult.isEmpty())){
|
|
|
-// productService.save(productSpecificationResult);
|
|
|
-// }
|
|
|
-// else if(!(checkSnTypeCodeResultForEach.equals("passed"))){
|
|
|
-// return ApiDTO.error(500,checkSnTypeCodeResultForEach);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if((!(checkDuplicatedResults.get(0).isEmpty()))&(!(checkDuplicatedResults.get(1).isEmpty()))&(!(checkDuplicatedResults.get(2).isEmpty()))){
|
|
|
-// return ApiDTO.error(500,"该产品规格对应的三个规则行已存在,未进行任何保存",checkDuplicatedResults);
|
|
|
-// }
|
|
|
-// return ApiDTO.ok("保存成功,未保存的规则行id为null",productSpecificationResults);
|
|
|
-// }
|
|
|
-
|
|
|
+ if (!p.getSnTypeCode().equals(product.getSnTypeCode())) {
|
|
|
+ List<Map<String, Object>> mapList = appDeviceService.getListBySQL(sql, new HashMap<>());
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ return ApiDTO.error(500, "代码 " + p.getSnTypeCode() + " 已经被使用,不允许修改");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 校验输入的SN类型对应的编号
|
|
|
String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
|
|
|
List<Product> checkDuplicatedResult = productService.findAll(
|
|
|
Arrays.asList(QueryParamExp.eq("snTypeCode", product.getSnTypeCode()),
|
|
|
QueryParamExp.eq("snType", product.getSnType())));
|
|
|
if (!checkDuplicatedResult.isEmpty()) {
|
|
|
- return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
|
|
|
+ if (product.getId() != null) {
|
|
|
+ List<Product> collect = checkDuplicatedResult.stream()
|
|
|
+ .filter(o -> !o.getId().equals(product.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
|
|
|
+ }
|
|
|
}
|
|
|
if (checkSnTypeCodeResult.equals("passed")) {
|
|
|
Product tmp = productService.save(product);
|