保存账套联系

This commit is contained in:
钱涛 2024-09-02 14:13:29 +08:00
parent 13665d8269
commit c72fa7fd7c
5 changed files with 395 additions and 0 deletions

View File

@ -9,6 +9,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 薪资账套保存参数
@ -39,6 +41,8 @@ public class SalarySobBasicSaveParam {
@DataCheck(require = true, message = "个税扣缴义务人的主键id不允许为空")
private Long taxAgentId;
private List<Long> taxAgentIds;
/**
* 薪资类型不允许为空
*

View File

@ -0,0 +1,72 @@
package com.engine.salary.entity.salarysob.po;
import com.engine.hrmelog.annotation.ElogTransform;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Collection;
import java.util.Date;
/**
* 数据
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SobTaxLinkPO {
@ElogTransform(name = "id")
private Long id;
/**
* 账套id
*/
@ElogTransform(name = "账套id")
private Long sobId;
/**
* 扣缴义务人id
*/
@ElogTransform(name = "扣缴义务人id")
private Long taxAgentId;
/**
* 是否已删除0未删除1已删除
*/
@ElogTransform(name = "是否已删除。0未删除、1已删除")
private Integer deleteType;
/**
* 更新时间
*/
@ElogTransform(name = "更新时间")
private Date updateTime;
/**
* 创建时间
*/
@ElogTransform(name = "创建时间")
private Date createTime;
/**
* 创建人
*/
@ElogTransform(name = "创建人")
private Long creator;
/**
* 租户ID
*/
@ElogTransform(name = "租户ID")
private String tenantKey;
//主键id集合
private Collection<Long> ids;
}

View File

@ -0,0 +1,73 @@
package com.engine.salary.mapper.salarysob;
import com.engine.salary.entity.salarysob.po.SobTaxLinkPO;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface SobTaxLinkMapper {
/**
* 查询所有记录
*
* @return 返回集合没有返回空List
*/
List<SobTaxLinkPO> listAll();
/**
* 条件查询
*
* @return 返回集合没有返回空List
*/
List<SobTaxLinkPO> listSome(SobTaxLinkPO sobTaxLink);
/**
* 根据主键查询
*
* @param id 主键
* @return 返回记录没有返回null
*/
SobTaxLinkPO getById(Long id);
/**
* 新增忽略null字段
*
* @param sobTaxLink 新增的记录
* @return 返回影响行数
*/
int insertIgnoreNull(SobTaxLinkPO sobTaxLink);
/**
* 修改修改所有字段
*
* @param sobTaxLink 修改的记录
* @return 返回影响行数
*/
int update(SobTaxLinkPO sobTaxLink);
/**
* 修改忽略null字段
*
* @param sobTaxLink 修改的记录
* @return 返回影响行数
*/
int updateIgnoreNull(SobTaxLinkPO sobTaxLink);
/**
* 删除记录
*
* @param sobTaxLink 待删除的记录
* @return 返回影响行数
*/
int delete(SobTaxLinkPO sobTaxLink);
/**
* 批量删除记录
* @param ids 主键id集合
*/
void deleteByIds(@Param("ids") Collection<Long> ids);
void deleteBySobId(Long id);
}

View File

