|
@@ -1,288 +0,0 @@
|
|
|
-package com.abi.qms.platform.service.impl;
|
|
|
-
|
|
|
-import com.abi.qms.platform.dao.entity.BaseBrand;
|
|
|
-import com.abi.qms.platform.dao.entity.BaseMaterial;
|
|
|
-import com.abi.qms.platform.dao.entity.BaseSku;
|
|
|
-import com.abi.qms.platform.dao.enums.ValidEnum;
|
|
|
-import com.abi.qms.platform.dao.mapper.BaseBrandMapper;
|
|
|
-import com.abi.qms.platform.dao.mapper.BaseMaterialMapper;
|
|
|
-import com.abi.qms.platform.dao.mapper.BaseSkuMapper;
|
|
|
-import com.abi.qms.platform.dao.vo.result.BaseSkuVO;
|
|
|
-import com.abi.qms.platform.dto.req.*;
|
|
|
-import com.abi.qms.platform.dto.res.ExcelImportRes;
|
|
|
-import com.abi.qms.platform.dto.res.GetSkuRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListSkuForSelectRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListSkuRes;
|
|
|
-import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
-import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
-import com.abi.qms.platform.service.SkuService;
|
|
|
-import com.abi.task.common.api.exception.BusinessException;
|
|
|
-import com.abi.task.common.api.exception.ErrorCodeEnum;
|
|
|
-import com.abi.task.common.excel.preperties.SkuProperty;
|
|
|
-import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 商品
|
|
|
- * </p>
|
|
|
- * 603版 已作废
|
|
|
- * @author Andy.Tan
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class SkuServiceImpl implements SkuService {
|
|
|
-
|
|
|
- /*@Autowired
|
|
|
- private BaseSkuMapper baseSkuMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BaseBrandMapper baseBrandMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BaseMaterialMapper baseMaterialMapper;
|
|
|
-
|
|
|
- *//**
|
|
|
- * 新增商品
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public void addSku(AddSkuReq req){
|
|
|
- //校验入参
|
|
|
- //TODO
|
|
|
- //查询是否存在商品编号
|
|
|
- QueryWrapper<BaseSku> skuQw = new QueryWrapper<>();
|
|
|
- skuQw.eq("sku_code",req.getSkuCode());
|
|
|
- List<BaseSku> sqkList = baseSkuMapper.selectList(skuQw);
|
|
|
- if(CollectionUtils.isNotEmpty(sqkList)){
|
|
|
- throw new BusinessException("商品编号"+req.getSkuCode()+"已存在,请勿重复创建");
|
|
|
- }
|
|
|
- //查询是否存在商品名称
|
|
|
- skuQw = new QueryWrapper<>();
|
|
|
- skuQw.eq("sku_name",req.getSkuName());
|
|
|
- sqkList = baseSkuMapper.selectList(skuQw);
|
|
|
- if(CollectionUtils.isNotEmpty(sqkList)){
|
|
|
- throw new BusinessException("商品名称"+req.getSkuName()+"已存在,请勿重复创建");
|
|
|
- }
|
|
|
-
|
|
|
- //1-新增
|
|
|
- BaseSku sku = new BaseSku();
|
|
|
- sku.setSkuCode(req.getSkuCode());
|
|
|
- sku.setSkuName(req.getSkuName());
|
|
|
- sku.setBrandCode(req.getBrandCode());
|
|
|
- sku.setSubBrandCode(req.getSubBrandCode());
|
|
|
- baseSkuMapper.insert(sku);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 编辑商品
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public void updateSku(UpdateSkuReq req){
|
|
|
-
|
|
|
- //1-查询商品
|
|
|
- BaseSku sku = baseSkuMapper.selectById(req.getId());
|
|
|
- AssertUtil.isNull(sku,"商品不存在");
|
|
|
-
|
|
|
- //2-修改商品
|
|
|
- sku.setSkuCode(req.getSkuCode());
|
|
|
- sku.setSkuName(req.getSkuName());
|
|
|
- sku.setBrandCode(req.getBrandCode());
|
|
|
- sku.setSubBrandCode(req.getSubBrandCode());
|
|
|
- baseSkuMapper.updateById(sku);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 分页查询商品
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public ListSkuRes listSku(ListSkuReq req){
|
|
|
-
|
|
|
- // 分页查询
|
|
|
- IPage<BaseSkuVO> iPage = baseSkuMapper.listSku(PageUtil.createPage(req), req);
|
|
|
- List<BaseSkuVO> qrFormatList = iPage.getRecords();
|
|
|
-
|
|
|
- // 封装出参、放入分页信息
|
|
|
- ListSkuRes res = new ListSkuRes();
|
|
|
- PageUtil.copyPageInfo(res, iPage);
|
|
|
- List<ListSkuRes.SkuBean> qrFormatBeanList = PojoConverterUtils.copyList(qrFormatList, ListSkuRes.SkuBean.class);
|
|
|
- res.setSkuBeanList(qrFormatBeanList);
|
|
|
-
|
|
|
- return res;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 查询商品明细
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public GetSkuRes getSku(GetSkuReq req){
|
|
|
-
|
|
|
- //1-查询商品对象
|
|
|
- BaseSkuVO baseSkuVO = baseSkuMapper.selectSkuById(req.getId());
|
|
|
- AssertUtil.isNull(baseSkuVO, "商品不存在");
|
|
|
-
|
|
|
- //转化出参
|
|
|
- GetSkuRes res = PojoConverterUtils.copy(baseSkuVO, GetSkuRes.class);
|
|
|
-
|
|
|
- return res;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 商品启用
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public void enableSku(EnableSkuReq req){
|
|
|
- List<Long> ids = req.getIds();
|
|
|
-
|
|
|
- //循环启用
|
|
|
- for (Long id : ids) {
|
|
|
- //1-查询活动对象
|
|
|
- BaseSku sku = baseSkuMapper.selectById(id);
|
|
|
- AssertUtil.isNull(sku, "商品不存在");
|
|
|
-
|
|
|
- if (!ValidEnum.NOT_VALID.is(sku.getValid())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //2-修改状态
|
|
|
- sku.setValid(ValidEnum.VALID.getCode());
|
|
|
- baseSkuMapper.updateById(sku);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 商品禁用
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public void disableSku(DisableSkuReq req){
|
|
|
- List<Long> ids = req.getIds();
|
|
|
-
|
|
|
- //循环禁用
|
|
|
- for (Long id : ids) {
|
|
|
- //1-查询活动对象
|
|
|
- BaseSku sku = baseSkuMapper.selectById(id);
|
|
|
- AssertUtil.isNull(sku, "商品不存在");
|
|
|
-
|
|
|
- if (!ValidEnum.VALID.is(sku.getValid())) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //校验物料
|
|
|
- QueryWrapper<BaseMaterial> bmQW = new QueryWrapper<>();
|
|
|
- bmQW.eq("sku_id", id);
|
|
|
- bmQW.eq("is_delete", 0);
|
|
|
- List<BaseMaterial> baseMaterials = baseMaterialMapper.selectList(bmQW);
|
|
|
- if(CollectionUtils.isNotEmpty(baseMaterials)){
|
|
|
- throw new BusinessException("SKU" + sku.getSkuName() + "已与物料" + baseMaterials.get(0).getMaterialName()+ "绑定,请解绑后再停用。" );
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //2-修改状态
|
|
|
- sku.setValid(ValidEnum.NOT_VALID.getCode());
|
|
|
- baseSkuMapper.updateById(sku);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 其他页面下拉选择SKU
|
|
|
- * @param listSkuForSelectReq
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public ListSkuForSelectRes listSkuForSelect(ListSkuForSelectReq listSkuForSelectReq) throws Exception {
|
|
|
- //1-查询所有有效的物料
|
|
|
- QueryWrapper<BaseSku> skuQw = new QueryWrapper<>();
|
|
|
- skuQw.eq("valid",1);
|
|
|
- skuQw.eq("is_delete",0);
|
|
|
- List<BaseSku> baseSkuList = baseSkuMapper.selectList(skuQw);
|
|
|
-
|
|
|
- //构造出参
|
|
|
- List<ListSkuForSelectRes.SkuBean> skuBeanList = PojoConverterUtils.copyList(baseSkuList, ListSkuForSelectRes.SkuBean.class);
|
|
|
- ListSkuForSelectRes res = new ListSkuForSelectRes();
|
|
|
- res.setSkuBeanList(skuBeanList);
|
|
|
-
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- *//**
|
|
|
- * 批量导入SKU
|
|
|
- * @param skuPropertiesList
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- *//*
|
|
|
- @Override
|
|
|
- public ExcelImportRes skulExcelImport(List<SkuProperty> skuPropertiesList) throws Exception {
|
|
|
- List<ExcelImportRes.FailBean> failList = new ArrayList<>();
|
|
|
-
|
|
|
- //1-循环导入,有异常则捕获
|
|
|
- for (int i = 0; i < skuPropertiesList.size(); i++) {
|
|
|
- SkuProperty skuProperty = skuPropertiesList.get(i);
|
|
|
- try {
|
|
|
- //1-校验必填与枚举
|
|
|
- Map<String, Object> returnMap = checkSkuProperty(skuProperty);
|
|
|
- String errotMessage = String.valueOf(returnMap.get("errorMessage"));
|
|
|
- BaseBrand barseBrand = (BaseBrand) returnMap.get("baseBrand");
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotBlank(errotMessage) || null == barseBrand) {
|
|
|
- throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), errotMessage);
|
|
|
- }
|
|
|
- AddSkuReq req = new AddSkuReq();
|
|
|
- req.setSkuCode(skuProperty.getSkuCode());
|
|
|
- req.setSkuName(skuProperty.getSkuName());
|
|
|
- req.setBrandCode(barseBrand.getParentBrandCode());
|
|
|
- req.setSubBrandCode(barseBrand.getBrandCode());
|
|
|
-
|
|
|
- addSku(req);
|
|
|
- } catch (BusinessException e) {
|
|
|
- failList.add(new ExcelImportRes.FailBean(i + 2, e.getMessage()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //2-返回导入结果
|
|
|
- ExcelImportRes res = new ExcelImportRes();
|
|
|
- res.setFailedCount(failList.size());
|
|
|
- res.setSuccessCount(skuPropertiesList.size() - res.getFailedCount());
|
|
|
- res.setFailBeanList(failList);
|
|
|
-
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String,Object> checkSkuProperty(SkuProperty skuProperty) {
|
|
|
- StringBuffer errorMessage = new StringBuffer();
|
|
|
- Map<String,Object> returnMap = new HashMap<String,Object>();
|
|
|
- //逐个字段校验
|
|
|
- if (org.apache.commons.lang3.StringUtils.isBlank(skuProperty.getSkuCode())) {
|
|
|
- errorMessage.append("SKUID").append("为空,");
|
|
|
- }
|
|
|
- if (org.apache.commons.lang3.StringUtils.isBlank(skuProperty.getSkuName())) {
|
|
|
- errorMessage.append("SKU名称").append("为空,");
|
|
|
- }
|
|
|
- if (org.apache.commons.lang3.StringUtils.isBlank(skuProperty.getSubBrandName())) {
|
|
|
- errorMessage.append("所属子品牌").append("为空,");
|
|
|
- }else {
|
|
|
- QueryWrapper<BaseBrand> brandQw = new QueryWrapper<>();
|
|
|
- brandQw.eq("brand_name",skuProperty.getSubBrandName());
|
|
|
- brandQw.eq("brand_level",2);
|
|
|
- BaseBrand baseBrand = baseBrandMapper.selectOne(brandQw);
|
|
|
- if (null == baseBrand){
|
|
|
- errorMessage.append("该子品牌").append("不存在");
|
|
|
- }
|
|
|
- returnMap.put("baseBrand",baseBrand);
|
|
|
- }
|
|
|
- returnMap.put("errorMessage",errorMessage.toString());
|
|
|
- return returnMap;
|
|
|
- }*/
|
|
|
-
|
|
|
-}
|