Commit 30ba8d1f authored by hongguangwu's avatar hongguangwu

合同-批量更新

parent 1753507b
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttributeConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDate;
/**
* 员工合同-批量更新的VO
*
* @author hgw
* @date 2022-7-1 17:40:40
*/
@Data
@Schema(description = "员工合同-批量更新的VO")
public class EmployeeContractUpdateVO extends RowIndex implements Serializable {
/**
* 合同申请编码
*/
@Length(max = 50, message = "合同申请编码不能超过50个字符")
@ExcelAttribute(name = "合同申请编码", isNotEmpty = true, maxLength = 50, needExport = true)
@Schema(description = "合同申请编码", name = "applyNo")
private String applyNo;
/**
* 员工姓名
*/
@Length(max = 20, message = "员工姓名不能超过20个字符")
@ExcelAttribute(name = "员工姓名", isNotEmpty = true, maxLength = 20, needExport = true)
@Schema(description = "员工姓名", name = "empName")
private String empName;
/**
* 合同编号
*/
@NotBlank(message = "合同编号不能为空")
@Length(max = 50, message = "合同编号不能超过50个字符")
@ExcelAttribute(name = "合同编号", maxLength = 50)
@Schema(description = "合同编号", name = "contractNo")
private String contractNo;
/**
* 档案柜号
*/
@Length(max = 50, message = "档案柜号不能超过50个字符")
@ExcelAttribute(name = "档案柜号", maxLength = 50)
@Schema(description = "档案柜号", name = "fileCabinetNo")
private String fileCabinetNo;
}
......@@ -51,7 +51,7 @@ import java.util.List;
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/getListByParam")
@RequestMapping("/temployeecontractinfo")
@Tag(name = "员工合同管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class TEmployeeContractInfoController {
......@@ -112,7 +112,7 @@ public class TEmployeeContractInfoController {
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeContractInfo>>
**/
@Operation(summary = "根据参数返回list", description = "根据参数返回list")
@GetMapping("/getListByParam")
@PostMapping("/getListByParam")
public R<List<TEmployeeContractInfo>> getListByParam(TEmployeeContractInfo tEmployeeContractInfo) {
return new R<>(tEmployeeContractInfoService.getTEmployeeContractList(tEmployeeContractInfo));
}
......@@ -235,4 +235,20 @@ public class TEmployeeContractInfoController {
return tEmployeeContractInfoService.batchImport(file.getInputStream());
}
/**
* 批量更新-合同
* @param file
* @return
* @Author hgw
* @Date 2022-7-1 18:45:22
**/
@SneakyThrows
@Operation(description = "批量更新-合同 hasPermission('temployeecontractinfo_batch_update')")
@SysLog("批量更新-合同")
@PostMapping("/batchUpdate")
@PreAuthorize("@pms.hasPermission('temployeecontractinfo_batch_update')")
public R<List<ErrorMessage>> batchUpdate(@RequestBody MultipartFile file) {
return tEmployeeContractInfoService.batchUpdate(file.getInputStream());
}
}
......@@ -46,6 +46,8 @@ public interface TEmployeeContractInfoMapper extends BaseMapper<TEmployeeContrac
List<TEmployeeContractInfo> getTEmployeeContractList(@Param("tEmployeeContractInfo") TEmployeeContractInfo tEmployeeContractInfo);
TEmployeeContractInfo getOneContractByApplyNo(@Param("applyNo") String applyNo);
/**
* 更新项目内的其他的合同在用状态
* @Author fxj
......
......@@ -104,6 +104,24 @@ public interface TEmployeeContractInfoService extends IService<TEmployeeContract
**/
R<String> filingContract(TEmployeeContractInfo tEmployeeContractInfo);
/**
* @param inputStream
* @Description: 批量导入
* @Author: hgw
* @Date: 2022/7/4 17:16
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
**/
R<List<ErrorMessage>> batchImport(InputStream inputStream);
/**
* @param inputStream
* @Description: 批量更新
* @Author: hgw
* @Date: 2022/7/4 17:16
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
**/
R<List<ErrorMessage>> batchUpdate(InputStream inputStream);
}
......@@ -30,6 +30,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.Constants.EmployeeContractConstants;
import com.yifu.cloud.plus.v1.yifu.archives.entity.*;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TEmployeeContractInfoMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.*;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeContractUpdateVO;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeContractVO;
import com.yifu.cloud.plus.v1.yifu.archives.vo.ErrorVO;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
......@@ -51,7 +52,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 员工合同
......@@ -458,6 +461,100 @@ public class TEmployeeContractInfoServiceImpl extends ServiceImpl<TEmployeeContr
return R.failed("参数不可为空");
}
@Override
public R<List<ErrorMessage>> batchUpdate(InputStream inputStream) {
List<ErrorMessage> errorMessageList = new ArrayList<>();
ExcelUtil<EmployeeContractUpdateVO> util1 = new ExcelUtil<>(EmployeeContractUpdateVO.class);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try {
EasyExcel.read(inputStream, EmployeeContractUpdateVO.class, new ReadListener<EmployeeContractUpdateVO>() {
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
/**
*临时存储
*/
private List<EmployeeContractUpdateVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(EmployeeContractUpdateVO data, AnalysisContext context) {
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex + 1);
ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
if (Common.isNotNull(errorMessage)) {
errorMessageList.add(errorMessage);
} else {
cachedDataList.add(data);
}
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
saveData();
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
updateContract(cachedDataList, errorMessageList);
log.info("存储数据库成功!");
}
}).sheet().doRead();
} catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
}
return R.ok(errorMessageList);
}
/**
* @Author hgw
* @Description 批量导入
* @Date 2022-7-1 18:48:01
**/
@Transactional
public void updateContract(List<EmployeeContractUpdateVO> excelVOList, List<ErrorMessage> errorMessageList) {
/// 个性化校验逻辑
EmployeeContractUpdateVO excel;
TEmployeeContractInfo contractInfo;
// 执行数据插入操作 组装
for (int i = 0; i < excelVOList.size(); i++) {
excel = excelVOList.get(i);
if (excel != null) {
if (Common.isNotNull(excel.getContractNo()) || Common.isNotNull(excel.getFileCabinetNo())) {
if (Common.isNotNull(excel.getApplyNo())) {
// 存储
contractInfo = baseMapper.getOneContractByApplyNo(excel.getApplyNo());
if (contractInfo != null && Common.isNotNull(contractInfo.getId())) {
contractInfo.setContractNo(excel.getContractNo());
contractInfo.setFileCabinetNo(excel.getFileCabinetNo());
this.updateById(contractInfo);
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), CommonConstants.SAVE_SUCCESS));
} else {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), EmployeeContractConstants.NO_INFO));
}
}
} else {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), EmployeeContractConstants.NO_INFO));
}
} else {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), EmployeeContractConstants.NO_INFO));
}
}
}
@Override
public R<List<ErrorMessage>> batchImport(InputStream inputStream) {
List<ErrorMessage> errorMessageList = new ArrayList<>();
......
......@@ -330,6 +330,15 @@
</where>
</select>
<!--tEmployeeContractInfo简单分页查询-->
<select id="getOneContractByApplyNo" resultMap="tEmployeeContrctInfoMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_employee_contract_info a
where a.DELETE_FLAG = 0 and a.APPLY_NO = #{applyNo}
limit 1
</select>
<!-- 根据员工ID更新合同在用状态 -->
<update id="updateInUseStatusById">
update t_employee_contract_info
......
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