1
0
Prechádzať zdrojové kódy

xwh修改在途库存导入修改添加的校验逻辑

xwh 4 rokov pred
rodič
commit
04a8b7d233

+ 1 - 0
kmall-admin/src/main/java/com/kmall/admin/controller/GoodsTransportInfoDetailController.java

@@ -9,6 +9,7 @@ import com.kmall.common.constant.JxlsXmlTemplateName;
 import com.kmall.common.utils.PageUtils;
 import com.kmall.common.utils.Query;
 import com.kmall.common.utils.R;
+import com.kmall.common.utils.RRException;
 import com.kmall.common.utils.excel.ExcelUtil;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;

+ 2 - 0
kmall-admin/src/main/java/com/kmall/admin/dao/GoodsTransportInfoDetailDao.java

@@ -20,4 +20,6 @@ public interface GoodsTransportInfoDetailDao extends BaseDao<GoodsTransportInfoD
     List<GoodsTransportInfoDetailEntity> searchListByStatusAndSku(@Param("query") Query query, @Param("wayStatus") Integer wayStatus, @Param("sku")String sku);
 
     int queryTotalByStatusAndSku(@Param("query") Query query, @Param("wayStatus") Integer wayStatus, @Param("sku")String sku);
+
+    Integer existGoodsBySkuAndsupplierId(@Param("sku") String sku,@Param("supplierId") Integer supplierId);
 }

+ 6 - 32
kmall-admin/src/main/java/com/kmall/admin/dto/GoodsTransportInfoDetailExcelDto.java

