Browse Source

sku规格新增导入

fgd 1 year ago
parent
commit
8ed8a57ec3

+ 12 - 0
sd-business/src/main/java/com/sd/business/controller/sku/SkuSpecController.java

@@ -3,16 +3,20 @@ package com.sd.business.controller.sku;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.sd.business.entity.sku.dto.SkuSpecDto;
+import com.sd.business.entity.sku.dto.SkuSpecImportDataDto;
 import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
 import com.sd.business.entity.sku.vo.SkuSpecVo;
 import com.sd.business.service.sku.SkuSpecService;
+import com.sd.framework.util.excel.util.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * <p>
@@ -79,4 +83,12 @@ public class SkuSpecController {
         return skuSpecService.getSkuInventoryQuantity(dto.getId());
     }
 
+    /**
+     * sku规格导入
+     */
+    @PostMapping("/skuSpecImport")
+    public void skuSpecImport(MultipartFile file) {
+        List<SkuSpecImportDataDto> list = ExcelUtil.read(file, SkuSpecImportDataDto.class);
+        skuSpecService.skuSpecImport(list);
+    }
 }

+ 56 - 0
sd-business/src/main/java/com/sd/business/entity/sku/dto/SkuSpecImportDataDto.java

@@ -0,0 +1,56 @@
+package com.sd.business.entity.sku.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * sku规格导入入参实体
+ */
+@Getter
+@Setter
+public class SkuSpecImportDataDto {
+
+    /**
+     * sku规格品号
+     */
+    @ExcelProperty("SKU")
+    private String skuSpecCode;
+
+    /**
+     * sku规格
+     */
+    @ExcelProperty("规格")
+    private String spec;
+
+    @ExcelProperty("图稿类型")
+    private String machinedPanelStr;
+
+    @ExcelProperty("图稿文件")
+    private String machinedPanelFileStr;
+
+    @ExcelProperty("裸垫品号")
+    private String bomSpecCode;
+    @ExcelProperty("opp膜品号")
+    private String packagingBomSpecCode_1;
+    @ExcelProperty("彩纸品号")
+    private String packagingBomSpecCode_2;
+    @ExcelProperty("松紧圈品号")
+    private String packagingBomSpecCode_3;
+    @ExcelProperty("松紧圈背带")
+    private String packagingBomSpecCode_4;
+    @ExcelProperty("热收缩膜")
+    private String packagingBomSpecCode_5;
+    @ExcelProperty("气泡袋")
+    private String packagingBomSpecCode_6;
+    @ExcelProperty("网包品号")
+    private String packagingBomSpecCode_7;
+    @ExcelProperty("吊牌品号")
+    private String packagingBomSpecCode_8;
+    @ExcelProperty("纸箱")
+    private String packagingBomSpecCode_9;
+    @ExcelProperty("不干胶品号")
+    private String packagingBomSpecCode_10;
+    @ExcelProperty("快递袋")
+    private String deliveryMaterialsBomSpecCode;
+}

+ 7 - 0
sd-business/src/main/java/com/sd/business/service/sku/SkuSpecService.java

@@ -9,6 +9,7 @@ import com.sd.business.entity.order.dto.SkuSpecPackageBomDto;
 import com.sd.business.entity.production.vo.OutBomVo;
 import com.sd.business.entity.sku.bo.SkuSpecBo;
 import com.sd.business.entity.sku.dto.SkuSpecDto;
+import com.sd.business.entity.sku.dto.SkuSpecImportDataDto;
 import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
 import com.sd.business.entity.sku.po.SkuSpec;
 import com.sd.business.entity.sku.vo.SkuSpecVo;
@@ -87,4 +88,10 @@ public interface SkuSpecService extends BaseService<SkuSpec> {
      * @return
      */
     List<OutBomVo> getSkuSpecMaterialList(SkuSpecPackageBomDto dto);
+
+    /**
+     * sku规格导入
+     * @param list
+     */
+    void skuSpecImport(List<SkuSpecImportDataDto> list);
 }

