package com.ruoyi.project.training.controller; import java.text.SimpleDateFormat; import java.util.*; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.project.plant.domain.TStaffmgr; import com.ruoyi.project.plant.mapper.TStaffmgrMapper; import com.ruoyi.project.plant.service.ITStaffmgrService; import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.mapper.SysUserMapper; import com.ruoyi.project.training.domain.TTraining; import com.ruoyi.project.training.domain.TTrainingbcc; import com.ruoyi.project.training.service.ITTrainingbccService; import org.apache.commons.lang.StringUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; 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 com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.project.training.domain.TTrainingbccDevice; import com.ruoyi.project.training.service.ITTrainingbccDeviceService; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.page.TableDataInfo; import javax.annotation.Resource; /** * 人员-装置级培训关系Controller * * @author ssy * @date 2024-06-19 */ @RestController @RequestMapping("/training/bccdevice") public class TTrainingbccDeviceController extends BaseController { @Autowired private ITTrainingbccDeviceService tTrainingbccDeviceService; @Autowired private ITTrainingbccService tTrainingbccService; @Resource private SysUserMapper sysUserMapper; @Autowired private ITStaffmgrService tStaffmgrService; /** * 查询人员-装置级培训关系列表 */ @GetMapping("/list") public TableDataInfo list(TTrainingbccDevice tTrainingbccDevice) { if (tTrainingbccDevice.getRegularId() == null) { SysUser user = sysUserMapper.selectUserById(getUserId()); tTrainingbccDevice.setStaffId(user.getStaffId()); } startPage(); List list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingbccDevice); for (TTrainingbccDevice t: list ) { TTrainingbcc tTrainingbcc = tTrainingbccService.selectTTrainingbccById(t.getRegularId()); t.setTrainingbcc(tTrainingbcc); // 判断是否过期 t.setIsLock(0); if (tTrainingbcc.getCourseEnddate()!=null) { int r = DateUtils.compareToDay(DateUtils.getNowDate(),tTrainingbcc.getCourseEnddate()); if (r >0) { t.setIsLock(1); } } //如果补赔,可以 if ("1".equals(t.getSupplementary())) { } } return getDataTable(list); } /** * 查询人员-装置级培训关系列表 */ @GetMapping("/deviceList") public Map deviceList(TTrainingbccDevice tTrainingDevice) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat sdf2 = new SimpleDateFormat("MM"); List list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingDevice); TTrainingbcc tTraining = new TTrainingbcc(); // tTraining.setYears(tTrainingDevice.getYear()); tTraining.setTrainingType(tTrainingDevice.getTrainingType()); List tTrainings = tTrainingbccService.selectTTrainingbccList(tTraining); List deviceLevelList = new ArrayList<>(); //查询人员 ,客户的需求:units值 TStaffmgr paramStaff = new TStaffmgr(); paramStaff.setUnits(tTrainingDevice.getUnits()); paramStaff.setDeptId(103l); List staffmgrs = tStaffmgrService.selectRecordList(paramStaff); try { //判断离职 if (!StringUtils.isEmpty(tTrainingDevice.getYear())) { Iterator iterator = staffmgrs.iterator(); while (iterator.hasNext()) { TStaffmgr t = iterator.next(); if (t.getLeftDate() != null && t.getDelFlag() == 9){ Calendar cal = Calendar.getInstance(); cal.setTime(t.getLeftDate()); Integer year = cal.get(Calendar.YEAR);//获取年 if (year < Integer.parseInt(tTrainingDevice.getYear())) { logger.debug(t.getName() + "离职年份小于数据"); iterator.remove(); } } } } }catch (Exception e) { logger.error(e.toString()); } logger.info("deviceList:" + staffmgrs.size()); for (int i = 0; i < tTrainings.size(); i++) { //每一类装置级培训数据 List device = new ArrayList<>(); List deviceDate = new ArrayList<>(); if (tTrainings.get(i).getCourseid() != null) { device.add(tTrainings.get(i).getCourseid()); deviceDate.add(tTrainings.get(i).getCourseid()); }else { device.add(""); deviceDate.add(""); } device.add(tTrainings.get(i).getCourse()); deviceDate.add(tTrainings.get(i).getCourse()); for (TStaffmgr s : staffmgrs) { //按人员筛 int m = 0; TTrainingbccDevice d = new TTrainingbccDevice(); for (TTrainingbccDevice t : list) { if (t.getStaffId().equals(s.getStaffid()) && t.getRegularId().equals(tTrainings.get(i).getId())) { if (tTrainings.get(i).getTrainingType().equals("10")) { if (tTrainings.get(i).getStartDate() == null) { m = 2; }else { m = 1; d = t; } }else { m = 1; d = t; } } } if (m == 0) { device.add("⚪"); deviceDate.add("N.A"); }else if (m == 2) { device.add("╳"); deviceDate.add("尚未开始培训"); }else { if (d.getSupplementary().equals("1")) { device.add("╳"); if (d.getStartDate() != null) { deviceDate.add(sdf.format(d.getStartDate())); }else { deviceDate.add("-"); } }else if (d.getSupplementary().equals("0")){ device.add("╳"); if (tTrainings.get(i).getRegularId() != null&&d.getStartDate() != null) { //判断结束日期和开始日期是否同一个月 if (tTrainings.get(i).getCourseEnddate()!= null) { Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(d.getStartDate()); int month1 = calendar1.get(Calendar.MONTH); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(tTrainings.get(i).getCourseEnddate()); int month2 = calendar2.get(Calendar.MONTH); if (month2 == month1) { deviceDate.add(sdf1.format(d.getStartDate())); }else { deviceDate.add(sdf1.format(d.getStartDate()) + "/" + sdf2.format(tTrainings.get(i).getCourseEnddate())); } }else { deviceDate.add(sdf1.format(d.getStartDate())); } }else { if(d.getStartDate() != null){ deviceDate.add(sdf.format(d.getStartDate())); } } }else if (d.getSupplementary().equals("2")){ device.add("新员工"); if (d.getStartDate() != null) { deviceDate.add(sdf.format(d.getStartDate())); }else { deviceDate.add("-"); } }else { device.add("/"); deviceDate.add("/"); } } } deviceLevelList.add(device); deviceLevelList.add(deviceDate); } AjaxResult ajaxResult = new AjaxResult(); ajaxResult.put("deviceLevelList", deviceLevelList); ajaxResult.put("staffmgrs" , staffmgrs); return ajaxResult; } /** * 导出人员-装置级培训关系列表 */ @Log(title = "人员-装置级培训关系", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(TTrainingbccDevice tTrainingbccDevice) { List list = tTrainingbccDeviceService.selectTTrainingbccDeviceList(tTrainingbccDevice); ExcelUtil util = new ExcelUtil(TTrainingbccDevice.class); return util.exportExcel(list, "device"); } /** * 获取人员-装置级培训关系详细信息 */ @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return AjaxResult.success(tTrainingbccDeviceService.selectTTrainingbccDeviceById(id)); } /** * 新增人员-装置级培训关系 */ @Log(title = "人员-装置级培训关系", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody TTrainingbccDevice tTrainingbccDevice) { return toAjax(tTrainingbccDeviceService.insertTTrainingbccDevice(tTrainingbccDevice)); } /** * 修改人员-装置级培训关系 */ @Log(title = "人员-装置级培训关系", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TTrainingbccDevice tTrainingbccDevice) { return toAjax(tTrainingbccDeviceService.updateTTrainingbccDevice(tTrainingbccDevice)); } @PutMapping("/updateDeviceLearnTime") @Log(title = "人员-装置级培训-更新时长", businessType = BusinessType.UPDATE) public AjaxResult updateDeviceLearnTime(@RequestBody TTrainingbccDevice tTrainingbccDevice) { TTrainingbccDevice t= tTrainingbccDeviceService.selectTTrainingbccDeviceById(tTrainingbccDevice.getId()); TTrainingbcc tTrainingbcc = tTrainingbccService.selectTTrainingbccById(t.getRegularId()); t.setLearnTime(t.getLearnTime() +1); if (tTrainingbcc.getTimerNeed() != null && tTrainingbcc.getTimerNeed() <= t.getLearnTime()) { t.setLearnState(1l); } return toAjax(tTrainingbccDeviceService.updateTTrainingbccDevice(t)); } /** * 删除人员-装置级培训关系 */ @Log(title = "人员-装置级培训关系", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(tTrainingbccDeviceService.deleteTTrainingbccDeviceByIds(ids)); } }