From 116e919af930037f4e5ece0b085e22feb0d50e5d Mon Sep 17 00:00:00 2001 From: jiaosong <jiaosong6760@dingtalk.com> Date: 星期一, 11 九月 2023 14:33:37 +0800 Subject: [PATCH] #平台素材库 --- server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java | 245 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 235 insertions(+), 10 deletions(-) diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java index 1ec2edb..8a62b1f 100644 --- a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java +++ b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java @@ -1,23 +1,36 @@ package com.doumee.service.business.impl; +import com.doumee.biz.system.SystemDictDataBiz; +import com.doumee.core.constants.ResponseStatus; +import com.doumee.core.exception.BusinessException; +import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; +import com.doumee.core.utils.Constants; +import com.doumee.core.utils.PinYinUtil; import com.doumee.core.utils.Utils; -import com.doumee.dao.business.BaseGoodsMapper; +import com.doumee.dao.business.*; import com.doumee.dao.business.join.BaseGoodsJoinMapper; -import com.doumee.dao.business.model.BaseGoods; -import com.doumee.dao.business.model.Goods; +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.BaseGoodsParamCreatRequest; import com.doumee.service.business.BaseGoodsService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.util.Date; import java.util.List; +import java.util.Objects; /** * 绱犳潗搴�-鍟嗗搧淇℃伅琛⊿ervice瀹炵幇 @@ -34,10 +47,90 @@ @Autowired private BaseGoodsJoinMapper baseGoodsJoinMapper; + @Autowired + private BaseGoodsParamMapper baseGoodsParamMapper; + + + @Autowired + private MultifileMapper multifileMapper; + + @Autowired + @Lazy + private SystemDictDataBiz systemDictDataBiz; + + @Autowired + private BrandMapper brandMapper; + + @Autowired + private GoodsMapper goodsMapper; + @Override - public Integer create(BaseGoods baseGoods) { - baseGoodsMapper.insert(baseGoods); - return baseGoods.getId(); + 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()+"銆戝凡瀛樺湪"); + } + + Integer integer = baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO)); + BaseGoods insert = new BaseGoods(); + insert.setCreator(user.getId()); + insert.setCreateDate(new Date()); + insert.setEditor(user.getId()); + insert.setEditDate(new Date()); + insert.setIsdeleted(Constants.ZERO); + insert.setRemark(baseGoods.getRemark()); + insert.setName(baseGoods.getName()); + insert.setStatus(Constants.ZERO); + insert.setSortnum(integer+Constants.ONE); + insert.setImgurl(baseGoods.getImgurl()); + insert.setCategoryId(baseGoods.getCategoryId()); + insert.setBrandId(baseGoods.getBrandId()); + insert.setZdPrice(baseGoods.getZdPrice()); + insert.setPrice(baseGoods.getPrice()); + insert.setContent(baseGoods.getContent()); + insert.setPinyin(PinYinUtil.getFullSpell(insert.getName())); + insert.setShortPinyin(PinYinUtil.getFirstSpell(insert.getName())); + baseGoodsMapper.insert(insert); + + + List<Multifile> multifileList = baseGoods.getMultifileList(); + if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ + for (int i = 0; i < multifileList.size(); i++) { + Multifile multifile = multifileList.get(i); + multifile.setCreator(user.getId()); + multifile.setCreateDate(new Date()); + multifile.setIsdeleted(Constants.ZERO); + multifile.setSortnum(i+Constants.ONE); + multifile.setObjId(insert.getId()); + multifile.setType(Constants.ZERO); + multifile.setObjType(Constants.ONE); + multifileMapper.insert(multifile); + } + } + + + List<BaseGoodsParamCreatRequest> goodsParamList = baseGoods.getBaseGoodsParamList(); + if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ + for (int i = 0; i < goodsParamList.size(); i++) { + BaseGoodsParamCreatRequest param = goodsParamList.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(param.getName()); + baseGoodsParam.setRemark(param.getRemark()); + baseGoodsParam.setStatus(Constants.ZERO); + baseGoodsParam.setSortnum(i+Constants.ONE); + baseGoodsParam.setPramaId(param.getPramaId()); + baseGoodsParam.setVal(param.getVal()); + baseGoodsParam.setGoodsId(insert.getId()); + baseGoodsParamMapper.insert(baseGoodsParam); + } + } + + return insert.getId(); } @Override @@ -57,6 +150,102 @@ return; } baseGoodsMapper.deleteBatchIds(ids); + } + + + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + @Override + 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()+"銆戝凡瀛樺湪"); + } + + UpdateWrapper<BaseGoods> wrapper = new UpdateWrapper<>(); + wrapper.lambda() + .eq(BaseGoods::getId,baseGoods.getId()) + .set(BaseGoods::getName,baseGoods.getName()) + .set(BaseGoods::getName,baseGoods.getName()) + .set(BaseGoods::getName,baseGoods.getName()) + .set(BaseGoods::getName,baseGoods.getName()); + baseGoodsMapper.update(null,wrapper); + + multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",baseGoods.getId())); + List<Multifile> multifileList = baseGoods.getMultifileList(); + if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ + for (int i = 0; i < multifileList.size(); i++) { + Multifile multifile = multifileList.get(i); + multifile.setCreator(user.getId()); + multifile.setCreateDate(new Date()); + multifile.setIsdeleted(Constants.ZERO); + multifile.setSortnum(i+Constants.ONE); + multifile.setObjId(baseGoods.getId()); + multifile.setType(Constants.ZERO); + multifile.setObjType(Constants.ONE); + multifileMapper.insert(multifile); + } + } + baseGoodsParamMapper.delete(new QueryWrapper<BaseGoodsParam>().eq("GOODS_ID",baseGoods.getId())); + List<BaseGoodsParamCreatRequest> goodsParamList = baseGoods.getBaseGoodsParamList(); + if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ + for (int i = 0; i < goodsParamList.size(); i++) { + BaseGoodsParamCreatRequest param = goodsParamList.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(param.getName()); + baseGoodsParam.setRemark(param.getRemark()); + baseGoodsParam.setStatus(Constants.ZERO); + baseGoodsParam.setSortnum(i+Constants.ONE); + baseGoodsParam.setPramaId(param.getPramaId()); + baseGoodsParam.setVal(param.getVal()); + baseGoodsParam.setGoodsId(baseGoods.getId()); + baseGoodsParamMapper.insert(baseGoodsParam); + } + } + } + + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + @Override + public void updateStatusByIds(List<Integer> idList, Integer status) { + if (CollectionUtils.isEmpty(idList)){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鐘舵�佷笉鑳戒负绌�"); + } + idList.forEach(s->updateStatusByIds(s,status)); + + } + + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + @Override + public void updateStatusByIds(Integer id, Integer status) { + + if (Objects.isNull(status)){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鐘舵�佷笉鑳戒负绌�"); + } + if (Constants.equalsInteger(status,Constants.ZERO)){ + BaseGoods baseGoods = new BaseGoods(); + baseGoods.setId(id); + baseGoods.setStatus(status); + baseGoodsMapper.updateById(baseGoods); + }else if (Constants.equalsInteger(status,Constants.ONE)){ + BaseGoods baseGoods = new BaseGoods(); + baseGoods.setId(id); + baseGoods.setStatus(status); + baseGoodsMapper.updateById(baseGoods); + + UpdateWrapper<Goods> goodsUpdate = new UpdateWrapper<>(); + goodsUpdate.lambda() + .eq(Goods::getType,Constants.ONE) + .eq(Goods::getGoodsId,id) + .set(Goods::getStatus,Constants.ONE); + goodsMapper.update(null,goodsUpdate); + } } @Override @@ -80,6 +269,41 @@ } @Override + public BaseGoodsDTO findByIdBaseGoods(Integer id) { + + MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>(); + + queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId) + .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId) + .selectAll(BaseGoods.class) + .selectAs(Brand::getName,BaseGoodsDTO::getBrandName) + .selectAs(BaseCategory::getSortnum,BaseGoodsDTO::getCategoryName); + + BaseGoodsDTO baseGoodsDTO = baseGoodsJoinMapper.selectJoinOne(BaseGoodsDTO.class, queryWrapper); + String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode() + + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode(); + baseGoodsDTO.setImgfullurl(prefixUrl+baseGoodsDTO.getImgurl()); + + List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>() + .eq("OBJ_ID", id) + .eq("OBJ_TYPE", Constants.ONE)); + if (!CollectionUtils.isEmpty(multifiles)){ + multifiles.forEach(s->s.setFilefullurl(prefixUrl+s.getFileurl())); + } + baseGoodsDTO.setMultifileList(multifiles); + + QueryWrapper<BaseGoodsParam> baseGoodsParamQuery = new QueryWrapper<>(); + baseGoodsParamQuery.select("base_goods_param.*,(select name from base_cate_param bcp where (bcp.id = base_goods_param.PRAMA_ID)) as paramName") + .lambda() + .eq(BaseGoodsParam::getGoodsId,id) + .orderByAsc(BaseGoodsParam::getSortnum); + List<BaseGoodsParam> baseGoodsParams = baseGoodsParamMapper.selectList(baseGoodsParamQuery); + baseGoodsDTO.setBaseGoodsParamList(baseGoodsParams); + return baseGoodsDTO; + + } + + @Override public BaseGoods findOne(BaseGoods baseGoods) { QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods); return baseGoodsMapper.selectOne(wrapper); @@ -98,7 +322,7 @@ Utils.MP.blankToNull(pageWrap.getModel()); if (pageWrap.getModel().getId() != null) { - queryWrapper.eq(BaseGoods::getId, pageWrap.getModel().getId()); + queryWrapper.like(BaseGoods::getId, pageWrap.getModel().getId()); } if (pageWrap.getModel().getName() != null) { queryWrapper.eq(BaseGoods::getName, pageWrap.getModel().getName()); @@ -106,15 +330,16 @@ if (pageWrap.getModel().getStatus() != null) { queryWrapper.eq(BaseGoods::getStatus, pageWrap.getModel().getStatus()); } - - if (pageWrap.getModel().getCategoryId() != null) { queryWrapper.eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId()); } if (pageWrap.getModel().getBrandId() != null) { queryWrapper.eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId()); } - + queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId) + .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId) + .selectAs(Brand::getName,BaseGoods::getBrandName) + .selectAs(BaseCategory::getSortnum,BaseGoods::getCategoryName); queryWrapper.orderByDesc(Goods::getId); return PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper)); } -- Gitblit v1.9.3