| | |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.CategoryMapper; |
| | | import com.doumee.dao.business.MultifileMapper; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.CategoryService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | |
| | | @Autowired |
| | | private CategoryMapper categoryMapper; |
| | | @Autowired |
| | | private MultifileMapper multifileMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public Integer create(Category category) { |
| | | // 类型:0=战区;1=商业化;2=擅长领域;3=讲师等级; |
| | | 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())) ) |
| | | ){ |
| | | || (Constants.equalsInteger(category.getType(),Constants.ZERO)&& StringUtils.isBlank(category.getDetail())) ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | |
| | | 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); |
| | | dealBatchMultiFiles(category, category.getFileList(), loginUserInfo,false); |
| | | return category.getId(); |
| | | } |
| | | |
| | | public void dealBatchMultiFiles(Category category, List<Multifile> fileList, LoginUserInfo user,boolean update) { |
| | | Date today = new Date(); |
| | | //清空原有的 |
| | | if(update){ |
| | | multifileMapper.delete(new UpdateWrapper<Multifile>().lambda() |
| | | .eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .eq(Multifile::getObjType,Constants.ZERO) |
| | | .eq(Multifile::getObjId,category.getId())); |
| | | } |
| | | if(fileList!=null && fileList.size()>0){ |
| | | List<Multifile> multifileList = new ArrayList<>(); |
| | | fileList.stream().forEach(s -> { |
| | | if(StringUtils.isNotBlank(s.getFileurl())){ |
| | | s.setIsdeleted(Constants.ZERO); |
| | | s.setCreator(user.getId()); |
| | | s.setCreateDate(today); |
| | | s.setObjId(category.getId()); |
| | | s.setType(Constants.ZERO); |
| | | s.setObjType(Constants.ZERO); |
| | | multifileList.add(s); |
| | | } |
| | | }); |
| | | if(multifileList.size()>0){ |
| | | multifileMapper.insert(multifileList); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | categoryMapper.update(new UpdateWrapper<Category>().lambda().set(Category::getDeleted,Constants.ONE).eq(Category::getId,id)); |
| | | |
| | | // categoryMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | || 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); |
| | | } |
| | |
| | | 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); |
| | | dealBatchMultiFiles(category, category.getFileList(), loginUserInfo,true); |
| | | } |
| | | @Override |
| | | public void updateStatus(Category category) { |
| | | if(Objects.isNull(category) |
| | | || Objects.isNull(category.getId())){ |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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(); |
| | | String path = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.CATEGORY_FILES).getCode(); |
| | | category.setIconFull(path + category.getIcon()); |
| | | } |
| | | return category; |
| | |
| | | |
| | | @Override |
| | | public List<Category> findList(Category category) { |
| | | category.setDeleted(Constants.ZERO); |
| | | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); |
| | | return categoryMapper.selectList(wrapper); |
| | | } |
| | |
| | | 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(); |
| | | String path = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.CATEGORY_FILES).getCode(); |
| | | for(Category cate : result.getRecords()){ |
| | | try { |
| | | if(StringUtils.isNotBlank(cate.getDetail())){ |
| | | cate.setDetailList(JSONArray.parseArray(cate.getDetail())); |
| | | if(Constants.equalsInteger(cate.getType(),Constants.ONE) ){ |
| | | initMultifileList(cate); |
| | | } |
| | | if(StringUtils.isNotBlank(cate.getIcon())){ |
| | | cate.setIconFull(path + cate.getIcon()); |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private void initMultifileList(Category cate) { |
| | | String path = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.CATEGORY_FILES).getCode(); |
| | | |
| | | Multifile find = new Multifile(); |
| | | find.setObjId(cate.getId()); |
| | | find.setObjType(Constants.ZERO); |
| | | find.setIsdeleted(Constants.ZERO); |
| | | List<Multifile> fileList= multifileMapper.selectList(new QueryWrapper<>(find)); |
| | | if(fileList!=null){ |
| | | for(Multifile f : fileList){ |
| | | if(StringUtils.isNotBlank(f.getFileurl())){ |
| | | f.setUrl(path+f.getFileurl()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | cate.setFileList(fileList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()); |
| | | } |
| | | if(Constants.equalsInteger(category.getType(),Constants.ONE) ){ |
| | | initMultifileList(category); |
| | | } |
| | | } |
| | | } |
| | | return categoryList; |