kongzy
2024-09-23 d015cc0b48ca51a2b93b6c60c91dc352a104b1e7
goal-manage/goal-manage-service/src/main/java/com/gkhy/safePlatform/targetDuty/service/impl/ExamineTemplateServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.targetDuty.entity.ExamineItem;
import com.gkhy.safePlatform.targetDuty.entity.TargetDivideDetail;
import com.gkhy.safePlatform.targetDuty.entity.TargetMng;
@@ -14,8 +15,12 @@
import com.gkhy.safePlatform.targetDuty.repository.ExamineItemRepository;
import com.gkhy.safePlatform.targetDuty.repository.ExamineTemplateRepository;
import com.gkhy.safePlatform.targetDuty.entity.ExamineTemplate;
import com.gkhy.safePlatform.targetDuty.service.CommonService;
import com.gkhy.safePlatform.targetDuty.service.ExamineItemService;
import com.gkhy.safePlatform.targetDuty.service.ExamineTemplateService;
import com.gkhy.safePlatform.targetDuty.service.baseService.ExamineItemBaseService;
import com.gkhy.safePlatform.targetDuty.service.baseService.ExamineTemplateBaseService;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
@@ -28,11 +33,10 @@
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -42,16 +46,16 @@
 * @since 2022-07-21 10:58:10
 */
@Service("examineTemplateService")
public class ExamineTemplateServiceImpl extends ServiceImpl<ExamineTemplateRepository, ExamineTemplate> implements ExamineTemplateService {
public class ExamineTemplateServiceImpl implements ExamineTemplateService {
    @Autowired
    private ExamineTemplateRepository examineTemplateRepository;
    private ExamineTemplateBaseService examineTemplateBaseService;
    @Autowired
    private ExamineItemRepository examineItemRepository;
    private ExamineItemBaseService examineItemBaseService;
    @Autowired
    private ExamineItemService examineItemService;
    @Resource
    private CommonService commonService;
    
   
   @Override
@@ -60,17 +64,34 @@
        Long pageSize = pageQuery.getPageSize();
        IPage<ExamineTemplate> page = new Page<>(pageIndex, pageSize);
        page = baseMapper.selectPage(page,
        page = examineTemplateBaseService.selectPage(page,
                QueryHelpPlus.getPredicate(ExamineTemplate.class, pageQuery.getSearchParams()));
        List<ExamineTemplateDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), ExamineTemplateDto.class);
        // TODO:获取设定人部门名称
        // --------------------------- 获取部门信息-----------------------
        //收集所用到的部门ID
        Set<Long> collectDepIdSet = new HashSet();
        respList.forEach(f->{
            collectDepIdSet.add(f.getSetPersonDepartmentId());
        });
        //获取部门名集合
        Map<Long,String> depNameMap = commonService.getDepName(collectDepIdSet);
        respList.forEach(f->{
            f.setSetPersonDepartmentName(depNameMap.get(f.getSetPersonDepartmentId()));
        });
        //获取考核项目明细
        respList.forEach(f->{
            List<ExamineItem> list = examineItemBaseService.selectList(new QueryWrapper<ExamineItem>().eq("examine_template_id",f.getId()));
            f.setExamineItemList(list);
        });
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
@@ -80,42 +101,76 @@
    @Override
    public List<ExamineTemplate> queryAll(ExamineTemplateQueryCriteria criteria) {
        return baseMapper.selectList(QueryHelpPlus.getPredicate(ExamineTemplate.class, criteria));
        return examineTemplateBaseService.queryAll(criteria);
    }
    @Override
    public ExamineTemplateDto selectOne(Serializable id) {
        ExamineTemplate template = this.getById(id);
        ExamineTemplate template = examineTemplateBaseService.getById(id);
        if(template == null){
            return null;
        }
        ExamineTemplateDto dto = BeanCopyUtils.copyBean(template, ExamineTemplateDto.class);
        List<ExamineItem> list = examineItemRepository.selectList(new QueryWrapper<ExamineItem>().eq("examine_template_id",template.getId()));
        List<ExamineItem> list = examineItemBaseService.selectList(new QueryWrapper<ExamineItem>().eq("examine_template_id",template.getId()));
        dto.setExamineItemList(list);
        return dto;
    }
    @Override
    public void addOrUpdate(ExamineTemplateSaveOrUpdate infoDto) {
    public void addOrUpdate(ExamineTemplateSaveOrUpdate infoDto, Authentication authentication) {
        if(!StringUtils.hasText(infoDto.getTitle())){
            throw new TargetDutyException("缺少title");
        }
        // 获取当前用户
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        //设置设定人ID和设定人部门ID
        infoDto.setSetPersonDepartmentId(currentUser.getDepId());
        infoDto.setSetPersonId(currentUser.getUid());
        if(StringUtils.hasText(infoDto.getDelExamineItems())){
            List<Long> idList = Arrays.stream(infoDto.getDelExamineItems().split(",")).map(s-> Long.parseLong(s.trim()))
                    .collect(Collectors.toList());
            examineItemService.removeByIds(idList);
            List<ExamineItem> delList = new ArrayList<>();
            idList.forEach(f->{
                ExamineItem info = new ExamineItem();
                info.setDelFlag(1);
                info.setId(f);
                delList.add(info);
            });
            examineItemBaseService.updateBatchById(delList);
        }
        ExamineTemplate examineTemplate = BeanCopyUtils.copyBean(infoDto, ExamineTemplate.class);
        examineTemplate.setSetTimem(new Timestamp(new java.util.Date().getTime()));
        if (infoDto.getId() == null) {
            this.save(examineTemplate);
            examineTemplateBaseService.save(examineTemplate);
        } else {
            this.update(examineTemplate,new UpdateWrapper<ExamineTemplate>().eq("id",examineTemplate.getId()));
            examineTemplateBaseService.update(examineTemplate,new UpdateWrapper<ExamineTemplate>().eq("id",examineTemplate.getId()));
        }
        List<ExamineItem> list = infoDto.getExamineItemList();
        list.forEach(f->{f.setExamineTemplateId(infoDto.getId());});
        examineItemService.saveOrUpdateBatch(list);
        examineItemBaseService.saveOrUpdateBatch(list);
    }
    @Override
    public void delete(Long[] ids) {
        if(ids == null){
            throw  new TargetDutyException(ResultCodes.CLIENT_PARAM_ILLEGAL);
        }
        List<Long> idList = Arrays.asList(ids);
        List<ExamineTemplate> delList = new ArrayList<>();
        idList.forEach(f->{
            ExamineTemplate info = new ExamineTemplate();
            info.setDelFlag(1);
            info.setId(f);
            delList.add(info);
        });
        examineTemplateBaseService.updateBatchById(delList);
    }
}