@@ -15,7 +15,7 @@ public class GoodsTransportInfoDetailExcelDto implements Serializable {
     /**
      * 供应商id
      */
-    private String supplierId;
+    private Integer supplierId;
     /**
      * 原产地
      */
@@ -23,7 +23,7 @@ public class GoodsTransportInfoDetailExcelDto implements Serializable {
     /**
      * 数量
      */
-    private String num;
+    private Integer num;
     /**
      * 创建人编号
      */
@@ -49,11 +49,11 @@ public class GoodsTransportInfoDetailExcelDto implements Serializable {
         this.sku = sku;
     }
 
-    public String getSupplierId() {
+    public Integer getSupplierId() {
         return supplierId;
     }
 
-    public void setSupplierId(String supplierId) {
+    public void setSupplierId(Integer supplierId) {
         this.supplierId = supplierId;
     }
 
@@ -65,11 +65,11 @@ public class GoodsTransportInfoDetailExcelDto implements Serializable {
         this.originCountry = originCountry;
     }
 
-    public String getNum() {
+    public Integer getNum() {
         return num;
     }
 
-    public void setNum(String num) {
+    public void setNum(Integer num) {
         this.num = num;
     }
 
@@ -88,30 +88,4 @@ public class GoodsTransportInfoDetailExcelDto implements Serializable {
     public void setModerSn(String moderSn) {
         this.moderSn = moderSn;
     }
-
-    @Override
-    public String toString() {
-        return "GoodsTransportInfoDetailExcelDto{" +
-                "wayStatus='" + wayStatus + '\'' +
-                ", sku='" + sku + '\'' +
-                ", supplierId='" + supplierId + '\'' +
-                ", originCountry='" + originCountry + '\'' +
-                ", num='" + num + '\'' +
-                ", createrSn='" + createrSn + '\'' +
-                ", moderSn='" + moderSn + '\'' +
-                '}';
-    }
-
-    public GoodsTransportInfoDetailExcelDto() {
-    }
-
-    public GoodsTransportInfoDetailExcelDto(String wayStatus, String sku, String supplierId, String originCountry, String num, String createrSn, String moderSn) {
-        this.wayStatus = wayStatus;
-        this.sku = sku;
-        this.supplierId = supplierId;
-        this.originCountry = originCountry;
-        this.num = num;
-        this.createrSn = createrSn;
-        this.moderSn = moderSn;
-    }
 }

+ 36 - 2
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsTransportInfoDetailServiceImpl.java

@@ -44,11 +44,27 @@ public class GoodsTransportInfoDetailServiceImpl implements GoodsTransportInfoDe
 
     @Override
     public int save(GoodsTransportInfoDetailEntity goodsTransportInfoDetail) {
+        // 判断sku和供应商id是否存在
+        Integer exist = goodsTransportInfoDetailDao.existGoodsBySkuAndsupplierId(goodsTransportInfoDetail.getSku(), goodsTransportInfoDetail.getSupplierId());
+        if (exist==null){
+            throw new RRException("sku和供应商id不匹配");
+        }
+        if (goodsTransportInfoDetail.getNum()<=0){
+            throw new RRException("数量应该大于0");
+        }
         return goodsTransportInfoDetailDao.save(goodsTransportInfoDetail);
     }
 
     @Override
     public int update(GoodsTransportInfoDetailEntity goodsTransportInfoDetail) {
+        // 判断sku和供应商id是否存在
+        Integer exist = goodsTransportInfoDetailDao.existGoodsBySkuAndsupplierId(goodsTransportInfoDetail.getSku(), goodsTransportInfoDetail.getSupplierId());
+        if (exist==null){
+            throw new RRException("sku和供应商id不匹配");
+        }
+        if (goodsTransportInfoDetail.getNum()<=0){
+            throw new RRException("数量应该大于0");
+        }
         return goodsTransportInfoDetailDao.update(goodsTransportInfoDetail);
     }
 
@@ -79,6 +95,9 @@ public class GoodsTransportInfoDetailServiceImpl implements GoodsTransportInfoDe
     @Override
     @Transactional
     public void saveExcelDtoList(List<GoodsTransportInfoDetailExcelDto> goodsTransportInfoDetailExcelDtoList) {
+        if (goodsTransportInfoDetailExcelDtoList==null || goodsTransportInfoDetailExcelDtoList.size()==0){
+            throw new RRException("请填写至少一行数据");
+        }
         goodsTransportInfoDetailExcelDtoList.forEach(goodsTransportInfoDetailExcelDto -> {
             GoodsTransportInfoDetailEntity goodsTransportInfoDetailEntity = new GoodsTransportInfoDetailEntity();
             if (goodsTransportInfoDetailExcelDto.getWayStatus()==null ||
@@ -86,11 +105,26 @@ public class GoodsTransportInfoDetailServiceImpl implements GoodsTransportInfoDe
                             && Integer.parseInt(goodsTransportInfoDetailExcelDto.getWayStatus()) != 1)){
                 throw new RRException("是否在途必填,且只能填0或1");
             }
+            if (goodsTransportInfoDetailExcelDto.getSupplierId()==null){
+                throw new RRException("供应商id必填");
+            }
+
+            // 判断sku和供应商id是否存在
+            Integer exist = goodsTransportInfoDetailDao.existGoodsBySkuAndsupplierId(goodsTransportInfoDetailExcelDto.getSku(), goodsTransportInfoDetailExcelDto.getSupplierId());
+            if (exist==null){
+                throw new RRException("sku和供应商id不匹配");
+            }
+            if (goodsTransportInfoDetailExcelDto.getNum()==null){
+                throw new RRException("数量必填");
+            }
+            if (goodsTransportInfoDetailExcelDto.getNum()<=0){
+                throw new RRException("数量要大于0");
+            }
             goodsTransportInfoDetailEntity.setWayStatus(Integer.parseInt(goodsTransportInfoDetailExcelDto.getWayStatus()));
             goodsTransportInfoDetailEntity.setSku(goodsTransportInfoDetailExcelDto.getSku());
-            goodsTransportInfoDetailEntity.setSupplierId(Integer.parseInt(goodsTransportInfoDetailExcelDto.getSupplierId()));
+            goodsTransportInfoDetailEntity.setSupplierId(goodsTransportInfoDetailExcelDto.getSupplierId());
             goodsTransportInfoDetailEntity.setOriginCountry(goodsTransportInfoDetailExcelDto.getOriginCountry());
-            goodsTransportInfoDetailEntity.setNum(Integer.parseInt(goodsTransportInfoDetailExcelDto.getNum()));
+            goodsTransportInfoDetailEntity.setNum(goodsTransportInfoDetailExcelDto.getNum());
             goodsTransportInfoDetailEntity.setCreaterSn(ShiroUtils.getUserId().toString());
             goodsTransportInfoDetailEntity.setModerSn(ShiroUtils.getUserId().toString());
             goodsTransportInfoDetailEntity.setTstm(new Date());

+ 4 - 1
kmall-admin/src/main/resources/mybatis/mapper/GoodsTransportInfoDetailDao.xml

@@ -102,8 +102,11 @@
 			AND sku LIKE CONCAT('%',#{sku},'%')
 		</if>
 	</select>
+    <select id="existGoodsBySkuAndsupplierId" resultType="java.lang.Integer">
+		select 1 from mall_goods where sku=#{sku} and supplier_id=#{supplierId} limit 1
+	</select>
 
-	<insert id="save" parameterType="com.kmall.admin.entity.GoodsTransportInfoDetailEntity" useGeneratedKeys="true" keyProperty="transItemId">
+    <insert id="save" parameterType="com.kmall.admin.entity.GoodsTransportInfoDetailEntity" useGeneratedKeys="true" keyProperty="transItemId">
 		insert into mall_goods_transport_info_detail(
 			`way_status`,
 			`sku`,

+ 3 - 0
kmall-admin/src/main/webapp/WEB-INF/page/shop/goodstransportinfodetail.html

@@ -19,6 +19,9 @@
                 <i-button @click="reloadSearch">重置</i-button>
             </div>
             <div class="buttons-group">
+                <a href="../statics/file/goods_transport_info_detail_import_yyyymmdd.v1.0.0.xls">
+                    <i-button type="ghost" icon="ios-cloud-upload-outline">在途商品明细模板下载</i-button>
+                </a>&nbsp;&nbsp;&nbsp;
                 <i-col style="display: inline-grid;">
                     <Upload :show-upload-list="false" :on-success="uploadExcelSuccess" :on-error="uploadExcelError" :on-format-error="uploadExcelFormatError"
                             :format="['xls','xlsx']"

+ 4 - 2
kmall-admin/src/main/webapp/js/shop/goodstransportinfodetail.js

@@ -60,8 +60,10 @@ let vm = new Vue({
         title: null,
 		goodsTransportInfoDetail: {},
         ruleValidate: {
-            sku:{required: true, message: 'sku不能为空', trigger: 'blur'}
-            // wayStatus:{required: true, message: '是否在途不能为空', trigger: 'blur'}
+            sku:{required: true, message: 'sku不能为空', trigger: 'blur'},
+            supplierId:{required: true, message: '供应商id不能为空', trigger: 'blur'},
+            originCountry:{required: true, message: '原产地不能为空', trigger: 'blur'},
+            num:{required: true, message: '数量不能为空', trigger: 'blur'}
         },
 		q: {
             wayStatus: null,

BIN
kmall-admin/src/main/webapp/statics/file/goods_transport_info_detail_import_yyyymmdd.v1.0.0.xls