+ 118 - 0
sd-business/src/main/java/com/sd/business/service/sku/impl/SkuSpecServiceImpl.java

@@ -11,6 +11,7 @@ import com.fjhx.tenant.service.dict.DictCommonDataService;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.sd.business.entity.artwork.po.ArtworkLibrary;
 import com.sd.business.entity.board.dto.SkuSpecQuotationDto;
 import com.sd.business.entity.board.vo.SkuSpecQuotationVo;
 import com.sd.business.entity.bom.bo.BomSpecBo;
@@ -26,6 +27,7 @@ import com.sd.business.entity.price.po.PriceBillingStandardDetail;
 import com.sd.business.entity.production.vo.OutBomVo;
 import com.sd.business.entity.sku.bo.SkuSpecBo;
 import com.sd.business.entity.sku.dto.SkuSpecDto;
+import com.sd.business.entity.sku.dto.SkuSpecImportDataDto;
 import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
 import com.sd.business.entity.sku.po.Sku;
 import com.sd.business.entity.sku.po.SkuSpec;
@@ -33,6 +35,8 @@ import com.sd.business.entity.sku.po.SkuSpecLink;
 import com.sd.business.entity.sku.vo.SkuSpecVo;
 import com.sd.business.entity.warehouse.constant.WarehouseConstant;
 import com.sd.business.mapper.sku.SkuSpecMapper;
+import com.sd.business.service.artwork.ArtworkLibraryService;
+import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.department.DepartmentService;
 import com.sd.business.service.inventory.InventoryService;
 import com.sd.business.service.price.PriceBillingStandardDetailService;
@@ -43,6 +47,7 @@ import com.sd.business.service.sku.SkuSpecService;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -82,6 +87,12 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
     @Autowired
     private DictCommonDataService dictCommonDataService;
 
