jiaosong
2023-09-18 9cce0085b767a7d1431be158fa469308798c0ecc
#联调修改
已添加1个文件
已修改5个文件
188 ■■■■■ 文件已修改
server/platform/src/main/java/com/doumee/api/business/BaseGoodsController.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/dto/BaseGoodsImportDTO.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/BaseGoodsService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/BaseCategoryServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/platform/src/main/java/com/doumee/api/business/BaseGoodsController.java
@@ -10,13 +10,15 @@
import com.doumee.dao.business.model.dto.BaseGoodsCreateOrUpdateRequest;
import com.doumee.dao.business.model.dto.BaseGoodsDTO;
import com.doumee.service.business.BaseGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -143,4 +145,14 @@
        baseGoodsService.update(baseGoods);
        return ApiResponse.success(null);
    }
    @ApiOperation("导入模板")
    @PostMapping("/importExcel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "file", required = true, paramType = "query", dataType = "file", dataTypeClass = File.class),
    })
    @RequiresPermissions("business:basegoods:create")
    public ApiResponse<Integer> importExcel (@ApiParam(value = "file") MultipartFile file) {
        return ApiResponse.success(baseGoodsService.importBaseGoodsBatch(file));
    }
}
server/service/src/main/java/com/doumee/dao/business/model/dto/BaseGoodsImportDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,44 @@
package com.doumee.dao.business.model.dto;
import com.doumee.core.annotation.excel.ExcelColumn;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @author T14
 */
@Data
@ApiModel("参数属性值")
public class BaseGoodsImportDTO {
    @ApiModelProperty(value = "商品ID")
    @ExcelColumn(name="商品ID")
    private String id;
    @ApiModelProperty(value = "商品名称")
    @ExcelColumn(name="商品名称")
    private String name;
    @ApiModelProperty(value = "商品类别")
    @ExcelColumn(name="商品类别")
    private String categoryName;
    @ApiModelProperty(value = "商品品牌")
    @ExcelColumn(name="商品品牌")
    private String brandName;
    @ApiModelProperty(value = "指导价")
    @ExcelColumn(name="指导价")
    private BigDecimal zdPrice;
    @ApiModelProperty(value = "入手价")
    @ExcelColumn(name="入手价")
    private BigDecimal price;
    @ApiModelProperty(value = "产品参数")
    @ExcelColumn(name="产品参数")
    private String baseGoodsParamString;
}
server/service/src/main/java/com/doumee/service/business/BaseGoodsService.java
@@ -5,6 +5,7 @@
import com.doumee.dao.business.model.BaseGoods;
import com.doumee.dao.business.model.dto.BaseGoodsCreateOrUpdateRequest;
import com.doumee.dao.business.model.dto.BaseGoodsDTO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -131,4 +132,13 @@
     * @return long
     */
    long count(BaseGoods baseGoods);
    /**
     * ä¼ä¸šç”¨æˆ·æ‰¹é‡å¯¼å…¥
     * @param file
     * @return
     */
    Integer importBaseGoodsBatch(MultipartFile file);
}
server/service/src/main/java/com/doumee/service/business/impl/BaseCategoryServiceImpl.java
@@ -61,7 +61,7 @@
        BaseCategory baseCategory1 = baseCategoryMapper.selectOne(wrapper);
        if (Objects.nonNull(baseCategory1)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息表");
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息已存在");
        }
        BaseCategory baseCategory2 = new BaseCategory();
        baseCategory2.setCreator(loginUserInfo.getId());
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -1,6 +1,7 @@
package com.doumee.service.business.impl;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.annotation.excel.ExcelImporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -14,6 +15,7 @@
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.model.dto.BaseGoodsCreateOrUpdateRequest;
import com.doumee.dao.business.model.dto.BaseGoodsDTO;
import com.doumee.dao.business.model.dto.BaseGoodsImportDTO;
import com.doumee.dao.business.model.dto.BaseGoodsParamCreatRequest;
import com.doumee.service.business.BaseGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -21,6 +23,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,16 +31,20 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * ç´ æåº“-商品信息表Service实现
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/07 11:41
 */
