package com.ruoyi.project.plant.controller; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; import com.alibaba.fastjson.JSON; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.file.ExcelUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.framework.config.RuoYiConfig; import com.ruoyi.project.common.domain.DataEntity; import com.ruoyi.project.plant.mapper.TStaffmgrMapper; import com.ruoyi.project.system.domain.SysDept; import com.ruoyi.project.system.domain.SysDictData; import com.ruoyi.project.system.service.ISysDeptService; import com.ruoyi.project.system.service.ISysDictTypeService; import com.ruoyi.project.system.service.ITAlarmPrincipalService; import com.ruoyi.project.training.domain.*; import com.ruoyi.project.training.service.*; import org.apache.commons.lang.StringUtils; import org.apache.poi.ss.usermodel.*; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.project.plant.domain.TStaffmgr; import com.ruoyi.project.plant.service.ITStaffmgrService; 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 org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; /** * 人员管理Controller * * @author ruoyi * @date 2020-11-25 */ @RestController @RequestMapping("/plant/staffmgr") public class TStaffmgrController extends BaseController { @Autowired private ITStaffmgrService tStaffmgrService; @Autowired private ISysDeptService iSysDeptService; @Autowired private ISysDictTypeService iSysDictTypeService; @Resource private TStaffmgrMapper tStaffmgrMapper; @Autowired private ITTrainingrecordsService tTrainingrecordsService; @Autowired private ITTrainingParticipantsService tTrainingParticipantsService; @Autowired private ITWorklicenseService tWorklicenseService; @Autowired private ITTrainingRegularService tTrainingRegularService; @Autowired private ITTrainingDeviceService tTrainingDeviceService; @Autowired private ITTrainingService tTrainingService; /** * 查询人员管理列表 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:list')") @GetMapping("/list") public TableDataInfo list(TStaffmgr tStaffmgr) { ServletUtils.getParameter("sexs"); startPage(); List list = tStaffmgrService.selectTStaffmgrList(tStaffmgr); return getDataTable(list); } /** * 查询人员公司级培训时间列表 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:list')") @GetMapping("/selectTime") public TableDataInfo selectTime(TStaffmgr tStaffmgr) { ServletUtils.getParameter("sexs"); startPage(); List list = tStaffmgrService.selectRecordList(tStaffmgr); List tTrainingParticipants = tTrainingParticipantsService.selectTTrainingParticipantsList(new TTrainingParticipants()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); for (int i = 0; i < list.size(); i++) { double time = 0; for (TTrainingParticipants t : tTrainingParticipants) { if (t.getStaffId().equals(list.get(i).getStaffid())) { if (t.getStartDate() != null) { if (sdf.format(t.getStartDate()).equals(sdf.format(new Date()))) { if (t.getTrainingDuration() != null) { time = time + Double.parseDouble(t.getTrainingDuration()); } } } } } list.get(i).setTrainingTime(String.valueOf(time)); } return getDataTable(list); } /** * 查询人员管理列表 * @return */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:list')") @GetMapping("/ogzList") public List ogzList(TStaffmgr tStaffmgr) { List list = tStaffmgrService.selectTStaffmgrList(tStaffmgr); return list; } /** * 上级领导字段查询人员管理列表 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:list')") @GetMapping("/pIdList") public AjaxResult pIdList(TStaffmgr tStaffmgr) { List list = tStaffmgrService.selectTStaffmgrList(tStaffmgr); return AjaxResult.success(list); } /** * 查询离职人员管理列表 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:list')") @GetMapping("/leftList") public List leftList(TStaffmgr tStaffmgr) { List list = tStaffmgrService.selectLeftTStaffmgrList(tStaffmgr); return list; } //学历统计 @GetMapping("/eduData") public List eduData(Map param) { param.put("params" , new HashMap<>()); Map data = new HashMap(); List list = tStaffmgrMapper.selectEduData(param); List education = iSysDictTypeService.selectDictDataByType("EDUCATION"); for (DataEntity d: list ) { for (SysDictData s: education ) { if (StringUtils.isBlank(d.getDataName())){ d.setDataName("未知"); break; } if (s.getDictValue().equals(d.getDataName())){ d.setDataName(s.getDictLabel()); break; } } } return list; } //英语统计 @GetMapping("/engData") public List engData(Map param) { param.put("params" , new HashMap<>()); List list = tStaffmgrMapper.selectEngData(param); List englishability = iSysDictTypeService.selectDictDataByType("ENGLISHABILITY"); for (DataEntity d: list ) { for (SysDictData s: englishability ) { if (StringUtils.isBlank(d.getDataName())){ d.setDataName("未知"); break; } if (s.getDictValue().equals(d.getDataName())){ d.setDataName(s.getDictLabel()); break; } } } return list; } //班值统计 @GetMapping("/teamData") public List teamData(Map param) { param.put("params" , new HashMap<>()); List list = tStaffmgrMapper.selectTeamData(param); List englishability = iSysDictTypeService.selectDictDataByType("TEAM_DIVIDE"); for (DataEntity d: list ) { for (SysDictData s: englishability ) { if (StringUtils.isBlank(d.getDataName())){ d.setDataName("未知"); break; } if (s.getDictValue().equals(d.getDataName())){ d.setDataName(s.getDictLabel()); break; } } } return list; } /** * 导出人员管理列表 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:export')") @Log(title = "人员管理", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(TStaffmgr tStaffmgr) { List list = tStaffmgrService.selectTStaffmgrList(tStaffmgr); ExcelUtil util = new ExcelUtil(TStaffmgr.class); return util.exportExcel(list, "staffmgr"); } /** * 获取人员管理详细信息 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { TStaffmgr staffmgr = tStaffmgrService.selectTStaffmgrById(id); return AjaxResult.success(staffmgr); } /** * 为参培人员名单获取人员管理详细信息 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:query')") @GetMapping("/byStaffId/{staffIds}") public AjaxResult byStaffId(@PathVariable String[] staffIds) { List staffmgrs = new ArrayList(); for (int i = 0; i tTrainingRegulars = tTrainingRegularService.selectTTrainingRegularList(regular); for (TTrainingRegular r : tTrainingRegulars) { if (r.getNotPlan().equals("true")) { String[] posts = r.getActualpostId().split(","); for (String post : posts) { if (post.equals(tStaffmgr.getActualpost())) { TTraining training = tTrainingService.selectTTrainingByRegularId(r.getId()); if (training.getStartDate() == null) { TTrainingDevice tTrainingDevice = new TTrainingDevice(); tTrainingDevice.setStaffId(tStaffmgr.getStaffid()); tTrainingDevice.setRegularId(training.getId()); tTrainingDevice.setStartDate(r.getPlanTrainingdate()); tTrainingDevice.setSupplementary("0"); tTrainingDeviceService.insertTTrainingDevice(tTrainingDevice); } else { TTrainingDevice tTrainingDevice = new TTrainingDevice(); tTrainingDevice.setStaffId(tStaffmgr.getStaffid()); tTrainingDevice.setRegularId(training.getId()); tTrainingDevice.setSupplementary("2"); tTrainingDeviceService.insertTTrainingDevice(tTrainingDevice); } } } } } } return toAjax(insertResult); } /** * 修改人员管理 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:edit')") @Log(title = "人员管理", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TStaffmgr tStaffmgr) { tStaffmgr.setPhoto(null); tStaffmgr.setUpdaterCode(getUserId().toString()); tStaffmgr.setUpdatedate(new Date()); TStaffmgr oldStaffmgr = tStaffmgrService.selectTStaffmgrById(tStaffmgr.getId()); if (tStaffmgr.getUnit().equals("10") || tStaffmgr.getUnit().equals("18")) { //部门为CBP/C或CBP的人员 TTrainingrecords tTrainingrecords = tTrainingrecordsService.selectTTrainingrecordsBystaffId(tStaffmgr.getId()); tTrainingrecords.setPlantCode(tStaffmgr.getPlantCode()); tTrainingrecords.setName(tStaffmgr.getName()); tTrainingrecords.setEmployeeid(tStaffmgr.getStaffid()); tTrainingrecords.setClasses(tStaffmgr.getTeam()); tTrainingrecords.setDeptId(tStaffmgr.getDeptId()); tTrainingrecordsService.updateTTrainingrecords(tTrainingrecords); } if (!tStaffmgr.getTeam().equals("18")) { //非W班组人员 TWorklicense tWorklicense = tWorklicenseService.selectTWorklicenseByEmployeeid(tStaffmgr.getStaffid()); tWorklicense.setPlantCode(tStaffmgr.getPlantCode()); tWorklicense.setClasses(tStaffmgr.getTeam()); tWorklicense.setName(tStaffmgr.getName()); tWorklicense.setEmployeeid(tStaffmgr.getStaffid()); tWorklicense.setPost(tStaffmgr.getActualpost()); tWorklicense.setDeptId(tStaffmgr.getDeptId()); tWorklicenseService.updateTWorklicense(tWorklicense); } return toAjax(tStaffmgrService.updateTStaffmgr(tStaffmgr)); } /** * 删除人员管理 */ @PreAuthorize("@ss.hasPermi('plant:staffmgr:remove')") @Log(title = "人员管理", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { for (int i = 0; i failRow =new ArrayList(); Workbook workbook = ExcelUtils.getWorkBook(file); Sheet sheet = workbook.getSheetAt(0); List list = new ArrayList(); //字典查询 List plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE"); List sex = iSysDictTypeService.selectDictDataByType("sys_user_sex"); List staff = iSysDictTypeService.selectDictDataByType("STAFF_UNIT"); List team = iSysDictTypeService.selectDictDataByType("TEAM_DIVIDE"); List actualpost = iSysDictTypeService.selectDictDataByType("ACTUALPOST"); List education = iSysDictTypeService.selectDictDataByType("EDUCATION"); List enAbility = iSysDictTypeService.selectDictDataByType("ENGLISHABILITY"); //部门查询 List dept = iSysDeptService.selectDeptList(new SysDept()); int rowNum = sheet.getPhysicalNumberOfRows(); int failNumber = 0; for (int i = 1; i < rowNum; i++) { try { logger.info("读取行数:" + i); Row row = sheet.getRow(i); int cellNum = row.getPhysicalNumberOfCells(); TStaffmgr entity = new TStaffmgr(); for (int j = 0; j < cellNum; j++) { Cell cell = row.getCell(j); cell.setCellType(CellType.STRING); String cellValue = ExcelUtils.getCellValue(cell); logger.info("cellValue:" + cellValue); if (j == 0) { for (SysDictData p : plant) { if (p.getDictLabel().equals(cellValue)) { entity.setPlantCode(p.getDictValue());//装置名称 } } } else if (j == 1) { entity.setStaffid(cellValue);//员工编号 } else if (j == 2) { entity.setName(cellValue);//员工姓名 } else if (j == 3) { for (SysDictData p : sex) { if (p.getDictLabel().equals(cellValue)) { entity.setSex(p.getDictValue());//性别 } } } else if (j == 4) { if (cellValue.length() > 3) { entity.setBirthday(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//出生日期 } } else if (j == 5) { for (SysDictData p : staff) { if (p.getDictLabel().equals(cellValue)) { entity.setUnit(p.getDictValue());//部门 } } } else if (j == 6) { for (SysDictData p : team) { if (p.getDictLabel().equals(cellValue.trim())) { entity.setTeam(p.getDictValue());//班值 } } } else if (j == 7) { for (SysDictData p : actualpost) { if (p.getDictLabel().equals(cellValue)) { entity.setActualpost(p.getDictValue());//实际岗位 } } } else if (j == 8) { entity.setContact(cellValue);//联系方式 } else if (j == 9) { for (SysDictData p : education) { if (p.getDictLabel().equals(cellValue)) { entity.setEducation(p.getDictValue());//学历 } } } else if (j == 10) { for (SysDictData p : enAbility) { if (p.getDictLabel().equals(cellValue)) { entity.setEnAbility(p.getDictValue());//英语能力 } } } else if (j == 11) { entity.setMail(cellValue);//邮箱 } else if (j == 12) { for (SysDept d : dept) { if (d.getDeptName().equals(cellValue)) { entity.setDeptId(d.getDeptId());//部门编号 } } } else if (j == 13) { entity.setRemarks(cellValue);//备注 } } entity.setCreaterCode(userId.toString()); logger.info("entity:" + entity); list.add(entity); }catch (Exception e){ failNumber++; logger.info("e:" + e); failRow.add(i + 1); } } int successNumber = 0; int failNum = 0; for (TStaffmgr t : list ) { failNum++; try { tStaffmgrService.insertTStaffmgr(t); if (t.getUnit().equals("10") || t.getUnit().equals("18")) { TTrainingrecords tTrainingrecords = new TTrainingrecords(); tTrainingrecords.setStaffId(t.getId()); tTrainingrecords.setPlantCode(t.getPlantCode()); tTrainingrecords.setName(t.getName()); tTrainingrecords.setEmployeeid(t.getStaffid()); tTrainingrecords.setClasses(t.getTeam()); tTrainingrecords.setDeptId(t.getDeptId()); tTrainingrecordsService.insertTTrainingrecords(tTrainingrecords); } if (!t.getTeam().equals("18")) { TWorklicense tWorklicense = new TWorklicense(); tWorklicense.setPlantCode(t.getPlantCode()); tWorklicense.setClasses(t.getTeam()); tWorklicense.setName(t.getName()); tWorklicense.setEmployeeid(t.getStaffid()); tWorklicense.setPost(t.getActualpost()); tWorklicense.setDeptId(t.getDeptId()); tWorklicenseService.insertTWorklicense(tWorklicense); } successNumber++; }catch (Exception e){ failNumber++; logger.info("e:" + e); failRow.add(failNum + 1); } } logger.info("list:" + JSON.toJSONString(list)); logger.info("successNumber:" +String.valueOf(successNumber)); logger.info("failNumber:" +String.valueOf(failNumber)); logger.info("failRow:" +String.valueOf(failRow)); return AjaxResult.success(String.valueOf(successNumber), failRow); } /** * 证件照上传 */ @PostMapping("/uploadPhoto") public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,String pType,String pId) throws IOException { if (!file.isEmpty()) { String url = FileUploadUtils.upload(RuoYiConfig.getFilePath("/"+ pType), file); TStaffmgr staffmgr = tStaffmgrService.selectTStaffmgrById(Long.parseLong(pId)); staffmgr.setPhoto(url); tStaffmgrService.updateTStaffmgr(staffmgr); return AjaxResult.success(); } return AjaxResult.error("上传失败,请联系管理员"); } }