feat: 专项附加扣除模块

This commit is contained in:
fcli 2022-11-02 17:27:07 +08:00
parent 5e69d07b7c
commit 171f726bd3
3 changed files with 1477 additions and 315 deletions

View File

@ -1,12 +1,9 @@
package com.engine.salary.biz;
import com.engine.salary.encrypt.datacollection.OtherDeductionPOEncrypt;
import com.engine.salary.encrypt.datacollection.OtherDeductionRecordDTOEncrypt;
import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
import com.engine.salary.encrypt.datacollection.SpecialAddDeductionEncrypt;
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.SpecialAddDeductionQueryParam;
import com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO;
import com.engine.salary.mapper.datacollection.OtherDeductionMapper;
import com.engine.salary.mapper.datacollection.SpecialAddDeductionMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
@ -18,58 +15,53 @@ import java.util.*;
import java.util.stream.Collectors;
public class SpecialAddDeductionBiz extends BaseBean {
/**
* 条件查询
*
* @param param
* @return
*/
public List<OtherDeductionPO> listSome(SpecialAddDeductionPO param) {
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
List<SpecialAddDeductionPO> list = mapper.insertSelective(param);
return OtherDeductionPOEncrypt.decryptOtherDeductionPOList(otherDeductionPOS);
} finally {
sqlSession.close();
}
}
/**
* 根据id获取
*
* @param id
* @return
*/
public OtherDeductionPO getById(Long id) {
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
OtherDeductionPO byId = mapper.getById(id);
return OtherDeductionPOEncrypt.decryptOtherDeductionPO(byId);
} finally {
sqlSession.close();
public SpecialAddDeductionPO getById(Long id) {
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
SpecialAddDeductionPO byId = mapper.getById(id);
return SpecialAddDeductionEncrypt.decrypt(byId);
}
}
public List<SpecialAddDeductionRecordDTO> listDTOByParam(SpecialAddDeductionQueryParam param) {
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
List<SpecialAddDeductionRecordDTO> specialAddDeductionRecordDTOS = mapper.listDtoByParam(param);
return SpecialAddDeductionEncrypt.decrypt(specialAddDeductionRecordDTOS);
}
}
public List<SpecialAddDeductionPO> listByDeclareMonthAndTaxAgentIds(Date declareMonth, List<Long> taxAgentIds) {
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
List<SpecialAddDeductionPO> pos = mapper.listByDeclareMonthAndTaxAgentIds(declareMonth, taxAgentIds);
return SpecialAddDeductionEncrypt.decrypt(pos);
}
}
/**
* 详情列表
* 批量插入
*
* @param param
* @return
*/
public List<OtherDeductionRecordDTO> recordList(OtherDeductionQueryParam param) {
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
List<OtherDeductionRecordDTO> otherDeductionRecordDTOS = mapper.recordList(param);
return OtherDeductionRecordDTOEncrypt.decryptOtherDeductionRecordDTOList(otherDeductionRecordDTOS);
} finally {
sqlSession.close();
public void batchSave(List<SpecialAddDeductionPO> param) {
if (CollectionUtils.isEmpty(param)) {
return;
}
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
SpecialAddDeductionEncrypt.encrypt(param);
List<List<SpecialAddDeductionPO>> partition = Lists.partition(param, 100);
partition.forEach(mapper::batchInsert);
sqlSession.commit();
}
}
@ -79,84 +71,55 @@ public class SpecialAddDeductionBiz extends BaseBean {
* @param param
* @return
*/
public void batchSave(List<OtherDeductionPO> param) {
if(CollectionUtils.isEmpty(param)){
public void batchUpdate(List<SpecialAddDeductionPO> param) {
if (CollectionUtils.isEmpty(param)) {
return;
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
OtherDeductionPOEncrypt.encryptOtherDeductionPOList(param);
List<List<OtherDeductionPO>> partition = Lists.partition(param, 100);
partition.forEach(mapper::insertData);
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
SpecialAddDeductionEncrypt.encrypt(param);
List<List<SpecialAddDeductionPO>> partition = Lists.partition(param, 100);
partition.forEach(mapper::updateBatchSelective);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
/**
* 批量插入
*
* @param param
* @return
*/
public void batchUpdate(List<OtherDeductionPO> param) {
if(CollectionUtils.isEmpty(param)){
return;
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
OtherDeductionPOEncrypt.encryptOtherDeductionPOList(param);
List<List<OtherDeductionPO>> partition = Lists.partition(param, 100);
partition.forEach(mapper::updateData);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
/**
* 处理导入数据
*
* @param pos
*/
public void handleImportData(List<OtherDeductionPO> pos) {
public void handleImportData(List<SpecialAddDeductionPO> pos) {
if (CollectionUtils.isEmpty(pos)) {
return;
}
OtherDeductionPO po = pos.get(0);
SpecialAddDeductionPO po = pos.get(0);
// 多条相同人的则以第一条为准如果逆序排列用于重复的则以最后一条为准Collections.reverse(pos);
// 去重通过记录的唯一条件(申报月份人员id个税扣缴义务人id)拼接
List<OtherDeductionPO> finalPos = pos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))), ArrayList::new));
List<SpecialAddDeductionPO> finalPos = pos.stream()
.collect(Collectors.collectingAndThen(
Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))),
ArrayList::new)
);
// 查询已有数据
List<OtherDeductionPO> list = listSome(OtherDeductionPO.builder().declareMonth(po.getDeclareMonth()).build());
List<SpecialAddDeductionPO> list = listByDeclareMonthAndTaxAgentIds(po.getDeclareMonth(), null);
// 待修改的 本地已存在则更新交集
List<OtherDeductionPO> updateList = list.stream().map(m -> {
Optional<OtherDeductionPO> optional = finalPos.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
OtherDeductionPO temp = null;
if (optional.isPresent()) {
temp = optional.get();
// 换成本地库的id
temp.setId(m.getId());
}
return temp;
}).filter(Objects::nonNull).collect(Collectors.toList());
List<SpecialAddDeductionPO> updateList = list.stream()
.map(m -> finalPos.stream()
.filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId()))
.findFirst()
.map(t -> t.setId(m.getId()))
.orElse(null)
).filter(Objects::nonNull).collect(Collectors.toList());
// 待新增的 导入比本地多则新增差集(导入 - local)
List<OtherDeductionPO> saveList = finalPos.stream().map(m -> {
Optional<OtherDeductionPO> optional = list.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
OtherDeductionPO temp = null;
if (!optional.isPresent()) {
temp = m;
}
return temp;
}).filter(Objects::nonNull).collect(Collectors.toList());
List<SpecialAddDeductionPO> saveList = finalPos.stream()
.filter(m -> list.stream().noneMatch(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId()))
).filter(Objects::nonNull).collect(Collectors.toList());
// 修改
if (CollectionUtils.isNotEmpty(updateList)) {
@ -166,43 +129,22 @@ public class SpecialAddDeductionBiz extends BaseBean {
if (CollectionUtils.isNotEmpty(saveList)) {
batchSave(saveList);
}
// 记录操作日志
// saveList.addAll(updateList);
//
// if (CollectionUtils.isNotEmpty(saveList)) {
// LoggerContext loggerContext = new LoggerContext();
// loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(message.getTenantKey(), message.getUserId(), 100351, "导入累计专项附加扣除"));
// loggerContext.setOperateType(OperateTypeEnum.ADD.getValue());
// loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(message.getTenantKey(), message.getUserId(), 100351, "导入累计专项附加扣除"));
// loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(message.getTenantKey(), message.getUserId(), 100351, "导入累计专项附加扣除"));
// loggerContext.setNewValueList(saveList);
// loggerContext.setTenant_key(message.getTenantKey());
// loggerContext.setOperator(message.getUserId().toString());
// loggerContext.setOperatorName(message.getOpreator());
// loggerContext.setClientIp(message.getClientIp());
// addUpDeductionLoggerTemplate.write(loggerContext);
// }
}
/**
* @description 批量删除
* @return void
* @author Harryxzy
* @date 2022/10/27 16:07
* @description 批量删除
*/
public void batchDeleteByIDS(List<Long> deleteIds) {
public void batchDeleteByIds(List<Long> deleteIds) {
if (CollectionUtils.isEmpty(deleteIds)) {
return;
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
List<List<Long>> partition = Lists.partition(deleteIds, 100);
partition.forEach(mapper::deleteData);
partition.forEach(mapper::deleteByIds);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
}

View File

@ -1,197 +1,607 @@
<?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.SpecialAddDeductionMapper">
<resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
<!--@mbg.generated-->
<!--@Table hrsa_special_add_deduction-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="employee_id" jdbcType="BIGINT" property="employeeId" />
<result column="tax_agent_id" jdbcType="BIGINT" property="taxAgentId" />
<result column="declare_month" jdbcType="TIMESTAMP" property="declareMonth" />
<result column="children_education" jdbcType="VARCHAR" property="childrenEducation" />
<result column="continuing_education" jdbcType="VARCHAR" property="continuingEducation" />
<result column="housing_loan_interest" jdbcType="VARCHAR" property="housingLoanInterest" />
<result column="housing_rent" jdbcType="VARCHAR" property="housingRent" />
<result column="supporting_elder" jdbcType="VARCHAR" property="supportingElder" />
<result column="serious_illness_treatment" jdbcType="VARCHAR" property="seriousIllnessTreatment" />
<result column="infant_care" jdbcType="VARCHAR" property="infantCare" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="creator" jdbcType="BIGINT" property="creator" />
<result column="delete_type" jdbcType="INTEGER" property="deleteType" />
<result column="tenant_key" jdbcType="VARCHAR" property="tenantKey" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, employee_id, tax_agent_id, declare_month, children_education, continuing_education,
housing_loan_interest, housing_rent, supporting_elder, serious_illness_treatment,
infant_care, create_time, update_time, creator, delete_type, tenant_key
</sql>
<select id="getById" parameterType="java.lang.Long" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List" />
from hrsa_special_add_deduction
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into hrsa_special_add_deduction
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="employeeId != null">
employee_id,
</if>
<if test="taxAgentId != null">
tax_agent_id,
</if>
<if test="declareMonth != null">
declare_month,
</if>
<if test="childrenEducation != null">
children_education,
</if>
<if test="continuingEducation != null">
continuing_education,
</if>
<if test="housingLoanInterest != null">
housing_loan_interest,
</if>
<if test="housingRent != null">
housing_rent,
</if>
<if test="supportingElder != null">
supporting_elder,
</if>
<if test="seriousIllnessTreatment != null">
serious_illness_treatment,
</if>
<if test="infantCare != null">
infant_care,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="creator != null">
creator,
</if>
<if test="deleteType != null">
delete_type,
</if>
<if test="tenantKey != null">
tenant_key,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="employeeId != null">
#{employeeId,jdbcType=BIGINT},
</if>
<if test="taxAgentId != null">
#{taxAgentId,jdbcType=BIGINT},
</if>
<if test="declareMonth != null">
#{declareMonth,jdbcType=TIMESTAMP},
</if>
<if test="childrenEducation != null">
#{childrenEducation,jdbcType=VARCHAR},
</if>
<if test="continuingEducation != null">
#{continuingEducation,jdbcType=VARCHAR},
</if>
<if test="housingLoanInterest != null">
#{housingLoanInterest,jdbcType=VARCHAR},
</if>
<if test="housingRent != null">
#{housingRent,jdbcType=VARCHAR},
</if>
<if test="supportingElder != null">
#{supportingElder,jdbcType=VARCHAR},
</if>
<if test="seriousIllnessTreatment != null">
#{seriousIllnessTreatment,jdbcType=VARCHAR},
</if>
<if test="infantCare != null">
#{infantCare,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="creator != null">
#{creator,jdbcType=BIGINT},
</if>
<if test="deleteType != null">
#{deleteType,jdbcType=INTEGER},
</if>
<if test="tenantKey != null">
#{tenantKey,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
<!--@mbg.generated-->
update hrsa_special_add_deduction
<set>
<if test="employeeId != null">
employee_id = #{employeeId,jdbcType=BIGINT},
</if>
<if test="taxAgentId != null">
tax_agent_id = #{taxAgentId,jdbcType=BIGINT},
</if>
<if test="declareMonth != null">
declare_month = #{declareMonth,jdbcType=TIMESTAMP},
</if>
<if test="childrenEducation != null">
children_education = #{childrenEducation,jdbcType=VARCHAR},
</if>
<if test="continuingEducation != null">
continuing_education = #{continuingEducation,jdbcType=VARCHAR},
</if>
<if test="housingLoanInterest != null">
housing_loan_interest = #{housingLoanInterest,jdbcType=VARCHAR},
</if>
<if test="housingRent != null">
housing_rent = #{housingRent,jdbcType=VARCHAR},
</if>
<if test="supportingElder != null">
supporting_elder = #{supportingElder,jdbcType=VARCHAR},
</if>
<if test="seriousIllnessTreatment != null">
serious_illness_treatment = #{seriousIllnessTreatment,jdbcType=VARCHAR},
</if>
<if test="infantCare != null">
infant_care = #{infantCare,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="creator != null">
creator = #{creator,jdbcType=BIGINT},
</if>
<if test="deleteType != null">
delete_type = #{deleteType,jdbcType=INTEGER},
</if>
<if test="tenantKey != null">
tenant_key = #{tenantKey,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
<!--@mbg.generated-->
<!--@Table hrsa_special_add_deduction-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="employee_id" jdbcType="BIGINT" property="employeeId"/>
<result column="tax_agent_id" jdbcType="BIGINT" property="taxAgentId"/>
<result column="declare_month" jdbcType="TIMESTAMP" property="declareMonth"/>
<result column="children_education" jdbcType="VARCHAR" property="childrenEducation"/>
<result column="continuing_education" jdbcType="VARCHAR" property="continuingEducation"/>
<result column="housing_loan_interest" jdbcType="VARCHAR" property="housingLoanInterest"/>
<result column="housing_rent" jdbcType="VARCHAR" property="housingRent"/>
<result column="supporting_elder" jdbcType="VARCHAR" property="supportingElder"/>
<result column="serious_illness_treatment" jdbcType="VARCHAR" property="seriousIllnessTreatment"/>
<result column="infant_care" jdbcType="VARCHAR" property="infantCare"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="creator" jdbcType="BIGINT" property="creator"/>
<result column="delete_type" jdbcType="INTEGER" property="deleteType"/>
<result column="tenant_key" jdbcType="VARCHAR" property="tenantKey"/>
</resultMap>
<select id="selectAllByPO" parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from hrsa_special_add_deduction
<where>
<sql id="Base_Column_List">
t1.id,
t1.employee_id,
t1.tax_agent_id,
t1.declare_month,
t1.children_education,
t1.continuing_education,
t1.housing_loan_interest,
t1.housing_rent,
t1.supporting_elder,
t1.serious_illness_treatment,
t1.infant_care,
t1.create_time,
t1.update_time,
t1.creator,
t1.delete_type,
t1.tenant_key
</sql>
</where>
</select>
<sql id="Special_Column_List">
t1.id,
t1.declare_month,
t1.employee_id,
t2.id AS tax_agent_id,
t2.name AS tax_agent_name,
e.lastname as username,
e.certificatenum as idNo,
d.departmentname AS departmentName,
e.mobile,
e.workcode as job_num,
e.companystartdate as hiredate,
t1.children_education,
t1.continuing_education,
t1.housing_loan_interest,
t1.housing_rent,
t1.serious_illness_treatment,
t1.supporting_elder,
t1.infant_care
</sql>
<sql id="paramSql">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<!-- 关键字(姓名、部门、工号 -->
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like CONCAT('%',#{param.keyword},'%')
OR d.departmentname like CONCAT('%',#{param.keyword},'%')
OR e.workcode like CONCAT('%',#{param.keyword},'%')
)
</if>
<!-- 申报月份 -->
<if test="param.declareMonthDate != null">
<if test="param.declareMonthDate.size() == 1">
AND t1.declare_month = #{param.declareMonthDate[0]}
</if>
<if test="param.declareMonthDate.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonthDate[0]} AND #{param.declareMonthDate[1]})
</if>
</if>
<!-- 姓名 -->
<if test="param.username != null and param.username != ''">
AND e.lastname like CONCAT('%',#{param.username},'%')
</if>
<!-- 个税扣缴义务人 -->
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
AND t1.tax_agent_id IN
<foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 部门 -->
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 工号 -->
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like CONCAT('%',#{param.jobNum},'%')
</if>
<!-- 入职日期 -->
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<!-- 手机号 -->
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like CONCAT('%',#{param.mobile},'%')
</if>
</sql>
<sql id="paramSql" databaseId="oracle">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like '%'||#{param.keyword}||'%'
OR d.departmentname like '%'||#{param.keyword}||'%'
OR e.workcode like '%'||#{param.keyword}||'%'
)
</if>
<if test="param.declareMonthDate != null">
<if test="param.declareMonthDate.size() == 1">
AND t1.declare_month = #{param.declareMonthDate[0]}
</if>
<if test="param.declareMonthDate.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonthDate[0]} AND #{param.declareMonthDate[1]})
</if>
</if>
<if test="param.username != null and param.username != ''">
AND e.lastname like '%'||#{param.username}||'%'
</if>
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
AND t1.tax_agent_id IN
<foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like '%'||#{param.jobNum}||'%'
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like '%'||#{param.mobile}||'%'
</if>
</sql>
<sql id="paramSql" databaseId="sqlserver">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like '%'+#{param.keyword}+'%'
OR d.departmentname like '%'+#{param.keyword}+'%'
OR e.workcode like '%'+#{param.keyword}+'%'
)
</if>
<if test="param.declareMonthDate != null">
<if test="param.declareMonthDate.size() == 1">
AND t1.declare_month = #{param.declareMonthDate[0]}
</if>
<if test="param.declareMonthDate.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonthDate[0]} AND #{param.declareMonthDate[1]})
</if>
</if>
<if test="param.username != null and param.username != ''">
AND e.lastname like '%'+#{param.username}+'%'
</if>
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
AND t1.tax_agent_id IN
<foreach collection="param.taxAgentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like '%'+#{param.jobNum}+'%'
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like '%'+#{param.mobile}+'%'
</if>
</sql>
<sql id="otherDeductionColumn">
</sql>
<select id="getById" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from hrsa_special_add_deduction t1
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into hrsa_special_add_deduction
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="employeeId != null">
employee_id,
</if>
<if test="taxAgentId != null">
tax_agent_id,
</if>
<if test="declareMonth != null">
declare_month,
</if>
<if test="childrenEducation != null">
children_education,
</if>
<if test="continuingEducation != null">
continuing_education,
</if>
<if test="housingLoanInterest != null">
housing_loan_interest,
</if>
<if test="housingRent != null">
housing_rent,
</if>
<if test="supportingElder != null">
supporting_elder,
</if>
<if test="seriousIllnessTreatment != null">
serious_illness_treatment,
</if>
<if test="infantCare != null">
infant_care,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="creator != null">
creator,
</if>
delete_type,
<if test="tenantKey != null">
tenant_key,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="employeeId != null">
#{employeeId,jdbcType=BIGINT},
</if>
<if test="taxAgentId != null">
#{taxAgentId,jdbcType=BIGINT},
</if>
<if test="declareMonth != null">
#{declareMonth,jdbcType=TIMESTAMP},
</if>
<if test="childrenEducation != null">
#{childrenEducation,jdbcType=VARCHAR},
</if>
<if test="continuingEducation != null">
#{continuingEducation,jdbcType=VARCHAR},
</if>
<if test="housingLoanInterest != null">
#{housingLoanInterest,jdbcType=VARCHAR},
</if>
<if test="housingRent != null">
#{housingRent,jdbcType=VARCHAR},
</if>
<if test="supportingElder != null">
#{supportingElder,jdbcType=VARCHAR},
</if>
<if test="seriousIllnessTreatment != null">
#{seriousIllnessTreatment,jdbcType=VARCHAR},
</if>
<if test="infantCare != null">
#{infantCare,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="creator != null">
#{creator,jdbcType=BIGINT},
</if>
0,
<if test="tenantKey != null">
#{tenantKey,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective"
parameterType="com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO">
<!--@mbg.generated-->
update hrsa_special_add_deduction
<set>
<if test="employeeId != null">
employee_id = #{employeeId,jdbcType=BIGINT},
</if>
<if test="taxAgentId != null">
tax_agent_id = #{taxAgentId,jdbcType=BIGINT},
</if>
<if test="declareMonth != null">
declare_month = #{declareMonth,jdbcType=TIMESTAMP},
</if>
<if test="childrenEducation != null">
children_education = #{childrenEducation,jdbcType=VARCHAR},
</if>
<if test="continuingEducation != null">
continuing_education = #{continuingEducation,jdbcType=VARCHAR},
</if>
<if test="housingLoanInterest != null">
housing_loan_interest = #{housingLoanInterest,jdbcType=VARCHAR},
</if>
<if test="housingRent != null">
housing_rent = #{housingRent,jdbcType=VARCHAR},
</if>
<if test="supportingElder != null">
supporting_elder = #{supportingElder,jdbcType=VARCHAR},
</if>
<if test="seriousIllnessTreatment != null">
serious_illness_treatment = #{seriousIllnessTreatment,jdbcType=VARCHAR},
</if>
<if test="infantCare != null">
infant_care = #{infantCare,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="creator != null">
creator = #{creator,jdbcType=BIGINT},
</if>
<if test="deleteType != null">
delete_type = #{deleteType,jdbcType=INTEGER},
</if>
<if test="tenantKey != null">
tenant_key = #{tenantKey,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateBatchSelective" parameterType="java.util.List">
<!--@mbg.generated-->
update hrsa_special_add_deduction
<trim prefix="set" suffixOverrides=",">
<trim prefix="employee_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.employeeId != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.employeeId,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim prefix="tax_agent_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.taxAgentId != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.taxAgentId,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim prefix="declare_month = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.declareMonth != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.declareMonth,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="children_education = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.childrenEducation != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.childrenEducation,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="continuing_education = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.continuingEducation != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.continuingEducation,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="housing_loan_interest = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.housingLoanInterest != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.housingLoanInterest,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="housing_rent = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.housingRent != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.housingRent,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="supporting_elder = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.supportingElder != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.supportingElder,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="serious_illness_treatment = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.seriousIllnessTreatment != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.seriousIllnessTreatment,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="infant_care = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.infantCare != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.infantCare,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.createTime != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="update_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.updateTime != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="creator = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.creator != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.creator,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim prefix="delete_type = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.deleteType != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.deleteType,jdbcType=INTEGER}
</if>
</foreach>
</trim>
<trim prefix="tenant_key = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.tenantKey != null">
when id = #{item.id,jdbcType=BIGINT} then #{item.tenantKey,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into hrsa_special_add_deduction
(employee_id, tax_agent_id, declare_month, children_education, continuing_education,
housing_loan_interest, housing_rent, supporting_elder, serious_illness_treatment,
infant_care, create_time, update_time, creator, delete_type, tenant_key)
values
<foreach collection="list" item="item" separator=",">
(#{item.employeeId,jdbcType=BIGINT}, #{item.taxAgentId,jdbcType=BIGINT},
#{item.declareMonth,jdbcType=TIMESTAMP},
#{item.childrenEducation,jdbcType=VARCHAR}, #{item.continuingEducation,jdbcType=VARCHAR},
#{item.housingLoanInterest,jdbcType=VARCHAR}, #{item.housingRent,jdbcType=VARCHAR},
#{item.supportingElder,jdbcType=VARCHAR}, #{item.seriousIllnessTreatment,jdbcType=VARCHAR},
#{item.infantCare,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
#{item.updateTime,jdbcType=TIMESTAMP},
#{item.creator,jdbcType=BIGINT}, 0, #{item.tenantKey,jdbcType=VARCHAR})
</foreach>
</insert>
<select id="listDtoByParam" resultType="com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO">
select
<include refid="Special_Column_List"/>
from hrsa_special_add_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
LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
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)
<include refid="paramSql"/>
<!-- 排序 -->
<if test="param.orderRule != null">
ORDER BY ${param.orderRule.orderRule} ${param.orderRule.ascOrDesc}
</if>
</select>
<select id="listByDeclareMonthAndTaxAgentIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from hrsa_special_add_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
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)
and declare_month=#{declareMonth,jdbcType=TIMESTAMP}
<if test="taxAgentIds != null and taxAgentIds.size() != 0">
AND t1.tax_agent_id IN
<foreach collection="taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
#{taxAgentId}
</foreach>
</if>
</select>
<select id="listByParam" resultType="com.engine.salary.entity.datacollection.dto.SpecialAddDeductionListDTO">
select
<include refid="Special_Column_List"/>
from hrsa_special_add_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
LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
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)
<include refid="paramSql"/>
order by t1.declare_month desc
</select>
<delete id="deleteByIds">
update hrsa_special_add_deduction
set delete_type = 1
where id in (
<foreach collection="ids" item="id" separator=",">
#{id}
</foreach>
) and delete_type = 0
</delete>
</mapper>

View File

@ -0,0 +1,810 @@
package com.engine.salary.service.impl;
import com.api.formmode.mybatis.util.SqlProxyHandle;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.biz.EmployBiz;
import com.engine.salary.biz.SpecialAddDeductionBiz;
import com.engine.salary.encrypt.datacollection.SpecialAddDeductionEncrypt;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionListDTO;
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.SpecialAddDeductionImportParam;
import com.engine.salary.entity.datacollection.param.SpecialAddDeductionParam;
import com.engine.salary.entity.datacollection.param.SpecialAddDeductionQueryParam;
import com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.enums.UserStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.datacollection.SpecialAddDeductionMapper;
import com.engine.salary.mapper.sys.SalarySysConfMapper;
import com.engine.salary.service.AddUpDeductionService;
import com.engine.salary.service.SalaryEmployeeService;
import com.engine.salary.service.SpecialAddDeductionService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.sys.entity.po.SalarySysConfPO;
import com.engine.salary.sys.entity.vo.OrderRuleVO;
import com.engine.salary.sys.service.SalarySysConfService;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelComment;
import com.engine.salary.util.excel.ExcelParseHelper;
import com.engine.salary.util.excel.ExcelUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.file.ImageFileManager;
import weaver.general.Util;
import weaver.hrm.User;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
public class SpecialAddDeductionServiceImpl extends Service implements SpecialAddDeductionService {
private SpecialAddDeductionMapper getSpecialAddDeductionMapper() {
return MapperProxyFactory.getProxy(SpecialAddDeductionMapper.class);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private AddUpDeductionService getAddUpDeductionService(User user) {
return ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
private SalarySysConfMapper getSalarySysConfMapper() {
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
}
private SalarySysConfService getSalarySysConfService(User user) {
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
}
@Override
public SpecialAddDeductionPO getById(Long id) {
return getSpecialAddDeductionMapper().getById(id);
}
@Override
public PageInfo<SpecialAddDeductionListDTO> listPage(SpecialAddDeductionQueryParam queryParam) {
//申报月份
List<String> declareMonth = queryParam.getDeclareMonth();
if (CollectionUtils.isNotEmpty(declareMonth)) {
queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
queryParam.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
}
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
queryParam.setOrderRule(orderRule);
long employeeId = user.getUID();
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
if (needAuth) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user)
.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(taxAgentIdsAsAdmin)) {
return new PageInfo<>(SpecialAddDeductionListDTO.class);
}
queryParam.setTaxAgentIds(taxAgentIdsAsAdmin);
}
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<SpecialAddDeductionListDTO> list = getSpecialAddDeductionMapper().listByParam(queryParam);
SpecialAddDeductionEncrypt.decrypt(list);
return new PageInfo<>(list, SpecialAddDeductionListDTO.class);
}
@Override
public PageInfo<SpecialAddDeductionRecordDTO> recordListPage(SpecialAddDeductionQueryParam queryParam) {
long employeeId = user.getUID();
//申报月份
List<String> declareMonth = queryParam.getDeclareMonth();
if (CollectionUtils.isNotEmpty(declareMonth)) {
queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
queryParam.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
}
Boolean needAuth = getTaxAgentService(user).isNeedAuth(employeeId);
if (needAuth) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user)
.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(taxAgentIdsAsAdmin)) {
return new PageInfo<>(SpecialAddDeductionRecordDTO.class);
}
queryParam.setTaxAgentIds(taxAgentIdsAsAdmin);
}
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<SpecialAddDeductionRecordDTO> list = getSpecialAddDeductionMapper().listDtoByParam(queryParam);
SpecialAddDeductionEncrypt.decrypt(list);
return new PageInfo<>(list, SpecialAddDeductionRecordDTO.class);
}
@Override
public Map<String, Object> preview(SpecialAddDeductionImportParam importParam) {
Map<String, Object> apidatas = new HashMap<String, Object>();
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
Validate.notBlank(imageId, "imageId为空");
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
List<SpecialAddDeductionListDTO> SpecialAddDeductions =
ExcelParseHelper.parse2Map(fileInputStream, SpecialAddDeductionListDTO.class, 0, 1, 11,
"SpecialAddDeductionTemplate.xlsx");
apidatas.put("preview", SpecialAddDeductions);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
public Map<String, Object> importData(SpecialAddDeductionImportParam importParam) {
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
long currentEmployeeId = user.getUID();
Map<String, Object> apidatas = new HashMap<String, Object>();
EmployBiz employBiz = new EmployBiz();
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
//查询对于人员信息导入筛选的全局配置
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
//检验参数
checkImportParam(importParam);
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
Validate.notBlank(imageId, "imageId为空");
//税款所属期
String declareMonthStr = Util.null2String(importParam.getDeclareMonth());
//个税扣缴义务人
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
List<SpecialAddDeductionListDTO> SpecialAddDeductions = ExcelParseHelper.parse2Map(fileInputStream, SpecialAddDeductionListDTO.class, 0, 1, 14, "SpecialAddDeductionTemplate.xlsx");
int total = SpecialAddDeductions.size();
int index = 0;
int successCount = 0;
int errorCount = 0;
//人员信息
List<DataCollectionEmployee> employees = employBiz.listEmployee();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
//税款所属期
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user)
.getAccountedEmployeeData(declareMonthStr);
// 查询已有数据
List<SpecialAddDeductionPO> list = getSpecialAddDeductionMapper()
.listByDeclareMonthAndTaxAgentIds(declareMonth, null);
// 错误excel内容
List<Map> errorData = new ArrayList<>();
//合规数据
List<SpecialAddDeductionPO> eligibleData = new ArrayList<>();
for (int i = 0; i < SpecialAddDeductions.size(); i++) {
SpecialAddDeductionListDTO dto = SpecialAddDeductions.get(i);
Date now = new Date();
//待插入数据库对象
SpecialAddDeductionPO po = SpecialAddDeductionPO.builder()
.tenantKey(DEFAULT_TENANT_KEY)
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.declareMonth(declareMonth).build();
//异常点数量
int errorSum = 0;
//行号
String rowIndex = String.format("第%s行", i + 2);
//相同的姓名
String userName = dto.getUsername();
String deparmentName = dto.getDepartmentName();
String mobile = dto.getMobile();
String workcode = dto.getJobNum();
List<Long> employeeSameIds = new ArrayList<>();
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
List<DataCollectionEmployee> emps = getSalaryEmployeeService(user)
.matchImportEmployee(employees, userName, deparmentName, mobile, workcode, null);
//含在职和离职选在职数据
if (CollectionUtils.isNotEmpty(emps) && emps.size() > 1) {
employeeSameIds = emps.stream()
.filter(e -> UserStatusEnum.getNormalStatus().contains(e.getStatus()))
.map(DataCollectionEmployee::getEmployeeId)
.collect(Collectors.toList());
}
if (CollectionUtils.isNotEmpty(emps) && emps.size() == 1) {
employeeSameIds = emps.stream()
.map(DataCollectionEmployee::getEmployeeId)
.collect(Collectors.toList());
}
//当人员信息导入筛选的全局配置为"0"姓名才是必填项
if (StringUtils.isBlank(userName) && "0".equals(confValue)) {
//姓名 不能为空
//错误消息对象
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "姓名不能为空");
errorData.add(errorMessageMap);
errorSum += 1;
} else if (CollectionUtils.isEmpty(employeeSameIds) || employeeSameIds.size() > 1) {
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "员工信息不存在或者存在多个员工");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
Long employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0) : null;
if (employeeId != null && employeeId > 0) {
po.setEmployeeId(employeeId);
} else {
//姓名错误系统内不存在该姓名
Map<String, String> errorMessageMap = new HashMap<>();
errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
String taxAgentName = dto.getTaxAgentName();
if (StringUtils.isBlank(taxAgentName)) {
//个税扣缴义务人不能为空
Map<String, String> errorMessageMap = new HashMap<>();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不能为空");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
if (StringUtils.isNotEmpty(taxAgentId) && !optionalTemp.get().getTaxAgentId().equals(Long.valueOf(taxAgentId))) {
//个税扣缴义务人与导入时选择的不一致
Map<String, String> errorMessageMap = new HashMap<>();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人与导入时选择的不一致");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
}
} else {
//个税扣缴义务人不存在
Map<String, String> errorMessageMap = new HashMap<>();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在或不在权限范围内");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
// 核心字段
po.setInfantCare(dto.getInfantCare())
.setSeriousIllnessTreatment(dto.getSeriousIllnessTreatment())
.setSupportingElder(dto.getSupportingElder())
.setHousingRent(dto.getHousingRent())
.setHousingLoanInterest(dto.getHousingLoanInterest())
.setContinuingEducation(dto.getContinuingEducation())
.setChildrenEducation(dto.getChildrenEducation());
//fixme 分权判断
//
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
SpecialAddDeductionPO finalPo = po;
Optional<SalaryAcctEmployeePO> optionalAcctEmp =
salaryAcctEmployees.stream()
.filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()))
.findFirst();
boolean isExist = list.stream()
.anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
if (optionalAcctEmp.isPresent() && isExist) {
Map<String, String> errorMessageMap = new HashMap<String, String>();
errorMessageMap.put("message", rowIndex + "该年月这条数据已经核算过,不可导入");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
if (errorSum == 0) {
successCount += 1;
// 合格数据
eligibleData.add(po);
} else {
errorCount += 1;
// 添加错误数据
}
}
//入库
SpecialAddDeductionBiz.handleImportData(eligibleData);
apidatas.put("successCount", successCount);
apidatas.put("errorCount", errorCount);
apidatas.put("errorData", errorData);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
private void checkImportParam(SpecialAddDeductionImportParam importParam) {
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
//税款所属期
String declareMonthStr = Util.null2String(importParam.getDeclareMonth());
//个税扣缴义务人
String taxAgentId = Util.null2String(importParam.getTaxAgentId());
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException("文件不存在");
}
if (StringUtils.isBlank(declareMonthStr)) {
throw new SalaryRunTimeException("税款所属期为空");
}
}
/**
* 导出
*
* @param param
* @return
*/
public XSSFWorkbook export(SpecialAddDeductionQueryParam param) {
//获取操作按钮资源
List<List<String>> rowList = getExcelRowList(param);
//获取excel
return ExcelUtil.genWorkbook(rowList, "其他免税扣除");
}
/**
* 获取excel数据行
*
* @return 导出数据行集合
*/
private List<List<String>> getExcelRowList(SpecialAddDeductionQueryParam param) {
long employeeId = user.getUID();
//excel标题
List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "子女教育", "继续教育", "住房贷款利息", "住房租金", "赡养老人", "大病医疗", "婴幼儿照护");
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
param.setOrderRule(orderRule);
//申报月份
List<String> declareMonth = param.getDeclareMonth();
if (CollectionUtils.isNotEmpty(declareMonth)) {
param.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
param.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
}
List<SpecialAddDeductionListDTO> list = getSpecialAddDeductionMapper().listByParam(param);
SpecialAddDeductionEncrypt.decrypt(list);
// 开启分权并且不是薪酬模块总管理员
if (getTaxAgentService(user).isOpenDevolution() && !getTaxAgentService(user).isChief(employeeId)) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
).collect(Collectors.toList());
}
final List<List<String>> dataRowList = Optional.ofNullable(list)
.map(List::stream)
.map(operatorStream -> operatorStream.map(dto -> {
List<String> cellList = new ArrayList<>();
cellList.add(Util.null2String(dto.getUsername()));
cellList.add(Util.null2String(dto.getTaxAgentName()));
cellList.add(Util.null2String(dto.getDepartmentName()));
cellList.add(Util.null2String(dto.getMobile()));
cellList.add(Util.null2String(dto.getJobNum()));
cellList.add(Util.null2String(dto.getIdNo()));
cellList.add(Util.null2String(dto.getHiredate()));
cellList.add(Util.null2String(dto.getChildrenEducation()));
cellList.add(Util.null2String(dto.getContinuingEducation()));
cellList.add(Util.null2String(dto.getHousingLoanInterest()));
cellList.add(Util.null2String(dto.getHousingRent()));
cellList.add(Util.null2String(dto.getSupportingElder()));
cellList.add(Util.null2String(dto.getSeriousIllnessTreatment()));
cellList.add(Util.null2String(dto.getInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
}
/**
* 导出详情列表
*
* @param param
* @return
*/
public XSSFWorkbook exportDetail(SpecialAddDeductionQueryParam param) {
SpecialAddDeductionBiz biz = new SpecialAddDeductionBiz();
EmployBiz employBiz = new EmployBiz();
Long id = param.getSpecialAddDeductionId();
if (id == null) {
throw new SalaryRunTimeException("id不能为空");
}
SpecialAddDeductionPO po = biz.getById(id);
if (po == null) {
throw new SalaryRunTimeException(String.format("专项附加扣除不存在" + "[id:%s]", id));
}
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()));
if (CollectionUtils.isEmpty(employeeList)) {
throw new SalaryRunTimeException("员工信息不存在");
}
//构建参数
param.setEmployeeId(po.getEmployeeId());
//申报月份
List<String> declareMonth = param.getDeclareMonth();
if (CollectionUtils.isNotEmpty(declareMonth)) {
param.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
param.setDeclareMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
}
//获取操作按钮资源
List<List<String>> rowList = getExcelRowDetailList(param);
//获取excel
return ExcelUtil.genWorkbook(rowList, "其他免税扣除明细");
}
/**
* 导出详情
*
* @param param
* @return
*/
private List<List<String>> getExcelRowDetailList(SpecialAddDeductionQueryParam param) {
//excel标题
List<String> title = Arrays.asList("姓名", "申报月份", "个税扣缴义务人", "部门", "手机号", "工号", "子女教育", "继续教育", "住房贷款利息", "住房租金", "赡养老人", "大病医疗", "婴幼儿照护");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
//查询详细信息
List<SpecialAddDeductionRecordDTO> list = getSpecialAddDeductionMapper().listDtoByParam(param);
SpecialAddDeductionEncrypt.decrypt(list);
final List<List<String>> dataRowList = Optional.ofNullable(list)
.map(List::stream)
.map(operatorStream -> operatorStream.map(dto -> {
List<String> cellList = new ArrayList<>();
cellList.add(Util.null2String(dto.getUsername()));
cellList.add(Util.null2String(dto.getDeclareMonth() == null ? "" : formatter.format(dto.getDeclareMonth())));
cellList.add(Util.null2String(dto.getTaxAgentName()));
cellList.add(Util.null2String(dto.getDepartmentName()));
cellList.add(Util.null2String(dto.getMobile()));
cellList.add(Util.null2String(dto.getJobNum()));
cellList.add(Util.null2String(dto.getChildrenEducation()));
cellList.add(Util.null2String(dto.getContinuingEducation()));
cellList.add(Util.null2String(dto.getHousingLoanInterest()));
cellList.add(Util.null2String(dto.getHousingRent()));
cellList.add(Util.null2String(dto.getSupportingElder()));
cellList.add(Util.null2String(dto.getSeriousIllnessTreatment()));
cellList.add(Util.null2String(dto.getInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
}
@Override
public List<SpecialAddDeductionPO> getSpecialAddDeductionList(YearMonth declareMonth, List<Long> employeeIds, Long taxAgentId) {
if (declareMonth == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100342, "参数有误:申报月份必传"));
}
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
return SpecialAddDeductionBiz.listByDeclareMonthAndTaxAgentIds(SalaryDateUtil.toDateStartOfMonth(declareMonth), null);
}
@Override
public void editData(SpecialAddDeductionParam specialAddDeductionParam) {
String declareMonthStr = specialAddDeductionParam.getDeclareMonth();
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
Long currentEmployeeId = (long) user.getUID();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
SpecialAddDeductionPO byId = SpecialAddDeductionBiz.getById(specialAddDeductionParam.getId());
if (byId == null) {
throw new SalaryRunTimeException("该数据不存在!");
}
Long taxAgentId = byId.getTaxAgentId();
boolean canEdit = taxAgentList.stream().anyMatch(t -> t.getTaxAgentId() == taxAgentId);
if (!canEdit) {
//没有编辑权限
throw new SalaryRunTimeException("该个税扣缴义务人无权限编辑此数据!");
}
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees =
getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp =
salaryAcctEmployees.stream()
.filter(f -> f.getEmployeeId().equals(specialAddDeductionParam.getEmployeeId()) && f.getTaxAgentId().equals(specialAddDeductionParam.getTaxAgentId()))
.findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可进行编辑!");
}
}
ArrayList<SpecialAddDeductionPO> updateList = new ArrayList<>();
SpecialAddDeductionPO build = SpecialAddDeductionPO.builder()
.id(specialAddDeductionParam.getId())
.childrenEducation(specialAddDeductionParam.getChildrenEducation())
.continuingEducation(specialAddDeductionParam.getContinuingEducation())
.housingLoanInterest(specialAddDeductionParam.getHousingLoanInterest())
.housingRent(specialAddDeductionParam.getHousingRent())
.build();
updateList.add(build);
SpecialAddDeductionBiz.batchUpdate(updateList);
}
@Override
public void createData(SpecialAddDeductionParam specialAddDeductionParam) {
long currentEmployeeId = user.getUID();
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
EmployBiz employBiz = new EmployBiz();
//查询对于人员信息导入筛选的全局配置
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
//税款所属期
String declareMonthStr = Util.null2String(specialAddDeductionParam.getDeclareMonth());
//人员信息
List<DataCollectionEmployee> employees = employBiz.listEmployee();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
//税款所属期
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 查询已有数据
List<SpecialAddDeductionPO> list = getSpecialAddDeductionMapper().listByDeclareMonthAndTaxAgentIds(declareMonth, null);
//合规数据
List<SpecialAddDeductionPO> insertData = new ArrayList<>();
Date now = new Date();
//待插入数据库对象
SpecialAddDeductionPO po = SpecialAddDeductionPO.builder()
.tenantKey(DEFAULT_TENANT_KEY)
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.declareMonth(declareMonth).build();
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
boolean employeeSameId = employees.stream()
.anyMatch(e -> Objects.equals(e.getEmployeeId(), specialAddDeductionParam.getEmployeeId()));
if (!employeeSameId) {
throw new SalaryRunTimeException("员工信息不存在");
}
po.setEmployeeId(specialAddDeductionParam.getEmployeeId());
String taxAgentName = specialAddDeductionParam.getTaxAgentName();
if (StringUtils.isBlank(taxAgentName)) {
//个税扣缴义务人不能为空
throw new SalaryRunTimeException("个税扣缴义务人不能为空");
} else {
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
} else {
//个税扣缴义务人不存在或不在权限范围内
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
}
}
//商业健康保险
po.setContinuingEducation(specialAddDeductionParam.getContinuingEducation())
.setChildrenEducation(specialAddDeductionParam.getChildrenEducation())
.setHousingLoanInterest(specialAddDeductionParam.getHousingLoanInterest())
.setHousingRent(specialAddDeductionParam.getHousingRent())
.setSupportingElder(specialAddDeductionParam.getSupportingElder())
.setSeriousIllnessTreatment(specialAddDeductionParam.getSeriousIllnessTreatment())
.setInfantCare(specialAddDeductionParam.getInfantCare());
//fixme 分权判断
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
SpecialAddDeductionPO finalPo = po;
Optional<SalaryAcctEmployeePO> optionalAcctEmp =
salaryAcctEmployees.stream()
.filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()))
.findFirst();
boolean isExist = list.stream()
.anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
if (optionalAcctEmp.isPresent() && isExist) {
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可导入");
}
}
insertData.add(po);
//入库
SpecialAddDeductionBiz.handleImportData(insertData);
}
@Override
public void deleteSelectData(AddUpDeductionRecordDeleteParam deleteParam) {
long currentEmployeeId = user.getUID();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
String declareMonthStr = deleteParam.getDeclareMonth();
List<Long> deleteIds = deleteParam.getIds();
// 已经核算过的不可操作
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees =
getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 判断是否有核算过
List<Long> deleteList = new ArrayList<>();
for (Long id : deleteIds) {
SpecialAddDeductionPO byId = SpecialAddDeductionBiz.getById(id);
if (byId == null) {
throw new SalaryRunTimeException("数据不存在或已被删除!");
}
// 判断是否在个税扣缴义务人范围内
boolean isNotInRegion =
taxAgentList.stream()
.noneMatch(m -> Objects.equals(m.getTaxAgentId(), byId.getTaxAgentId()));
if (isNotInRegion) {
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
}
// 判断用户是否存在
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp =
salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(byId.getEmployeeId()) && f.getTaxAgentId().equals(byId.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("所选数据在该年月中已经核算过并归档,不可进行删除!");
}
}
deleteList.add(byId.getId());
}
SpecialAddDeductionBiz.batchDeleteByIds(deleteList);
}
@Override
public void deleteAllData(AddUpDeductionRecordDeleteParam deleteParam) {
String declareMonthStr = deleteParam.getDeclareMonth();
long currentEmployeeId = user.getUID();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList =
getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
List<Long> taxAgentIds = taxAgentList.stream()
.map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId)
.collect(Collectors.toList());
SpecialAddDeductionBiz specialAddDeductionBiz = new SpecialAddDeductionBiz();
Date declareMonthDate = null;
try {
declareMonthDate = sdf.parse(declareMonthStr + "-01");
} catch (Exception e) {
throw new SalaryRunTimeException("日期异常");
}
if (deleteParam.getTaxAgentId() != null && (!deleteParam.getTaxAgentId().equals(""))) {
// 设置了个税扣缴义务人
Long taxAgentId = SalaryEntityUtil.string2Long(deleteParam.getTaxAgentId());
boolean canDelete = taxAgentIds.stream().anyMatch(t -> Objects.equals(t, taxAgentId));
if (!canDelete) {
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内!");
}
ArrayList<Long> tai = new ArrayList<>();
tai.add(taxAgentId);
taxAgentIds = tai;
}
// 获取所有想要删除的数据
List<SpecialAddDeductionPO> list = specialAddDeductionBiz.listByDeclareMonthAndTaxAgentIds(declareMonthDate, taxAgentIds);
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user)
.getAccountedEmployeeData(declareMonthStr);
for (SpecialAddDeductionPO item : list) {
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(item.getEmployeeId()) && f.getTaxAgentId().equals(item.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("有员工在该年月中已经完成核算并归档,不能进行一键清空!");
}
}
}
List<Long> deleteIds = list.stream().map(SpecialAddDeductionPO::getId).collect(Collectors.toList());
specialAddDeductionBiz.batchDeleteByIds(deleteIds);
}
@Override
public XSSFWorkbook downloadTemplate(SpecialAddDeductionQueryParam param) {
// 1.工作簿名称
String sheetName = SalaryI18nUtil.getI18nLabel(101604, "其他免税扣除导入模板");
String[] header = {
SalaryI18nUtil.getI18nLabel(85429, "姓名"),
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
SalaryI18nUtil.getI18nLabel(86185, "部门"),
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
SalaryI18nUtil.getI18nLabel(86317, "工号"),
SalaryI18nUtil.getI18nLabel(86318, "证件号码"),
SalaryI18nUtil.getI18nLabel(86319, "入职日期"),
SalaryI18nUtil.getI18nLabel(91238, "商业健康保险"),
SalaryI18nUtil.getI18nLabel(91239, "税延养老保险"),
SalaryI18nUtil.getI18nLabel(84500, "其他"),
SalaryI18nUtil.getI18nLabel(91240, "准予扣除的捐赠额")
};
// 2.表头
List<List<Object>> rows = new ArrayList<>();
List<Object> headerList = Arrays.asList(header);
rows.add(headerList);
// 4.注释
List<ExcelComment> excelComments = Lists.newArrayList();
excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(7, 0, 10, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(8, 0, 11, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(9, 0, 12, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(10, 0, 13, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments);
return book;
}
}