|
@@ -0,0 +1,153 @@
|
|
|
+package com.zhongzheng.modules.top.system.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.top.financial.domain.TopCostInstTpItem;
|
|
|
+import com.zhongzheng.modules.top.financial.domain.TopCostTpItem;
|
|
|
+import com.zhongzheng.modules.top.financial.service.ITopCostInstTpItemService;
|
|
|
+import com.zhongzheng.modules.top.financial.service.ITopCostTpItemService;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopCostCategoryAddBo;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopCostCategoryEditBo;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopCostCategoryQueryBo;
|
|
|
+import com.zhongzheng.modules.top.system.domain.TopCostCategory;
|
|
|
+import com.zhongzheng.modules.top.system.domain.TopInstCategory;
|
|
|
+import com.zhongzheng.modules.top.system.mapper.TopCostCategoryMapper;
|
|
|
+import com.zhongzheng.modules.top.system.service.ITopCostCategoryService;
|
|
|
+import com.zhongzheng.modules.top.system.vo.TopCostCategoryVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 机构成本类别Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2023-07-27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TopCostCategoryServiceImpl extends ServiceImpl<TopCostCategoryMapper, TopCostCategory> implements ITopCostCategoryService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITopCostTpItemService iTopCostTpItemService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TopCostCategoryVo queryById(Long categoryId){
|
|
|
+ TopCostCategory db = this.baseMapper.selectById(categoryId);
|
|
|
+ return BeanUtil.toBean(db, TopCostCategoryVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TopCostCategoryVo> queryList(TopCostCategoryQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<TopCostCategory> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getCategoryName()), TopCostCategory::getCategoryName, bo.getCategoryName());
|
|
|
+ lqw.eq(bo.getStatus() != null, TopCostCategory::getStatus, bo.getStatus());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<TopCostCategoryVo> entity2Vo(Collection<TopCostCategory> collection) {
|
|
|
+ List<TopCostCategoryVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, TopCostCategoryVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<TopCostCategory> page = (Page<TopCostCategory>)collection;
|
|
|
+ Page<TopCostCategoryVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(TopCostCategoryAddBo bo) {
|
|
|
+ TopCostCategory add = BeanUtil.toBean(bo, TopCostCategory.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(TopCostCategoryEditBo bo) {
|
|
|
+ TopCostCategory update = BeanUtil.toBean(bo, TopCostCategory.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(TopCostCategory entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ if(Validator.isNotEmpty(entity.getStatus())&&entity.getStatus()==-1){
|
|
|
+ if(iTopCostTpItemService.count(new LambdaQueryWrapper<TopCostTpItem>()
|
|
|
+ .eq(TopCostTpItem::getItemCategory, entity.getCategoryId())
|
|
|
+ .ne(TopCostTpItem::getStatus, -1))>0){
|
|
|
+ throw new CustomException("该分类已被使用,无法编辑和删除");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(checkNameUnique(entity)){
|
|
|
+ throw new CustomException("名称重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteBatch(TopCostCategoryEditBo bo) {
|
|
|
+ for(Long id : bo.getCategoryIds()){
|
|
|
+ TopCostCategoryEditBo update = new TopCostCategoryEditBo();
|
|
|
+ update.setCategoryId(id);
|
|
|
+ update.setStatus(-1);
|
|
|
+ this.updateByEditBo(update);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkNameUnique(TopCostCategory entity) {
|
|
|
+ if(Validator.isEmpty(entity.getCategoryName())){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ TopCostCategory info = getOne(new LambdaQueryWrapper<TopCostCategory>()
|
|
|
+ .eq(TopCostCategory::getCategoryName,entity.getCategoryName()).ne(TopCostCategory::getStatus,-1)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (Validator.isNotNull(info)) {
|
|
|
+ if(Validator.isNotEmpty(entity.getCategoryId())){
|
|
|
+ if(entity.getCategoryId().longValue() != info.getCategoryId().longValue()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|