|
|
@@ -25,6 +25,7 @@ import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -75,20 +76,34 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public DocBaseDTO saveData(ProductListDTO productListDTO){
|
|
|
Product product = productListDTO.getMain();
|
|
|
List<ProductDetail> productDetailList = productListDTO.getItems();
|
|
|
DocBaseDTO docBaseDTO = null;
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ Long userId = BaseContextHolder.getUserId();
|
|
|
+
|
|
|
+ //校验明细仓库是否重复
|
|
|
+ validRepeatWarehouse(productDetailList);
|
|
|
+
|
|
|
if(product.getId() == 0){
|
|
|
//保存
|
|
|
String code = pushMaxnubmer(product.getPr_code(), product.getId());
|
|
|
- product.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
- product.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ product.setCompanyId(companyId);
|
|
|
+ product.setCreatorId(userId);
|
|
|
product.setCreateTime(new Date());
|
|
|
//保存主表
|
|
|
getMapper().insertSelective(product);
|
|
|
//保存明细表数据
|
|
|
- productDetailMapper.batchInsert(productDetailList);
|
|
|
+ if (productDetailList.size() > 0) {
|
|
|
+ for (ProductDetail productDetail : productDetailList){
|
|
|
+ productDetail.setPd_prodid(product.getId());
|
|
|
+ productDetail.setCompanyId(companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ productDetailMapper.batchInsert(productDetailList);
|
|
|
+ }
|
|
|
//生成库存初始化数据并过账
|
|
|
generateProdIOPost(product, productDetailList);
|
|
|
|
|
|
@@ -116,8 +131,12 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
List<ProductDetail> updateItems = new ArrayList<ProductDetail>();
|
|
|
for(ProductDetail productDetail : productDetailList){
|
|
|
if (productDetail.getId() == 0){
|
|
|
+ productDetail.setUpdaterId(userId);
|
|
|
+ productDetail.setUpdateTime(new Date());
|
|
|
insertItems.add(productDetail);
|
|
|
}else{
|
|
|
+ productDetail.setUpdaterId(userId);
|
|
|
+ productDetail.setUpdateTime(new Date());
|
|
|
updateItems.add(productDetail);
|
|
|
}
|
|
|
}
|
|
|
@@ -144,6 +163,27 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
return docBaseDTO;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验明细仓库是否重复
|
|
|
+ * @param productDetailList
|
|
|
+ */
|
|
|
+ private void validRepeatWarehouse(List<ProductDetail> productDetailList) {
|
|
|
+ if (productDetailList.size() > 0){
|
|
|
+ boolean flag = true; //假设不重复
|
|
|
+ for (int i = 0; i < productDetailList.size() - 1; i ++){
|
|
|
+ for (int j = i + 1; j < productDetailList.size(); j++){
|
|
|
+ if (productDetailList.get(i).getPd_whcode().equals(productDetailList.get(j).getPd_whcode())){
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!flag){
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_PRODWHCODE_REPEAT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 物料发生过除库存初始化外的出入库单时,不能新增,修改,删除
|
|
|
* @param id
|
|
|
@@ -331,6 +371,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
|
|
|
String code = getMapper().getCodeById(id);
|
|
|
getMapper().deleteByPrimaryKey(id);
|
|
|
+ productDetailMapper.deleteByProdId(id);
|
|
|
DocBaseDTO docBaseDTO = generateMsgObj(id, code);
|
|
|
//记录LOG
|
|
|
messageLogService.delete(docBaseDTO);
|
|
|
@@ -403,8 +444,13 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Product getDataById(Long id) {
|
|
|
- return getMapper().selectByPrimaryKey(id);
|
|
|
+ public ProductListDTO getDataById(Long id) {
|
|
|
+ ProductListDTO productListDTO = new ProductListDTO();
|
|
|
+ Product product = getMapper().selectByPrimaryKey(id);
|
|
|
+ List<ProductDetail> productDetails = productDetailMapper.selectByProdId(id);
|
|
|
+ productListDTO.setMain(product);
|
|
|
+ productListDTO.setItems(productDetails);
|
|
|
+ return productListDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -426,7 +472,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
public boolean deleteDetailById(Long id) {
|
|
|
Long prodId = productDetailMapper.selectProdidByPrimaryKey(id);
|
|
|
validProductOperation(prodId, BizExceptionCode.BIZ_RELDELETE_DELETEPROD);
|
|
|
- String prCode = getMapper().selectByPrimaryKey(id).getPr_code();
|
|
|
+ String prCode = getMapper().selectByPrimaryKey(prodId).getPr_code();
|
|
|
//找到原始单据,反过账并删除
|
|
|
String inoutCode = getMapper().selectProdIOCode(prCode, BaseContextHolder.getCompanyId(), "库存初始化");
|
|
|
if (!StringUtils.isEmpty(inoutCode)) {
|