diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhPingceController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhPingceController.java index c55a18a..6b9f22e 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhPingceController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhPingceController.java @@ -16,14 +16,7 @@ import com.ruoyi.kaohe.util.PinYinUtil; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -162,8 +155,9 @@ public class KhPingceController extends BaseController { * 考核任务 修改被考核对象(添加/删除被考核对象) * 传参:id、pcBkhdxs、addOrDel、bkhdxType */ + // @PreAuthorize("@ss.hasPermi('kaohe:pingce:modifyBkhdx')") @Log(title = "考核评测", businessType = BusinessType.UPDATE) - @DeleteMapping("/modifyBkhdx") + @PutMapping("/modifyBkhdx") @Transactional public AjaxResult modifyBkhdx(@RequestBody ModifyBkhdxParam bkhdxParam) { Long id = bkhdxParam.getId(); @@ -176,7 +170,7 @@ public class KhPingceController extends BaseController { vote.setPingceId(id); List khVotes = khVoteService.selectKhVoteList(vote); - if (bkhdxParam.getAddOrDel().equals("0")) { //0添加被考核对象 + if (bkhdxParam.getAddOrDel().equals("0")) { //0添加被考核对象 1删除 for (Bkhdx item : pcEmps) { KhPcEmp pcEmp = new KhPcEmp(); pcEmp.setPcId(bkhdxParam.getId()); @@ -242,58 +236,92 @@ public class KhPingceController extends BaseController { /** - * 删除考核评测——————清理数据库时调用, 清除已完成的全部关联数据、进行中的仅清除voteemp已打票的成绩 保留考核项及关联的voteemp - * vote_recard表直接全部清除 截断表即可 + * ids传入为null——————清理数据库时调用, 清除已完成的全部关联数据、进行中的仅清除voteemp的打票成绩 保留考核项及关联的voteemp + * ids有值 按任务id-----修改所有关联的vote的voteemp数据为原始状态 + * 清理数据库时:vote_recard表手动直接全部清除 截断表即可 */ // @PreAuthorize("@ss.hasPermi('kaohe:pingce:remove')") @Log(title = "考核评测", businessType = BusinessType.DELETE) @DeleteMapping("/clean") @Transactional - public AjaxResult removeTest() { - //已完成的数据直接清除任务及所有关联数据 - KhPingce khPingce = new KhPingce(); - khPingce.setState("2"); - List wPingces = khPingceService.selectKhPingceList(khPingce); - if (wPingces != null && wPingces.size() > 0) { - List wIds = wPingces.stream().map(KhPingce::getId).collect(Collectors.toList()); - khPingceService.deleteKhPingceByIds2(wIds.toArray(new Long[wIds.size()])); - } - - //进行中 的数据 修改关联的vote及voteemp数据为原始状态 - KhPingce jxz = new KhPingce(); - jxz.setState("1"); - List jxzPingces = khPingceService.selectKhPingceList(jxz); - List jxzIds = jxzPingces.stream().map(KhPingce::getId).collect(Collectors.toList()); - for (Long jxzId : jxzIds) { - KhVote vote = new KhVote(); - vote.setPingceId(jxzId); - List votes = khVoteService.selectKhVoteList(vote); - List vIds = votes.stream().map(KhVote::getId).collect(Collectors.toList()); - if (vIds != null && vIds.size() > 0) { - //修改voteemp - for (Long vId : vIds) { - KhVoteEmp vemp = new KhVoteEmp(); - vemp.setVoteId(vId); - List vEmps = khVoteEmpService.selectKhVoteEmpList(vemp); - if (vEmps != null && vEmps.size() > 0) { - //修改关联的员工数据到最初创建状态 - for (KhVoteEmp uPEmp : vEmps) { - uPEmp.setVoteNum(BigDecimal.ZERO); - uPEmp.setVoteScore(BigDecimal.ZERO); - uPEmp.setAvgScore(BigDecimal.ZERO); - uPEmp.setEndScore(BigDecimal.ZERO); - if (uPEmp.getKhitemTypeid().equals(1L)) { - uPEmp.setOptionA(BigDecimal.ZERO); - uPEmp.setOptionB(BigDecimal.ZERO); - uPEmp.setOptionC(BigDecimal.ZERO); - uPEmp.setOptionD(BigDecimal.ZERO); + public AjaxResult removeTest(@RequestParam Long[] ids) { + if(ids!=null&&ids.length>0){ //按任务id-----修改所有关联的vote的voteemp数据为原始状态 + for (Long jxzId : ids) { + KhVote vote = new KhVote(); + vote.setPingceId(jxzId); + List votes = khVoteService.selectKhVoteList(vote); + List vIds = votes.stream().map(KhVote::getId).collect(Collectors.toList()); + if (vIds != null && vIds.size() > 0) { + //修改voteemp + for (Long vId : vIds) { + KhVoteEmp vemp = new KhVoteEmp(); + vemp.setVoteId(vId); + List vEmps = khVoteEmpService.selectKhVoteEmpList(vemp); + if (vEmps != null && vEmps.size() > 0) { + //修改关联的员工数据到最初创建状态 + for (KhVoteEmp uPEmp : vEmps) { + uPEmp.setVoteNum(BigDecimal.ZERO); + uPEmp.setVoteScore(BigDecimal.ZERO); + uPEmp.setAvgScore(BigDecimal.ZERO); + uPEmp.setEndScore(BigDecimal.ZERO); + if (uPEmp.getKhitemTypeid().equals(1L)) { + uPEmp.setOptionA(BigDecimal.ZERO); + uPEmp.setOptionB(BigDecimal.ZERO); + uPEmp.setOptionC(BigDecimal.ZERO); + uPEmp.setOptionD(BigDecimal.ZERO); + } + khVoteEmpService.updateKhVoteEmp(uPEmp); + } + } + } + } + } + }else{//null认为清理所有 (已完成删除全部数据,进行中数据清除评分数据) + //已完成的数据直接清除任务及所有关联数据————完全删除已完成任务 + KhPingce khPingce = new KhPingce(); + khPingce.setState("2"); + List wPingces = khPingceService.selectKhPingceList(khPingce); + if (wPingces != null && wPingces.size() > 0) { + List wIds = wPingces.stream().map(KhPingce::getId).collect(Collectors.toList()); + khPingceService.deleteKhPingceByIds2(wIds.toArray(new Long[wIds.size()])); + } + //进行中 的数据 修改关联的vote及voteemp数据为原始状态 + KhPingce jxz = new KhPingce(); + jxz.setState("1"); + List jxzPingces = khPingceService.selectKhPingceList(jxz); + List jxzIds = jxzPingces.stream().map(KhPingce::getId).collect(Collectors.toList()); + for (Long jxzId : jxzIds) { + KhVote vote = new KhVote(); + vote.setPingceId(jxzId); + List votes = khVoteService.selectKhVoteList(vote); + List vIds = votes.stream().map(KhVote::getId).collect(Collectors.toList()); + if (vIds != null && vIds.size() > 0) { + //修改voteemp + for (Long vId : vIds) { + KhVoteEmp vemp = new KhVoteEmp(); + vemp.setVoteId(vId); + List vEmps = khVoteEmpService.selectKhVoteEmpList(vemp); + if (vEmps != null && vEmps.size() > 0) { + //修改关联的员工数据到最初创建状态 + for (KhVoteEmp uPEmp : vEmps) { + uPEmp.setVoteNum(BigDecimal.ZERO); + uPEmp.setVoteScore(BigDecimal.ZERO); + uPEmp.setAvgScore(BigDecimal.ZERO); + uPEmp.setEndScore(BigDecimal.ZERO); + if (uPEmp.getKhitemTypeid().equals(1L)) { + uPEmp.setOptionA(BigDecimal.ZERO); + uPEmp.setOptionB(BigDecimal.ZERO); + uPEmp.setOptionC(BigDecimal.ZERO); + uPEmp.setOptionD(BigDecimal.ZERO); + } + khVoteEmpService.updateKhVoteEmp(uPEmp); } - khVoteEmpService.updateKhVoteEmp(uPEmp); } } } } } + return toAjax(1); } }