Commit 8b21e6ba authored by huyuchen's avatar huyuchen

项目余额调整快捷功能

parent f1751fde
package com.yifu.cloud.plus.v1.ekp.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 款项认领差额费导入
*
* @author huyc
* @date 2024-07-04 14:54:40
*/
@Data
@ColumnWidth(30)
public class ClaimInfotVO extends RowIndex implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 项目编码
*/
@NotNull(message = "项目编码不能为空")
@ExcelAttribute(name = "项目编码",isNotEmpty = true, errorInfo = "项目编码不能为空")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="项目编码")
private String deptNo;
/**
* 项目名称
*/
@ExcelAttribute(name = "项目名称")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="项目名称")
private String deptName;
/**
* 调整金额
*/
@NotNull(message = "调整金额不能为空")
@ExcelAttribute(name = "调整金额",isNotEmpty = true, errorInfo = "调整金额不能为空", isFloat = true,max = "999999999.99")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="调整金额")
private BigDecimal money;
}
package com.yifu.cloud.plus.v1.ekp.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 款项认领差额费导入
*
* @author huyc
* @date 2024-07-04 14:54:40
*/
@Data
@ColumnWidth(30)
public class ClaimRebackInfotVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 款项认领明细单号
*/
@ExcelAttribute(name = "款项认领明细单号")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="款项认领明细单号")
private String claimNo;
@ExcelAttribute(name = "项目编码")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="项目编码")
private String deptNo;
/**
* 项目名称
*/
@ExcelAttribute(name = "项目名称")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="项目名称")
private String deptName;
/**
* 认领金额
*/
@ExcelAttribute(name = "认领金额")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="认领金额")
private BigDecimal claimMoney;
/**
* 核销金额
*/
@ExcelAttribute(name = "核销金额")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="核销金额")
private BigDecimal cancelMoney;
/**
* 剩余金额
*/
@NotNull(message = "剩余金额")
@ExcelAttribute(name = "剩余金额")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="剩余金额")
private BigDecimal surMoney;
/**
* 调整金额
*/
@NotNull(message = "调整金额")
@ExcelAttribute(name = "调整金额")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="调整金额")
private BigDecimal adjustMoney;
/**
* 剩余金额调整为
*/
@NotNull(message = "剩余金额调整为")
@ExcelAttribute(name = "剩余金额调整为")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="剩余金额调整为")
private BigDecimal afterAdjustMoney;
/**
* 入账日期
*/
@NotNull(message = "入账日期")
@ExcelAttribute(name = "入账日期")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="入账日期")
private Date claimTime;
/**
* 异常说明
*/
@NotNull(message = "异常说明")
@ExcelAttribute(name = "异常说明")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty(value ="异常说明")
private String errorInfo;
}
package com.yifu.cloud.plus.v1.ekp.controller;
import com.yifu.cloud.plus.v1.ekp.service.EkpSalaryInfoService;
import com.yifu.cloud.plus.v1.ekp.vo.EkpSocialPushInfoVo;
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.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpSalaryParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
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.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -39,4 +48,22 @@ public class TEkpSalaryInfoController {
public Boolean pushSalaryInfoToEkp(@RequestBody List<EkpSalaryParam> unPushList) {
return salaryInfoService.pushSalaryInfoToEkp(unPushList);
}
/**
* 差额费导入
*
* @author huyc
* @date 2024-7-4
**/
@SneakyThrows
@Operation(description = "差额费导入")
@SysLog("差额费导入")
@PostMapping("/importClaimInfo")
public R<List<ErrorMessage>> importClaimInfo(@RequestBody MultipartFile file) {
YifuUser user = SecurityUtils.getUser();
if (Common.isEmpty(user)){
return R.failed(CommonConstants.USER_FAIL);
}
return salaryInfoService.importClaimInfo(file.getInputStream());
}
}
......@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.ekp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.ekp.entity.EkpSalaryInfo;
import com.yifu.cloud.plus.v1.ekp.vo.ClaimRebackInfotVO;
import com.yifu.cloud.plus.v1.ekp.vo.EkpDeptInfoVo;
import com.yifu.cloud.plus.v1.ekp.vo.EkpSocialSumInfoVo;
import org.apache.ibatis.annotations.Mapper;
......@@ -31,4 +32,19 @@ public interface EkpSalaryInfoMapper extends BaseMapper<EkpSalaryInfo> {
* @return
*/
EkpSocialSumInfoVo getCostSumInfo(@Param("card") String empIdCard, @Param("month") String createMonth);
/**
* 根据项目编码查询款项认领明细
* @param
* @return
*/
ClaimRebackInfotVO getClaimInfoByDeptNo(@Param("deptNo") String deptNo,@Param("flag") String flag);
/**
* 根据项目编码查询款项认领明细
* @param
* @return
*/
List<ClaimRebackInfotVO> getClaimBigInfoByDeptNoAndUser(@Param("deptNo") String deptNo);
}
......@@ -2,9 +2,12 @@ package com.yifu.cloud.plus.v1.ekp.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.ekp.entity.EkpSalaryInfo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpSalaryParam;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.util.List;
/**
......@@ -18,4 +21,6 @@ public interface EkpSalaryInfoService extends IService<EkpSalaryInfo> {
@Transactional
// @ShardingTransactionType(TransactionType.BASE)
Boolean pushSalaryInfoToEkp(List<EkpSalaryParam> unPushList);
R<List<ErrorMessage>> importClaimInfo(InputStream inputStream);
}
package com.yifu.cloud.plus.v1.ekp.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.ListUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.ekp.entity.EkpSalaryInfo;
import com.yifu.cloud.plus.v1.ekp.mapper.EkpSalaryInfoMapper;
import com.yifu.cloud.plus.v1.ekp.service.EkpSalaryInfoService;
import com.yifu.cloud.plus.v1.ekp.vo.ClaimInfotVO;
import com.yifu.cloud.plus.v1.ekp.vo.ClaimRebackInfotVO;
import com.yifu.cloud.plus.v1.ekp.vo.EkpDeptInfoVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.BigDecimalUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.LocalDateTimeUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpSalaryParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
......@@ -248,6 +254,128 @@ public class EkpSalaryInfoServiceImpl extends ServiceImpl<EkpSalaryInfoMapper, E
+ "_" + salaryInfo.getFd_3b10afe8c70742());
}
@Override
public R<List<ErrorMessage>> importClaimInfo(InputStream inputStream) {
List<ErrorMessage> errorMessageList = new ArrayList<>();
ExcelUtil<ClaimInfotVO> util1 = new ExcelUtil<>(ClaimInfotVO.class);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try {
EasyExcel.read(inputStream, ClaimInfotVO.class, new ReadListener<ClaimInfotVO>() {
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT1;
/**
*临时存储
*/
private List<ClaimInfotVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(ClaimInfotVO 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());
importListAdd(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);
}
/**
* 差额费导入
* @param excelVOList
* @param errorMessageList
* @author huyc
* @date 2024-07-04 14:52:16
*/
@Transactional
public void importListAdd(List<ClaimInfotVO> excelVOList, List<ErrorMessage> errorMessageList) {
ClaimInfotVO excel;
String deptNo;
String deptName;
BigDecimal money;
ClaimRebackInfotVO info;
// 执行数据插入操作 组装 PostDto
for (int i = 0; i < excelVOList.size(); i++) {
excel = excelVOList.get(i);
deptNo = excel.getDeptNo();
money = excel.getMoney();
deptName = excel.getDeptName();
ClaimRebackInfotVO backInfo = new ClaimRebackInfotVO();
//先找到彭超创建的款项认领明细
info = baseMapper.getClaimInfoByDeptNo(deptNo,"1");
//
if (money.compareTo(BigDecimal.ZERO) > 0) {
//调整金额大于零的先找到彭超创建的款项认领明细直接加
if (Optional.ofNullable(info).isPresent()) {
info.setAdjustMoney(money);
info.setAfterAdjustMoney(BigDecimalUtils.safeAdd(info.getSurMoney(),money));
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), info.getErrorInfo(),info));
} else {
//找到除了彭超之外的最早的一条款项认领明细
info = baseMapper.getClaimInfoByDeptNo(deptNo,"2");
if (Optional.ofNullable(info).isPresent()) {
info.setAdjustMoney(money);
info.setAfterAdjustMoney(BigDecimalUtils.safeAdd(info.getSurMoney(),money));
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), info.getErrorInfo(),info));
} else {
backInfo.setDeptName(deptName);
backInfo.setDeptNo(deptNo);
backInfo.setAdjustMoney(money);
backInfo.setErrorInfo("未找到该项目对应的款项认领明细");
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), backInfo.getErrorInfo(),backInfo));
}
}
} else {
//调整金额小于零的先找到剩余金额大于零的彭超创建的款项认领明细去扣减
info = baseMapper.getClaimInfoByDeptNo(deptNo,"3");
if (Optional.ofNullable(info).isPresent()) {
if (BigDecimalUtils.safeAdd(info.getSurMoney(),money).compareTo(BigDecimal.ZERO) >=0) {
info.setAdjustMoney(money);
info.setAfterAdjustMoney(BigDecimalUtils.safeAdd(info.getSurMoney(),money));
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), info.getErrorInfo(),info));
} else {
this.subSwitch(deptNo,backInfo,errorMessageList,money,deptName,excel);
}
} else {
this.subSwitch(deptNo,backInfo,errorMessageList,money,deptName,excel);
}
}
}
}
/**
* @Description: 推送ekp时更改日期格式
* @Author: huyc
......@@ -258,4 +386,31 @@ public class EkpSalaryInfoServiceImpl extends ServiceImpl<EkpSalaryInfoMapper, E
return sb.toString();
}
public void subSwitch(String deptNo,ClaimRebackInfotVO backInfo,List<ErrorMessage>errorMessageList,
BigDecimal money,String deptName,ClaimInfotVO excel) {
List<ClaimRebackInfotVO> infoList = baseMapper.getClaimBigInfoByDeptNoAndUser(deptNo);
if (Optional.ofNullable(infoList).isPresent()) {
for (ClaimRebackInfotVO subInfo : infoList) {
//分批去减去金额
if (BigDecimalUtils.safeAdd(subInfo.getSurMoney(),money).compareTo(BigDecimal.ZERO) >=0) {
subInfo.setAdjustMoney(money);
subInfo.setAfterAdjustMoney(BigDecimalUtils.safeSubtract(subInfo.getSurMoney(),money));
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), subInfo.getErrorInfo(),subInfo));
break;
} else {
subInfo.setAdjustMoney(subInfo.getSurMoney());
subInfo.setAfterAdjustMoney(BigDecimal.ZERO);
money = BigDecimalUtils.safeAdd(subInfo.getSurMoney(),money);
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), subInfo.getErrorInfo(),subInfo));
}
}
}
if (BigDecimal.ZERO.compareTo(money) > 0 ) {
backInfo.setDeptNo(deptNo);
backInfo.setDeptName(deptName);
backInfo.setAdjustMoney(money);
backInfo.setErrorInfo("项目编码及剩余仍需扣除金额:" + money.toString());
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), backInfo.getErrorInfo(),backInfo));
}
}
}
......@@ -150,4 +150,48 @@
where fd_3adfe8c7e4cf7a = #{card} and fd_3adfe8cb96c41e = #{month}
</select>
<!--根据项目编码和申请人查询款项认领明细-->
<select id="getClaimInfoByDeptNo" resultType="com.yifu.cloud.plus.v1.ekp.vo.ClaimRebackInfotVO">
select
fd_3afb4689209aa2 deptNo,
fd_3afb468b23b0e2 deptName,
fd_3afb4c634ebd08 claimNo,
fd_3afb46ab98d9a8 claimMoney,
fd_3afb46ac507904 cancelMoney,
fd_3afb46d05d19ec surMoney,
DATE_FORMAT(fd_3b5f41db9fb154,'%Y-%m-%d') claimTime
from
ekp_94b6cd1535e4b34865c8
where
fd_3afb4689209aa2 = #{deptNo}
<if test="flag != null and flag == 3">
and fd_3afb46d05d19ec > 0
</if>
<if test="flag != null and (flag == 1 or flag == 3)">
and fd_3b2a70e26f520a = '1817fbe83899f5f34c1ee9b463bbf9c1'
</if>
order by fd_3b5f41db9fb154 asc
<if test="flag != null">
limit 1
</if>
</select>
<!--根据项目编码和申请人查询款项认领明细-->
<select id="getClaimBigInfoByDeptNoAndUser" resultType="com.yifu.cloud.plus.v1.ekp.vo.ClaimRebackInfotVO">
select
fd_3afb4689209aa2 deptNo,
fd_3afb468b23b0e2 deptName,
fd_3afb4c634ebd08 claimNo,
fd_3afb46ab98d9a8 claimMoney,
fd_3afb46ac507904 cancelMoney,
fd_3afb46d05d19ec surMoney,
DATE_FORMAT(fd_3b5f41db9fb154,'%Y-%m-%d') claimTime
from
ekp_94b6cd1535e4b34865c8
where
fd_3afb4689209aa2 = #{deptNo}
and fd_3afb46d05d19ec > 0
order by fd_3b5f41db9fb154 asc
</select>
</mapper>
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