|
@@ -146,7 +146,6 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
public ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException {
|
|
public ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException {
|
|
Integer relationId = productSaveDto.getRelationId();
|
|
Integer relationId = productSaveDto.getRelationId();
|
|
Integer authType = productSaveDto.getAuthType();
|
|
Integer authType = productSaveDto.getAuthType();
|
|
- Integer productId = productSaveDto.getProductId();
|
|
|
|
Integer authId = productSaveDto.getAuthId();
|
|
Integer authId = productSaveDto.getAuthId();
|
|
Integer infoId = productSaveDto.getInfoId();
|
|
Integer infoId = productSaveDto.getInfoId();
|
|
Integer productTypeId = productSaveDto.getProductTypeId();
|
|
Integer productTypeId = productSaveDto.getProductTypeId();
|
|
@@ -197,17 +196,65 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
boolean newRelation = null == relationId;
|
|
boolean newRelation = null == relationId;
|
|
ProductRelationVo dbRelation = null;
|
|
ProductRelationVo dbRelation = null;
|
|
ProductFormVo dbProduct = null;
|
|
ProductFormVo dbProduct = null;
|
|
- if (!newRelation) {
|
|
|
|
|
|
+ // 数据库设备id
|
|
|
|
+ Integer dbProductId = null;
|
|
|
|
+ // 当前设备id
|
|
|
|
+ Integer productId = null;
|
|
|
|
+ // 数据库中sn码对应设备id
|
|
|
|
+ Integer productIdBySnCode = authProductMapper.getProductIdBySnCode(snCode);
|
|
|
|
+ if (newRelation) {
|
|
|
|
+ // 添加
|
|
|
|
+ if (1 == authType) {
|
|
|
|
+ // 新设备,设备id为null
|
|
|
|
+ if (null != productIdBySnCode) {
|
|
|
|
+ return ResponseJson.error("该商品SN码已存在,请重新输入", null);
|
|
|
|
+ }
|
|
|
|
+ } else if (2 == authType){
|
|
|
|
+ // 关联设备
|
|
|
|
+ productId = productIdBySnCode;
|
|
|
|
+ // 检测机构是否已关联该设备
|
|
|
|
+ ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
+ if (null != productRelation) {
|
|
|
|
+ return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ // 编辑
|
|
dbRelation = authProductMapper.getProductRelation(relationId, null, null);
|
|
dbRelation = authProductMapper.getProductRelation(relationId, null, null);
|
|
dbProduct = authProductMapper.getProductFormData(relationId);
|
|
dbProduct = authProductMapper.getProductFormData(relationId);
|
|
- }
|
|
|
|
- Integer productIdBySnCode = authProductMapper.getProductIdBySnCode(snCode);
|
|
|
|
- if (1 == authType) {
|
|
|
|
- if (null != productIdBySnCode && !productIdBySnCode.equals(productId)) {
|
|
|
|
- return ResponseJson.error("该商品SN码已存在,请重新输入", null);
|
|
|
|
|
|
+ dbProductId = dbProduct.getProductId();
|
|
|
|
+ if (1 == dbRelation.getAuthType()) {
|
|
|
|
+ // 原本为新增设备
|
|
|
|
+ if (1 == authType) {
|
|
|
|
+ // 设备id不变
|
|
|
|
+ productId = dbProductId;
|
|
|
|
+ if (null != productIdBySnCode && !productIdBySnCode.equals(productId)) {
|
|
|
|
+ return ResponseJson.error("该商品SN码已存在,请重新输入", null);
|
|
|
|
+ }
|
|
|
|
+ } else if (2 == authType){
|
|
|
|
+ productId = productIdBySnCode;
|
|
|
|
+ // 检测机构是否已关联该设备
|
|
|
|
+ ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
+ if (null != productRelation) {
|
|
|
|
+ return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (2 == dbRelation.getAuthType()){
|
|
|
|
+ // 原本为关联设备
|
|
|
|
+ if (1 == authType) {
|
|
|
|
+ // 设备id为null
|
|
|
|
+ if (null != productIdBySnCode) {
|
|
|
|
+ return ResponseJson.error("该商品SN码已存在,请重新输入", null);
|
|
|
|
+ }
|
|
|
|
+ } else if (2 == authType) {
|
|
|
|
+ productId = productIdBySnCode;
|
|
|
|
+ // 检测机构是否已关联该设备
|
|
|
|
+ ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
+ if (null != productRelation && !productRelation.getRelationId().equals(dbRelation.getRelationId())) {
|
|
|
|
+ return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- productId = productIdBySnCode;
|
|
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
组装商品数据
|
|
组装商品数据
|
|
@@ -259,33 +306,17 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
if (1 == authType) {
|
|
if (1 == authType) {
|
|
// 插入授权商品
|
|
// 插入授权商品
|
|
authProductMapper.insertProduct(product);
|
|
authProductMapper.insertProduct(product);
|
|
- // 插入机构设备关联关系
|
|
|
|
- relationId = authProductMapper.insertProductRelation(authId, product.getProductId(), authType);
|
|
|
|
} else {
|
|
} else {
|
|
- // 检测机构是否已关联该设备
|
|
|
|
- ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
- if (null != productRelation) {
|
|
|
|
- // 设置手动回滚事务
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
- return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
- }
|
|
|
|
// 关联设备,更新设备
|
|
// 关联设备,更新设备
|
|
authProductMapper.updateProductByProductId(product);
|
|
authProductMapper.updateProductByProductId(product);
|
|
- // 插入机构设备关联关系
|
|
|
|
- relationId = authProductMapper.insertProductRelation(authId, product.getProductId(), authType);
|
|
|
|
}
|
|
}
|
|
|
|
+ // 插入机构设备关联关系
|
|
|
|
+ relationId = authProductMapper.insertProductRelation(authId, product.getProductId(), authType);
|
|
} else {
|
|
} else {
|
|
if (1 == dbRelation.getAuthType()) {
|
|
if (1 == dbRelation.getAuthType()) {
|
|
// 更新设备
|
|
// 更新设备
|
|
authProductMapper.updateProductByProductId(product);
|
|
authProductMapper.updateProductByProductId(product);
|
|
if (2 == authType) {
|
|
if (2 == authType) {
|
|
- // 检测机构是否已关联该设备
|
|
|
|
- ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
- if (null != productRelation) {
|
|
|
|
- // 设置手动回滚事务
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
- return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
- }
|
|
|
|
// 更新机构设备关联关系
|
|
// 更新机构设备关联关系
|
|
authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|
|
authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|
|
// 原本关联的新增设备若无关联机构,删除该设备
|
|
// 原本关联的新增设备若无关联机构,删除该设备
|
|
@@ -301,13 +332,6 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
} else {
|
|
} else {
|
|
// 更新设备
|
|
// 更新设备
|
|
authProductMapper.updateProductByProductId(product);
|
|
authProductMapper.updateProductByProductId(product);
|
|
- // 检测机构是否已关联该设备
|
|
|
|
- ProductRelationVo productRelation = authProductMapper.getProductRelation(null, productId, authId);
|
|
|
|
- if (null != productRelation && !productRelation.getRelationId().equals(relationId)) {
|
|
|
|
- // 设置手动回滚事务
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
- return ResponseJson.error("不能重复关联同一台设备");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
// 更新机构设备关联关系
|
|
// 更新机构设备关联关系
|
|
authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|
|
authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|