+    @Autowired
+    private BomSpecService bomSpecService;
+
+    @Autowired
+    private ArtworkLibraryService artworkLibraryService;
+
     @Override
     public Page<SkuSpecVo> getPage(SkuSpecSelectDto dto) {
         IWrapper<SkuSpec> wrapper = getWrapper();
@@ -183,6 +194,113 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
 
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void skuSpecImport(List<SkuSpecImportDataDto> list) {
+        if (ObjectUtil.isEmpty(list)) {
+            throw new ServiceException("sku规格信息不能为空");
+        }
+        List<String> skuSpecCodes = list.stream().map(SkuSpecImportDataDto::getSkuSpecCode).collect(Collectors.toList());
+        Map<String, SkuSpec> skuSpecMap = this.mapKEntity(SkuSpec::getCode, q -> q.in(SkuSpec::getCode, skuSpecCodes));
+        List<ArtworkLibrary> artworkLibraryList = artworkLibraryService.list();
+        List<BomSpec> bomSpecList = bomSpecService.list();
+        Map<String, BomSpec> bomSpecMap = bomSpecList.stream().collect(Collectors.toMap(BomSpec::getCode, item -> item, (v1, v2) -> v2));
+        List<SkuSpecLink> skuSpecLinkList = new ArrayList<>();
+
+        for (SkuSpecImportDataDto dto : list) {
+            SkuSpec skuSpec = skuSpecMap.get(dto.getSkuSpecCode());
+            if (skuSpec == null) {
+                continue;
+            }
+            // 保存图稿类型
+            String machinedPanelStr = dto.getMachinedPanelStr();
+            if (StrUtil.isNotBlank(machinedPanelStr)) {
+                machinedPanelStr = machinedPanelStr.replace(" ", "");
+                if (machinedPanelStr.startsWith("激光体位线") || machinedPanelStr.startsWith("激光图案")) {
+                    skuSpec.setMachinedPanel("10");
+                } else if (machinedPanelStr.startsWith("激光logo")) {
+                    skuSpec.setMachinedPanel("20");
+                }
+            }
+            // 保存图稿文件
+            String machinedPanelFileStr = dto.getMachinedPanelFileStr();
+            if (StrUtil.isNotBlank(machinedPanelFileStr)) {
+                String spec = dto.getSpec();
+                String sp = "";
+                if (StrUtil.isNotBlank(spec)) {
+                    sp = spec.split("\\*")[1].replace("cm", "").replace(" ", "");
+                }
+                for (ArtworkLibrary artworkLibrary : artworkLibraryList) {
+                    String[] ar = artworkLibrary.getArtworkName().split("_");
+                    String ar0 = ar[0];
+                    String arl = ar[ar.length - 1];
+
+                    if (machinedPanelFileStr.startsWith(ar0) && arl.equals(sp)) {
+                        skuSpec.setArtworkLibraryId(artworkLibrary.getId());
+                        break;
+                    } else if (machinedPanelFileStr.equals(artworkLibrary.getArtworkName())){
+                        skuSpec.setArtworkLibraryId(artworkLibrary.getId());
+                        break;
+                    }
+                }
+            }
+            // 保存裸垫
+            BomSpec bomSpec = bomSpecMap.get(dto.getBomSpecCode());
+            if (bomSpec != null) {
+                skuSpec.setBomSpecId(bomSpec.getId());
+                skuSpec.setLength(bomSpec.getLength());
+                skuSpec.setWidth(bomSpec.getWidth());
+                skuSpec.setHeight(bomSpec.getHeight());
+                skuSpec.setNetWeight(bomSpec.getNetWeight());
+            }
+            // 保存包材
+            List<String> bomSpecCodes = new ArrayList<>();
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_1());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_2());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_3());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_4());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_5());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_6());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_7());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_8());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_9());
+            bomSpecCodes.add(dto.getPackagingBomSpecCode_10());
+            bomSpecCodes.removeAll(Collections.singleton(null));
+            for (String bomSpecCode : bomSpecCodes) {
+                BomSpec packagingBomSpec = bomSpecMap.get(bomSpecCode);
+                if (packagingBomSpec != null) {
+                    SkuSpecLink skuSpecLink = new SkuSpecLink();
+                    skuSpecLink.setSkuId(skuSpec.getSkuId());
+                    skuSpecLink.setSkuSpecId(skuSpec.getId());
+                    skuSpecLink.setBomSpecId(packagingBomSpec.getId());
+                    skuSpecLink.setDepartmentId(0L);
+                    skuSpecLink.setType(1);
+                    skuSpecLink.setQuantity(BigDecimal.ONE);
+                    skuSpecLinkList.add(skuSpecLink);
+                }
+            }
+            // 保存快递包材
+            BomSpec deliveryMaterialsBomSpec = bomSpecMap.get(dto.getDeliveryMaterialsBomSpecCode());
+            if (deliveryMaterialsBomSpec != null) {
+                SkuSpecLink skuSpecLink = new SkuSpecLink();
+                skuSpecLink.setSkuId(skuSpec.getSkuId());
+                skuSpecLink.setSkuSpecId(skuSpec.getId());
+                skuSpecLink.setBomSpecId(deliveryMaterialsBomSpec.getId());
+                skuSpecLink.setDepartmentId(0L);
+                skuSpecLink.setType(2);
+                skuSpecLink.setQuantity(BigDecimal.ONE);
+                skuSpecLinkList.add(skuSpecLink);
+            }
+        }
+
+        this.updateBatchById(skuSpecMap.values());
+        if (!skuSpecLinkList.isEmpty()) {
+            List<Long> skuSpecIds = skuSpecLinkList.stream().map(SkuSpecLink::getSkuSpecId).distinct().collect(Collectors.toList());
+            skuSpecLinkService.remove(q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds));
+            skuSpecLinkService.saveBatch(skuSpecLinkList);
+        }
+    }
+
     @Override
     public List<SkuSpecQuotationVo> getSkuSpecQuotationList(SkuSpecQuotationDto dto) {
         Assert.notNull(dto.getDepartmentId(), "事业部id不能为空");