TTrainingbccDeviceController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package com.ruoyi.project.training.controller;
  2. import java.text.SimpleDateFormat;
  3. import java.util.*;
  4. import com.ruoyi.common.utils.DateUtils;
  5. import com.ruoyi.project.plant.domain.TStaffmgr;
  6. import com.ruoyi.project.plant.mapper.TStaffmgrMapper;
  7. import com.ruoyi.project.plant.service.ITStaffmgrService;
  8. import com.ruoyi.project.system.domain.SysUser;
  9. import com.ruoyi.project.system.mapper.SysUserMapper;
  10. import com.ruoyi.project.training.domain.TTraining;
  11. import com.ruoyi.project.training.domain.TTrainingbcc;
  12. import com.ruoyi.project.training.service.ITTrainingbccService;
  13. import org.apache.commons.lang.StringUtils;
  14. import org.springframework.security.access.prepost.PreAuthorize;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.PutMapping;
  19. import org.springframework.web.bind.annotation.DeleteMapping;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  25. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  26. import com.ruoyi.project.training.domain.TTrainingbccDevice;
  27. import com.ruoyi.project.training.service.ITTrainingbccDeviceService;
  28. import com.ruoyi.framework.web.controller.BaseController;
  29. import com.ruoyi.framework.web.domain.AjaxResult;
  30. import com.ruoyi.common.utils.poi.ExcelUtil;
  31. import com.ruoyi.framework.web.page.TableDataInfo;
  32. import javax.annotation.Resource;
  33. /**
  34. * 人员-装置级培训关系Controller
  35. *
  36. * @author ssy
  37. * @date 2024-06-19
  38. */
  39. @RestController
  40. @RequestMapping("/training/bccdevice")
  41. public class TTrainingbccDeviceController extends BaseController
  42. {
  43. @Autowired
  44. private ITTrainingbccDeviceService tTrainingbccDeviceService;
  45. @Autowired
  46. private ITTrainingbccService tTrainingbccService;
  47. @Resource
  48. private SysUserMapper sysUserMapper;
  49. @Autowired
  50. private ITStaffmgrService tStaffmgrService;
  51. /**
  52. * 查询人员-装置级培训关系列表
  53. */
  54. @GetMapping("/list")
  55. public TableDataInfo list(TTrainingbccDevice tTrainingbccDevice)
  56. {
  57. if (tTrainingbccDevice.getRegularId() == null) {
  58. SysUser user = sysUserMapper.selectUserById(getUserId());
  59. tTrainingbccDevice.setStaffId(user.getStaffId());
  60. }
  61. startPage();
  62. List<TTrainingbccDevice> list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingbccDevice);
  63. for (TTrainingbccDevice t: list
  64. ) {
  65. TTrainingbcc tTrainingbcc = tTrainingbccService.selectTTrainingbccById(t.getRegularId());
  66. t.setTrainingbcc(tTrainingbcc);
  67. // 判断是否过期
  68. t.setIsLock(0);
  69. if (tTrainingbcc.getCourseEnddate()!=null) {
  70. int r = DateUtils.compareToDay(DateUtils.getNowDate(),tTrainingbcc.getCourseEnddate());
  71. if (r >0) {
  72. t.setIsLock(1);
  73. }
  74. }
  75. //如果补赔,可以
  76. if ("1".equals(t.getSupplementary())) {
  77. }
  78. }
  79. return getDataTable(list);
  80. }
  81. /**
  82. * 查询人员-装置级培训关系列表
  83. */
  84. @GetMapping("/deviceList")
  85. public Map<String, Object> deviceList(TTrainingbccDevice tTrainingDevice)
  86. {
  87. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  88. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
  89. SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
  90. List<TTrainingbccDevice> list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingDevice);
  91. TTrainingbcc tTraining = new TTrainingbcc();
  92. // tTraining.setYears(tTrainingDevice.getYear());
  93. tTraining.setTrainingType(tTrainingDevice.getTrainingType());
  94. List<TTrainingbcc> tTrainings = tTrainingbccService.selectTTrainingbccList(tTraining);
  95. List<List> deviceLevelList = new ArrayList<>();
  96. //查询人员 ,客户的需求:units值
  97. TStaffmgr paramStaff = new TStaffmgr();
  98. paramStaff.setUnits(tTrainingDevice.getUnits());
  99. paramStaff.setDeptId(103l);
  100. List<TStaffmgr> staffmgrs = tStaffmgrService.selectRecordList(paramStaff);
  101. try {
  102. //判断离职
  103. if (!StringUtils.isEmpty(tTrainingDevice.getYear())) {
  104. Iterator<TStaffmgr> iterator = staffmgrs.iterator();
  105. while (iterator.hasNext()) {
  106. TStaffmgr t = iterator.next();
  107. if (t.getLeftDate() != null && t.getDelFlag() == 9){
  108. Calendar cal = Calendar.getInstance();
  109. cal.setTime(t.getLeftDate());
  110. Integer year = cal.get(Calendar.YEAR);//获取年
  111. if (year < Integer.parseInt(tTrainingDevice.getYear())) {
  112. logger.debug(t.getName() + "离职年份小于数据");
  113. iterator.remove();
  114. }
  115. }
  116. }
  117. }
  118. }catch (Exception e) {
  119. logger.error(e.toString());
  120. }
  121. logger.info("deviceList:" + staffmgrs.size());
  122. for (int i = 0; i < tTrainings.size(); i++) {
  123. //每一类装置级培训数据
  124. List<String> device = new ArrayList<>();
  125. List<String> deviceDate = new ArrayList<>();
  126. if (tTrainings.get(i).getCourseid() != null) {
  127. device.add(tTrainings.get(i).getCourseid());
  128. deviceDate.add(tTrainings.get(i).getCourseid());
  129. }else {
  130. device.add("");
  131. deviceDate.add("");
  132. }
  133. device.add(tTrainings.get(i).getCourse());
  134. deviceDate.add(tTrainings.get(i).getCourse());
  135. for (TStaffmgr s : staffmgrs) {
  136. //按人员筛
  137. int m = 0;
  138. TTrainingbccDevice d = new TTrainingbccDevice();
  139. for (TTrainingbccDevice t : list) {
  140. if (t.getStaffId().equals(s.getStaffid()) && t.getRegularId().equals(tTrainings.get(i).getId())) {
  141. if (tTrainings.get(i).getTrainingType().equals("10")) {
  142. if (tTrainings.get(i).getStartDate() == null) {
  143. m = 2;
  144. }else {
  145. m = 1;
  146. d = t;
  147. }
  148. }else {
  149. m = 1;
  150. d = t;
  151. }
  152. }
  153. }
  154. if (m == 0) {
  155. device.add("⚪");
  156. deviceDate.add("N.A");
  157. }else if (m == 2) {
  158. device.add("╳");
  159. deviceDate.add("尚未开始培训");
  160. }else {
  161. if (d.getSupplementary().equals("1")) {
  162. device.add("╳");
  163. if (d.getStartDate() != null) {
  164. deviceDate.add(sdf.format(d.getStartDate()));
  165. }else {
  166. deviceDate.add("-");
  167. }
  168. }else if (d.getSupplementary().equals("0")){
  169. device.add("╳");
  170. if (tTrainings.get(i).getRegularId() != null&&d.getStartDate() != null) {
  171. //判断结束日期和开始日期是否同一个月
  172. if (tTrainings.get(i).getCourseEnddate()!= null) {
  173. Calendar calendar1 = Calendar.getInstance();
  174. calendar1.setTime(d.getStartDate());
  175. int month1 = calendar1.get(Calendar.MONTH);
  176. Calendar calendar2 = Calendar.getInstance();
  177. calendar2.setTime(tTrainings.get(i).getCourseEnddate());
  178. int month2 = calendar2.get(Calendar.MONTH);
  179. if (month2 == month1) {
  180. deviceDate.add(sdf1.format(d.getStartDate()));
  181. }else {
  182. deviceDate.add(sdf1.format(d.getStartDate()) + "/" + sdf2.format(tTrainings.get(i).getCourseEnddate()));
  183. }
  184. }else {
  185. deviceDate.add(sdf1.format(d.getStartDate()));
  186. }
  187. }else {
  188. if(d.getStartDate() != null){
  189. deviceDate.add(sdf.format(d.getStartDate()));
  190. }
  191. }
  192. }else if (d.getSupplementary().equals("2")){
  193. device.add("新员工");
  194. if (d.getStartDate() != null) {
  195. deviceDate.add(sdf.format(d.getStartDate()));
  196. }else {
  197. deviceDate.add("-");
  198. }
  199. }else {
  200. device.add("/");
  201. deviceDate.add("/");
  202. }
  203. }
  204. }
  205. deviceLevelList.add(device);
  206. deviceLevelList.add(deviceDate);
  207. }
  208. AjaxResult ajaxResult = new AjaxResult();
  209. ajaxResult.put("deviceLevelList", deviceLevelList);
  210. ajaxResult.put("staffmgrs" , staffmgrs);
  211. return ajaxResult;
  212. }
  213. /**
  214. * 导出人员-装置级培训关系列表
  215. */
  216. @Log(title = "人员-装置级培训关系", businessType = BusinessType.EXPORT)
  217. @GetMapping("/export")
  218. public AjaxResult export(TTrainingbccDevice tTrainingbccDevice)
  219. {
  220. List<TTrainingbccDevice> list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingbccDevice);
  221. ExcelUtil<TTrainingbccDevice> util = new ExcelUtil<TTrainingbccDevice>(TTrainingbccDevice.class);
  222. return util.exportExcel(list, "device");
  223. }
  224. /**
  225. * 获取人员-装置级培训关系详细信息
  226. */
  227. @GetMapping(value = "/{id}")
  228. public AjaxResult getInfo(@PathVariable("id") Long id)
  229. {
  230. return AjaxResult.success(tTrainingbccDeviceService.selectTTrainingbccDeviceById(id));
  231. }
  232. /**
  233. * 新增人员-装置级培训关系
  234. */
  235. @Log(title = "人员-装置级培训关系", businessType = BusinessType.INSERT)
  236. @PostMapping
  237. public AjaxResult add(@RequestBody TTrainingbccDevice tTrainingbccDevice)
  238. {
  239. return toAjax(tTrainingbccDeviceService.insertTTrainingbccDevice(tTrainingbccDevice));
  240. }
  241. /**
  242. * 修改人员-装置级培训关系
  243. */
  244. @Log(title = "人员-装置级培训关系", businessType = BusinessType.UPDATE)
  245. @PutMapping
  246. public AjaxResult edit(@RequestBody TTrainingbccDevice tTrainingbccDevice)
  247. {
  248. return toAjax(tTrainingbccDeviceService.updateTTrainingbccDevice(tTrainingbccDevice));
  249. }
  250. @PutMapping("/updateDeviceLearnTime")
  251. @Log(title = "人员-装置级培训-更新时长", businessType = BusinessType.UPDATE)
  252. public AjaxResult updateDeviceLearnTime(@RequestBody TTrainingbccDevice tTrainingbccDevice)
  253. {
  254. TTrainingbccDevice t= tTrainingbccDeviceService.selectTTrainingbccDeviceById(tTrainingbccDevice.getId());
  255. TTrainingbcc tTrainingbcc = tTrainingbccService.selectTTrainingbccById(t.getRegularId());
  256. t.setLearnTime(t.getLearnTime() +1);
  257. if (tTrainingbcc.getTimerNeed() != null && tTrainingbcc.getTimerNeed() <= t.getLearnTime()) {
  258. t.setLearnState(1l);
  259. }
  260. return toAjax(tTrainingbccDeviceService.updateTTrainingbccDevice(t));
  261. }
  262. /**
  263. * 删除人员-装置级培训关系
  264. */
  265. @Log(title = "人员-装置级培训关系", businessType = BusinessType.DELETE)
  266. @DeleteMapping("/{ids}")
  267. public AjaxResult remove(@PathVariable Long[] ids)
  268. {
  269. return toAjax(tTrainingbccDeviceService.deleteTTrainingbccDeviceByIds(ids));
  270. }
  271. }