Commit 23ba4a37 authored by fangxinjiang's avatar fangxinjiang

附属信息-工作记录

parent d5d129bd
......@@ -31,7 +31,7 @@ public class EmpFamilyExcelVO implements Serializable {
/**
* 员工姓名
*/
@NotNull(message = "员工编码不可为空")
@NotNull(message = "员工姓名不可为空")
@ExcelProperty(value ="员工姓名")
private String empName;
/**
......
package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 员工伤残excel 对应的实体
*
* @author fxz
* @date 2022/3/21
*/
@Data
@ColumnWidth(30)
public class EmpWorkRecordExcelVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 员工身份证
*/
@NotNull(message = "员工身份证不可为空")
@ExcelProperty(value ="员工身份证")
private String empIdcard;
/**
* 员工姓名
*/
@NotNull(message = "员工姓名不可为空")
@ExcelProperty(value ="员工姓名")
private String empName;
/**
* 工作单位
*/
@NotNull(message = "工作单位不可为空")
@ExcelProperty(value ="工作单位")
private String workUnit;
/**
* 工作部门
*/
@NotNull(message = "工作部门不可为空")
@ExcelProperty(value ="工作部门")
private String workDepart;
/**
* 工作岗位
*/
@ExcelProperty(value ="工作岗位")
private String workJob;
/**
* 开始工作日期
*/
@NotNull(message = "开始工作日期不可为空")
@ExcelProperty(value ="开始工作日期")
private LocalDateTime startDate;
/**
* 结束工作日期
*/
@ExcelProperty(value ="结束工作日期")
private LocalDateTime endDate;
/**
* 是否在岗:0是/1否
*/
@NotNull(message = "是否在岗不可为空")
@ExcelProperty(value ="是否在岗")
private String workingStatus;
/**
* 工作类型
*/
@ExcelProperty(value ="工作类型")
private String workingType;
/*JSR303 是一套JavaBean参数校验的标准,它定义了很多常用的校验注解,我们可以直接将这些注解加在我们JavaBean的属性上面,就可以在需要校验的时候进行校验了。注解如下:
参考配置
@Null 限制只能为null
@NotNull 限制必须不为null
@AssertFalse 限制必须为false
@AssertTrue 限制必须为true
@DecimalMax(value) 限制必须为一个不大于指定值的数字
@DecimalMin(value) 限制必须为一个不小于指定值的数字
@Digits(integer,fraction) 限制必须为一个小数,且整数部分的位数不能超过integer,小数部分的位数不能超过fraction
@Future 限制必须是一个将来的日期
@Max(value) 限制必须为一个不大于指定值的数字
@Min(value) 限制必须为一个不小于指定值的数字
@Past 限制必须是一个过去的日期
@Pattern(value) 限制必须符合指定的正则表达式
@Size(max,min) 限制字符长度必须在min到max之间
@Past 验证注解的元素值(日期类型)比当前时间早
@NotEmpty 验证注解的元素值不为null且不为空(字符串长度不为0、集合大小不为0)
@NotBlank 验证注解的元素值不为空(不为null、去除首位空格后长度为0),不同于@NotEmpty,@NotBlank只应用于字符串且在比较时会去除字符串的空格
@Email 验证注解的元素值是Email,也可以通过正则表达式和flag指定自定义的email格式*/
}
......@@ -17,10 +17,17 @@
package com.yifu.cloud.plus.v1.yifu.archives.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpWorkRecording;
import com.yifu.cloud.plus.v1.yifu.archives.service.TEmpWorkRecordingService;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmpFamilyExcelVO;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmpWorkRecordExcelVO;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
......@@ -29,8 +36,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 员工工作履历信息表
......@@ -56,7 +66,7 @@ public class TEmpWorkRecordingController {
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_get')" )
public R getTEmpWorkRecordingPage(Page page, TEmpWorkRecording tEmpWorkRecording) {
public R<IPage<TEmpWorkRecording>> getTEmpWorkRecordingPage(Page page, TEmpWorkRecording tEmpWorkRecording) {
return R.ok(tEmpWorkRecordingService.page(page, Wrappers.query(tEmpWorkRecording)));
}
......@@ -69,7 +79,7 @@ public class TEmpWorkRecordingController {
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_get')" )
public R getById(@PathVariable("id" ) Long id) {
public R<TEmpWorkRecording> getById(@PathVariable("id" ) Long id) {
return R.ok(tEmpWorkRecordingService.getById(id));
}
......@@ -82,7 +92,7 @@ public class TEmpWorkRecordingController {
@SysLog("新增员工工作履历信息表" )
@PostMapping
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_add')" )
public R save(@RequestBody TEmpWorkRecording tEmpWorkRecording) {
public R<Boolean> save(@RequestBody TEmpWorkRecording tEmpWorkRecording) {
return R.ok(tEmpWorkRecordingService.save(tEmpWorkRecording));
}
......@@ -95,7 +105,7 @@ public class TEmpWorkRecordingController {
@SysLog("修改员工工作履历信息表" )
@PutMapping
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_edit')" )
public R updateById(@RequestBody TEmpWorkRecording tEmpWorkRecording) {
public R<Boolean> updateById(@RequestBody TEmpWorkRecording tEmpWorkRecording) {
return R.ok(tEmpWorkRecordingService.updateById(tEmpWorkRecording));
}
......@@ -108,8 +118,40 @@ public class TEmpWorkRecordingController {
@SysLog("通过id删除员工工作履历信息表" )
@DeleteMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_del')" )
public R removeById(@PathVariable Long id) {
public R<Boolean> removeById(@PathVariable Long id) {
return R.ok(tEmpWorkRecordingService.removeById(id));
}
/**
* 通过id删除员工工作信息表
* @param ids
* @return R
*/
@Operation(summary = "通过id删除员工家庭信息表", description = "通过id删除员工家庭信息表 @pms.hasPermission('archives_tempworkrecording_del_batch')")
@SysLog("通过id删除员工家庭信息表" )
@DeleteMapping("/removeByIds" )
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_del_batch')" )
public R<Boolean> removeByIds(String ids) {
List<String> idList = null;
if (Common.isNotNull(ids)){
idList = Common.initStrToList(ids, CommonConstants.COMMA_STRING);
}
return R.ok(tEmpWorkRecordingService.removeByIds(idList));
}
/**
* 批量新增员工工作信息
*
* @param excelVOList
* @return
* @Author fxj
* @Date 2019-08-16
**/
@Operation(description = "批量新增员工家庭信息 hasPermission('archives_tempworkrecording_importListAdd')")
@SysLog("批量新增员工工作信息")
@PostMapping("/importListAdd")
@PreAuthorize("@pms.hasPermission('archives_tempworkrecording_importListAdd')")
public R<List<ErrorMessage>> batchAddByJsonString(@RequestExcel List<EmpWorkRecordExcelVO> excelVOList, BindingResult bindingResult) {
return tEmpWorkRecordingService.importEmpFamilys(excelVOList, bindingResult);
}
}
......@@ -18,7 +18,13 @@
package com.yifu.cloud.plus.v1.yifu.archives.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpWorkRecording;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmpWorkRecordExcelVO;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.validation.BindingResult;
import java.util.List;
/**
* 员工工作履历信息表
......@@ -28,4 +34,5 @@ import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpWorkRecording;
*/
public interface TEmpWorkRecordingService extends IService<TEmpWorkRecording> {
R<List<ErrorMessage>> importEmpFamilys(List<EmpWorkRecordExcelVO> excelVOList, BindingResult bindingResult);
}
......@@ -16,11 +16,27 @@
*/
package com.yifu.cloud.plus.v1.yifu.archives.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpWorkRecording;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeInfo;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TEmpWorkRecordingMapper;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TEmployeeInfoMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.TEmpWorkRecordingService;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmpWorkRecordExcelVO;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import java.util.*;
/**
* 员工工作履历信息表
......@@ -28,7 +44,86 @@ import org.springframework.stereotype.Service;
* @author fxj
* @date 2022-06-18 09:39:46
*/
@RequiredArgsConstructor
@Service
public class TEmpWorkRecordingServiceImpl extends ServiceImpl<TEmpWorkRecordingMapper, TEmpWorkRecording> implements TEmpWorkRecordingService {
private final TEmployeeInfoMapper employeeInfoMapper;
@Override
public R<List<ErrorMessage>> importEmpFamilys(List<EmpWorkRecordExcelVO> excelVOList, BindingResult bindingResult) {
// 通用校验获取失败的数据
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
Map<Long,ErrorMessage> errorMsgMap = new HashMap<>();
if (Common.isNotNull(errorMessageList)){
errorMessageList.stream().forEach(errorMessage -> errorMsgMap.put(errorMessage.getLineNum(),errorMessage));
}
// 个性化校验逻辑
List<TEmpWorkRecording> list = this.list();
TEmployeeInfo emp;
TEmpWorkRecording exist;
Set<String> errorMsg;
// 执行数据插入操作 组装
for (int i = 0; i < excelVOList.size(); i++) {
// 已有验证报错直接下一个
if (Common.isNotNull(errorMsgMap.get(i+2))){
continue;
}
errorMsg = new HashSet<>();
EmpWorkRecordExcelVO excel = excelVOList.get(i);
emp = employeeInfoMapper.selectOne(Wrappers.<TEmployeeInfo>query().lambda()
.eq(TEmployeeInfo::getEmpIdcard,excel.getEmpIdcard())
.eq(TEmployeeInfo::getDeleteFlag, CommonConstants.ZERO_STRING)
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isEmpty(emp)){
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_EMP_NOT_EXIST, excel.getEmpIdcard()));
}
if (CommonConstants.ONE_STRING.equals(emp.getFileStatus())){
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_EMP_REDUCED, excel.getEmpIdcard()));
}
// 检查添加人员是否已经存在
boolean match = list.stream().anyMatch(info -> excel.getWorkDepart().equals(info.getWorkDepart())
&& excel.getWorkUnit().equals(info.getWorkUnit())
&& excel.getWorkJob().equals(info.getWorkJob())
&& excel.getEmpIdcard().equals(info.getEmpIdcard()));
if (match) {
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_EMP_FAMILY_NAME_EXISTING, excel.getEmpName()));
}
exist = baseMapper.selectOne(Wrappers.<TEmpWorkRecording>query().lambda()
.eq(TEmpWorkRecording::getEmpIdcard,excel.getEmpIdcard())
.eq(TEmpWorkRecording::getWorkUnit,excel.getWorkUnit())
.eq(TEmpWorkRecording::getWorkJob,excel.getWorkJob())
.eq(TEmpWorkRecording::getWorkDepart,excel.getWorkDepart())
.eq(TEmpWorkRecording::getDeleteFlag,CommonConstants.ZERO_STRING)
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isNotNull(exist)){
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_EMP_WORK_RECORD_EXISTING, excel.getEmpName()));
}
// 数据合法情况
if (CollUtil.isEmpty(errorMsg)) {
insertExcelPost(excel,emp);
} else {
// 数据不合法
errorMessageList.add(new ErrorMessage((long) (i + 2), errorMsg));
}
}
if (CollUtil.isNotEmpty(errorMessageList)) {
return R.failed(errorMessageList);
}
return R.ok();
}
/**
* 插入excel work record
*/
private void insertExcelPost(EmpWorkRecordExcelVO excel,TEmployeeInfo emp) {
TEmpWorkRecording insert = new TEmpWorkRecording();
BeanUtil.copyProperties(excel, insert);
insert.setDeleteFlag(CommonConstants.ZERO_STRING);
insert.setEmpCode(emp.getEmpCode());
insert.setEmpId(emp.getId());
insert.setEmpCode(emp.getEmpCode());
this.save(insert);
}
}
......@@ -180,4 +180,8 @@ public interface ErrorCodes {
* 员工已减档
*/
String ARCHIVES_EMP_REDUCED = "archives.emp.reduced";
/**
* 已存在对应身份证的工作记录信息
*/
String ARCHIVES_EMP_WORK_RECORD_EXISTING = "archives.emp.work.record.existing";
}
......@@ -45,6 +45,8 @@ archives.emp.family.name.existing=\u5DF2\u5B58\u5728\u5BF9\u5E94\u8EAB\u4EFD\u8B
archives.emp.not.exist=\u65E0\u5BF9\u5E94\u8EAB\u4EFD\u8BC1\u7684\u5458\u5DE5\u4FE1\u606F
archives.emp.reduced=\u5458\u5DE5\u5DF2\u51CF\u6863
archives.emp.work.record.existing=\u5DF2\u5B58\u5728\u5BF9\u5E94\u8EAB\u4EFD\u8BC1\u7684\u5DE5\u4F5C\u8BB0\u5F55\u4FE1\u606F
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment