|  |  |  | 
|---|
|  |  |  | 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.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.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.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.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()); | 
|---|
|  |  |  | baseCategoryMapper.insert(baseCategory2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (baseCategory.getBaseCategoryRequestParamList().size() != count){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | baseCategory.getBaseCategoryRequestParamList().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 | 
|---|
|  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"品类主键缺失"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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(),"品类信息表"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UpdateWrapper<BaseCategory> updateWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | updateWrapper.lambda() | 
|---|
|  |  |  | .eq(BaseCategory::getId,baseCategory.getId()) | 
|---|
|  |  |  | .set(BaseCategory::getName,baseCategory.getName()) | 
|---|
|  |  |  | .set(BaseCategory::getImgurl,baseCategory.getImgurl()) | 
|---|
|  |  |  | .set(BaseCategory::getSortnum,baseCategory.getSortnum()); | 
|---|
|  |  |  | baseCategoryMapper.update(null,updateWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count(); | 
|---|
|  |  |  | if (baseCategory.getBaseCategoryRequestParamList().size() != count){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryWrapper<BaseCateParam> baseCateParamQuery = new QueryWrapper<>(); | 
|---|
|  |  |  | baseCateParamQuery.lambda() | 
|---|
|  |  |  | .eq(BaseCateParam::getCategoryId,baseCategory.getId()); | 
|---|
|  |  |  | baseCateParamMapper.delete(baseCateParamQuery); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | baseCategory.getBaseCategoryRequestParamList().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); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(baseCategory); | 
|---|
|  |  |  | return baseCategoryMapper.selectList(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<BaseCategory> findPage(PageWrap<BaseCategory> pageWrap) { | 
|---|
|  |  |  | IPage<BaseCategory> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(baseCategoryIPage.getRecords())){ | 
|---|
|  |  |  | baseCategoryIPage.getRecords().forEach(s->s.setImgfullurl(getPreUrl()+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.SYSTEM, Constants.FILE_DIR).getCode() | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.CATEGORY_IMG).getCode(); | 
|---|
|  |  |  | return prefixUrl; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|