@ -0,0 +1,215 @@
<?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.salarysob.SobTaxLinkMapper">
<resultMap id="BaseResultMap" type="com.engine.salary.entity.salarysob.po.SobTaxLinkPO">
<result column="create_time" property="createTime"/>
<result column="creator" property="creator"/>
<result column="delete_type" property="deleteType"/>
<result column="id" property="id"/>
<result column="sob_id" property="sobId"/>
<result column="tax_agent_id" property="taxAgentId"/>
<result column="tenant_key" property="tenantKey"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<!-- 表字段 -->
<sql id="baseColumns">
t
.
create_time
, t.creator
, t.delete_type
, t.id
, t.sob_id
, t.tax_agent_id
, t.tenant_key
, t.update_time
</sql>
<!-- 查询全部 -->
<select id="listAll" resultMap="BaseResultMap">
SELECT
<include refid="baseColumns"/>
FROM hrsa_sob_tax_link t
WHERE delete_type = 0
</select>
<!-- 根据主键获取单条记录 -->
<select id="getById" resultMap="BaseResultMap" parameterType="Long">
SELECT
<include refid="baseColumns"/>
FROM hrsa_sob_tax_link t
WHERE id = #{id} AND delete_type = 0
</select>
<!-- 条件查询 -->
<select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salarysob.po.SobTaxLinkPO">
SELECT
<include refid="baseColumns"/>
FROM hrsa_sob_tax_link t
WHERE delete_type = 0
<if test="createTime != null">
AND create_time = #{createTime}
</if>
<if test="creator != null">
AND creator = #{creator}
</if>
<if test="deleteType != null">
AND delete_type = #{deleteType}
</if>
<if test="id != null">
AND id = #{id}
</if>
<if test="sobId != null">
AND sob_id = #{sobId}
</if>
<if test="taxAgentId != null">
AND tax_agent_id = #{taxAgentId}
</if>
<if test="tenantKey != null">
AND tenant_key = #{tenantKey}
</if>
<if test="updateTime != null">
AND update_time = #{updateTime}
</if>
<if test="ids != null and ids.size()>0">
AND id IN
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
ORDER BY id DESC
</select>
<!-- 插入不为NULL的字段 -->
<insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SobTaxLinkPO">
INSERT INTO hrsa_sob_tax_link
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="createTime != null">
create_time,
</if>
<if test="creator != null">
creator,
</if>
<if test="deleteType != null">
delete_type,
</if>
<if test="id != null">
id,
</if>
<if test="sobId != null">
sob_id,
</if>
<if test="taxAgentId != null">
tax_agent_id,
</if>
<if test="tenantKey != null">
tenant_key,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="createTime != null">
#{createTime},
</if>
<if test="creator != null">
#{creator},
</if>
<if test="deleteType != null">
#{deleteType},
</if>
<if test="id != null">
#{id},
</if>
<if test="sobId != null">
#{sobId},
</if>
<if test="taxAgentId != null">
#{taxAgentId},
</if>
<if test="tenantKey != null">
#{tenantKey},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
</trim>
</insert>
<!-- 更新,更新全部字段 -->
<update id="update" parameterType="com.engine.salary.entity.salarysob.po.SobTaxLinkPO">
UPDATE hrsa_sob_tax_link
<set>
create_time=#{createTime},
creator=#{creator},
delete_type=#{deleteType},
sob_id=#{sobId},
tax_agent_id=#{taxAgentId},
tenant_key=#{tenantKey},
update_time=#{updateTime},
</set>
WHERE id = #{id} AND delete_type = 0
</update>
<!-- 更新不为NULL的字段 -->
<update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SobTaxLinkPO">
UPDATE hrsa_sob_tax_link
<set>
<if test="createTime != null">
create_time=#{createTime},
</if>
<if test="creator != null">
creator=#{creator},
</if>
<if test="deleteType != null">
delete_type=#{deleteType},
</if>
<if test="sobId != null">
sob_id=#{sobId},
</if>
<if test="taxAgentId != null">
tax_agent_id=#{taxAgentId},
</if>
<if test="tenantKey != null">
tenant_key=#{tenantKey},
</if>
<if test="updateTime != null">
update_time=#{updateTime},
</if>
</set>
WHERE id = #{id} AND delete_type = 0
</update>
<!-- 根据主键删除记录 -->
<delete id="delete">
UPDATE hrsa_sob_tax_link
SET delete_type=1
WHERE id = #{id}
AND delete_type = 0
</delete>
<delete id="deleteByIds">
UPDATE hrsa_sob_tax_link
SET delete_type = 1
WHERE delete_type = 0
AND id IN
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteBySobId">
UPDATE hrsa_sob_tax_link
SET delete_type = 1
WHERE delete_type = 0
AND sob_id=#{sobId}
</delete>
</mapper>

View File

@ -30,6 +30,7 @@ import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
import com.engine.salary.enums.salarysob.SalaryEmployeeStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.salarysob.SalarySobMapper;
import com.engine.salary.mapper.salarysob.SobTaxLinkMapper;
import com.engine.salary.mapper.taxagent.TaxAgentExtRangeMapper;
import com.engine.salary.service.*;
import com.engine.salary.service.auth.AuthService;
@ -118,6 +119,11 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
return MapperProxyFactory.getProxy(TaxAgentExtRangeMapper.class);
}
private SobTaxLinkMapper getSobTaxLinkMapper() {
return MapperProxyFactory.getProxy(SobTaxLinkMapper.class);
}
private SalarySobExtRangeService getSalarySobExtRangeService(User user) {
return ServiceUtil.getService(SalarySobExtRangeServiceImpl.class, user);
}
@ -345,6 +351,9 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "新建薪资账套") + ": " + salarySobPO.getName());
loggerContext.setNewValues(salarySobPO);
SalaryElogConfig.salarySobLoggerTemplate.write(loggerContext);
//保存个税扣缴义务人联系
saveSobTaxLink(saveParam, salarySobPO);
// 新建薪资账套时保存默认的员工信息字段
saveDefaultEmpField(salarySobPO);
// 新建薪资账套时保存默认的薪资项目
@ -355,6 +364,24 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
return salarySobPO.getId();
}
private void saveSobTaxLink(SalarySobBasicSaveParam saveParam, SalarySobPO salarySobPO) {
getSobTaxLinkMapper().deleteBySobId(salarySobPO.getId());
List<Long> taxAgentIds = saveParam.getTaxAgentIds();
for (Long taxAgentId : taxAgentIds) {
SobTaxLinkPO taxLinkPO = SobTaxLinkPO.builder()
.id(IdGenerator.generate())
.taxAgentId(taxAgentId)
.sobId(salarySobPO.getId())
.creator((long) user.getUID())
.createTime(new Date())
.updateTime(new Date())
.deleteType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build();
getSobTaxLinkMapper().insertIgnoreNull(taxLinkPO);
}
}
/**
* 新建薪资账套时保存默认的员工信息字段
@ -578,6 +605,10 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
.setDescription(saveParam.getDescription())
.setUpdateTime(new Date());
salarySobMapper.updateById(newSalarySobPO);
//保存个税扣缴义务人联系
saveSobTaxLink(saveParam, salarySobPO);
// 记录日志
SalarySobPO salarySobPO4log = getSalarySobMapper().getById(newSalarySobPO.getId());
LoggerContext<SalarySobPO> loggerContext = new LoggerContext<>();