diff --git a/src/main/java/com/ydool/staff/controller/PersonnelController.java b/src/main/java/com/ydool/staff/controller/PersonnelController.java index 0f93457..7394e4f 100644 --- a/src/main/java/com/ydool/staff/controller/PersonnelController.java +++ b/src/main/java/com/ydool/staff/controller/PersonnelController.java @@ -1,5 +1,9 @@ package com.ydool.staff.controller; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.write.handler.SheetWriteHandler; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.ydool.common.base.BaseController; import com.ydool.common.constant.UrlConstant; @@ -8,31 +12,37 @@ import com.ydool.staff.dto.PersonnelDto; import com.ydool.staff.dto.PersonnelUpdateDto; import com.ydool.staff.entity.SelectRequest; import com.ydool.staff.excel.ExcelPersonnel; -import com.ydool.staff.request.ChangeRequest; +import com.ydool.staff.excel.PersonnelExportVO; import com.ydool.staff.request.GiveAuditRequest; import com.ydool.staff.request.PersonnelDeleteRequest; import com.ydool.staff.request.PersonnelRequest; import com.ydool.staff.request.PersonnelUpdateRequest; import com.ydool.staff.service.IAttachmentService; import com.ydool.staff.service.IPersonnelService; +import com.ydool.system.entity.DictData; +import com.ydool.system.service.impl.DictDataServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.DataValidation; +import org.apache.poi.ss.usermodel.DataValidationConstraint; +import org.apache.poi.ss.usermodel.DataValidationHelper; +import org.apache.poi.ss.util.CellRangeAddressList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; +import java.lang.reflect.Field; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; /** * @author msh @@ -48,9 +58,11 @@ public class PersonnelController extends BaseController { private IPersonnelService personnelService; @Autowired IAttachmentService attachmentService; + @Autowired + DictDataServiceImpl dataService; - @PostMapping( "personnelList") - @ApiOperation(value = "人员列表",response = PersonnelDto.class) + @PostMapping("personnelList") + @ApiOperation(value = "人员列表", response = PersonnelDto.class) @ApiImplicitParams({ @ApiImplicitParam(name = "orderBy", value = "排序顺序 降序:desc,升序:asc"), @ApiImplicitParam(name = "column", value = "排序字段 字段名"), @@ -59,53 +71,132 @@ public class PersonnelController extends BaseController { @ApiImplicitParam(name = "isInfo", value = "是否退休列表"), @ApiImplicitParam(name = "deptId", value = "部门id"), }) - public AjaxResult personnelList(@RequestBody SelectRequest request, String orderBy,String column,Boolean isInfo,String deptId){ - return personnelService.personnelList(getPage(),request,orderBy,column,isInfo,deptId); + public AjaxResult personnelList(@RequestBody SelectRequest request, String orderBy, String column, Boolean isInfo, String deptId) { + return personnelService.personnelList(getPage(), request, orderBy, column, isInfo, deptId); } @GetMapping("getById") - @ApiOperation(value = "查询一条",response = PersonnelUpdateDto.class) + @ApiOperation(value = "查询一条", response = PersonnelUpdateDto.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "id",value = "id" ), - @ApiImplicitParam(name = "type",value = "修改类型,修改传update,审批传audit" ), - @ApiImplicitParam(name = "personnelType",value = "人员类型,人员:personnel,变更change" ), + @ApiImplicitParam(name = "id", value = "id"), + @ApiImplicitParam(name = "type", value = "修改类型,修改传update,审批传audit"), + @ApiImplicitParam(name = "personnelType", value = "人员类型,人员:personnel,变更change"), }) - public AjaxResult getById(String id,String type,String personnelType){ - return personnelService.getById(id,type,personnelType); + public AjaxResult getById(String id, String type, String personnelType) { + return personnelService.getById(id, type, personnelType); } @PostMapping(value = "savePersonnel") - @ApiOperation(value = "新增人员申报",response = PersonnelRequest.class) - public AjaxResult savePersonnel(@Validated @RequestBody PersonnelRequest personnelRequest){ + @ApiOperation(value = "新增人员申报", response = PersonnelRequest.class) + public AjaxResult savePersonnel(@Validated @RequestBody PersonnelRequest personnelRequest) { return personnelService.savePersonnel(personnelRequest); } + @PostMapping(value = "deletePersonnel") - @ApiOperation(value = "删除/批量删除人员",response = PersonnelDeleteRequest.class) - public AjaxResult deletePersonnel(@RequestBody PersonnelDeleteRequest request){ + @ApiOperation(value = "删除/批量删除人员", response = PersonnelDeleteRequest.class) + public AjaxResult deletePersonnel(@RequestBody PersonnelDeleteRequest request) { return personnelService.deleteByIds(request); } + @PostMapping(value = "updatePersonnel") @ApiOperation(value = "修改人员") - public AjaxResult updatePersonnel(@RequestBody PersonnelUpdateRequest personnelDeleteRequest){ + public AjaxResult updatePersonnel(@RequestBody PersonnelUpdateRequest personnelDeleteRequest) { return personnelService.updatePersonnel(personnelDeleteRequest); } @PostMapping(value = "updateChange") @ApiOperation(value = "人员变更") - public AjaxResult updateChange(@RequestBody PersonnelUpdateRequest request){ + public AjaxResult updateChange(@RequestBody PersonnelUpdateRequest request) { return personnelService.updateChange(request); } @GetMapping("getEntityParam") - @ApiOperation(value = "获取实体参数名",response = ExcelPersonnel.class) - public AjaxResult getEntityParam(){ - return personnelService.getEntityParam(); + @ApiOperation(value = "获取实体参数名", response = ExcelPersonnel.class) + public AjaxResult getEntityParam() { + return personnelService.getEntityParam(); } @PostMapping("export") @ApiOperation(value = "导出接口") - public void export(@RequestBody PersonnelDeleteRequest personnelParam,HttpServletResponse response){ - personnelService.export(personnelParam,response); + public void export(@RequestBody PersonnelDeleteRequest personnelParam, HttpServletResponse response) { + personnelService.export(personnelParam, response); + } + + @GetMapping("import-template") + @ApiOperation(value = "导入模板") + public void importTemplate(HttpServletResponse response) { + try { + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + String fileName = URLEncoder.encode("企业人员申报.xlsx", StandardCharsets.UTF_8.name()); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + + Map> dicData = getDictData(); + + // 创建ExcelWriter对象并指定模板 + EasyExcel.write(response.getOutputStream(), PersonnelExportVO.class) + .registerWriteHandler(new SheetWriteHandler() { + @Override + public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { + } + + @Override + public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { + Field[] declaredFields = writeSheetHolder.getClazz().getDeclaredFields(); + // 创建约束,指定下拉列表的选项 + for (int i = 0; i < declaredFields.length; i++) { + String name = declaredFields[i].getName(); + List listOfValues = dicData.get(name); + if (listOfValues != null && !listOfValues.isEmpty()) { + CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 20000, i, i); + DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); + DataValidationConstraint constraint = helper.createExplicitListConstraint(listOfValues.toArray(new String[0])); + DataValidation dataValidation = helper.createValidation(constraint, cellRangeAddressList); + dataValidation.setShowErrorBox(true); + writeSheetHolder.getSheet().addValidationData(dataValidation); + } + } + } + }) + .sheet("企业人员申报").doWrite(new ArrayList()); // 这里传null是因为我们只是导出模板,没有数据需要写入 + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Map> getDictData() { + Map codeKeyMap = getStringStringMap(); + + Map> map = new HashMap<>(); + codeKeyMap.forEach((code, key) -> { + List dictDataList = dataService.listByCode(code); + List dataList = dictDataList.stream().map(DictData::getLabel).collect(Collectors.toList()); + map.put(key, dataList); + }); + + List dictSex = dataService.listByCode("t_dict_sex"); + List gender = dictSex.stream().map(DictData::getValue).collect(Collectors.toList()); + map.put("gender", gender); + map.put("personnelCharacter", Arrays.asList("年薪人员", "非年薪人员")); + map.put("freshGraduate", Arrays.asList("是", "否")); + + return map; + } + + private static Map getStringStringMap() { + Map codeKeyMap = new HashMap<>(); + codeKeyMap.put("t_dict_nation", "nation"); + codeKeyMap.put("t_dict_politics_status", "politicsStatus"); + codeKeyMap.put("t_dict_education", "education"); + codeKeyMap.put("t_dict_specialty_name", "jobTitle"); + codeKeyMap.put("t_dict_position", "position"); + codeKeyMap.put("t_dict_personnel_type", "personnelType"); + codeKeyMap.put("t_dict_department", "presentDept"); + codeKeyMap.put("t_dict_contract_form", "contractModality"); + codeKeyMap.put("t_dict_hire", "hireType"); + codeKeyMap.put("t_dict_credentials", "qualification"); + codeKeyMap.put("t_dict_staff_state", "workState"); + return codeKeyMap; } /** @@ -123,7 +214,7 @@ public class PersonnelController extends BaseController { @PostMapping(value = "giveAudit") @ApiOperation(value = "送审") - public AjaxResult giveAudit(@RequestBody GiveAuditRequest request){ + public AjaxResult giveAudit(@RequestBody GiveAuditRequest request) { return personnelService.giveAudit(request); } @@ -131,15 +222,15 @@ public class PersonnelController extends BaseController { @ApiOperation(value = "查看近两月是否有人退休") @Scheduled(cron = "0 0 7 * * ?") /*每天7点更新一次*/ //@Scheduled(cron = "0 */1 * * * ?") /*每分钟更新一次*/ - public void getPersonnelRetire(){ + public void getPersonnelRetire() { personnelService.getPersonnelRetire(); } @GetMapping("updatePersonnelRetire") @ApiOperation(value = "处理退休事件") - @ApiImplicitParam(name = "id",value = "人员id") - public AjaxResult updatePersonnelRetire(String id){ - return personnelService.updatePersonnelRetire(id); + @ApiImplicitParam(name = "id", value = "人员id") + public AjaxResult updatePersonnelRetire(String id) { + return personnelService.updatePersonnelRetire(id); } } diff --git a/src/main/java/com/ydool/staff/excel/ExcelPersonnel.java b/src/main/java/com/ydool/staff/excel/ExcelPersonnel.java index e5ef9fc..649391f 100644 --- a/src/main/java/com/ydool/staff/excel/ExcelPersonnel.java +++ b/src/main/java/com/ydool/staff/excel/ExcelPersonnel.java @@ -7,10 +7,10 @@ import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.alibaba.excel.annotation.write.style.HeadStyle; import com.ydool.common.converter.EasyExcelLocalDateConverter; import io.swagger.annotations.ApiModelProperty; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; + import java.time.LocalDate; @@ -26,27 +26,27 @@ import java.time.LocalDate; @ContentStyle(verticalAlignment = VerticalAlignment.CENTER) public class ExcelPersonnel { - @ExcelProperty(value = "统一社会信用代码" ) + @ExcelProperty(value = "统一社会信用代码") @ApiModelProperty(value = "统一社会信用代码") private String socialCreditCode; - @ExcelProperty("姓名") - @ApiModelProperty(value = "姓名") - private String userName; - - @ExcelProperty("企业名称") @ApiModelProperty(value = "企业名称") private String companyName; + @ExcelProperty("姓名") + @ApiModelProperty(value = "姓名") + private String userName; + + @ExcelProperty("性别") @ApiModelProperty(value = "性别") private String gender; - @ExcelProperty(value = "出生日期" , converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "出生日期", converter = EasyExcelLocalDateConverter.class) @ApiModelProperty(value = "出生日期") private LocalDate birthday; @@ -136,7 +136,7 @@ public class ExcelPersonnel { private Integer annualSalary; - @ExcelProperty(value = "入职时间" , converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "入职时间", converter = EasyExcelLocalDateConverter.class) @ApiModelProperty(value = "入职时间") private LocalDate hireDate; @@ -146,17 +146,17 @@ public class ExcelPersonnel { private LocalDate retirementTime; - @ExcelProperty(value ="离职时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "离职时间", converter = EasyExcelLocalDateConverter.class) @ApiModelProperty(value = "离职时间") private LocalDate resignationTime; - @ExcelProperty(value = "退休返聘开始时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘开始时间", converter = EasyExcelLocalDateConverter.class) @ApiModelProperty(value = "退休返聘开始时间") private LocalDate txfpStartTime; - @ExcelProperty(value = "退休返聘结束时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘结束时间", converter = EasyExcelLocalDateConverter.class) @ApiModelProperty(value = "退休返聘结束时间") private LocalDate txfpEndTime; diff --git a/src/main/java/com/ydool/staff/excel/PersonnelExportVO.java b/src/main/java/com/ydool/staff/excel/PersonnelExportVO.java index c887d93..0dc0309 100644 --- a/src/main/java/com/ydool/staff/excel/PersonnelExportVO.java +++ b/src/main/java/com/ydool/staff/excel/PersonnelExportVO.java @@ -2,38 +2,37 @@ package com.ydool.staff.excel; import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.annotation.write.style.HeadRowHeight; +import com.alibaba.excel.annotation.write.style.HeadStyle; import com.ydool.common.converter.EasyExcelLocalDateConverter; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.VerticalAlignment; import java.time.LocalDate; @Data -@AllArgsConstructor -@NoArgsConstructor +@HeadRowHeight(20) +@ColumnWidth(20) +@HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER) +@ContentStyle(verticalAlignment = VerticalAlignment.CENTER) public class PersonnelExportVO { - @ExcelProperty(value = "统一社会信用代码" ) - private String socialCreditCode; - - - @ExcelProperty("姓名") - private String userName; - @ExcelProperty("企业名称") private String companyName; + @ExcelProperty("姓名") + private String userName; + + @ExcelProperty("性别") private String gender; - @ExcelProperty(value = "出生日期" , converter = EasyExcelLocalDateConverter.class) - private LocalDate birthday; - - @ExcelProperty("身份证号") private String numberId; @@ -66,7 +65,7 @@ public class PersonnelExportVO { private String hireType; - @ExcelProperty("执业资格证书") + @ExcelProperty("执业资格") private String qualification; @@ -90,7 +89,7 @@ public class PersonnelExportVO { private String personnelType; - @ExcelProperty("工作状态") + @ExcelProperty("职工状态") private String workState; @@ -102,23 +101,19 @@ public class PersonnelExportVO { private Integer annualSalary; - @ExcelProperty(value = "入职时间" , converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "入职时间", converter = EasyExcelLocalDateConverter.class) private LocalDate hireDate; - @ExcelProperty(value = "退休时间", converter = EasyExcelLocalDateConverter.class) - private LocalDate retirementTime; - - - @ExcelProperty(value ="离职时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "离职时间", converter = EasyExcelLocalDateConverter.class) private LocalDate resignationTime; - @ExcelProperty(value = "退休返聘开始时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘开始时间", converter = EasyExcelLocalDateConverter.class) private LocalDate txfpStartTime; - @ExcelProperty(value = "退休返聘结束时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘结束时间", converter = EasyExcelLocalDateConverter.class) private LocalDate txfpEndTime; @@ -130,21 +125,4 @@ public class PersonnelExportVO { private String remark; - @ExcelProperty("初审意见") - private String firstTrialRemark; - - - @ExcelProperty("终审意见") - private String finalTrialRemark; - - - @ExcelProperty("变更标志") - private String alterationSign; - - - @ExcelProperty("单据状态") - private String receipts; - - - } diff --git a/src/main/java/com/ydool/staff/excel/PersonnelFailMsgVO.java b/src/main/java/com/ydool/staff/excel/PersonnelFailMsgVO.java index fb334a7..ec2779b 100644 --- a/src/main/java/com/ydool/staff/excel/PersonnelFailMsgVO.java +++ b/src/main/java/com/ydool/staff/excel/PersonnelFailMsgVO.java @@ -1,10 +1,14 @@ package com.ydool.staff.excel; import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.annotation.write.style.HeadRowHeight; +import com.alibaba.excel.annotation.write.style.HeadStyle; import com.ydool.common.converter.EasyExcelLocalDateConverter; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.VerticalAlignment; import java.time.LocalDate; @@ -14,8 +18,10 @@ import java.time.LocalDate; * @date 2023/2/14 11:55 */ @Data -@AllArgsConstructor -@NoArgsConstructor +@HeadRowHeight(20) +@ColumnWidth(20) +@HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER) +@ContentStyle(verticalAlignment = VerticalAlignment.CENTER) public class PersonnelFailMsgVO { @ExcelProperty("统一社会信用代码") @@ -34,7 +40,7 @@ public class PersonnelFailMsgVO { private String gender; - @ExcelProperty(value = "出生日期" , converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "出生日期", converter = EasyExcelLocalDateConverter.class) private LocalDate birthday; @ExcelProperty("身份证号") @@ -105,7 +111,7 @@ public class PersonnelFailMsgVO { private Integer annualSalary; - @ExcelProperty(value = "入职时间" , converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "入职时间", converter = EasyExcelLocalDateConverter.class) private LocalDate hireDate; @@ -113,15 +119,15 @@ public class PersonnelFailMsgVO { private LocalDate retirementTime; - @ExcelProperty(value ="离职时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "离职时间", converter = EasyExcelLocalDateConverter.class) private LocalDate resignationTime; - @ExcelProperty(value = "退休返聘开始时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘开始时间", converter = EasyExcelLocalDateConverter.class) private LocalDate txfpStartTime; - @ExcelProperty(value = "退休返聘结束时间",converter = EasyExcelLocalDateConverter.class) + @ExcelProperty(value = "退休返聘结束时间", converter = EasyExcelLocalDateConverter.class) private LocalDate txfpEndTime; @@ -133,22 +139,6 @@ public class PersonnelFailMsgVO { private String remark; - @ExcelProperty("初审意见") - private String firstTrialRemark; - - - @ExcelProperty("终审意见") - private String finalTrialRemark; - - - @ExcelProperty("变更标志") - private String alterationSign; - - - - @ExcelProperty("单据状态") - private String receipts; - @ExcelProperty(value = "结果") private String failMsg; } diff --git a/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java b/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java index ef34b50..0279d45 100644 --- a/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java +++ b/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; /** *

