| | |
| | | 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.BaseCateParamMapper; |
| | | import com.doumee.dao.business.BaseCategoryMapper; |
| | | import com.doumee.dao.business.model.BaseCateParam; |
| | | import com.doumee.dao.business.model.BaseCategory; |
| | | import com.doumee.dao.business.model.dto.BaseCategoryRequest; |
| | | import com.doumee.service.business.BaseCateParamService; |
| | | import com.doumee.service.business.BaseCategoryService; |
| | | 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 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; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 素材库-品类信息表Service实现 |
| | |
| | | @Autowired |
| | | private BaseCategoryMapper baseCategoryMapper; |
| | | |
| | | @Autowired |
| | | private BaseCateParamMapper baseCateParamMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | @Override |
| | | public Integer create(BaseCategory baseCategory) { |
| | | baseCategoryMapper.insert(baseCategory); |
| | | return baseCategory.getId(); |
| | | public Integer create(BaseCategoryRequest baseCategory) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(BaseCategory::getName,baseCategory.getName()) |
| | | .eq(BaseCategory::getIsdeleted,Constants.ZERO); |
| | | |
| | | BaseCategory baseCategory1 = baseCategoryMapper.selectOne(wrapper); |
| | | if (Objects.nonNull(baseCategory1)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息已存在"); |
| | | } |
| | | BaseCategory baseCategory2 = new BaseCategory(); |
| | | baseCategory2.setCreator(loginUserInfo.getId()); |
| | | baseCategory2.setCreateDate(new Date()); |
| | | baseCategory2.setEditor(loginUserInfo.getId()); |
| | | baseCategory2.setEditDate(new Date()); |
| | | baseCategory2.setIsdeleted(Constants.ZERO); |
| | | baseCategory2.setName(baseCategory.getName()); |
| | | baseCategory2.setRemark(baseCategory.getRemark()); |
| | | baseCategory2.setStatus(baseCategory.getStatus()); |
| | | baseCategory2.setSortnum(baseCategory.getSortnum()); |
| | | baseCategory2.setImgurl(baseCategory.getImgurl()); |
| | | baseCategory2.setPinyin(PinYinUtil.getFullSpell(baseCategory.getName())); |
| | | baseCategory2.setShortPinyin(PinYinUtil.getFirstSpell(baseCategory.getName())); |
| | | baseCategory2.setPriceRate(baseCategory.getPriceRate()); |
| | | baseCategoryMapper.insert(baseCategory2); |
| | | |
| | | 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(),"属性存在重复"); |
| | | } |
| | | 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(baseCategory2.getId()); |
| | | baseCateParamMapper.insert(baseCateParam); |
| | | }); |
| | | } |
| | | return baseCategory2.getId(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | baseCategoryMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | @Override |
| | | public void update(BaseCategoryRequest baseCategory) { |
| | | |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | if (Objects.isNull(baseCategory.getId()) |
| | | || Objects.isNull(baseCategory.getName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(BaseCategory::getName,baseCategory.getName()) |
| | | .eq(BaseCategory::getIsdeleted,Constants.ZERO); |
| | | |
| | | BaseCategory baseCategory1 = baseCategoryMapper.selectOne(wrapper); |
| | | 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,updateWrapper); |
| | | |
| | | 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.getBaseCateParamList().forEach(s->{ |
| | | BaseCateParam baseCateParam = new BaseCateParam(); |
| | | baseCateParam.setIsdeleted(Constants.ZERO); |
| | | baseCateParam.setName(s.getName()); |
| | | baseCateParam.setRemark(s.getRemark()); |
| | | baseCateParam.setStatus(s.getStatus()); |
| | | baseCateParam.setSortnum(s.getSortnum()); |
| | | baseCateParam.setCategoryId(baseCategory.getId()); |
| | | 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) { |
| | | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(baseCategory); |
| | | return baseCategoryMapper.selectList(wrapper); |
| | | wrapper.eq("ISDELETED",Constants.ZERO); |
| | | wrapper.eq("STATUS",Constants.ZERO); |
| | | 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 |
| | | public PageData<BaseCategory> findPage(PageWrap<BaseCategory> pageWrap) { |
| | | IPage<BaseCategory> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | |
| | | 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()); |
| | |
| | | if (pageWrap.getModel().getShortPinyin() != null) { |
| | | queryWrapper.lambda().eq(BaseCategory::getShortPinyin, pageWrap.getModel().getShortPinyin()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | queryWrapper.lambda().orderByAsc(BaseCategory::getSortnum); |
| | | |
| | | IPage<BaseCategory> baseCategoryIPage = baseCategoryMapper.selectPage(page, queryWrapper); |
| | | String preUrl = getPreUrl(); |
| | | if (!CollectionUtils.isEmpty(baseCategoryIPage.getRecords())){ |
| | | baseCategoryIPage.getRecords().forEach(s->s.setImgfullurl(preUrl+s.getImgurl())); |
| | | } |
| | | return PageData.from(baseCategoryMapper.selectPage(page, queryWrapper)); |
| | | |
| | | return PageData.from(baseCategoryIPage); |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(baseCategory); |
| | | return baseCategoryMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | private String getPreUrl(){ |
| | | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); |
| | | return prefixUrl; |
| | | } |
| | | } |