package com.zbooksoft.gdmis.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruili.wcp.service.config.ModuleService; import com.ruili.wcp.service.config.ViewService; import com.zbooksoft.gdmis.dao.StudyMaterialMapper; import com.zbooksoft.gdmis.data.entity.CatAjjxx; import com.zbooksoft.gdmis.data.entity.StudyMaterial; import com.zbooksoft.gdmis.service.CatAjjxxService; import com.zbooksoft.gdmis.service.StudyMaterialService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import java.util.List; @Slf4j @Service public class StudyMaterialServiceImpl extends ServiceImpl implements StudyMaterialService { @Autowired private ModuleService moduleService; @Autowired private ViewService viewService; @Autowired private StudyMaterialService studyMaterialService; @Autowired private JdbcTemplate jdbcTemplate; @Autowired private CatAjjxxService catAjjxxService; @Override public String addByIdList(Long studyId, List idList) { int successCount = 0; int errorCount = 0; String errorMsg = ""; //通过id取专题名称返回 String sql = "SELECT TYPE_NAME FROM UTL_STUDY_TYPE WHERE ID=" + studyId; String typeName = jdbcTemplate.queryForObject(sql, String.class); for (Long id : idList) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("key_id", id); if (studyMaterialService.count(wrapper) == 0) { CatAjjxx catAjjxx = catAjjxxService.getById(id); StudyMaterial studyMaterial = new StudyMaterial(); studyMaterial.setKeyId(id); studyMaterial.setTypeId(studyId); studyMaterial.setTypeName(typeName); studyMaterial.setArchivalCode(catAjjxx.getSgdh()); studyMaterial.setTitle(catAjjxx.getZlmc()); studyMaterial.setSecurityClassification(catAjjxx.getMj()); studyMaterial.setDeptName(catAjjxx.getXcdwmc()); studyMaterial.setProjectName(catAjjxx.getXmkyqmc()); studyMaterial.setProjectNumber(catAjjxx.getXmkyqbh()); studyMaterial.setConfluenceNum(catAjjxx.getHjpzh()); studyMaterial.setFormationDate(catAjjxx.getXcsj()); studyMaterialService.saveOrUpdate(studyMaterial); successCount++; } else { errorCount++; } } if (errorCount == 0) { errorMsg = "成功添加" + successCount + "条!可以继续选择数据,完成后请手动关闭窗口!"; } else { if (successCount == 0) { errorMsg = "加入失败的条数为" + errorCount + "条!可以继续选择数据,完成后请手动关闭窗口!"; } else { errorMsg = "成功添加条数为" + successCount + "条," + "加入失败的条数为" + errorCount + "条!可以继续选择数据,完成后请手动关闭窗口!"; } } return errorMsg; } }