diff --git a/ruoyi-kaohe/pom.xml b/ruoyi-kaohe/pom.xml index f024544..f68c93e 100644 --- a/ruoyi-kaohe/pom.xml +++ b/ruoyi-kaohe/pom.xml @@ -32,6 +32,10 @@ json 20210307 + + com.ruoyi + ruoyi-system + \ No newline at end of file diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java index aed4af2..1f3d2d2 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java @@ -1,6 +1,8 @@ package com.ruoyi.kaohe.controller; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.net.URLEncoder; import java.util.*; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; @@ -10,6 +12,7 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.kaohe.domain.*; import com.ruoyi.kaohe.service.IKhVoteEmpService; import com.ruoyi.kaohe.service.IKhVoteService; +import com.ruoyi.kaohe.util.EnhancedJsonExporter; import com.ruoyi.kaohe.util.PinYinUtil; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; @@ -51,14 +54,16 @@ public class KhKhrwResultController extends BaseController { @PreAuthorize("@ss.hasPermi('kaohe:kh_result:generate')") @PostMapping("/generateResult") public AjaxResult generateResult(KhPingce pc) { //传递参数 id、pcTitle、bkhdxtype + boolean isUpdate=false; //查询是否已经生成结果 KhKhrwResult resultQuery = new KhKhrwResult(); resultQuery.setPcId(pc.getId()); List khKhrwResults = khKhrwResultService.selectKhKhrwResultList(resultQuery); if(khKhrwResults!=null&&khKhrwResults.size()>0){ - return AjaxResult.error("该考核任务已有生成结果!"); + isUpdate=true; + pc.setPcResultId(khKhrwResults.get(0).getId()); } - return khKhrwResultService.generateResult(pc); + return khKhrwResultService.generateResult(pc,isUpdate); } /** @@ -83,6 +88,20 @@ public class KhKhrwResultController extends BaseController { ExcelUtil util = new ExcelUtil(KhKhrwResult.class); util.exportExcel(response, list, "考核结果数据"); } + /** + * 根据考核结果id导出具体考核结果 + */ + @PreAuthorize("@ss.hasPermi('kaohe:kh_result:export')") + @Log(title = "考核结果", businessType = BusinessType.EXPORT) + @PostMapping("/exportById") + public void exportById(HttpServletResponse response, Long id) throws Exception { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("汇总数据.xlsx", "UTF-8")); + KhKhrwResult khrwResult = khKhrwResultService.selectKhKhrwResultById(id); + String tableHeader = khrwResult.getTableHeader(); + String tableData = khrwResult.getTableData(); + EnhancedJsonExporter.exportWithMergedHeader(tableHeader,tableData,response); + } /** * 获取考核结果详细信息 diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java index 4a585a0..5d327bf 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java @@ -1,5 +1,6 @@ package com.ruoyi.kaohe.controller; +import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.kaohe.domain.KhPcEmp; @@ -44,7 +45,7 @@ public class KhVoteController extends BaseController { @Autowired private IKhVoteEmpService voteEmpService; - /*@Scheduled(cron = "0 * * * * ?") // 每分钟的第0秒执行一次 监测时间修改评分状态 + @Scheduled(cron = "0 * * * * ?") // 每分钟的第0秒执行一次 监测时间修改评分状态 public void performTask() { System.out.println("进入定时任务-------------------------------------------------------------"); //获取所有未完成的评分任务 @@ -67,7 +68,7 @@ public class KhVoteController extends BaseController { System.out.println("执行定时任务: " + System.currentTimeMillis() + " 修改评分任务: " + vote.getVoteTitle() + " 状态为已完成"); } } - }*/ + } /** * 查询投票评测列表 @@ -122,27 +123,48 @@ public class KhVoteController extends BaseController { @Transactional public AjaxResult add(@RequestBody KhVote khVote) { khVoteService.insertKhVote(khVote); - //根据评测id查询职工评测关联 职工 - KhPcEmp query = new KhPcEmp(); - query.setPcId(khVote.getPingceId()); - List pcEmps = pcEmpService.selectKhPcEmpList(query); - for (KhPcEmp pcEmp : pcEmps) { - //新增投票选项关联表 - KhVoteEmp voteEmp = new KhVoteEmp(); - voteEmp.setBkhdxId(pcEmp.getBkhdxId()); - voteEmp.setBkhdxName(pcEmp.getBkhdxName()); - voteEmp.setVoteId(khVote.getId()); - voteEmp.setVoteTitle(khVote.getVoteTitle()); - voteEmp.setPercentage(khVote.getPercentage()); - voteEmp.setKhitemTypeid(khVote.getKhitemTypeid()); - if(khVote.getKhitemTypeid().equals(1L)){ - voteEmp.setOptionA(BigDecimal.ZERO); - voteEmp.setOptionB(BigDecimal.ZERO); - voteEmp.setOptionC(BigDecimal.ZERO); - voteEmp.setOptionD(BigDecimal.ZERO); + if(khVote.getSamePercent()==null||khVote.getSamePercent().equals("0")){ + //根据评测id查询职工评测关联 职工 + KhPcEmp query = new KhPcEmp(); + query.setPcId(khVote.getPingceId()); + List pcEmps = pcEmpService.selectKhPcEmpList(query); + for (KhPcEmp pcEmp : pcEmps) { + //新增投票选项关联表 + KhVoteEmp voteEmp = new KhVoteEmp(); + voteEmp.setBkhdxId(pcEmp.getBkhdxId()); + voteEmp.setBkhdxName(pcEmp.getBkhdxName()); + voteEmp.setVoteId(khVote.getId()); + voteEmp.setVoteTitle(khVote.getVoteTitle()); + voteEmp.setPercentage(khVote.getPercentage()); + voteEmp.setKhitemTypeid(khVote.getKhitemTypeid()); + if(khVote.getKhitemTypeid().equals(1L)){ + voteEmp.setOptionA(BigDecimal.ZERO); + voteEmp.setOptionB(BigDecimal.ZERO); + voteEmp.setOptionC(BigDecimal.ZERO); + voteEmp.setOptionD(BigDecimal.ZERO); + } + voteEmpService.insertKhVoteEmp(voteEmp); + } + }else{ + for (KhVoteEmp vEmp : khVote.getVoteEmps()) { + //新增投票选项关联表 + KhVoteEmp voteEmp = new KhVoteEmp(); + voteEmp.setBkhdxId(vEmp.getBkhdxId()); + voteEmp.setBkhdxName(vEmp.getBkhdxName()); + voteEmp.setVoteId(khVote.getId()); + voteEmp.setVoteTitle(khVote.getVoteTitle()); + voteEmp.setPercentage(vEmp.getPercentage()); + voteEmp.setKhitemTypeid(khVote.getKhitemTypeid()); + if(khVote.getKhitemTypeid().equals(1L)){ + voteEmp.setOptionA(BigDecimal.ZERO); + voteEmp.setOptionB(BigDecimal.ZERO); + voteEmp.setOptionC(BigDecimal.ZERO); + voteEmp.setOptionD(BigDecimal.ZERO); + } + voteEmpService.insertKhVoteEmp(voteEmp); } - voteEmpService.insertKhVoteEmp(voteEmp); } + return AjaxResult.success(); } @@ -158,10 +180,23 @@ public class KhVoteController extends BaseController { KhVoteEmp query = new KhVoteEmp(); query.setVoteId(khVote.getId()); List khVoteEmps = voteEmpService.selectKhVoteEmpList(query); - for (KhVoteEmp khVoteEmp : khVoteEmps) { - khVoteEmp.setPercentage(khVote.getPercentage()); - khVoteEmp.setVoteTitle(khVote.getVoteTitle()); - voteEmpService.updateKhVoteEmp(khVoteEmp); + if (khVote.getSamePercent()==null||khVote.getSamePercent().equals("0")) { + for (KhVoteEmp khVoteEmp : khVoteEmps) { + khVoteEmp.setPercentage(khVote.getPercentage()); + khVoteEmp.setVoteTitle(khVote.getVoteTitle()); + voteEmpService.updateKhVoteEmp(khVoteEmp); + } + }else{ + //修改投票选项关联表 + for (KhVoteEmp khVoteEmp : khVoteEmps) { + for (KhVoteEmp vEmp : khVote.getVoteEmps()) { + if (vEmp.getBkhdxId().equals(khVoteEmp.getBkhdxId())) { + khVoteEmp.setPercentage(vEmp.getPercentage()); + } + } + khVoteEmp.setVoteTitle(khVote.getVoteTitle()); + voteEmpService.updateKhVoteEmp(khVoteEmp); + } } khVoteService.updateKhVote(khVote); return AjaxResult.success(); diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhEmployee.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhEmployee.java index 916105d..64c83a3 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhEmployee.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhEmployee.java @@ -26,9 +26,9 @@ public class KhEmployee extends BaseEntity { private Long userId; /** - * 职工所属部门 + * 部门ID */ - @Excel(name = "职工所属部门") + @Excel(name = "部门ID") private Long deptId; /** diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVote.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVote.java index f9f4a31..be33ef2 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVote.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVote.java @@ -81,7 +81,32 @@ public class KhVote extends BaseEntity * @return */ private List itemIds; + /** + * 被考核对象评分占比是否一致得参数,仅新增时使用 0相同 1不同 + * @return + */ + private String samePercent; + /** + * 被考核对象评分占比不一致时 保存所有考核对象的评分,仅新增时使用 + * @return + */ + private List voteEmps; + public String getSamePercent() { + return samePercent; + } + + public void setSamePercent(String samePercent) { + this.samePercent = samePercent; + } + + public List getVoteEmps() { + return voteEmps; + } + + public void setVoteEmps(List voteEmps) { + this.voteEmps = voteEmps; + } public List getItemIds() { return itemIds; diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhKhrwResultService.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhKhrwResultService.java index 06d5601..699a766 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhKhrwResultService.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhKhrwResultService.java @@ -62,5 +62,5 @@ public interface IKhKhrwResultService */ public int deleteKhKhrwResultById(Long id); - AjaxResult generateResult(KhPingce pc); + AjaxResult generateResult(KhPingce pc,boolean isUpdate); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhEmployeeServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhEmployeeServiceImpl.java index b632232..f36a839 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhEmployeeServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhEmployeeServiceImpl.java @@ -2,12 +2,14 @@ package com.ruoyi.kaohe.service.impl; import java.util.List; +import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.system.mapper.SysDeptMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,145 +22,130 @@ import javax.annotation.Resource; /** * 职工信息Service业务层处理 - * + * * @author hs * @date 2025-06-17 */ @Service -public class KhEmployeeServiceImpl implements IKhEmployeeService -{ +public class KhEmployeeServiceImpl implements IKhEmployeeService { @Resource private KhEmployeeMapper khEmployeeMapper; + @Resource + private SysDeptMapper deptMapper; private static final Logger log = LoggerFactory.getLogger(KhEmployeeServiceImpl.class); /** * 查询职工信息 - * + * * @param id 职工信息主键 * @return 职工信息 */ @Override - public KhEmployee selectKhEmployeeById(Long id) - { + public KhEmployee selectKhEmployeeById(Long id) { return khEmployeeMapper.selectKhEmployeeById(id); } /** * 查询职工信息列表 - * + * * @param khEmployee 职工信息 * @return 职工信息 */ @Override - public List selectKhEmployeeList(KhEmployee khEmployee) - { + public List selectKhEmployeeList(KhEmployee khEmployee) { return khEmployeeMapper.selectKhEmployeeList(khEmployee); } /** * 新增职工信息 - * + * * @param khEmployee 职工信息 * @return 结果 */ @Override - public int insertKhEmployee(KhEmployee khEmployee) - { + public int insertKhEmployee(KhEmployee khEmployee) { khEmployee.setCreateTime(DateUtils.getNowDate()); return khEmployeeMapper.insertKhEmployee(khEmployee); } /** * 修改职工信息 - * + * * @param khEmployee 职工信息 * @return 结果 */ @Override - public int updateKhEmployee(KhEmployee khEmployee) - { + public int updateKhEmployee(KhEmployee khEmployee) { khEmployee.setUpdateTime(DateUtils.getNowDate()); return khEmployeeMapper.updateKhEmployee(khEmployee); } /** * 批量删除职工信息 - * + * * @param ids 需要删除的职工信息主键 * @return 结果 */ @Override - public int deleteKhEmployeeByIds(Long[] ids) - { + public int deleteKhEmployeeByIds(Long[] ids) { return khEmployeeMapper.deleteKhEmployeeByIds(ids); } /** * 删除职工信息信息 - * + * * @param id 职工信息主键 * @return 结果 */ @Override - public int deleteKhEmployeeById(Long id) - { + public int deleteKhEmployeeById(Long id) { return khEmployeeMapper.deleteKhEmployeeById(id); } @Override public String importEmp(List empList, boolean updateSupport, String operName) { - if (StringUtils.isNull(empList) || empList.size() == 0) - { + if (StringUtils.isNull(empList) || empList.size() == 0) { throw new ServiceException("导入职工数据不能为空!"); } int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); - for (KhEmployee employee : empList) - { - try - { + for (KhEmployee employee : empList) { + try { + //根据deptId查询deptName + SysDept sysDept = deptMapper.selectDeptById(employee.getDeptId()); + employee.setDeptName(sysDept.getDeptName()); // 验证是否存在这个职工 KhEmployee param = new KhEmployee(); param.setEmpName(employee.getEmpName()); param.setDeptId(employee.getDeptId()); List e = khEmployeeMapper.selectKhEmployeeList(param); - if (StringUtils.isNull(e)||e.size()==0) - { + if (StringUtils.isNull(e) || e.size() == 0) { khEmployeeMapper.insertKhEmployee(employee); successNum++; successMsg.append("
" + successNum + "、账号 " + employee.getEmpName() + " 导入成功"); - } - else if (updateSupport) - { + } else if (updateSupport) { employee.setId(e.get(0).getId()); khEmployeeMapper.updateKhEmployee(employee); successNum++; successMsg.append("
" + successNum + "、账号 " + employee.getEmpName() + " 更新成功"); - } - else - { + } else { failureNum++; failureMsg.append("
" + failureNum + "、账号 " + employee.getEmpName() + " 已存在"); } - } - catch (Exception e) - { + } catch (Exception e) { failureNum++; String msg = "
" + failureNum + "、账号 " + employee.getEmpName() + " 导入失败:"; failureMsg.append(msg + e.getMessage()); log.error(msg, e); } } - if (failureNum > 0) - { + if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); throw new ServiceException(failureMsg.toString()); - } - else - { + } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); } return successMsg.toString(); diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhKhrwResultServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhKhrwResultServiceImpl.java index 1ba078a..8b54aaa 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhKhrwResultServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhKhrwResultServiceImpl.java @@ -108,7 +108,7 @@ public class KhKhrwResultServiceImpl implements IKhKhrwResultService } @Override - public AjaxResult generateResult(KhPingce pc) { + public AjaxResult generateResult(KhPingce pc,boolean isUpdate) { JSONArray children = new JSONArray(); JSONObject tableColumn = new JSONObject(); tableColumn.put("name", "khdx"); @@ -250,7 +250,13 @@ public class KhKhrwResultServiceImpl implements IKhKhrwResultService pcResult.setPcName(pc.getPcTitle()); pcResult.setTableHeader(children.toJSONString()); pcResult.setTableData(endData.toJSONString()); - this.insertKhKhrwResult(pcResult); - return AjaxResult.success(); + if(isUpdate){ + pcResult.setId(pc.getPcResultId()); + this.updateKhKhrwResult(pcResult); + return AjaxResult.success("更新成功"); + }else{ + this.insertKhKhrwResult(pcResult); + return AjaxResult.success("生成成功"); + } } } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java index 236ae8e..943fdf0 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java @@ -1,12 +1,17 @@ package com.ruoyi.kaohe.service.impl; import java.util.List; +import java.util.stream.Collectors; + import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.kaohe.domain.KhVoteEmp; +import com.ruoyi.kaohe.mapper.KhVoteEmpMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.kaohe.mapper.KhVoteMapper; import com.ruoyi.kaohe.domain.KhVote; import com.ruoyi.kaohe.service.IKhVoteService; +import org.springframework.transaction.annotation.Transactional; /** * 投票评测Service业务层处理 @@ -19,7 +24,8 @@ public class KhVoteServiceImpl implements IKhVoteService { @Autowired private KhVoteMapper khVoteMapper; - + @Autowired + private KhVoteEmpMapper khVoteEmpMapper; /** * 查询投票评测 * @@ -77,8 +83,18 @@ public class KhVoteServiceImpl implements IKhVoteService * @return 结果 */ @Override + @Transactional public int deleteKhVoteByIds(Long[] ids) { + //voteid查询职工评分修改对应值 同步删除关联表对应数据 + for (Long id : ids) { + KhVoteEmp query = new KhVoteEmp(); + query.setVoteId(id); + List khVoteEmps = khVoteEmpMapper.selectKhVoteEmpList(query); + List veIds = khVoteEmps.stream().map(KhVoteEmp::getId).collect(Collectors.toList()); + khVoteEmpMapper.deleteKhVoteEmpByIds(veIds.toArray(new Long[veIds.size()])); + } + return khVoteMapper.deleteKhVoteByIds(ids); } diff --git a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml index de2d09d..351422f 100644 --- a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml +++ b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml @@ -19,6 +19,7 @@ + @@ -27,7 +28,7 @@ - select id, pingce_id, pingce_name, khitem_id, khitem_name, khitem_typeId, vote_items, vote_title, v_description, s_time, e_time, max_num, percentage, state, create_by, create_time, update_by, update_time, remark from kh_vote + select id, pingce_id, pingce_name, khitem_id, khitem_name, khitem_typeId, vote_items, vote_title, v_description, s_time, e_time, max_num, percentage, `state`,same_percent, create_by, create_time, update_by, update_time, remark from kh_vote