|  |  |  | 
|---|
|  |  |  | 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.BaseCateParamMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.BaseCategoryMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaseCategory baseCategory1 = baseCategoryMapper.selectOne(wrapper); | 
|---|
|  |  |  | if (Objects.nonNull(baseCategory1)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息表"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BaseCategory baseCategory2 = new BaseCategory(); | 
|---|
|  |  |  | baseCategory2.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | baseCategory2.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | baseCategory2.setName(baseCategory.getName()); | 
|---|
|  |  |  | baseCategory2.setRemark(baseCategory.getRemark()); | 
|---|
|  |  |  | baseCategory2.setAttrFirst(baseCategory.getAttrFirst()); | 
|---|
|  |  |  | baseCategory2.setAttrSecond(baseCategory.getAttrSecond()); | 
|---|
|  |  |  | baseCategory2.setStatus(baseCategory.getStatus()); | 
|---|
|  |  |  | baseCategory2.setSortnum(baseCategory.getSortnum()); | 
|---|
|  |  |  | baseCategory2.setImgurl(baseCategory.getImgurl()); | 
|---|
|  |  |  | baseCategory2.setPinyin(baseCategory.getPinyin()); | 
|---|
|  |  |  | baseCategory2.setShortPinyin(baseCategory.getShortPinyin()); | 
|---|
|  |  |  | baseCategory2.setPinyin(PinYinUtil.getFullSpell(baseCategory.getName())); | 
|---|
|  |  |  | baseCategory2.setShortPinyin(PinYinUtil.getFirstSpell(baseCategory.getName())); | 
|---|
|  |  |  | baseCategory2.setPriceRate(baseCategory.getPriceRate()); | 
|---|
|  |  |  | baseCategoryMapper.insert(baseCategory2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){ | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  | long count = baseCategory.getBaseCateParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (baseCategory.getBaseCategoryRequestParamList().size() != count){ | 
|---|
|  |  |  | if (baseCategory.getBaseCateParamList().size() != count){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | baseCategory.getBaseCategoryRequestParamList().forEach(s->{ | 
|---|
|  |  |  | baseCategory.getBaseCateParamList().forEach(s->{ | 
|---|
|  |  |  | BaseCateParam baseCateParam = new BaseCateParam(); | 
|---|
|  |  |  | baseCateParam.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | baseCateParam.setCreateDate(new Date()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateById(BaseCategoryRequest baseCategory) { | 
|---|
|  |  |  | public void update(BaseCategoryRequest baseCategory) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Objects.nonNull(baseCategory.getId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"品类主键缺失"); | 
|---|
|  |  |  | if (Objects.isNull(baseCategory.getId()) | 
|---|
|  |  |  | || Objects.isNull(baseCategory.getName())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.nonNull(baseCategory1) && (!baseCategory1.getId().equals(baseCategory.getId()))){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息表"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(baseCategory.getPriceRate() == null){ | 
|---|
|  |  |  | baseCategory.setPriceRate(new BigDecimal(1.2)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UpdateWrapper<BaseCategory> updateWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | updateWrapper.lambda() | 
|---|
|  |  |  | .eq(BaseCategory::getId,baseCategory.getId()) | 
|---|
|  |  |  | .set(BaseCategory::getName,baseCategory.getName()) | 
|---|
|  |  |  | .set(BaseCategory::getPinyin,PinYinUtil.getFullSpell(baseCategory.getName())) | 
|---|
|  |  |  | .set(BaseCategory::getShortPinyin,PinYinUtil.getFirstSpell(baseCategory.getName())) | 
|---|
|  |  |  | .set(BaseCategory::getImgurl,baseCategory.getImgurl()) | 
|---|
|  |  |  | .set(BaseCategory::getPriceRate,baseCategory.getPriceRate()) | 
|---|
|  |  |  | .set(BaseCategory::getSortnum,baseCategory.getSortnum()); | 
|---|
|  |  |  | baseCategoryMapper.update(null,wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){ | 
|---|
|  |  |  | baseCategoryMapper.update(null,updateWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  | if (baseCategory.getBaseCategoryRequestParamList().size() != count){ | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long count = baseCategory.getBaseCateParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  | if (baseCategory.getBaseCateParamList().size() != count){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> ids = new ArrayList<>(); | 
|---|
|  |  |  | baseCategory.getBaseCateParamList().forEach(s->{ | 
|---|
|  |  |  | if(s.getId() !=null){ | 
|---|
|  |  |  | ids. add(s.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | QueryWrapper<BaseCateParam> baseCateParamQuery = new QueryWrapper<>(); | 
|---|
|  |  |  | baseCateParamQuery.lambda() | 
|---|
|  |  |  | .eq(BaseCateParam::getCategoryId,baseCategory.getId()); | 
|---|
|  |  |  | baseCateParamQuery.lambda() | 
|---|
|  |  |  | .notIn(ids!=null && ids.size()>0,BaseCateParam::getId,ids); | 
|---|
|  |  |  | //刪除逻辑 | 
|---|
|  |  |  | baseCateParamMapper.delete(baseCateParamQuery); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | baseCategory.getBaseCategoryRequestParamList().forEach(s->{ | 
|---|
|  |  |  | baseCategory.getBaseCateParamList().forEach(s->{ | 
|---|
|  |  |  | BaseCateParam baseCateParam = new BaseCateParam(); | 
|---|
|  |  |  | baseCateParam.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | baseCateParam.setCreateDate(new Date()); | 
|---|
|  |  |  | baseCateParam.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | baseCateParam.setEditDate(new Date()); | 
|---|
|  |  |  | baseCateParam.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | baseCateParam.setName(s.getName()); | 
|---|
|  |  |  | baseCateParam.setRemark(s.getRemark()); | 
|---|
|  |  |  | baseCateParam.setStatus(s.getStatus()); | 
|---|
|  |  |  | baseCateParam.setSortnum(s.getSortnum()); | 
|---|
|  |  |  | baseCateParam.setCategoryId(baseCategory.getId()); | 
|---|
|  |  |  | baseCateParamMapper.insert(baseCateParam); | 
|---|
|  |  |  | if(s.getId() !=null ){ | 
|---|
|  |  |  | //更新数据 | 
|---|
|  |  |  | baseCateParam.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | baseCateParam.setEditDate(new Date()); | 
|---|
|  |  |  | baseCateParam.setId(s.getId()); | 
|---|
|  |  |  | baseCateParamMapper.updateById(baseCateParam); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //新增 | 
|---|
|  |  |  | baseCateParam.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | baseCateParam.setCreateDate(new Date()); | 
|---|
|  |  |  | baseCateParamMapper.insert(baseCateParam); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateById(BaseCategory baseCategory) { | 
|---|
|  |  |  | baseCategoryMapper.updateById(baseCategory); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateDisableById(BaseCategory baseCategory) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | if(baseCategory.getId() == null || baseCategory.getStatus() == null){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(baseCategory.getStatus(), Constants.ONE) | 
|---|
|  |  |  | && !Constants.equalsInteger(baseCategory.getStatus(), Constants.ZERO)){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BaseCategory param= new BaseCategory(); | 
|---|
|  |  |  | param.setId(baseCategory.getId()); | 
|---|
|  |  |  | param.setEditDate(new Date()); | 
|---|
|  |  |  | param.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | param.setId(baseCategory.getId()); | 
|---|
|  |  |  | param.setStatus(baseCategory.getStatus()); | 
|---|
|  |  |  | baseCategoryMapper.updateById(param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public BaseCategory findById(Integer id) { | 
|---|
|  |  |  | return baseCategoryMapper.selectById(id); | 
|---|
|  |  |  | BaseCategory  model = baseCategoryMapper.selectById(id); | 
|---|
|  |  |  | if(StringUtils.isNotBlank(model.getImgurl())){ | 
|---|
|  |  |  | model.setImgfullurl( | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() + | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.CATEGORY_IMG).getCode() + model.getImgurl() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return  model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<BaseCategory> findList(BaseCategory baseCategory) { | 
|---|
|  |  |  | baseCategory.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(baseCategory); | 
|---|
|  |  |  | return baseCategoryMapper.selectList(wrapper); | 
|---|
|  |  |  | List<BaseCategory> list = baseCategoryMapper.selectList(wrapper); | 
|---|
|  |  |  | list.forEach(i->{ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(i.getImgurl())){ | 
|---|
|  |  |  | i.setImgfullurl( | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() + | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.CATEGORY_IMG).getCode() + i.getImgurl() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.lambda().eq(BaseCategory::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getName() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(BaseCategory::getName, pageWrap.getModel().getName()); | 
|---|
|  |  |  | queryWrapper.lambda().like(BaseCategory::getName, pageWrap.getModel().getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRemark() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(BaseCategory::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IPage<BaseCategory> baseCategoryIPage = baseCategoryMapper.selectPage(page, queryWrapper); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategoryIPage.getRecords())){ | 
|---|
|  |  |  | baseCategoryIPage.getRecords().forEach(s->s.setImgfullurl(getPreUrl()+s.getImgfullurl())); | 
|---|
|  |  |  | baseCategoryIPage.getRecords().forEach(s->s.setImgfullurl(getPreUrl()+s.getImgurl())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return PageData.from(baseCategoryIPage); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String getPreUrl(){ | 
|---|
|  |  |  | String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode() | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.CATEGORY_IMG).getCode(); | 
|---|
|  |  |  | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); | 
|---|
|  |  |  | return prefixUrl; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|