jiangping
2023-09-19 b96db512032a8a8889a28afb654cf360c63ad226
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -81,9 +81,9 @@
    @Override
    public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",baseGoods.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在");
        }
//        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",baseGoods.getName()))>0){
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在");
//        }
        Integer integer = baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO));
        BaseGoods insert = new BaseGoods();
@@ -150,7 +150,12 @@
    @Override
    public void deleteById(Integer id) {
        baseGoodsMapper.deleteById(id);
        BaseGoods model = new BaseGoods();
        model.setId(id);
        model.setEditDate(new Date());
        model.setIsdeleted(Constants.ONE);
        updateById(model);
//        baseGoodsMapper.deleteById(id);
    }
    @Override
@@ -164,7 +169,10 @@
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        baseGoodsMapper.deleteBatchIds(ids);
        for(Integer id : ids){
            deleteById(id);
        }
//        baseGoodsMapper.deleteBatchIds(ids);
    }
@@ -173,11 +181,11 @@
    public void update(BaseGoodsCreateOrUpdateRequest baseGoods) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>()
                .eq("ISDELETED",Constants.ZERO).ne("id",baseGoods.getId())
                .eq("name",baseGoods.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在");
        }
//        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>()
//                .eq("ISDELETED",Constants.ZERO).ne("id",baseGoods.getId())
//                .eq("name",baseGoods.getName()))>0){
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在");
//        }
        UpdateWrapper<BaseGoods> wrapper = new UpdateWrapper<>();
        wrapper.lambda()
@@ -301,16 +309,16 @@
        MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId)
                .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId)
                .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId)
                .selectAll(BaseGoods.class)
                .selectAs(Brand::getName,BaseGoodsDTO::getBrandName)
                .selectAs(BaseCategory::getSortnum,BaseGoodsDTO::getCategoryName)
                .selectAs(BaseCategory::getName,BaseGoodsDTO::getCategoryName)
                .eq(BaseGoods::getId,id);
        BaseGoodsDTO baseGoodsDTO = baseGoodsJoinMapper.selectJoinOne(BaseGoodsDTO.class, queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        baseGoodsDTO.setImgfullurl(prefixUrl+baseGoodsDTO.getImgurl());
        baseGoodsDTO.setImgfullurl(StringUtils.isNotBlank(baseGoodsDTO.getImgurl()) ? prefixUrl+baseGoodsDTO.getImgurl() : null);
        List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>()
                .eq("OBJ_ID", id)
@@ -373,21 +381,8 @@
    @Override
    public PageData<BaseGoods> findCompanyPage(PageWrap<BaseGoods> pageWrap ,Integer companyId) {
        //查询企业已经存在的商品
        List<Integer> collect = new ArrayList<>();
        if(Objects.nonNull(companyId)){
            QueryWrapper<Goods> goodsQuery = new QueryWrapper<>();
            goodsQuery.lambda().eq(Goods::getIsdeleted,Constants.ZERO)
                    .eq(Goods::getCompanyId,companyId)
                    .isNotNull(Goods::getGoodsId);
            List<Goods> goods = goodsMapper.selectList(goodsQuery);
            if (CollectionUtils.isEmpty(goods)){
                 collect = goods.stream().map(s -> s.getGoodsId()).collect(Collectors.toList());
            }
        }
    public PageData<BaseGoods> findCompanyPage(PageWrap<BaseGoods> pageWrap) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        pageWrap.getModel().setIsdeleted(Constants.ZERO);
        IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
@@ -404,8 +399,7 @@
                .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())
                .notIn(!CollectionUtils.isEmpty(collect),BaseGoods::getId, collect);
                .notExists(user.getType().equals(Constants.UserType.COMPANY.getKey())," select 1 from goods g where g.GOODS_ID = t.id and g.TYPE = 1  and  g.company_id = "+user.getCompanyId()+"  ");
        queryWrapper.orderByDesc(Goods::getId);
        PageData<BaseGoods> pageData =PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper));
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
@@ -435,9 +429,10 @@
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            //处理批量上传
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
            String platformDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
            String basePath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
                    + proDir + File.separator ;
                    + proDir + platformDir ;
            OssModel ossModel = baseDataService.initOssModel();
            for (int index = 0; index < dataList.size(); index++) {
                BaseGoodsImportDTO  s = dataList.get(index);
@@ -477,11 +472,12 @@
                QueryWrapper<Brand> brandQuery = new QueryWrapper<>();
                brandQuery.lambda()
                        .eq(Brand::getType,Constants.ONE)
                        .eq(Brand::getName,s.getBrandName());
                brandQuery.lambda()
                        .eq(Brand::getIsdeleted,Constants.ZERO);
                brandQuery.lambda()
                        .eq(Brand::getType,Constants.ZERO);
                        .eq(Brand::getType,Constants.ONE);
                Brand brand = brandMapper.selectOne(brandQuery.last("limit 1"));
                if (Objects.isNull(brand)){
@@ -495,7 +491,7 @@
                        File[]  files = dir.listFiles();
                        if(files!=null && files.length>0){
                            for(File f:files){
                                if(StringUtils.isBlank(baseCategory.getImgurl()) && isImgFile(f)){
                                if(isImgFile(f)){
                                    //取第一张图片作为列表图
                                    baseGoods.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
                                }
@@ -526,7 +522,7 @@
                    for(int i=0;i<mulFiles.size();i++){
                        String str = mulFiles.get(i);
                        Multifile f = new Multifile();
                        f.setObjType(Constants.ZERO);
                        f.setObjType(Constants.ONE);
                        f.setName(str);
                        f.setType(Constants.ZERO);
                        f.setObjId(baseGoods.getId());
@@ -542,30 +538,38 @@
                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)) {
                    for (int i = 0; i < collect.size(); i++) {
                        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())) {
                            List<String> s2 = collect.get(i);
                            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);
                        .stream()
                        .map(s1 -> Arrays.asList(s1.split("[:,:]")) )
                        .filter(s1->!CollectionUtils.isEmpty(s1))
                        .collect(Collectors.toList());
                if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())) {
                    for (int i = 0; i < baseCategory.getBaseCateParamList().size(); i++) {
                        BaseCateParam baseCateParam = baseCategory.getBaseCateParamList().get(i);
                        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.setGoodsId(baseGoods.getId());
                        if (!CollectionUtils.isEmpty(collect)) {
                            List<String> list = collect.stream()
                                    .filter(s3 -> s3.get(0).equals(baseCateParam.getName()))
                                    .findFirst()
                                    .orElse(new ArrayList<>());
                            baseGoodsParam.setVal(list.size() > 1 ? list.get(1) : null);
                        }
                        baseGoodsParamMapper.insert(baseGoodsParam);
                    }
                    ;
                }