From 4f912f23e61912cb3195ca168f23bb521bf8b309 Mon Sep 17 00:00:00 2001 From: Mr.Shi <1878285526@qq.com> Date: 星期四, 21 九月 2023 13:37:16 +0800 Subject: [PATCH] 企业端 --- server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java | 102 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 75 insertions(+), 27 deletions(-) diff --git a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java index 16e0905..02cde3d 100644 --- a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java +++ b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java @@ -29,6 +29,8 @@ import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -64,6 +66,8 @@ @Autowired private CategoryMapper categoryMapper; @Autowired + private BaseCategoryMapper baseCategoryMapper; + @Autowired private CateAttrMapper cateAttrMapper; @Autowired private CateParamMapper cateParamMapper; @@ -82,7 +86,8 @@ @Autowired private CateParamSelectMapper cateParamSelectMapper; - + @Autowired + private RedisTemplate redisTemplate; @Override @@ -130,6 +135,8 @@ return goods.getId(); } + + @Async @Override @Transactional( rollbackFor = {Exception.class, BusinessException.class}) public Integer createPlat(GoodCreatePlatRequest param){ @@ -153,6 +160,11 @@ if(category.getPlatCateId() == null){ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇峰墠寰�銆愮被鍒鐞嗐�戝厛鍏宠仈骞冲彴绫诲埆锛�"); } + BaseCategory baseCategory = baseCategoryMapper.selectById(category.getPlatCateId()); + if(baseCategory == null){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇峰墠寰�銆愮被鍒鐞嗐�戝厛鍏宠仈骞冲彴绫诲埆锛�"); + } + BaseGoods bp = new BaseGoods(); bp.setCategoryId(category.getPlatCateId()); bp.setIsdeleted(Constants.ZERO); @@ -175,24 +187,39 @@ // 濡傛灉閫夋嫨骞冲彴鍟嗗搧鍜屾煡璇㈢粨鏋滃涓嶄笂锛屾彁绀洪敊璇� throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋纭�夋嫨骞冲彴鍟嗗搧锛�"); } - for(BaseGoods model : goodsList){ - //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝� - Goods goods = initGoodsPlatParam(user,model,param); - if(goods == null){ - continue; + List<Multifile> multifileList = new ArrayList<>(); + List<GoodsParam> goodsParamList = new ArrayList<>(); + try{ + for(BaseGoods model : goodsList){ + //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝� + //鍒嗙被鍔犱环绯绘暟 + + model.setCateRatePrice(baseCategory.getPriceRate()); + Goods goods = initGoodsPlatParam(user,model,param); + if(goods == null){ + continue; + } + goodsMapper.insert(goods); + //寮�濮嬪鐞嗛檮浠� + dealPlatMultifule(goods.getId(),user,model,multifileList); + //寮�濮嬪鐞嗗弬鏁伴厤缃� + dealPlatGoodsParam(model,goods,user,goodsParamList); } - goodsMapper.insert(goods); - //寮�濮嬪鐞嗛檮浠� - dealPlatMultifule(goods.getId(),user,model); - //寮�濮嬪鐞嗗弬鏁伴厤缃� - dealPlatGoodsParam(model,goods,user); + if(multifileList.size()>0){ + multifileMapper.insertBatch(multifileList); + } + if(goodsParamList.size()>0){ + goodsParamMapper.insertBatch(goodsParamList); + } + }catch (Exception e){ + e.printStackTrace(); + }finally { + redisTemplate.opsForValue().set(user.getCompanyId()+Constants.OPEN_SYNC_SWITCH,false); } - - return 1; } - private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) { + private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user,List<GoodsParam> paramList) { BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); baseGoodsParam.setGoodsId(model.getId()); baseGoodsParam.setIsdeleted(Constants.ZERO); @@ -220,7 +247,8 @@ goodsParam.setVal(bgParam.getVal()); goodsParam.setName(bgParam.getName()); goodsParam.setPramaId(Objects.isNull(cateParam)?null:cateParam.getId()); - goodsParamMapper.insert(goodsParam); + paramList.add(goodsParam); +// goodsParamMapper.insert(goodsParam); } } } @@ -257,7 +285,7 @@ /** * 寮�濮嬪鐞嗗钩鍙板晢鍝佸叧鑱旈檮浠讹紝澶嶅埗涓�濂楀埌浼佷笟鍟嗗搧涓� */ - private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) { + private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) { Multifile f = new Multifile(); f.setObjId(model.getId()); f.setIsdeleted(Constants.ZERO); @@ -276,7 +304,8 @@ multifile.setName(multifile.getName()); multifile.setSortnum(multifile.getSortnum()); multifile.setCompanyId(user.getCompanyId()); - multifileMapper.insert(multifile); + fileList.add(multifile); +// multifileMapper.insert(multifile); } } } @@ -288,13 +317,14 @@ return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING); } } + throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"鏁版嵁寮傚父璇峰埛鏂伴噸璇�"); } //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠� -// if(model.getCateRatePrice()==null){ -// model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); -// } + if(model.getCateRatePrice()==null){ + model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); + } //杩斿洖 .multiply(model.getCateRatePrice()) - return (Constants.formatBigdecimal(model.getPrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING); + return (Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING); } @@ -509,7 +539,7 @@ throw new BusinessException(ResponseStatus.DATA_EMPTY); } //鎷夊紡鍟嗗搧 涓� 涓婃灦鏃讹紝闇�瑕侀檺鍒� 骞冲彴鍟嗗搧鏄惁宸蹭笅鏋� - if(dbGoods.getType().equals(Constants.goodsType.PULL)&&goods.getStatus().equals(Constants.ZERO)){ + if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&goods.getStatus().equals(Constants.ZERO)){ BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); if(Objects.isNull(baseGoods)){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌骞冲彴鍟嗗搧淇℃伅"); @@ -547,7 +577,7 @@ continue; } //鎷夊紡鍟嗗搧 涓� 涓婃灦鏃讹紝闇�瑕侀檺鍒� 骞冲彴鍟嗗搧鏄惁宸蹭笅鏋� - if(dbGoods.getType().equals(Constants.goodsType.PULL)&&batchDisableDTO.getStatus().equals(Constants.ZERO)){ + if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&batchDisableDTO.getStatus().equals(Constants.ZERO)){ BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); if(Objects.isNull(baseGoods)||!baseGoods.getStatus().equals(Constants.ZERO)){ errNum++; @@ -751,8 +781,8 @@ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍝佺墝鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒"); } if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){ - throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+m.getName()+"銆戝凡瀛樺湪"); - }; + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(num)+"銆戣銆�"+m.getName()+"銆戝凡瀛樺湪"); + } Goods newModel = new Goods(); newModel.setRemark(m.getId()); newModel.setCategoryId(cate.getId()); @@ -1063,11 +1093,12 @@ String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); goodsIPage.getRecords().forEach(i->{ + i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl()); i.setPrefixUrl(prefixUrl); i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM "))); i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>() .eq("GOODS_ID",i.getId()) - .apply(" name in ( select cp.NAME from cate_param cp where cp.CATEGORY_ID = "+i.getCategoryId()+" and cp.ISSHOW = 1 and cp.ISDELETED = 0 and cp.STATUS = 0 ) ") .orderByAsc(" SORTNUM "))); }); return PageData.from(goodsIPage); @@ -1108,12 +1139,29 @@ String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); goodsList.forEach(i->{ + i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl()); i.setPrefixUrl(prefixUrl); i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM "))); - i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM "))); + i.setGoodsParamList(goodsParamMapper.selectList( + new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()) + .apply(" name in ( select cp.NAME from cate_param cp where cp.CATEGORY_ID = "+i.getCategoryId()+" and cp.ISSHOW = 1 and cp.ISDELETED = 0 and cp.STATUS = 0 ) ") + .orderByAsc(" SORTNUM "))); }); return goodsList; } + + + @Override + @Transactional + public void openSyncSwitch() { + LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + Boolean openSyncSwitch = (Boolean)redisTemplate.opsForValue().get(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH); + if(openSyncSwitch!=null && openSyncSwitch ){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏁版嵁鍚屾涓紝璇风◢鍚庡埛鏂伴噸璇�"); + } + redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH,true); + } } -- Gitblit v1.9.3