|  |  |  | 
|---|
|  |  |  | 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 com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.github.yulichang.base.MPJBaseMapper; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.checkerframework.checker.units.qual.C; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分类信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CategoryMapper categoryMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | 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 = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | category.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | category.setCreateTime(new Date()); | 
|---|
|  |  |  | category.setCreateUser(loginUserInfo.getId()); | 
|---|
|  |  |  | category.setUpdateTime(new Date()); | 
|---|
|  |  |  | category.setUpdateUser(loginUserInfo.getId()); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList()) | 
|---|
|  |  |  | && !Constants.equalsInteger(category.getType(),Constants.THREE)){ | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | 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 = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | category.setUpdateTime(new Date()); | 
|---|
|  |  |  | category.setIsFixed(null); | 
|---|
|  |  |  | category.setUpdateUser(loginUserInfo.getId()); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList()) | 
|---|
|  |  |  | && !Constants.equalsInteger(category.getType(),Constants.THREE)){ | 
|---|
|  |  |  | category.setDetail(category.getDetailList().toJSONString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | categoryMapper.updateById(category); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateStatus(Category category) { | 
|---|
|  |  |  | if(Objects.isNull(category) | 
|---|
|  |  |  | || Objects.isNull(category.getId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | 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.eq(Category::getIsFixed, pageWrap.getModel().getIsFixed()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.orderByAsc(Category::getSortnum); | 
|---|
|  |  |  | return PageData.from(categoryMapper.selectJoinPage(page, Category.class,queryWrapper)); | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); | 
|---|
|  |  |  | return categoryMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Category> getCategoryList(Integer type){ | 
|---|
|  |  |  | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda().eq(Category::getDeleted,Constants.ZERO).eq(Category::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .eq(Objects.nonNull(type),Category::getType,type)); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ | 
|---|
|  |  |  | String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() | 
|---|
|  |  |  | +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); | 
|---|
|  |  |  | for (Category category:categoryList) { | 
|---|
|  |  |  | if(StringUtils.isNotBlank(category.getDetail())){ | 
|---|
|  |  |  | category.setDetailList(JSONArray.parseArray(category.getDetail())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StringUtils.isNotBlank(category.getIcon())){ | 
|---|
|  |  |  | category.setIconFull(path + category.getIcon()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return categoryList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|