/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.assessment.service.impl; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.AllArgsConstructor; import org.springblade.common.cache.SysCache; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; import org.springblade.modules.assessment.entity.AssessmentConfigEntity; import org.springblade.modules.assessment.excel.AssessmentConfigExcel; import org.springblade.modules.assessment.mapper.AssessmentConfigMapper; import org.springblade.modules.assessment.service.IAssessmentConfigService; import org.springblade.modules.assessment.vo.AssessmentConfigVO; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IUserService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Objects; /** * 考核权重配置表 服务实现类 * * @author Aix * @since 2024-02-21 */ @Service @AllArgsConstructor public class AssessmentConfigServiceImpl extends BaseServiceImpl implements IAssessmentConfigService { private final IUserService userService; @Override public IPage selectAssessmentConfigPage(IPage page, AssessmentConfigVO assessmentConfig) { return page.setRecords(baseMapper.selectAssessmentConfigPage(page, assessmentConfig)); } @Override public List exportAssessmentConfig(Wrapper queryWrapper) { List assessmentConfigList = baseMapper.exportAssessmentConfig(queryWrapper); //assessmentConfigList.forEach(assessmentConfig -> { // assessmentConfig.setTypeName(DictCache.getValue(DictEnum.YES_NO, AssessmentConfig.getType())); //}); return assessmentConfigList; } @Override @Transactional(rollbackFor = Exception.class) public void importData(List data, Boolean isCovered) { data.forEach(configExcel -> { System.out.println("username:" + configExcel.getUserName()); System.out.println("username:" + configExcel.getAssessorUserName()); if (configExcel.getUserName() != null && configExcel.getDeptName() != null) { AssessmentConfigEntity po = Objects.requireNonNull(BeanUtil.copy(configExcel, AssessmentConfigEntity.class)); // 被考核人信息 QueryWrapper qw = new QueryWrapper(); qw.eq("name", po.getUserName().trim()); qw.eq("dept_id", Func.toStrWithEmpty(SysCache.getDeptIds("000000", po.getDeptName().trim()), StringPool.EMPTY)); User user = userService.getOne(qw); if (null == user) { throw new RuntimeException("用户:" + po.getUserName() + ",离职或者不存在员工信息中,请核对数据"); } po.setUserId(user.getId()); po.setDeptId(Func.toLong(user.getDeptId())); po.setDeptName(po.getDeptName()); po.setPostName(SysCache.getPostName(Func.toLong(user.getPostId()))); //考核人信息 QueryWrapper beQw = new QueryWrapper(); beQw.eq("name", po.getAssessorUserName().trim()); beQw.eq("dept_id", Func.toStrWithEmpty(SysCache.getDeptIds("000000", po.getAssessorDeptName().trim()), StringPool.EMPTY)); User beUser = userService.getOne(beQw); if (null == beUser) { throw new RuntimeException("用户:" + po.getAssessorUserName() + ",离职或者不存在员工信息中,请核对数据"); } po.setAssessorUserId(beUser.getId()); po.setAssessorDeptId(Func.toLong(beUser.getDeptId())); po.setAssessorDeptName(po.getAssessorDeptName()); po.setAssessorPostName(SysCache.getPostName(Func.toLong(beUser.getPostId()))); // 覆盖数据 if (isCovered) { QueryWrapper configQw = new QueryWrapper(); configQw.eq("user_id", po.getUserId()); configQw.eq("assessor_user_id", po.getAssessorUserId()); AssessmentConfigEntity assessmentConfig = getOne(configQw); if (assessmentConfig != null && assessmentConfig.getId() != null) { po.setId(assessmentConfig.getId()); } } saveOrUpdate(po); } }); } }