|  |  | 
 |  |  | package com.doumee.service.business.impl; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSONArray; | 
 |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
 |  |  | import com.doumee.core.constants.Constants; | 
 |  |  | import com.doumee.core.constants.Constants; | 
 |  |  | 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.Utils; | 
 |  |  | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 分类信息表Service实现 | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CategoryMapper categoryMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(Category category) { | 
 |  |  |         if(Objects.isNull(category) | 
 |  |  |         || Objects.isNull(category.getType()) | 
 |  |  |         || Objects.isNull(category.getName()) | 
 |  |  |         || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList())) | 
 |  |  |         || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) ) | 
 |  |  |         ){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         LoginUserInfo loginUserInfo = category.getLoginUserInfo(); | 
 |  |  |         category.setCreateTime(new Date()); | 
 |  |  |         category.setDeleted(Constants.ZERO); | 
 |  |  |         category.setCreateUser(loginUserInfo.getId()); | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())){ | 
 |  |  |             category.setDetail(category.getDetailList().toJSONString()); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(category.getType(),Constants.ONE)){ | 
 |  |  |             category.setIsFixed(Constants.ZERO); | 
 |  |  |         } | 
 |  |  |         categoryMapper.insert(category); | 
 |  |  |         return category.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(Integer id) { | 
 |  |  |         categoryMapper.deleteById(id); | 
 |  |  |         categoryMapper.update(new UpdateWrapper<Category>().lambda().set(Category::getDeleted,Constants.ONE).eq(Category::getId,id)); | 
 |  |  |  | 
 |  |  | //        categoryMapper.deleteById(id); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void updateById(Category category) { | 
 |  |  |         if(Objects.isNull(category) | 
 |  |  |                 || Objects.isNull(category.getId()) | 
 |  |  |                 || Objects.isNull(category.getType()) | 
 |  |  |                 || Objects.isNull(category.getName()) | 
 |  |  |                 || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList())) | 
 |  |  |                 || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) ) | 
 |  |  |         ){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         LoginUserInfo loginUserInfo = category.getLoginUserInfo(); | 
 |  |  |         category.setUpdateTime(new Date()); | 
 |  |  |         category.setIsFixed(null); | 
 |  |  |         category.setUpdateUser(loginUserInfo.getId()); | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())){ | 
 |  |  |             category.setDetail(category.getDetailList().toJSONString()); | 
 |  |  |         } | 
 |  |  |         categoryMapper.updateById(category); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Category findById(Integer id) { | 
 |  |  |         return categoryMapper.selectById(id); | 
 |  |  |         Category category = categoryMapper.selectById(id); | 
 |  |  |         if(Objects.isNull(category)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(StringUtils.isNotBlank(category.getDetail())){ | 
 |  |  |             category.setDetailList(JSONArray.parseArray(category.getDetail())); | 
 |  |  |         } | 
 |  |  |         if(StringUtils.isNotBlank(category.getIcon())){ | 
 |  |  |             String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() | 
 |  |  |                     +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); | 
 |  |  |             category.setIconFull(path + category.getIcon()); | 
 |  |  |         } | 
 |  |  |         return category; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |         queryWrapper.orderByAsc(Category::getSortnum); | 
 |  |  |         PageData<Category> result =PageData.from(categoryMapper.selectJoinPage(page, Category.class,queryWrapper)); | 
 |  |  |         if(result!=null && result.getRecords()!=null){ | 
 |  |  |             String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() | 
 |  |  |                     +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); | 
 |  |  |             for(Category cate : result.getRecords()){ | 
 |  |  |                 try { | 
 |  |  |                     if(StringUtils.isNotBlank(cate.getDetail())){ | 
 |  |  |                         cate.setDetailList(JSONArray.parseArray(cate.getDetail())); | 
 |  |  |                     } | 
 |  |  |                     if(StringUtils.isNotBlank(cate.getIcon())){ | 
 |  |  |                         cate.setIconFull(path + cate.getIcon()); | 
 |  |  |                     } | 
 |  |  |                 }catch (Exception e){ | 
 |  |  |  | 
 |  |  |                 } |