Browse Source

物料资料修改

chenw 7 years ago
parent
commit
a8b8d0c084

+ 1 - 3
applications/document/document-server/src/main/java/com/usoftchina/saas/document/controller/ProductController.java

@@ -99,9 +99,7 @@ public class ProductController {
 
     @GetMapping("/read/{id}")
     public Result getDataById(@PathVariable("id") Long id){
-        Map<String, Object> map = new HashMap<String, Object>();
-        map.put("main", productService.getDataById(id));
-        return Result.success(map);
+        return Result.success(productService.getDataById(id));
     }
 
     @GetMapping("/ReserveCost")

+ 2 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductDetailMapper.java

@@ -25,4 +25,6 @@ public interface ProductDetailMapper extends CommonBaseMapper<ProductDetail> {
     Long selectProdidByPrimaryKey(Long id);
 
     List<ProductDetail> selectByProdId(Long id);
+
+    boolean deleteByProdId(Long id);
 }

+ 1 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/ProductService.java

@@ -101,7 +101,7 @@ public interface ProductService extends CommonBaseService<ProductMapper, Product
      * @param id
      * @return
      */
-    Product getDataById(Long id);
+    ProductListDTO getDataById(Long id);
 
     /**
      * 物料库存数量金额表

+ 28 - 7
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/ProductServiceImpl.java

@@ -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,10 +76,13 @@ 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);
@@ -86,13 +90,20 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         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);
 
@@ -120,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);
                     }
                 }
@@ -157,7 +172,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
             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(i).getPd_whcode())){
+                    if (productDetailList.get(i).getPd_whcode().equals(productDetailList.get(j).getPd_whcode())){
                         flag = false;
                         break;
                     }
@@ -356,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);
@@ -428,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
@@ -451,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)) {

+ 5 - 2
applications/document/document-server/src/main/resources/mapper/ProductDetailMapper.xml

@@ -255,7 +255,7 @@
         )
         VALUES
         <foreach collection="list" item="item" index="index" open="" close="" separator=",">
-            values ( #{item.pd_prodid,jdbcType=INTEGER}, #{item.pd_prodcode,jdbcType=VARCHAR},
+            ( #{item.pd_prodid,jdbcType=INTEGER}, #{item.pd_prodcode,jdbcType=VARCHAR},
             #{item.pd_detno,jdbcType=INTEGER}, #{item.pd_whcode,jdbcType=VARCHAR}, #{item.pd_whname,jdbcType=VARCHAR},
             #{item.pd_whid,jdbcType=INTEGER}, #{item.pd_price,jdbcType=DOUBLE}, #{item.pd_amount,jdbcType=DOUBLE},
             #{item.companyId,jdbcType=INTEGER}, #{item.updaterId,jdbcType=INTEGER}, #{item.updateTime,jdbcType=TIMESTAMP},
@@ -324,9 +324,12 @@
         </foreach>
     </update>
     <select id="selectProdidByPrimaryKey" resultType="java.lang.Long">
-        SELECT PD_PRODID FROM PRODUCTDETAIL WHERE PD_ID=#{id}
+        SELECT PD_PRODID FROM PRODUCTDETAIL WHERE ID=#{id}
     </select>
     <select id="selectByProdId" resultType="com.usoftchina.saas.document.entities.ProductDetail">
         SELECT * FROM PRODUCTDETAIL WHERE PD_PRODID=#{id}
     </select>
+    <delete id="deleteByProdId" >
+        DELETE FROM PRODUCTDETAIL WHERE PD_PRODID=#{id}
+    </delete>
 </mapper>

+ 1 - 1
applications/document/document-server/src/main/resources/mapper/ProductMapper.xml

@@ -903,7 +903,7 @@
         </where>
     </select>
 
-    <select id="selectOrderCountByProdCode" resultType="java.lang.Long">
+    <select id="selectOrderCountByProdCode" resultType="java.lang.Integer">
         SELECT COUNT(*) FROM PRODINOUT LEFT JOIN PRODIODETAIL ON PI_ID=PD_PIID AND PRODINOUT.COMPANYID=PRODIODETAIL.COMPANYID
         WHERE PRODIODETAIL.COMPANYID = #{companyId} AND PD_PRODID = #{id}
     </select>