| | |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.join.GoodsJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.business.model.dto.BatchDisableDTO; |
| | | import com.doumee.dao.business.model.dto.GoodCreatePlatRequest; |
| | | import com.doumee.dao.business.model.dto.GoodsRequest; |
| | | import com.doumee.service.business.GoodsService; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 商品信息表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private GoodsJoinMapper goodsJoinMapper; |
| | | @Autowired |
| | | private CateParamSelectMapper cateParamSelectMapper; |
| | | |
| | | @Autowired |
| | | private BaseGoodsMapper baseGoodsMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | | goodsParam.setIsdeleted(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setStatus(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | } |
| | | } |
| | | return goods.getId(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Integer companyCreate(Goods goods) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(user.getType()==1){ |
| | | goods.setCompanyId(user.getCompanyId()); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户类别错误,无法进行该操作"); |
| | | } |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).eq("name",goods.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在"); |
| | | } |
| | | goods.setStatus(Constants.ZERO); |
| | | goods.setCreateDate(new Date()); |
| | | goods.setCreator(user.getId()); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | //处理拼音问题 |
| | | goods.setPinyin(PinYinUtil.getFullSpell(goods.getName())); |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goodsMapper.insert(goods); |
| | | |
| | | List<Multifile> multifileList = goods.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(goods.getId()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setObjType(Constants.ZERO); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | List<GoodsParam> goodsParamList = goods.getGoodsParamList(); |
| | | if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ |
| | | for (int i = 0; i < goodsParamList.size(); i++) { |
| | | GoodsParam goodsParam = goodsParamList.get(i); |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | | goodsParam.setIsdeleted(Constants.ZERO); |
| | | goodsParam.setStatus(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(goodsParam.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | } |
| | | } |
| | | return goods.getId(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void companyUpdateById(Goods goods) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(user.getType()==1){ |
| | | goods.setCompanyId(user.getCompanyId()); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户类别错误,无法进行该操作"); |
| | | } |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在"); |
| | | }; |
| | | goods.setStatus(Constants.ZERO); |
| | | goods.setEditDate(new Date()); |
| | | goods.setEditor(user.getId()); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | //处理拼音问题 |
| | | goods.setPinyin(PinYinUtil.getFullSpell(goods.getName())); |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goodsMapper.updateById(goods); |
| | | |
| | | multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId())); |
| | | List<Multifile> multifileList = goods.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(goods.getId()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setObjType(Constants.ZERO); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | goodsParamMapper.delete(new QueryWrapper<GoodsParam>().eq("GOODS_ID",goods.getId())); |
| | | List<GoodsParam> goodsParamList = goods.getGoodsParamList(); |
| | | if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ |
| | | for (int i = 0; i < goodsParamList.size(); i++) { |
| | | GoodsParam goodsParam = goodsParamList.get(i); |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | | goodsParam.setIsdeleted(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setStatus(Constants.ZERO); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(goodsParam.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateByIdInBatch(List<Goods> goodss) { |
| | | if (CollectionUtils.isEmpty(goodss)) { |
| | |
| | | @Override |
| | | public void updateDisableById(Goods goods) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Goods dbGoods = goodsMapper.selectById(goods.getId()); |
| | | if(Objects.isNull(dbGoods)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | //拉式商品 且 上架时,需要限制 平台商品是否已下架 |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL)&&goods.getStatus().equals(Constants.ZERO)){ |
| | | BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); |
| | | if(Objects.isNull(baseGoods)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到平台商品信息"); |
| | | } |
| | | if(!baseGoods.getStatus().equals(Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"平台商品已下架,无法上架"); |
| | | } |
| | | } |
| | | goods.setEditDate(new Date()); |
| | | goods.setEditor(user.getId()); |
| | | goodsMapper.updateById(goods); |
| | | } |
| | | |
| | | /** |
| | | * 批量上下架 |
| | | * @param batchDisableDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String batchUpdateDisableById(BatchDisableDTO batchDisableDTO) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(StringUtils.isBlank(batchDisableDTO.getIds())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请选择对应的商品进行该操作"); |
| | | } |
| | | if(!(batchDisableDTO.getStatus().equals(Constants.ZERO)||batchDisableDTO.getStatus().equals(Constants.ONE))){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"操作类型错误"); |
| | | } |
| | | Integer okNum = 0; |
| | | Integer errNum = 0; |
| | | List<String> goodsList = Arrays.asList(batchDisableDTO.getIds().split(",")); |
| | | for (String goodsId:goodsList) { |
| | | Goods dbGoods = goodsMapper.selectById(goodsId); |
| | | if(Objects.isNull(dbGoods)){ |
| | | errNum++; |
| | | continue; |
| | | } |
| | | //拉式商品 且 上架时,需要限制 平台商品是否已下架 |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL)&&batchDisableDTO.getStatus().equals(Constants.ZERO)){ |
| | | BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); |
| | | if(Objects.isNull(baseGoods)||!baseGoods.getStatus().equals(Constants.ZERO)){ |
| | | errNum++; |
| | | continue; |
| | | } |
| | | } |
| | | dbGoods.setEditDate(new Date()); |
| | | dbGoods.setEditor(user.getId()); |
| | | dbGoods.setStatus(batchDisableDTO.getStatus()); |
| | | goodsMapper.updateById(dbGoods); |
| | | okNum++; |
| | | } |
| | | return "更新成功数量("+okNum+");更新失败数量("+errNum+")"; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Goods findById(Integer id) { |
| | | Goods goods = goodsMapper.selectById(id); |