|  | @@ -0,0 +1,112 @@
 | 
	
		
			
				|  |  | +package com.xunmei.core.drill.service.impl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  | +import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.DictConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.ErrorMsgConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.domain.CoreDrillDictionaryBranch;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.dto.CoreDrillDictBranchInsertDto;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.dto.CoreDrillDictBranchPageDto;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.dto.CoreDrillDictBranchUpdateDto;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.vo.CoreDrillDictionaryBranchDetailVo;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.drill.vo.CoreDrillDictionaryBranchPageVo;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.web.page.TableDataInfo;
 | 
	
		
			
				|  |  | +import com.xunmei.common.security.utils.DictUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.common.security.utils.SecurityUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.core.drill.mapper.CoreDrillDictionaryBranchMapper;
 | 
	
		
			
				|  |  | +import com.xunmei.core.drill.service.ICoreDrillDictionaryBranchService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SysDictData;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 | 
	
		
			
				|  |  | +import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class CoreDrillDictionaryBranchServiceImpl extends ServiceImpl<CoreDrillDictionaryBranchMapper, CoreDrillDictionaryBranch> implements ICoreDrillDictionaryBranchService {
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private CoreDrillDictionaryBranchMapper branchMapper;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private RemoteOrgService orgService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public TableDataInfo<CoreDrillDictionaryBranchPageVo> selectPage(CoreDrillDictBranchPageDto dto) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysOrg org = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +        if (Boolean.TRUE.equals(dto.getCheckSub())) {
 | 
	
		
			
				|  |  | +            dto.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Page<CoreDrillDictionaryBranchPageVo> page = branchMapper.selectPageData(dto.getPageRequest(),dto);
 | 
	
		
			
				|  |  | +        page.getRecords()
 | 
	
		
			
				|  |  | +                .forEach(coreDrillDictionaryPageVo -> {
 | 
	
		
			
				|  |  | +                    if (StringUtil.isNullOrEmpty(coreDrillDictionaryPageVo.getDrillCategory())) {
 | 
	
		
			
				|  |  | +                        return;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    coreDrillDictionaryPageVo.setDrillCategoryName(DictUtils.getDictLabel(DictConstants.CORE_DRILL_CATEGORY, Integer.parseInt(coreDrillDictionaryPageVo.getDrillCategory())));
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //抓换为TableDataInfo适配前端
 | 
	
		
			
				|  |  | +        return TableDataInfo.build(page);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public CoreDrillDictionaryBranchDetailVo getCoreDrillDictionaryBranchById(Long id) {
 | 
	
		
			
				|  |  | +        CoreDrillDictionaryBranchDetailVo detailVo = branchMapper.getCoreDrillDictionaryBranchById(id);
 | 
	
		
			
				|  |  | +        if (ObjectUtil.isNotEmpty(detailVo.getDrillCategory())){
 | 
	
		
			
				|  |  | +            detailVo.setDrillCategoryName(DictUtils.getDictLabel(DictConstants.CORE_DRILL_CATEGORY, Integer.parseInt(detailVo.getDrillCategory())));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return detailVo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int deleteCoreDrillDictionaryBranchById(Long id) {
 | 
	
		
			
				|  |  | +        return branchMapper.deleteById(id);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int insertCoreDrillDictionaryBranch(CoreDrillDictBranchInsertDto insertDto) {
 | 
	
		
			
				|  |  | +        final CoreDrillDictionaryBranch dictionaryBranch = new CoreDrillDictionaryBranch();
 | 
	
		
			
				|  |  | +        final List<SysDictData> drillTypeDictList = DictUtils.getDictCache(DictConstants.CORE_DRILL_TYPE);
 | 
	
		
			
				|  |  | +        BeanUtils.copyProperties(insertDto, dictionaryBranch);
 | 
	
		
			
				|  |  | +        if (null != drillTypeDictList && ObjectUtil.isNotEmpty(drillTypeDictList)) {
 | 
	
		
			
				|  |  | +            drillTypeDictList.stream().filter(dict -> ObjectUtil.equal(dict.getDictValue(), insertDto.getDrillType())).findFirst().ifPresent(dict -> dictionaryBranch.setDrillTypeName(dict.getDictLabel()));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        dictionaryBranch.setDrillCategoryName(DictUtils.getDictLabel(DictConstants.CORE_DRILL_CATEGORY, insertDto.getDrillCategory()));
 | 
	
		
			
				|  |  | +        dictionaryBranch.setDrillProjects(insertDto.getDrillProjects());
 | 
	
		
			
				|  |  | +        SysOrg sysOrg = getOrg(SecurityUtils.getLoginUser().getOrgId());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setOrgId(sysOrg.getId());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setOrgName(sysOrg.getShortName());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setOrgPath(sysOrg.getPath());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setCreateBy(SecurityUtils.getUserId().toString());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +        //dictionaryBranch.setUpdateBy(SecurityUtils.getUserId().toString());
 | 
	
		
			
				|  |  | +        //dictionaryBranch.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        return branchMapper.insert(dictionaryBranch);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int updateCoreDrillDictionaryBranch(CoreDrillDictBranchUpdateDto updateDto) {
 | 
	
		
			
				|  |  | +        if (null != updateDto && updateDto.getId() == null){
 | 
	
		
			
				|  |  | +            return 0;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        final CoreDrillDictionaryBranch dictionaryBranch = new CoreDrillDictionaryBranch();
 | 
	
		
			
				|  |  | +        BeanUtils.copyProperties(updateDto, dictionaryBranch);
 | 
	
		
			
				|  |  | +        dictionaryBranch.setUpdateBy(SecurityUtils.getUserId().toString());
 | 
	
		
			
				|  |  | +        dictionaryBranch.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        return branchMapper.updateById(dictionaryBranch);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private SysOrg getOrg(Long orgId) {
 | 
	
		
			
				|  |  | +        return RemoteCallHandlerExecutor.executeRemoteCall(() ->
 | 
	
		
			
				|  |  | +                orgService.selectOrgById(orgId, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |