Merge branch 'feature/SpecialAddUpMerge' into release/2.1.3.2211.03

This commit is contained in:
fcli 2022-11-10 09:33:22 +08:00
commit 459f7e5053
8 changed files with 198 additions and 24 deletions

View File

@ -0,0 +1,17 @@
package com.engine.salary.entity.datacollection.param;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @description 数据采集-专项附加扣除一键累计参数
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AddDeductionAutoAddParam {
String yearMonth = "";
}

View File

@ -1,4 +1,5 @@
package com.engine.salary.mapper.datacollection;
import java.util.Date;
import com.engine.salary.entity.datacollection.AddUpDeduction;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
@ -61,6 +62,8 @@ public interface AddUpDeductionMapper {
*/
void updateData(@Param("collection") List<AddUpDeduction> updateList);
void updateDataAndDeclareMonth(@Param("collection") List<AddUpDeduction> updateList);
List<AddUpDeductionRecordDTO> recordList(@Param("param") AddUpDeductionQueryParam param);
@ -71,4 +74,8 @@ public interface AddUpDeductionMapper {
* @date 2022/10/27 9:54
*/
void deleteData(@Param("collection")List<Long> longs);
int countByDeclareAfter(@Param("minDeclareMonth") Date minDeclareMonth,
@Param("maxDeclareMonth") Date maxDeclareMonth,
@Param("taxAgentIds") List<Long> taxAgentIds);
}

View File

@ -1,6 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.engine.salary.mapper.datacollection.AddUpDeductionMapper">
<sql id="Base_Column_List">
add_up_child_education,
add_up_continuing_education,
add_up_housing_loan_interest,
add_up_housing_rent,
add_up_support_elderly,
create_time,
creator,
declare_month,
delete_type,
employee_id,
id,
tax_agent_id,
tenant_key,
update_time,
add_up_illness_medical,
add_up_infant_care
</sql>
<resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.AddUpDeduction">
<result column="add_up_child_education" property="addUpChildEducation"/>
<result column="add_up_continuing_education" property="addUpContinuingEducation"/>
@ -553,6 +571,73 @@
</foreach>
</update>
<update id="updateDataAndDeclareMonth" parameterType="java.util.List">
update hrsa_add_up_deduction
<trim prefix="set" suffixOverrides=",">
<trim prefix="add_up_child_education =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpChildEducation!=null">
when id=#{item.id} then #{item.addUpChildEducation}
</if>
</foreach>
</trim>
<trim prefix="add_up_continuing_education =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpContinuingEducation!=null">
when id=#{item.id} then #{item.addUpContinuingEducation}
</if>
</foreach>
</trim>
<trim prefix="add_up_housing_loan_interest =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpHousingLoanInterest!=null">
when id=#{item.id} then #{item.addUpHousingLoanInterest}
</if>
</foreach>
</trim>
<trim prefix="add_up_housing_rent =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpHousingRent!=null">
when id=#{item.id} then #{item.addUpHousingRent}
</if>
</foreach>
</trim>
<trim prefix="add_up_support_elderly =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpSupportElderly!=null">
when id=#{item.id} then #{item.addUpSupportElderly}
</if>
</foreach>
</trim>
<trim prefix="add_up_illness_medical =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpIllnessMedical!=null">
when id=#{item.id} then #{item.addUpIllnessMedical}
</if>
</foreach>
</trim>
<trim prefix="add_up_infant_care =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.addUpInfantCare!=null">
when id=#{item.id} then #{item.addUpInfantCare}
</if>
</foreach>
</trim>
<trim prefix="declare_month =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.declareMonth!=null">
when id=#{item.id} then #{item.declareMonth}
</if>
</foreach>
</trim>
</trim>
where
id in
<foreach collection="collection" item="item" index="index" separator="," open="(" close=")">
#{item.id}
</foreach>
</update>
<select id="recordList" resultType="com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO">
SELECT
<include refid="addUpDeductionColumn"/>
@ -569,5 +654,23 @@
ORDER BY t1.declare_month DESC
</select>
<select id="countByDeclareAfter" resultType="java.lang.Integer">
select
count(*)
from hrsa_add_up_deduction t1
LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
LEFT JOIN hrmresource e ON e.id = t1.employee_id
LEFT JOIN hrmdepartment d ON d.id = e.departmentid
WHERE
t1.delete_type = 0 AND t2.delete_type = 0
AND e.status not in (7)
and (e.accounttype is null or e.accounttype = 0)
<if test="taxAgentIds != null and taxAgentIds.size() != 0">
and tax_agent_id in
<foreach collection="taxAgentIds" item="taxAgentId" open="(" separator="," close=")">
#{taxAgentId}
</foreach>
</if>
and declare_month <![CDATA[>]]> #{minDeclareMonth} and declare_month <![CDATA[<]]> #{maxDeclareMonth}
</select>
</mapper>

View File

@ -154,5 +154,5 @@ public interface AddUpDeductionService {
* @return void
* @author lfc
*/
void autoAddAll(Date operateTime);
String autoAddAll(Date yearMonth);
}

View File

@ -8,6 +8,7 @@ import com.engine.salary.util.page.PageInfo;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.time.YearMonth;
import java.util.Date;
import java.util.List;
import java.util.Map;

View File

@ -63,9 +63,7 @@ import weaver.hrm.User;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.*;
import java.util.*;
import java.util.stream.Collectors;
@ -641,7 +639,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
}
@Override
public void autoAddAll(Date operateTime) {
public String autoAddAll(Date yearMonth) {
int uid = user.getUID();
Boolean isChief = getTaxAgentService(user).isChief((long) uid);
Collection<TaxAgentPO> taxAgents;
@ -650,26 +648,51 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
} else {
taxAgents = getTaxAgentService(user).listAllTaxAgentsAsAdmin((long) uid);
}
LocalDateTime yearMonthTime = DateUtil.toLocalDateTime(yearMonth);
//设置时间到下一年1月1号
Instant instant = yearMonthTime.plusYears(1L)
.withMonth(1).withDayOfMonth(1)
.atZone(ZoneOffset.systemDefault()).toInstant();
Date nextYearStart = Date.from(instant);
int countByDeclareAfter = getAddUpDeductionMapper()
.countByDeclareAfter(yearMonth, nextYearStart,
taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList())
);
if (countByDeclareAfter > 0) {
throw new SalaryRunTimeException("无法累计,请检查当前累计年度内该月后是否有累计专项附加扣除记录!");
}
List<AddUpDeduction> updateList = new ArrayList<>();
List<AddUpDeduction> insertList = new ArrayList<>();
List<Long> errorMessages = new ArrayList<>();
List<SalaryAcctEmployeePO> accountedEmployeeData =
getAccountedEmployeeData(DateUtil.format(yearMonth, "yyyy-MM"));
for (TaxAgentPO taxAgent : taxAgents) {
Collection<Long> employeeIds = getTaxAgentService(user)
.listEmployeeIdsInTaxAgent(taxAgent.getId());
List<SpecialAddDeductionPO> employeePOs = getSpecialAddDeductionService(user)
.getSpecialAddDeductionPOByEmployee(null, taxAgent.getId());
//获取上月员工数据用于累加
LocalDateTime lastMonthDateTime = LocalDateTime.now().minusMonths(1);
LocalDateTime lastMonthDateTime = yearMonthTime.minusMonths(1);
YearMonth lastMonth = YearMonth.of(lastMonthDateTime.getYear(), lastMonthDateTime.getMonth());
Map<Long, List<AddUpDeduction>> lastEmpInfo = getEmpInfoByYearMonth(taxAgent, employeePOs, lastMonth);
//获取当月员工数据用于更新
LocalDateTime currentMonthDateTime = LocalDateTime.now();
YearMonth currentMonth = YearMonth.of(currentMonthDateTime.getYear(), currentMonthDateTime.getMonth());
YearMonth currentMonth = YearMonth.of(yearMonthTime.getYear(), yearMonthTime.getMonth());
Map<Long, List<AddUpDeduction>> currentEmpInfo = getEmpInfoByYearMonth(taxAgent, employeePOs, currentMonth);
employeePOs.forEach(employeePO -> {
Long employeeId = employeePO.getEmployeeId();
// 如果该员工当前月份已经核算不做累计
SalaryAcctEmployeePO anyAccountedEmployee = accountedEmployeeData.stream()
.filter(e -> e.getEmployeeId().equals(employeeId))
.filter(e -> e.getTaxAgentId().equals(taxAgent.getId()))
.findAny().orElse(null);
if (anyAccountedEmployee != null) {
errorMessages.add(employeeId);
return;
}
AddUpDeduction addUpDeduction = Optional.ofNullable(lastEmpInfo.get(employeeId))
.flatMap(list -> list.stream().findFirst())
.orElseGet(AddUpDeduction::new);
@ -677,7 +700,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
addUpDeduction.setEmployeeId(employeeId);
addUpDeduction.setTaxAgentId(taxAgent.getId());
addUpDeduction.setDeclareMonth(DateUtil.beginOfMonth(operateTime));
addUpDeduction.setDeclareMonth(DateUtil.beginOfMonth(yearMonth));
addUpDeduction.setCreator((long) user.getUID());
addUpDeduction.setTenantKey(DEFAULT_TENANT_KEY);
@ -686,13 +709,13 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
.flatMap(c -> c.stream().findFirst())
.orElse(null);
if (oldInfo == null) {
addUpDeduction.setCreateTime(operateTime);
addUpDeduction.setUpdateTime(operateTime);
addUpDeduction.setCreateTime(yearMonth);
addUpDeduction.setUpdateTime(yearMonth);
insertList.add(AddUpDeductionEncrypt.encryptAddUpDeduction(addUpDeduction));
} else {
addUpDeduction.setId(oldInfo.getId());
addUpDeduction.setCreateTime(oldInfo.getCreateTime());
addUpDeduction.setUpdateTime(operateTime);
addUpDeduction.setUpdateTime(yearMonth);
updateList.add(AddUpDeductionEncrypt.encryptAddUpDeduction(addUpDeduction));
}
});
@ -700,7 +723,16 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
Lists.partition(insertList, 100)
.forEach(l -> getAddUpDeductionMapper().insertData((List<AddUpDeduction>) l));
Lists.partition(updateList, 100)
.forEach(l -> getAddUpDeductionMapper().updateData((List<AddUpDeduction>) l));
.forEach(l -> getAddUpDeductionMapper().updateDataAndDeclareMonth((List<AddUpDeduction>) l));
if (!errorMessages.isEmpty()) {
String userNames = getSalaryEmployeeService(user)
.listByIds(errorMessages)
.stream()
.map(DataCollectionEmployee::getUsername)
.collect(Collectors.joining(","));
return "一键累计完成!员工" + userNames + "在该年月已核算归档,跳过本次累计";
}
return "一键累计完成!";
}
/**

View File

@ -1,13 +1,13 @@
package com.engine.salary.web;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO;
import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpDeductionImportParam;
import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam;
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordParam;
import com.engine.salary.entity.datacollection.param.*;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.AddUpDeductionWrapper;
@ -347,8 +347,20 @@ public class AddUpDeductionController {
@POST
@Path("/autoAddAll")
@Produces(MediaType.APPLICATION_JSON)
public String autoAddAll(@Context HttpServletRequest request, @Context HttpServletResponse response) {
public String autoAddAll(@Context HttpServletRequest request, @Context HttpServletResponse response,
@RequestBody AddDeductionAutoAddParam param) {
DateTime date = null;
if (StrUtil.isNotEmpty(param.getYearMonth())) {
try {
date = DateUtil.parse(param.getYearMonth(), "yyyy-MM");
} catch (Exception e) {
//ignore
// 放在service中处理这里处理了页面上收不到
}
} else {
date = DateUtil.beginOfMonth(new Date());
}
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<User, Void>(user).run(getAddUpDeductionWrapper(user)::autoAddAll, user);
return new ResponseResult<Date, String>(user).run(getAddUpDeductionWrapper(user)::autoAddAll, date);
}
}

View File

@ -25,7 +25,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.general.BaseBean;
import weaver.hrm.User;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -171,10 +170,13 @@ public class AddUpDeductionWrapper extends Service {
return getAddUpDeductionService(user).getAddUpDeduction(param);
}
public void autoAddAll(User opt) {
public String autoAddAll(Date yearMonth) {
if (isLog) {
log.info("一键累计, 操作人 「{}」", opt.getUsername());
log.info("一键累计, 操作人 「{}」", user.getUsername());
}
getAddUpDeductionService(user).autoAddAll(new Date());
if (yearMonth == null) {
throw new SalaryRunTimeException("一键累计传入日期格式错误");
}
return getAddUpDeductionService(user).autoAddAll(yearMonth);
}
}