| package com.doumee.service.business.impl; | 
|   | 
| 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.BjParamMapper; | 
| import com.doumee.dao.business.model.BjParam; | 
| import com.doumee.dao.business.model.News; | 
| import com.doumee.dao.system.model.SystemUser; | 
| import com.doumee.dao.web.response.BjParamConfigResponse; | 
| import com.doumee.service.business.BjParamService; | 
| 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 com.github.yulichang.wrapper.MPJLambdaWrapper; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
| import org.springframework.util.StringUtils; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Objects; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * 志邦家选计算器配置信息表报价Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2024/07/05 15:39 | 
|  */ | 
| @Service | 
| public class BjParamServiceImpl implements BjParamService { | 
|   | 
|     @Autowired | 
|     private BjParamMapper bjParamMapper; | 
|   | 
|     @Override | 
|     public Long create(BjParam bjParam) { | 
|         LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         bjParam.setIsdeleted(Constants.ZERO); | 
|         bjParam.setEditor(userInfo.getId()); | 
|         bjParam.setCreator(userInfo.getId()); | 
|         bjParam.setCreateDate(new Date()); | 
|         bjParam.setEditDate(bjParam.getCreateDate()); | 
|         bjParamMapper.insert(bjParam); | 
|         return bjParam.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(Long id) { | 
|         LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         bjParamMapper.update(null,new UpdateWrapper<BjParam>().lambda() | 
|                 .set(BjParam::getIsdeleted,Constants.ONE ) | 
|                 .set(BjParam::getEditor,userInfo.getId() ) | 
|                 .set(BjParam::getEditDate,new Date() ) | 
|                 .eq(BjParam::getParentId,id) | 
|                 .or().eq(BjParam::getId,id)); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(BjParam bjParam) { | 
|         UpdateWrapper<BjParam> deleteWrapper = new UpdateWrapper<>(bjParam); | 
|         bjParamMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Long> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         for(Long id : ids){ | 
|             deleteById(id); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(BjParam bjParam) { | 
|         LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         bjParam.setEditor(userInfo.getId()); | 
|         bjParam.setEditDate(new Date()); | 
|         bjParamMapper.updateById(bjParam); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<BjParam> bjParams) { | 
|         if (CollectionUtils.isEmpty(bjParams)) { | 
|             return; | 
|         } | 
|         for (BjParam bjParam: bjParams) { | 
|             this.updateById(bjParam); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public BjParam findById(Long id) { | 
|         return bjParamMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public BjParam findOne(BjParam bjParam) { | 
|         QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam); | 
|         return bjParamMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<BjParam> findList(BjParam bjParam) { | 
|         QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam); | 
|         return bjParamMapper.selectList(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public   List<BjParam> findTree() { | 
|         BjParam param = new BjParam(); | 
|         param.setIsdeleted(Constants.ZERO); | 
|         MPJLambdaWrapper<BjParam> wrapper = new MPJLambdaWrapper<BjParam>(); | 
|         wrapper.selectAll(BjParam.class) | 
|                 .selectAs(SystemUser::getRealname,BjParam::getEditorName) | 
|                 .leftJoin(SystemUser.class,SystemUser::getId,BjParam::getEditor) | 
|                 .eq(BjParam::getIsdeleted,Constants.ZERO ) | 
|                 .orderByAsc(BjParam::getSortnum); | 
|         List<BjParam> list =  bjParamMapper.selectJoinList(BjParam.class,wrapper); | 
|         List<BjParam> treeList = new ArrayList<>(); | 
|         if(list!=null && list.size()>0){ | 
|             for(BjParam model : list){ | 
|                 if(model.getParentId() == null){ | 
|                     initModelChildData(model,list); | 
|                     treeList.add(model); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         return treeList; | 
|     } | 
|   | 
|     private void initModelChildData(BjParam param, List<BjParam> list) { | 
|         List<BjParam> clist = new ArrayList<>(); | 
|         param.setHasChildren(Boolean.TRUE); | 
|         if(list!=null && list.size()>0){ | 
|             for(BjParam model : list){ | 
|                 if(model.getParentId() != null &&  param.getId()!=null && param.getId().equals(model.getParentId())){ | 
|                     param.setHasChildren(Boolean.FALSE); | 
|                     model.setHasChildren(Boolean.TRUE); | 
|                     clist.add(model); | 
|                 } | 
|             } | 
|         } | 
|         param.setChildren(clist); | 
|     } | 
|   | 
|     @Override | 
|     public PageData<BjParam> findPage(PageWrap<BjParam> pageWrap) { | 
|         IPage<BjParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         QueryWrapper<BjParam> queryWrapper = new QueryWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         if (pageWrap.getModel().getId() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getId, pageWrap.getModel().getId()); | 
|         } | 
|         if (pageWrap.getModel().getIsdeleted() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|         } | 
|         if (pageWrap.getModel().getCreateDate() != null) { | 
|             queryWrapper.lambda().ge(BjParam::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|             queryWrapper.lambda().le(BjParam::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|         } | 
|         if (pageWrap.getModel().getCreator() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getCreator, pageWrap.getModel().getCreator()); | 
|         } | 
|         if (pageWrap.getModel().getEditDate() != null) { | 
|             queryWrapper.lambda().ge(BjParam::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|             queryWrapper.lambda().le(BjParam::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|         } | 
|         if (pageWrap.getModel().getEditor() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getEditor, pageWrap.getModel().getEditor()); | 
|         } | 
|         if (pageWrap.getModel().getType() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getType, pageWrap.getModel().getType()); | 
|         } | 
|         if (pageWrap.getModel().getInfo() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getInfo, pageWrap.getModel().getInfo()); | 
|         } | 
|         if (pageWrap.getModel().getName() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getName, pageWrap.getModel().getName()); | 
|         } | 
|         if (pageWrap.getModel().getRate() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getRate, pageWrap.getModel().getRate()); | 
|         } | 
|         if (pageWrap.getModel().getParentId() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getParentId, pageWrap.getModel().getParentId()); | 
|         } | 
|         if (pageWrap.getModel().getSortnum() != null) { | 
|             queryWrapper.lambda().eq(BjParam::getSortnum, pageWrap.getModel().getSortnum()); | 
|         } | 
|         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|                 queryWrapper.orderByDesc(sortData.getProperty()); | 
|             } else { | 
|                 queryWrapper.orderByAsc(sortData.getProperty()); | 
|             } | 
|         } | 
|         return PageData.from(bjParamMapper.selectPage(page, queryWrapper)); | 
|     } | 
|   | 
|     @Override | 
|     public long count(BjParam bjParam) { | 
|         QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam); | 
|         return bjParamMapper.selectCount(wrapper); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public BjParamConfigResponse getBjParamConfig(){ | 
|         BjParamConfigResponse bjParamConfigResponse = new BjParamConfigResponse(); | 
|         List<BjParam> bjParamList =  bjParamMapper.selectList(new QueryWrapper<BjParam>() | 
|                .lambda().eq(BjParam::getIsdeleted,Constants.ZERO).orderByAsc(BjParam::getSortnum)); | 
|         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(bjParamList)){ | 
|             List<BjParam> roughList = bjParamList.stream().filter(i->i.getType().equals(Constants.ZERO+"")&& StringUtils.isEmpty(i.getParentId())).collect(Collectors.toList()); | 
|             if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(roughList)){ | 
|                 for (BjParam bjParam:roughList) { | 
|                     bjParam.setChildren( | 
|                             bjParamList.stream().filter(i->i.getType().equals(Constants.ZERO+"") | 
|                                     && Objects.nonNull(i.getParentId()) | 
|                                     && i.getParentId().equals(bjParam.getId())).collect(Collectors.toList()) | 
|                     ); | 
|                 } | 
|             } | 
|             List<BjParam> exquisiteList = bjParamList.stream().filter(i->i.getType().equals(Constants.ONE+"")&& StringUtils.isEmpty(i.getParentId())).collect(Collectors.toList()); | 
|             if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(exquisiteList)){ | 
|                 for (BjParam bjParam:exquisiteList) { | 
|                     bjParam.setChildren( | 
|                             bjParamList.stream().filter(i->i.getType().equals(Constants.ONE+"") | 
|                                     && Objects.nonNull(i.getParentId()) | 
|                                     && i.getParentId().equals(bjParam.getId())).collect(Collectors.toList()) | 
|                     ); | 
|                 } | 
|             } | 
|             bjParamConfigResponse.setRoughList(roughList); | 
|             bjParamConfigResponse.setExquisiteList(exquisiteList); | 
|         } | 
|         return bjParamConfigResponse; | 
|     } | 
|   | 
|   | 
|   | 
| } |