TTrainingParticipantsController.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package com.ruoyi.project.training.controller;
  2. import java.text.SimpleDateFormat;
  3. import java.util.*;
  4. import com.ruoyi.project.plant.domain.TStaffmgr;
  5. import com.ruoyi.project.plant.service.ITStaffmgrService;
  6. import com.ruoyi.project.system.service.ISysDeptService;
  7. import com.ruoyi.project.system.service.ISysDictTypeService;
  8. import com.ruoyi.project.training.domain.TTrainingCompanylevel;
  9. import com.ruoyi.project.training.domain.TTrainingMatrix;
  10. import com.ruoyi.project.training.service.ITTrainingCompanylevelService;
  11. import com.ruoyi.project.training.service.ITTrainingMatrixService;
  12. import org.apache.commons.lang.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  16. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  17. import com.ruoyi.project.training.domain.TTrainingParticipants;
  18. import com.ruoyi.project.training.service.ITTrainingParticipantsService;
  19. import com.ruoyi.framework.web.controller.BaseController;
  20. import com.ruoyi.framework.web.domain.AjaxResult;
  21. import com.ruoyi.common.utils.poi.ExcelUtil;
  22. import com.ruoyi.framework.web.page.TableDataInfo;
  23. /**
  24. * 人员-公司级培训关系Controller
  25. *
  26. * @author ruoyi
  27. * @date 2021-05-30
  28. */
  29. @RestController
  30. @RequestMapping("/training/participants")
  31. public class TTrainingParticipantsController extends BaseController
  32. {
  33. @Autowired
  34. private ITTrainingParticipantsService tTrainingParticipantsService;
  35. @Autowired
  36. private ITTrainingCompanylevelService tTrainingCompanylevelService;
  37. @Autowired
  38. private ITStaffmgrService tStaffmgrService;
  39. @Autowired
  40. private ISysDeptService iSysDeptService;
  41. @Autowired
  42. private ISysDictTypeService iSysDictTypeService;
  43. @Autowired
  44. private ITTrainingMatrixService tTrainingMatrixService;
  45. /**
  46. * 查询人员-公司级培训关系列表
  47. */
  48. @GetMapping("/list")
  49. public TableDataInfo list(TTrainingParticipants tTrainingParticipants)
  50. {
  51. startPage();
  52. List<TTrainingParticipants> list = tTrainingParticipantsService.selectTTrainingParticipantsList(tTrainingParticipants);
  53. return getDataTable(list);
  54. }
  55. /**
  56. * 查询人员-公司级培训关系列表
  57. */
  58. @GetMapping("/companyList")
  59. public Map<String, Object> companyList(TTrainingParticipants tTrainingParticipants)
  60. {
  61. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  62. List<TTrainingParticipants> list = tTrainingParticipantsService.selectTTrainingParticipantsList(tTrainingParticipants);
  63. List<List> companyLevelList = new ArrayList<>();
  64. List<TTrainingCompanylevel> tTrainingCompanylevels = tTrainingCompanylevelService.selectTTrainingCompanylevelList(new TTrainingCompanylevel());
  65. TStaffmgr staffmgr = new TStaffmgr();
  66. staffmgr.setUnits("10,18,20,30");
  67. staffmgr.setLeftYear(String.valueOf(Calendar.getInstance().YEAR));
  68. List<TStaffmgr> staffmgrs = tStaffmgrService.selectRecordList(staffmgr);
  69. try {
  70. //判断离职
  71. if (!StringUtils.isEmpty(staffmgr.getLeftYear())) {
  72. Iterator<TStaffmgr> iterator = staffmgrs.iterator();
  73. while (iterator.hasNext()) {
  74. TStaffmgr t = iterator.next();
  75. if (t.getLeftDate() != null && t.getDelFlag() == 9){
  76. Calendar cal = Calendar.getInstance();
  77. cal.setTime(t.getLeftDate());
  78. Integer year = cal.get(Calendar.YEAR);//获取年
  79. if (year < Integer.parseInt(staffmgr.getLeftYear())) {
  80. logger.debug(t.getName() + "离职年份小于数据");
  81. iterator.remove();
  82. }
  83. }
  84. }
  85. }
  86. }catch (Exception e) {
  87. logger.error(e.toString());
  88. }
  89. for (int i = 0; i < tTrainingCompanylevels.size(); i++) {
  90. //每一类公司级培训数据
  91. List<String> company = new ArrayList<>();
  92. List<String> companyDate = new ArrayList<>();
  93. company.add(tTrainingCompanylevels.get(i).getCourseCode());
  94. companyDate.add(tTrainingCompanylevels.get(i).getCourseCode());
  95. company.add(tTrainingCompanylevels.get(i).getItem());
  96. companyDate.add(tTrainingCompanylevels.get(i).getItem());
  97. if (tTrainingCompanylevels.get(i).getFrequency() != null) {
  98. company.add("每" + tTrainingCompanylevels.get(i).getFrequency() + "年一次");
  99. companyDate.add("每" + tTrainingCompanylevels.get(i).getFrequency() + "年一次");
  100. }else {
  101. TTrainingMatrix matrix = new TTrainingMatrix();
  102. matrix.setCourseCode(tTrainingCompanylevels.get(i).getCourseCode());
  103. matrix.setDeptId(tTrainingCompanylevels.get(i).getDeptId());
  104. List<TTrainingMatrix> matrixList = tTrainingMatrixService.selectTTrainingMatrixList(matrix);
  105. if (matrixList.size() > 0) {
  106. company.add(matrixList.get(0).getFrequency());
  107. companyDate.add(matrixList.get(0).getFrequency());
  108. }else {
  109. company.add("一次");
  110. companyDate.add("一次");
  111. }
  112. }
  113. for (TStaffmgr s : staffmgrs) {
  114. //按人员筛
  115. int m = 0;
  116. TTrainingParticipants f = new TTrainingParticipants();
  117. for (TTrainingParticipants t : list) {
  118. if (t.getStaffId().equals(s.getStaffid()) && t.getCompanyId().equals(tTrainingCompanylevels.get(i).getId())) {
  119. m = 1;
  120. f = t;
  121. }
  122. }
  123. if (m == 0) {
  124. company.add("⚪");
  125. companyDate.add("N.A");
  126. }else {
  127. company.add("╳");
  128. if (f.getStartDate() != null) {
  129. companyDate.add(sdf.format(f.getStartDate()));
  130. }else {
  131. companyDate.add("-");
  132. }
  133. }
  134. }
  135. companyLevelList.add(company);
  136. companyLevelList.add(companyDate);
  137. }
  138. AjaxResult ajaxResult = new AjaxResult();
  139. ajaxResult.put("companyLevelList", companyLevelList);
  140. ajaxResult.put("staffmgrs" , staffmgrs);
  141. return ajaxResult;
  142. }
  143. /**
  144. * 导出人员-公司级培训关系列表
  145. */
  146. @Log(title = "人员-公司级培训关系", businessType = BusinessType.EXPORT)
  147. @GetMapping("/export")
  148. public AjaxResult export(TTrainingParticipants tTrainingParticipants)
  149. {
  150. List<TTrainingParticipants> list = tTrainingParticipantsService.selectTTrainingParticipantsList(tTrainingParticipants);
  151. ExcelUtil<TTrainingParticipants> util = new ExcelUtil<TTrainingParticipants>(TTrainingParticipants.class);
  152. return util.exportExcel(list, "participants");
  153. }
  154. /**
  155. * 获取人员-公司级培训关系详细信息
  156. */
  157. @GetMapping(value = "/{id}")
  158. public AjaxResult getInfo(@PathVariable("id") Long id)
  159. {
  160. return AjaxResult.success(tTrainingParticipantsService.selectTTrainingParticipantsById(id));
  161. }
  162. /**
  163. * 新增人员-公司级培训关系
  164. */
  165. @Log(title = "人员-公司级培训关系", businessType = BusinessType.INSERT)
  166. @PostMapping
  167. public AjaxResult add(@RequestBody TTrainingParticipants tTrainingParticipants)
  168. {
  169. return toAjax(tTrainingParticipantsService.insertTTrainingParticipants(tTrainingParticipants));
  170. }
  171. /**
  172. * 修改人员-公司级培训关系
  173. */
  174. @Log(title = "人员-公司级培训关系", businessType = BusinessType.UPDATE)
  175. @PutMapping
  176. public AjaxResult edit(@RequestBody TTrainingParticipants tTrainingParticipants)
  177. {
  178. return toAjax(tTrainingParticipantsService.updateTTrainingParticipants(tTrainingParticipants));
  179. }
  180. /**
  181. * 删除人员-公司级培训关系
  182. */
  183. @Log(title = "人员-公司级培训关系", businessType = BusinessType.DELETE)
  184. @DeleteMapping("/{ids}")
  185. public AjaxResult remove(@PathVariable Long[] ids)
  186. {
  187. return toAjax(tTrainingParticipantsService.deleteTTrainingParticipantsByIds(ids));
  188. }
  189. /**
  190. * 删除所有历史人员-公司级培训关系
  191. */
  192. @Log(title = "人员-公司级培训关系", businessType = BusinessType.DELETE)
  193. @DeleteMapping("/deleteAll")
  194. public AjaxResult deleteAll()
  195. {
  196. return toAjax(tTrainingParticipantsService.deleteTTrainingParticipantsAll());
  197. }
  198. }