@Slf4j
@Service
public class BaseGoodsServiceImpl implements BaseGoodsService {
@@ -64,6 +71,10 @@
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private BaseCategoryMapper baseCategoryMapper;
    @Override
    public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) {
@@ -333,7 +344,7 @@
                    .selectAs(BaseCategory::getName,BaseGoods::getCategoryName)
                    .eq(BaseGoods::getIsdeleted, Constants.ZERO)
                    .like(StringUtils.isNotBlank(pageWrap.getModel().getName()), BaseGoods::getName,pageWrap.getModel().getName())
                    .eq(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId())
                    .like(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId())
                    .eq(pageWrap.getModel().getCategoryId()!=null,BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId())
                    .eq(pageWrap.getModel().getBrandId()!=null,BaseGoods::getBrandId, pageWrap.getModel().getBrandId())
                    .eq(pageWrap.getModel().getStatus()!=null,BaseGoods::getStatus, pageWrap.getModel().getStatus());
@@ -353,4 +364,105 @@
        QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods);
        return baseGoodsMapper.selectCount(wrapper);
    }
    @Override
    public Integer importBaseGoodsBatch(MultipartFile file) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        try {
            ExcelImporter ie = new ExcelImporter(file,0,0);
            List<BaseGoodsImportDTO> dataList = ie.getDataList(BaseGoodsImportDTO.class,null);
            if(dataList == null || dataList.size() ==0){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            List<String> comNameList = dataList.stream().map(s -> s.getName().trim()).distinct().collect(Collectors.toList());
            if (!(dataList.size() == comNameList.size())){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品名称有已存在");
            }
//            List<String> collect1 = dataList.stream().filter(s->{
//                if (StringUtils.isBlank(s.getBrandName())){
//                    throw new BusinessException(ResponseStatus.BAD_REQUEST);
//                }else {
//                    return true;
//                }
//            }).map(s -> s.getCategoryName()).collect(Collectors.toList());
//            QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>();
//            wrapper.lambda()
//                    .in(BaseCategory::getName,collect1);
//            List<BaseCategory> baseCategories = baseCategoryMapper.selectList(wrapper);
            dataList.forEach(s->{
                BaseGoods baseGoods = new BaseGoods();
                baseGoods.setCreator(user.getId());
                baseGoods.setCreateDate(new Date());
                baseGoods.setEditor(user.getId());
                baseGoods.setEditDate(new Date());
                baseGoods.setIsdeleted(Constants.ZERO);
                baseGoods.setName(s.getName());
                baseGoods.setStatus(Constants.ZERO);
                if (StringUtils.isBlank(s.getCategoryName())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品类别不可为空");
                }
                QueryWrapper<BaseCategory> categoryQuery = new QueryWrapper<>();
                categoryQuery.lambda()
                    .eq(BaseCategory::getName,s.getCategoryName());
                BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery);
                QueryWrapper<Brand> brandQuery = new QueryWrapper<>();
                brandQuery.lambda()
                        .eq(Brand::getName,s.getBrandName());
                Brand brand = brandMapper.selectOne(brandQuery);
//                baseGoods.setImgurl();
                baseGoods.setCategoryId(baseCategory.getId());
                baseGoods.setBrandId(brand.getId());
                baseGoodsMapper.insert(baseGoods);
                String baseGoodsParamString = s.getBaseGoodsParamString();
                List<List<String>> collect = Arrays.asList(baseGoodsParamString.split("\n"))
                        .stream().map(s1 -> Arrays.asList(s1.split("[:,:]")) ).collect(Collectors.toList());
                if (!CollectionUtils.isEmpty(collect)){
                    Integer i = 0;
                    collect.forEach(s2->{
                        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){
                            BaseCateParam baseCateParam = baseCategory.getBaseCateParamList()
                                    .stream().filter(s3 -> s3.getName().equals(s2.get(0))).findFirst()
                                    .orElseThrow(()->new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"配置参数不存在"));
                            BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
                            baseGoodsParam.setCreator(user.getId());
                            baseGoodsParam.setCreateDate(new Date());
                            baseGoodsParam.setEditor(user.getId());
                            baseGoodsParam.setEditDate(new Date());
                            baseGoodsParam.setIsdeleted(Constants.ZERO);
                            baseGoodsParam.setName(baseCateParam.getName());
                            baseGoodsParam.setRemark(baseCateParam.getRemark());
                            baseGoodsParam.setStatus(Constants.ZERO);
                            baseGoodsParam.setSortnum(i+Constants.ONE);
                            baseGoodsParam.setPramaId(baseCateParam.getId());
                            baseGoodsParam.setVal(s2.size() > 1 ? s2.get(1) : null );
                            baseGoodsParam.setGoodsId(baseGoods.getId());
                            baseGoodsParamMapper.insert(baseGoodsParam);
                        }
                    });
                }
            });
        }catch (Exception e) {
            log.error(String.format("批量插入异常%s ",e.getMessage()));
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),e.getMessage());
        }finally {
        }
        return null;
    }
}
server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java
@@ -158,7 +158,7 @@
        if (Objects.isNull(user.getCompanyId())) {
            wrapper.lambda().eq(Brand::getType,Constants.ONE);
        }else {
            wrapper.lambda().eq(Brand::getType,brand.getCompanyId())
            wrapper.lambda().eq(Brand::getCompanyId,brand.getCompanyId())
                    .or().eq(Brand::getType,Constants.ZERO);
        }
        List<Brand> list = brandMapper.selectList(wrapper);