@@ -93,6 +94,15 @@ public class OrganizationServiceImpl extends BaseService organizationIds = organizationMapper.selectList(Wrappers.lambdaQuery(Organization.class).eq(Organization::getAuditState, 3).in(Organization::getId, asList)) + .stream().map(Organization::getId).collect(Collectors.toList()); + + List places = placesMapper.selectList(Wrappers.lambdaQuery(Places.class).in(Places::getOrganizationId, organizationIds)); + + if (places.stream().anyMatch(e -> personnelService.count(Wrappers.lambdaQuery(Personnel.class).eq(Personnel::getRecruitNumber, e.getOdd())) > 0)) { + return AjaxResult.fail("招聘单号已被使用!"); + } + int i = organizationMapper.deleteBatchIds(asList); if (i > 0) { personnelIndicatorsMapper.delete(new LambdaQueryWrapper().in(PersonnelIndicators::getOrganizationId, asList)); @@ -173,7 +183,7 @@ public class OrganizationServiceImpl extends BaseService().eq(Personnel::getRecruitNumber, place.getOdd())); - if (count wrapper = selectWrapper(request, orderBy, column,isInfo); + public AjaxResult personnelList(Page page, SelectRequest request, String orderBy, String column, Boolean isInfo, String deptId) { + QueryWrapper wrapper = selectWrapper(request, orderBy, column, isInfo); User user = userService.getOne(new QueryWrapper().lambda() .eq(User::getId, StpUtil.getLoginIdAsString()) .last("limit 1") @@ -161,9 +151,9 @@ public class PersonnelServiceImpl extends BaseService wrapper = new LambdaQueryWrapper() .eq(PersonnelMiddle::getBeforeId, id).eq(PersonnelMiddle::getState, "1") .eq(PersonnelMiddle::getType, personnelType); PersonnelMiddle middle = personnelMiddleMapper.selectOne(wrapper); - if (ObjectUtil.isNotEmpty(middle)){ - BeanUtil.copyProperties(personnelMapper.selectById(middle.getAfterId()),personnel); - }else { - BeanUtil.copyProperties(personnelMapper.selectById(id),personnel); + if (ObjectUtil.isNotEmpty(middle)) { + BeanUtil.copyProperties(personnelMapper.selectById(middle.getAfterId()), personnel); + } else { + BeanUtil.copyProperties(personnelMapper.selectById(id), personnel); } } - if (ObjectUtil.isEmpty(personnel))return AjaxResult.fail().msg("该人员不存在!"); + if (ObjectUtil.isEmpty(personnel)) return AjaxResult.fail().msg("该人员不存在!"); PersonnelUpdateDto personnelUpdateDto = BeanUtil.copyProperties(personnel, PersonnelUpdateDto.class); LambdaQueryWrapper wrapper = new LambdaQueryWrapper() .eq(Audit::getPersonnelId, id) - .eq(Audit::getPerType,personnelType) + .eq(Audit::getPerType, personnelType) .eq(Audit::getApprover, StpUtil.getLoginIdAsString()) .eq(Audit::getAuditState, ArgsConst.WAITING); Audit audit = auditMapper.selectOne(wrapper); - if (ObjectUtil.isNotEmpty(audit)){ + if (ObjectUtil.isNotEmpty(audit)) { personnelUpdateDto.setAuditBtn(true); } personnelUpdateDto.setBeforeId(id); @@ -225,13 +215,13 @@ public class PersonnelServiceImpl extends BaseService list = list(new LambdaQueryWrapper().eq(Personnel::getState,"2").eq(Personnel::getAuditState,3).eq(Personnel::getWorkState,"在职")); + List list = list(new LambdaQueryWrapper().eq(Personnel::getState, "2").eq(Personnel::getAuditState, 3).eq(Personnel::getWorkState, "在职")); List dtos = BeanUtil.copyToList(list, PersonnelByExchangeDto.class); for (PersonnelByExchangeDto dto : dtos) { CompanyName companyName = companyNameMapper.selectById(dto.getCompanyName()); dto.setCompanyName(companyName.getCompanyName()); - //Dept dept = deptMapper.selectById(dto.getPresentDept()); - //dto.setPresentDept(dept.getName()); + // Dept dept = deptMapper.selectById(dto.getPresentDept()); + // dto.setPresentDept(dept.getName()); } return AjaxResult.ok().data(dtos); } @@ -245,7 +235,7 @@ public class PersonnelServiceImpl extends BaseService asList = Arrays.asList(ids.getIds()); for (String s : asList) { - Personnel personnel = personnelMapper.selectOne(new LambdaQueryWrapper().eq(Personnel::getId,s).eq(Personnel::getAlterationSign,"1") - .eq(Personnel::getChangeAlterationSign,"1").in(Personnel::getAuditState,1,2).in(Personnel::getChangeAuditState,1,2)); - if (ObjectUtil.isNotEmpty(personnel)){ + Personnel personnel = personnelMapper.selectOne(new LambdaQueryWrapper().eq(Personnel::getId, s).eq(Personnel::getAlterationSign, "1") + .eq(Personnel::getChangeAlterationSign, "1").in(Personnel::getAuditState, 1, 2).in(Personnel::getChangeAuditState, 1, 2)); + if (ObjectUtil.isNotEmpty(personnel)) { return AjaxResult.fail().msg("该人员有变更中或待审批数据,不能删除!"); } } @@ -306,19 +296,19 @@ public class PersonnelServiceImpl extends BaseService auditFiles = request.getAuditFileList(); PersonnelMiddle middle = new PersonnelMiddle(); String type = ArgsConst.CHANGE; - PersonnelMiddle personnelMiddle = personnelMiddleMapper.selectOne(new LambdaQueryWrapper().eq(PersonnelMiddle::getAfterId, request.getId()).eq(PersonnelMiddle::getState,"1")); - String id = null;String card = null;String jobTitle = null;String engage = null;String education =null;String audit = null; - if (ObjectUtil.isNotNull(personnelMiddle)){ + PersonnelMiddle personnelMiddle = personnelMiddleMapper.selectOne(new LambdaQueryWrapper().eq(PersonnelMiddle::getAfterId, request.getId()).eq(PersonnelMiddle::getState, "1")); + String id = null; + String card = null; + String jobTitle = null; + String engage = null; + String education = null; + String audit = null; + if (ObjectUtil.isNotNull(personnelMiddle)) { id = personnelMiddle.getBeforeId(); card = StringUtils.join(saveFilePath(cardFiles, ArgsConst.CARD_FILE, type, id), ','); jobTitle = StringUtils.join(saveFilePath(jobTitleFiles, ArgsConst.JOBTITLE_FILE, type, id), ','); - engage = StringUtils.join(saveFilePath(engageFiles, ArgsConst.ENGAGE_FILE, type,id), ','); + engage = StringUtils.join(saveFilePath(engageFiles, ArgsConst.ENGAGE_FILE, type, id), ','); education = StringUtils.join(saveFilePath(educationFiles, ArgsConst.EDUCATION_FILE, type, id), ','); audit = StringUtils.join(saveFilePath(auditFiles, ArgsConst.AUDIT_FILE, type, id), ','); saveAttachment(cardFiles, ArgsConst.CARD_FILE, id, ArgsConst.UPDATE); @@ -363,11 +358,11 @@ public class PersonnelServiceImpl extends BaseService().eq(Alteration::getRelevancyId, id).eq(Alteration::getFieldName, fieldName)); - if (ObjectUtil.isNotEmpty(one)){ + if (ObjectUtil.isNotEmpty(one)) { one.setDetails(details); one.setFieldName(fieldName); one.setType(type); @@ -522,7 +518,7 @@ public class PersonnelServiceImpl extends BaseService nameAndPath(String file, String id) { @@ -563,30 +559,30 @@ public class PersonnelServiceImpl extends BaseService wrapper = new QueryWrapper<>(); - if(ArgsConst.PERSONNEL.equals(request.getType())){ - wrapper.lambda().ne(Personnel::getAuditState,"3"); - }else{ - wrapper.lambda().eq(isInfo,Personnel::getIsInfo,true).eq(Personnel::getAuditState,"3").ne(Personnel::getState,1).ne(Personnel::getState,0); + if (ArgsConst.PERSONNEL.equals(request.getType())) { + wrapper.lambda().ne(Personnel::getAuditState, "3"); + } else { + wrapper.lambda().eq(isInfo, Personnel::getIsInfo, true).eq(Personnel::getAuditState, "3").ne(Personnel::getState, 1).ne(Personnel::getState, 0); } - wrapper.lambda().eq(StrUtil.isNotBlank(request.getPersonnelType()),Personnel::getPersonnelType,request.getPersonnelType()) - .eq(StrUtil.isNotBlank(request.getPresentDept()),Personnel::getPresentDept,request.getPresentDept()) - .eq(StrUtil.isNotBlank(request.getPoliticsStatus()),Personnel::getPoliticsStatus,request.getPoliticsStatus()) - .eq(StrUtil.isNotBlank(request.getHireType()),Personnel::getHireType,request.getHireType()) - .eq(StrUtil.isNotBlank(request.getPosition()),Personnel::getPosition,request.getPosition()) - .eq(StrUtil.isNotBlank(request.getContractModality()),Personnel::getContractModality,request.getContractModality()) - .eq(StrUtil.isNotBlank(request.getQualification()),Personnel::getQualification,request.getQualification()) - .eq(StrUtil.isNotBlank(request.getPersonnelType()),Personnel::getPersonnelType,request.getPersonnelType()) - .eq(ObjectUtil.isNotNull(request.getHireDate()),Personnel::getHireDate,request.getHireDate()) - .eq(ObjectUtil.isNotNull(request.getResignationTime()),Personnel::getResignationTime,request.getResignationTime()) - .eq(StrUtil.isNotBlank(request.getWorkState()),Personnel::getWorkState,request.getWorkState()) - .eq(StrUtil.isNotBlank(request.getReceipts()),Personnel::getReceipts,request.getReceipts()) - .eq(StrUtil.isNotBlank(request.getAlterationSign()),Personnel::getAlterationSign,request.getAlterationSign()) - .eq(StrUtil.isNotBlank(request.getChangeAlterationSign()),Personnel::getChangeAlterationSign,request.getChangeAlterationSign()); + wrapper.lambda().eq(StrUtil.isNotBlank(request.getPersonnelType()), Personnel::getPersonnelType, request.getPersonnelType()) + .eq(StrUtil.isNotBlank(request.getPresentDept()), Personnel::getPresentDept, request.getPresentDept()) + .eq(StrUtil.isNotBlank(request.getPoliticsStatus()), Personnel::getPoliticsStatus, request.getPoliticsStatus()) + .eq(StrUtil.isNotBlank(request.getHireType()), Personnel::getHireType, request.getHireType()) + .eq(StrUtil.isNotBlank(request.getPosition()), Personnel::getPosition, request.getPosition()) + .eq(StrUtil.isNotBlank(request.getContractModality()), Personnel::getContractModality, request.getContractModality()) + .eq(StrUtil.isNotBlank(request.getQualification()), Personnel::getQualification, request.getQualification()) + .eq(StrUtil.isNotBlank(request.getPersonnelType()), Personnel::getPersonnelType, request.getPersonnelType()) + .eq(ObjectUtil.isNotNull(request.getHireDate()), Personnel::getHireDate, request.getHireDate()) + .eq(ObjectUtil.isNotNull(request.getResignationTime()), Personnel::getResignationTime, request.getResignationTime()) + .eq(StrUtil.isNotBlank(request.getWorkState()), Personnel::getWorkState, request.getWorkState()) + .eq(StrUtil.isNotBlank(request.getReceipts()), Personnel::getReceipts, request.getReceipts()) + .eq(StrUtil.isNotBlank(request.getAlterationSign()), Personnel::getAlterationSign, request.getAlterationSign()) + .eq(StrUtil.isNotBlank(request.getChangeAlterationSign()), Personnel::getChangeAlterationSign, request.getChangeAlterationSign()); - wrapper.lambda().like(Personnel::getUserName,request.getUserName()) - .like(Personnel::getNumberId,request.getNumberId()) + wrapper.lambda().like(Personnel::getUserName, request.getUserName()) + .like(Personnel::getNumberId, request.getNumberId()) .exists(StrUtil.isNotBlank(request.getCompanyName()), "select t2.id from t_lc_company_name t2 where " + "t_lc_personnel.company_name = t2.id and t2.company_name like '%" + request.getCompanyName() + "%'"); wrapper.lambda().orderByDesc(Personnel::getCreatedAt); @@ -599,70 +595,72 @@ public class PersonnelServiceImpl extends BaseService list = list(); List personnelList = BeanUtil.copyToList(list, ExcelPersonnel.class); for (ExcelPersonnel excelPersonnel : personnelList) { CompanyName companyName = companyNameMapper.selectById(excelPersonnel.getCompanyName()); Dept dept = deptMapper.selectById(excelPersonnel.getPresentDept()); - if (ObjectUtil.isNotEmpty(companyName)){ + if (ObjectUtil.isNotEmpty(companyName)) { excelPersonnel.setCompanyName(companyName.getCompanyName()); } - if (ObjectUtil.isNotEmpty(dept)){ + if (ObjectUtil.isNotEmpty(dept)) { excelPersonnel.setPresentDept(dept.getName()); } - excelPersonnel.setGender("1".equals(excelPersonnel.getGender())?"男":"女"); - excelPersonnel.setFreshGraduate("1".equals(excelPersonnel.getFreshGraduate())?"是":"否"); + excelPersonnel.setGender("1".equals(excelPersonnel.getGender()) ? "男" : "0".equals(excelPersonnel.getGender()) ? "女" : "未知"); + excelPersonnel.setFreshGraduate("1".equals(excelPersonnel.getFreshGraduate()) ? "是" : "否"); } String fileName = "企业人员申报" + System.currentTimeMillis() + ".xlsx"; - Set includeColumnFiledNames = new HashSet<>(); - for (String s : param.getIds()) { - includeColumnFiledNames.add(s); - } - //导出 - EasyExcelAlibabaUtil.exportDownload(response, ExcelPersonnel.class, personnelList, fileName,includeColumnFiledNames); + Set includeColumnFiledNames = new HashSet<>(Arrays.asList(param.getIds())); + // 导出 + EasyExcelAlibabaUtil.exportDownload(response, ExcelPersonnel.class, personnelList, fileName, includeColumnFiledNames); } @Override + @Transactional(rollbackFor = Exception.class) public AjaxResult importPersonnel(MultipartFile excl) { -//判断文件类型 String reg = ".+(.xlsx)$"; String suffix = FileUtil.getSuffix(excl.getOriginalFilename()); - if (!Pattern.matches(reg, excl.getOriginalFilename())){ + if (!Pattern.matches(reg, excl.getOriginalFilename())) { return AjaxResult.fail("必须上传后缀为" + suffix + "的文件"); } - if (!"企业人员申报模板.xlsx".equals(excl.getOriginalFilename())){ - return AjaxResult.fail("必须上传 企业人员申报模板.xlsx 文件"); + if (!"企业人员申报.xlsx".equals(excl.getOriginalFilename())) { + return AjaxResult.fail("必须上传 企业人员申报.xlsx 文件"); } - //导出数据 + // 导出数据 List failList = new ArrayList<>(); if (!excl.isEmpty()) { - List personnelExportVOS = EasyExcelAlibabaUtil.excelToList(excl, - PersonnelExportVO.class); - if (CollectionUtil.isEmpty(personnelExportVOS)){ - return AjaxResult.fail("模板必须要有数据"); + List personnelExportVOS = EasyExcelAlibabaUtil.excelToList(excl, PersonnelExportVO.class); + if (CollectionUtil.isEmpty(personnelExportVOS)) { + return AjaxResult.fail("导入数据不能为空!"); } for (PersonnelExportVO personnelExportVO : personnelExportVOS) { - System.out.println("通讯录信息" + personnelExportVO); - //校验通讯录信息 + // 校验通讯录信息 PersonnelFailMsgVO failMsgVO = checkPersonnelExportVO(personnelExportVO); - //错误数据 不保存 + // 错误数据 不保存 if (StrUtil.isNotBlank(failMsgVO.getFailMsg())) { failList.add(failMsgVO); } else { - //转义 + // 转义 Personnel personnel = BeanUtil.copyProperties(personnelExportVO, Personnel.class); + CompanyName selectOne = companyNameMapper.selectOne(Wrappers.lambdaQuery(CompanyName.class).eq(CompanyName::getCompanyName, personnelExportVO.getCompanyName())); + if (selectOne != null) { + personnel.setCompanyName(selectOne.getId()); + personnel.setSocialCreditCode(selectOne.getCreditCode()); + } + personnel.setBirthday(birthday(personnelExportVO.getNumberId())); + personnel.setRetirementTime(retirementTime(personnelExportVO.getNumberId())); personnel.setFreshGraduate("是".equals(personnelExportVO.getFreshGraduate()) ? "1" : "0"); - //保存 + personnel.setGender("男".equals(personnelExportVO.getGender()) ? "1" : "女".equals(personnelExportVO.getGender()) ? "0" : "2"); + // 保存 failMsgVO.setFailMsg(failMsgVO.getFailMsg() + (save(personnel) ? "导入成功" : "导入失败")); failList.add(failMsgVO); } } - } - //导出导入结果 - String download = EasyExcelAlibabaUtil.download(PersonnelFailMsgVO.class, failList, "通讯录导入结果"); + // 导出导入结果 + String download = EasyExcelAlibabaUtil.download(PersonnelFailMsgVO.class, failList, "企业人员申报导入结果"); return AjaxResult.ok().data(download).msg("导入完成"); } @@ -681,38 +679,38 @@ public class PersonnelServiceImpl extends BaseService().eq(Config::getParamKey, ConfigCache.SYS_USER_LEADERSHIP)); audit.setAuditState(ArgsConst.WAITING); User user = userMapper.selectOne(new LambdaQueryWrapper().eq(User::getLoginName, config.getParamValue())); audit.setApprover(user.getId()); - //通知 + // 通知 User loginUser = userMapper.selectById(loginId); WorkFlowNotice workFlowNotice = new WorkFlowNotice(); workFlowNotice.setStatus(Boolean.FALSE); workFlowNotice.setUserId(user.getId()); - if (request.getType().equals(ArgsConst.PERSONNEL)){ + if (request.getType().equals(ArgsConst.PERSONNEL)) { workFlowNotice.setTitle(loginUser.getUserName() + "的企业人员申报待你审批"); workFlowNotice.setFlowType(ArgsConst.PERSONNEL); - }else if(request.getType().equals(ArgsConst.CHANGE)){ + } else if (request.getType().equals(ArgsConst.CHANGE)) { workFlowNotice.setTitle(loginUser.getUserName() + "的人员变更申报待你审批"); workFlowNotice.setFlowType(ArgsConst.CHANGE); - }else { + } else { workFlowNotice.setTitle(loginUser.getUserName() + "的人员选调申报待你审批"); workFlowNotice.setFlowType(ArgsConst.EXCHANGE); } @@ -721,21 +719,21 @@ public class PersonnelServiceImpl extends BaseService().eq(PersonnelMiddle::getAfterId, id)); - if (ObjectUtil.isNotEmpty(one)){ + if (ObjectUtil.isNotEmpty(one)) { Personnel personnel = get(one.getBeforeId()); Personnel personnel1 = get(id); personnel.setChangeAuditState(2); personnel1.setChangeAuditState(2); updateById(personnel); updateById(personnel1); - }else { + } else { Personnel personnel = get(id); personnel.setChangeAuditState(2); updateById(personnel); @@ -743,14 +741,14 @@ public class PersonnelServiceImpl extends BaseService pOptional = Optional.ofNullable(personnelMapper.selectCount(Wrappers.lambdaQuery(Personnel.class).eq(Personnel::getRecruitNumber, personnelExportVO.getRecruitNumber()))); + Optional placesOptional = Optional.ofNullable(placesMapper.selectOne(Wrappers.lambdaQuery(Places.class).eq(Places::getOdd, personnelExportVO.getRecruitNumber()))); + + if (pOptional.isPresent() && placesOptional.isPresent() && pOptional.get() > placesOptional.get().getSum()) { + failMsgVO.setFailMsg("招聘名额已用完!"); } return failMsgVO; } + /** + * 计算退休时间 + * @param numberId + * @return + */ + public LocalDate retirementTime(String numberId) { + // 330225 1996 09 05 0012 + String org_birthday = numberId.substring(6, 14); + String org_gender = numberId.substring(16, 17); + String sex = Integer.parseInt(org_gender) % 2 == 1 ? "男" : "女"; + String birthday = org_birthday.substring(0, 4) + "-" + org_birthday.substring(4, 6) + "-" + org_birthday.substring(6, 8); + System.out.println("birthday = " + birthday); + int plusNum = sex.equals("男") ? 60 : 50; + String dateStr = (Integer.parseInt(org_birthday.substring(0, 4)) + plusNum) + "-" + org_birthday.substring(4, 6) + "-" + org_birthday.substring(6, 8); + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate dateParam = LocalDate.parse(dateStr, df); + System.out.println("String => LocalDate: " + dateParam); + return dateParam; + } - public String verifyIds(String[] ids,String type){ + /** + * 出手日期 + * @param numberId + * @return + */ + public LocalDate birthday(String numberId) { + // 330225 1996 09 05 0012 + String org_birthday = numberId.substring(6, 14); + String birthday = org_birthday.substring(0, 4) + "-" + org_birthday.substring(4, 6) + "-" + org_birthday.substring(6, 8); + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate dateParam = LocalDate.parse(birthday, df); + System.out.println("String => LocalDate: " + dateParam); + return dateParam; + } + + + public String verifyIds(String[] ids, String type) { String message = ""; for (String id : ids) { - if (ArgsConst.PERSONNEL.equals(type)){ + if (ArgsConst.PERSONNEL.equals(type)) { Personnel personnel = get(id); if (1 == (personnel.getAuditState())) { - return message="该数据已送审请勿重复操作!"; + return message = "该数据已送审请勿重复操作!"; } if ("0".equals(personnel.getAlterationSign())) { - return message="变更数据未保存,不能送审!"; + return message = "变更数据未保存,不能送审!"; } - }else if (ArgsConst.CHANGE.equals(type)){ + } else if (ArgsConst.CHANGE.equals(type)) { Personnel personnel = get(id); if (1 == (personnel.getChangeAuditState())) { - return message="该数据已送审请勿重复操作!"; + return message = "该数据已送审请勿重复操作!"; } if ("0".equals(personnel.getChangeAlterationSign())) { - return message="变更数据未保存,不能送审!"; + return message = "变更数据未保存,不能送审!"; } - }else if (ArgsConst.EXCHANGE.equals(type)) { + } else if (ArgsConst.EXCHANGE.equals(type)) { Exchange exchange = exchangeMapper.selectById(id); Personnel personnel = get(exchange.getPersonnelId()); - if ("1".equals(personnel.getAlterationSign())||"1".equals(personnel.getChangeAlterationSign())){ - return message="该人员有变更数据,不能进行选调!"; + if ("1".equals(personnel.getAlterationSign()) || "1".equals(personnel.getChangeAlterationSign())) { + return message = "该人员有变更数据,不能进行选调!"; } if ("1".equals(exchange.getAuditState())) { - return message="该数据已送审请勿重复操作!"; + return message = "该数据已送审请勿重复操作!"; } } } @@ -818,9 +873,9 @@ public class PersonnelServiceImpl extends BaseService list = list(new LambdaQueryWrapper() - .ne(Personnel::getAlterationSign,1).eq(Personnel::getAuditState,3).eq(Personnel::getState,2) - .eq(Personnel::getWorkState,"在职").between(Personnel::getRetirementTime, nowDate, starTime).eq(Personnel::getIsInfo,false).orderByDesc(Personnel::getRetirementTime)); - if (CollectionUtil.isNotEmpty(list)){ + .ne(Personnel::getAlterationSign, 1).eq(Personnel::getAuditState, 3).eq(Personnel::getState, 2) + .eq(Personnel::getWorkState, "在职").between(Personnel::getRetirementTime, nowDate, starTime).eq(Personnel::getIsInfo, false).orderByDesc(Personnel::getRetirementTime)); + if (CollectionUtil.isNotEmpty(list)) { CacheUtil.put(ConfigCache.SCHEDULED_CODE_PERSONNEL_RETIRE, ConfigCache.SCHEDULED_CODE_PERSONNEL_RETIRE, "scheduled", true); Config config = configMapper.selectOne(new LambdaQueryWrapper().eq(Config::getParamKey, ConfigCache.SYS_USER_LEADERSHIP)); User user = userMapper.selectOne(new LambdaQueryWrapper().eq(User::getLoginName, config.getParamValue())); @@ -829,7 +884,7 @@ public class PersonnelServiceImpl extends BaseService i if (ObjectUtil.isNull(dictData)) return ""; return dictData.getLabel(); } + + public List listByCode(String typeCode) { + DictType grapeDictType = dictTypeService.getOne(new LambdaQueryWrapper().eq(DictType::getCode, typeCode)); + if (grapeDictType == null) return new ArrayList<>(); + List list = list(new LambdaQueryWrapper() + .eq(DictData::getDataType, grapeDictType.getCode()) + .eq(DictData::getStatus, 1) + .orderByAsc(DictData::getSortNo)); + return list; + } }