2022-10-31 16:19:42 +08:00
|
|
|
|
package com.engine.salary.biz;
|
|
|
|
|
|
|
2022-12-13 13:34:22 +08:00
|
|
|
|
import com.engine.salary.encrypt.EncryptUtil;
|
2022-11-04 09:41:32 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionListDTO;
|
2022-11-02 17:27:07 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.SpecialAddDeductionRecordDTO;
|
|
|
|
|
|
import com.engine.salary.entity.datacollection.param.SpecialAddDeductionQueryParam;
|
2022-10-31 16:19:42 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.po.SpecialAddDeductionPO;
|
|
|
|
|
|
import com.engine.salary.mapper.datacollection.SpecialAddDeductionMapper;
|
2022-11-04 15:16:27 +08:00
|
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
2022-10-31 16:19:42 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
|
|
import weaver.conn.mybatis.MyBatisFactory;
|
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
public class SpecialAddDeductionBiz extends BaseBean {
|
2022-12-13 13:34:22 +08:00
|
|
|
|
private EncryptUtil encryptUtil = new EncryptUtil();
|
|
|
|
|
|
|
2022-11-04 15:16:27 +08:00
|
|
|
|
private SpecialAddDeductionMapper mapper() {
|
|
|
|
|
|
return MapperProxyFactory.getProxy(SpecialAddDeductionMapper.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-31 16:19:42 +08:00
|
|
|
|
/**
|
2022-11-02 17:27:07 +08:00
|
|
|
|
* 根据id获取
|
2022-10-31 16:19:42 +08:00
|
|
|
|
*
|
2022-11-02 17:27:07 +08:00
|
|
|
|
* @param id
|
2022-10-31 16:19:42 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public SpecialAddDeductionPO getById(Long id) {
|
|
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
2022-10-31 16:19:42 +08:00
|
|
|
|
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
|
2022-11-02 17:27:07 +08:00
|
|
|
|
SpecialAddDeductionPO byId = mapper.getById(id);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decrypt(byId, SpecialAddDeductionPO.class);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public List<SpecialAddDeductionRecordDTO> listDTOByParam(SpecialAddDeductionQueryParam param) {
|
2022-11-04 15:16:27 +08:00
|
|
|
|
List<SpecialAddDeductionRecordDTO> specialAddDeductionRecordDTOS = mapper().listDtoByParam(param);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decryptList(specialAddDeductionRecordDTOS, SpecialAddDeductionRecordDTO.class);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-04 15:16:27 +08:00
|
|
|
|
|
2022-11-04 09:41:32 +08:00
|
|
|
|
public List<SpecialAddDeductionListDTO> listByParam(SpecialAddDeductionQueryParam param) {
|
2022-11-04 15:16:27 +08:00
|
|
|
|
List<SpecialAddDeductionListDTO> specialAddDeductionListDTOS = mapper().listByParam(param);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decryptList(specialAddDeductionListDTOS, SpecialAddDeductionListDTO.class);
|
2022-11-04 09:41:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<SpecialAddDeductionPO> listByTaxAgentIds(List<Long> taxAgentIds) {
|
|
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
|
|
|
|
|
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
|
|
|
|
|
|
List<SpecialAddDeductionPO> pos = mapper.listByTaxAgentIds(taxAgentIds);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decryptList(pos, SpecialAddDeductionPO.class);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-02 17:27:07 +08:00
|
|
|
|
|
2022-10-31 16:19:42 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public void batchSave(List<SpecialAddDeductionPO> param) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
2022-10-31 16:19:42 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-11-02 17:27:07 +08:00
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
|
|
|
|
|
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
encryptUtil.encryptList(param, SpecialAddDeductionPO.class);
|
2022-11-02 17:27:07 +08:00
|
|
|
|
List<List<SpecialAddDeductionPO>> partition = Lists.partition(param, 100);
|
|
|
|
|
|
partition.forEach(mapper::batchInsert);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public void batchUpdate(List<SpecialAddDeductionPO> param) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
2022-10-31 16:19:42 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
2022-11-02 17:27:07 +08:00
|
|
|
|
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
encryptUtil.encryptList(param, SpecialAddDeductionPO.class);
|
2022-11-02 17:27:07 +08:00
|
|
|
|
List<List<SpecialAddDeductionPO>> partition = Lists.partition(param, 100);
|
|
|
|
|
|
partition.forEach(mapper::updateBatchSelective);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理导入数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param pos
|
|
|
|
|
|
*/
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public void handleImportData(List<SpecialAddDeductionPO> pos) {
|
2022-10-31 16:19:42 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(pos)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-11-02 17:27:07 +08:00
|
|
|
|
SpecialAddDeductionPO po = pos.get(0);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
// 多条相同人的则以第一条为准,如果逆序排列(用于重复的则以最后一条为准)Collections.reverse(pos);
|
|
|
|
|
|
// 去重(通过记录的唯一条件(申报月份,人员id,个税扣缴义务人id)拼接)
|
2022-11-02 17:27:07 +08:00
|
|
|
|
List<SpecialAddDeductionPO> finalPos = pos.stream()
|
|
|
|
|
|
.collect(Collectors.collectingAndThen(
|
2022-11-04 15:16:27 +08:00
|
|
|
|
Collectors.toCollection(() ->
|
|
|
|
|
|
new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))),
|
|
|
|
|
|
ArrayList::new)
|
2022-11-02 17:27:07 +08:00
|
|
|
|
);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
// 查询已有数据
|
2022-11-04 09:41:32 +08:00
|
|
|
|
List<SpecialAddDeductionPO> list = listByTaxAgentIds(null);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
// 待修改的 本地已存在则更新【交集】
|
2022-11-02 17:27:07 +08:00
|
|
|
|
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());
|
2022-10-31 16:19:42 +08:00
|
|
|
|
// 待新增的 导入比本地多,则新增【差集(导入 - local)】
|
2022-11-02 17:27:07 +08:00
|
|
|
|
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());
|
2022-10-31 16:19:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 修改
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(updateList)) {
|
|
|
|
|
|
batchUpdate(updateList);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 保存
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
|
|
|
|
|
batchSave(saveList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @return void
|
2022-11-02 17:27:07 +08:00
|
|
|
|
* @description 批量删除
|
2022-10-31 16:19:42 +08:00
|
|
|
|
*/
|
2022-11-02 17:27:07 +08:00
|
|
|
|
public void batchDeleteByIds(List<Long> deleteIds) {
|
2022-10-31 16:19:42 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(deleteIds)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-11-02 17:27:07 +08:00
|
|
|
|
try (SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession()) {
|
|
|
|
|
|
SpecialAddDeductionMapper mapper = sqlSession.getMapper(SpecialAddDeductionMapper.class);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
List<List<Long>> partition = Lists.partition(deleteIds, 100);
|
2022-11-02 17:27:07 +08:00
|
|
|
|
partition.forEach(mapper::deleteByIds);
|
2022-10-31 16:19:42 +08:00
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-04 15:16:27 +08:00
|
|
|
|
|
|
|
|
|
|
public List<SpecialAddDeductionPO> getByEmployeeId(List<Long> employeeIds, Long taxAgentId) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(employeeIds)) {
|
2022-11-08 13:46:56 +08:00
|
|
|
|
employeeIds = Collections.emptyList();
|
2022-11-04 15:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
return mapper().getByEmployeeIds(employeeIds, taxAgentId)
|
|
|
|
|
|
.stream()
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
.filter(s -> s.getEmployeeId() != null)
|
2022-12-13 13:34:22 +08:00
|
|
|
|
.map(item -> encryptUtil.decrypt(item, SpecialAddDeductionPO.class))
|
2022-11-04 15:16:27 +08:00
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
2022-10-31 16:19:42 +08:00
|
|
|
|
}
|