|
@@ -0,0 +1,257 @@
|
|
|
+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.enums.ValidEnum;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseBrandMapper;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseMaterialMapper;
|
|
|
+import com.abi.qms.platform.dao.vo.result.MaterialVO;
|
|
|
+import com.abi.qms.platform.dto.req.*;
|
|
|
+import com.abi.qms.platform.dto.res.GetMaterialRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListBrandForSelectRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListMaterialForSelectRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListMaterialRes;
|
|
|
+import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
+import com.abi.qms.platform.service.MaterialService;
|
|
|
+import com.abi.task.common.api.exception.BusinessException;
|
|
|
+import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.Query;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.redisson.misc.Hash;
|
|
|
+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;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 物料
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Andy.Tan
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MaterialServiceImpl implements MaterialService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseMaterialMapper baseMaterialMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseBrandMapper baseBrandMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增物料
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addMaterial(AddMaterialReq req){
|
|
|
+ //校验入参
|
|
|
+ //查询是否存在相同名称的物料
|
|
|
+ QueryWrapper<BaseMaterial> materialQw = new QueryWrapper<>();
|
|
|
+ materialQw.eq("material_name",req.getMaterialName());
|
|
|
+ List<BaseMaterial> materialList = baseMaterialMapper.selectList(materialQw);
|
|
|
+ if(CollectionUtils.isNotEmpty(materialList)){
|
|
|
+ throw new BusinessException("物料"+req.getMaterialName()+"已存在,请勿重复创建");
|
|
|
+ }
|
|
|
+ //查询是否存在物料号
|
|
|
+ materialQw = new QueryWrapper<>();
|
|
|
+ materialQw.eq("material_code",req.getMaterialCode());
|
|
|
+ materialList = baseMaterialMapper.selectList(materialQw);
|
|
|
+ if(CollectionUtils.isNotEmpty(materialList)){
|
|
|
+ throw new BusinessException("物料号"+req.getMaterialCode()+"已存在,请勿重复创建");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1-新增
|
|
|
+ BaseMaterial material = new BaseMaterial();
|
|
|
+ material.setMaterialCode(req.getMaterialCode());
|
|
|
+ material.setMaterialName(req.getMaterialName());
|
|
|
+ material.setMaterialType(req.getMaterialType());
|
|
|
+ material.setBrandCode(req.getBrandCode());
|
|
|
+ material.setDescription(req.getDescription());
|
|
|
+ baseMaterialMapper.insert(material);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑物料
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateMaterial(UpdateMaterialReq req){
|
|
|
+
|
|
|
+ //1-查询物料
|
|
|
+ BaseMaterial material = baseMaterialMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(material,"物料不存在");
|
|
|
+
|
|
|
+ //2-修改物料
|
|
|
+ material.setMaterialName(req.getMaterialName());
|
|
|
+ material.setMaterialType(req.getMaterialType());
|
|
|
+ material.setBrandCode(req.getBrandCode());
|
|
|
+ material.setDescription(req.getDescription());
|
|
|
+ material.setValid(req.getValid());
|
|
|
+ baseMaterialMapper.updateById(material);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询物料
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ListMaterialRes listMaterial(ListMaterialReq req){
|
|
|
+
|
|
|
+ //1-分页查询
|
|
|
+ IPage<MaterialVO> iPage = baseMaterialMapper.listMaterial(PageUtil.createPage(req), req);
|
|
|
+ List<MaterialVO> materialList = iPage.getRecords();
|
|
|
+
|
|
|
+ //封装出参
|
|
|
+ ListMaterialRes res = new ListMaterialRes();
|
|
|
+ //放入分页信息
|
|
|
+ PageUtil.copyPageInfo(res, iPage);
|
|
|
+ //放入出参列表
|
|
|
+ List<ListMaterialRes.MaterialBean> materialBeanList = PojoConverterUtils.copyList(materialList, ListMaterialRes.MaterialBean.class);
|
|
|
+ res.setMaterialBeanList(materialBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物料明细
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GetMaterialRes getMaterial(GetMaterialReq req){
|
|
|
+
|
|
|
+ //1-查询物料对象
|
|
|
+ BaseMaterial material = baseMaterialMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(material, "物料不存在");
|
|
|
+
|
|
|
+ //转化出参
|
|
|
+ GetMaterialRes res = PojoConverterUtils.copy(material, GetMaterialRes.class);
|
|
|
+
|
|
|
+ return res;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物料启用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void enableMaterial(EnableMaterialReq req){
|
|
|
+ List<Long> ids = req.getIds();
|
|
|
+
|
|
|
+ //循环启用
|
|
|
+ for (Long id : ids) {
|
|
|
+ //1-查询活动对象
|
|
|
+ BaseMaterial material = baseMaterialMapper.selectById(id);
|
|
|
+ AssertUtil.isNull(material, "物料不存在");
|
|
|
+
|
|
|
+ if (!ValidEnum.NOT_VALID.is(material.getValid())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-修改状态
|
|
|
+ material.setValid(ValidEnum.VALID.getCode());
|
|
|
+ baseMaterialMapper.updateById(material);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物料禁用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void disableMaterial(DisableMaterialReq req){
|
|
|
+ List<Long> ids = req.getIds();
|
|
|
+
|
|
|
+ //循环禁用
|
|
|
+ for (Long id : ids) {
|
|
|
+ //1-查询活动对象
|
|
|
+ BaseMaterial material = baseMaterialMapper.selectById(id);
|
|
|
+ AssertUtil.isNull(material, "物料不存在");
|
|
|
+
|
|
|
+ if (!ValidEnum.VALID.is(material.getValid())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-修改状态
|
|
|
+ material.setValid(ValidEnum.NOT_VALID.getCode());
|
|
|
+ baseMaterialMapper.updateById(material);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下拉选择物料列表
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public ListMaterialForSelectRes listMaterialForSelect(ListMaterialForSelectReq req) {
|
|
|
+ //1-查询所有有效的物料
|
|
|
+ QueryWrapper<BaseMaterial> materialQw = new QueryWrapper<>();
|
|
|
+ materialQw.eq("valid",1);
|
|
|
+ materialQw.eq("is_delete",0);
|
|
|
+ List<BaseMaterial> baseMaterialList = baseMaterialMapper.selectList(materialQw);
|
|
|
+
|
|
|
+ //构造出参
|
|
|
+ List<ListMaterialForSelectRes.MaterialBean> materialBeanList = PojoConverterUtils.copyList(baseMaterialList, ListMaterialForSelectRes.MaterialBean.class);
|
|
|
+ ListMaterialForSelectRes res = new ListMaterialForSelectRes();
|
|
|
+ res.setMaterialBeanList(materialBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下拉选择品牌列表
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public ListBrandForSelectRes listBrandForSelect(ListBrandForSelectReq req) {
|
|
|
+ //1-查询所有品牌
|
|
|
+ QueryWrapper<BaseBrand> baseBrandQw = new QueryWrapper<>();
|
|
|
+ baseBrandQw.eq("is_delete",0);
|
|
|
+ List<BaseBrand> baseBrandList = baseBrandMapper.selectList(baseBrandQw);
|
|
|
+
|
|
|
+ //出参列表
|
|
|
+ List<ListBrandForSelectRes.BrandBean> brandBeanList = new ArrayList<>();
|
|
|
+
|
|
|
+ //2-构造树形结构
|
|
|
+ //定义map用来存放父类bean
|
|
|
+ Map<String,ListBrandForSelectRes.BrandBean> brandBeanMap = new HashMap<>();
|
|
|
+ //分一级和二级两组
|
|
|
+ List<BaseBrand> l1BrandList = baseBrandList.stream().filter(brand -> brand.getBrandLevel() == 1).collect(Collectors.toList());
|
|
|
+ List<BaseBrand> l2BrandList = baseBrandList.stream().filter(brand -> brand.getBrandLevel() == 2).collect(Collectors.toList());
|
|
|
+ //循环放入一级
|
|
|
+ for(BaseBrand brand:l1BrandList){
|
|
|
+ ListBrandForSelectRes.BrandBean brandBean = new ListBrandForSelectRes.BrandBean();
|
|
|
+ brandBean.setBrandCode(brand.getBrandCode());
|
|
|
+ brandBean.setBrandName(brand.getBrandName());
|
|
|
+ brandBean.setSubBrandBeanList(new ArrayList<>());
|
|
|
+ //放入出参列表
|
|
|
+ brandBeanList.add(brandBean);
|
|
|
+ //放入map
|
|
|
+ brandBeanMap.put(brandBean.getBrandCode(),brandBean);
|
|
|
+ }
|
|
|
+ //循环放入二级
|
|
|
+ for(BaseBrand brand:l2BrandList){
|
|
|
+ ListBrandForSelectRes.BrandBean parentBrandBean = brandBeanMap.get(brand.getParentBrandCode());
|
|
|
+ if(parentBrandBean==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //构建bean
|
|
|
+ ListBrandForSelectRes.BrandBean brandBean = new ListBrandForSelectRes.BrandBean();
|
|
|
+ brandBean.setBrandCode(brand.getBrandCode());
|
|
|
+ brandBean.setBrandName(brand.getBrandName());
|
|
|
+ //加入子品牌
|
|
|
+ parentBrandBean.getSubBrandBeanList().add(brandBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ //构造出参
|
|
|
+ ListBrandForSelectRes res = new ListBrandForSelectRes();
|
|
|
+ res.setBrandBeanList(brandBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|