2022-03-08 18:10:03 +08:00
|
|
|
|
package com.engine.salary.biz;
|
|
|
|
|
|
|
2022-12-13 10:49:51 +08:00
|
|
|
|
import com.engine.salary.encrypt.EncryptUtil;
|
2022-03-08 18:10:03 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpSituation;
|
2022-03-09 16:40:14 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.AddUpSituationRecordDTO;
|
2022-03-08 18:10:03 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam;
|
|
|
|
|
|
import com.engine.salary.mapper.datacollection.AddUpSituationMapper;
|
2022-05-26 13:41:58 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
2022-03-08 18:10:03 +08:00
|
|
|
|
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 AddUpSituationBiz extends BaseBean {
|
|
|
|
|
|
|
2022-12-13 10:49:51 +08:00
|
|
|
|
private EncryptUtil encryptUtil = new EncryptUtil();
|
2022-03-08 18:10:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 条件查询
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<AddUpSituation> listSome(AddUpSituation param) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
2024-03-14 15:28:14 +08:00
|
|
|
|
if (CollectionUtils.isNotEmpty(param.getEmployeeIds())) {
|
2023-10-20 09:43:04 +08:00
|
|
|
|
List<AddUpSituation> addUpSituations = new ArrayList<>();
|
|
|
|
|
|
List<List<Long>> partition = Lists.partition((List<Long>) param.getEmployeeIds(), 500);
|
2024-03-14 15:28:14 +08:00
|
|
|
|
partition.forEach(l -> {
|
2023-10-20 09:43:04 +08:00
|
|
|
|
param.setEmployeeIds(l);
|
|
|
|
|
|
addUpSituations.addAll(mapper.listSome(param));
|
|
|
|
|
|
});
|
2024-03-14 15:28:14 +08:00
|
|
|
|
return encryptUtil.decryptList(addUpSituations, AddUpSituation.class);
|
|
|
|
|
|
} else {
|
2023-10-20 09:43:04 +08:00
|
|
|
|
List<AddUpSituation> addUpSituations = mapper.listSome(param);
|
|
|
|
|
|
return encryptUtil.decryptList(addUpSituations, AddUpSituation.class);
|
|
|
|
|
|
}
|
2022-03-08 18:10:03 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据id获取
|
2022-03-09 18:58:30 +08:00
|
|
|
|
*
|
2022-03-08 18:10:03 +08:00
|
|
|
|
* @param id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public AddUpSituation getById(Long id) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
AddUpSituation byId = mapper.getById(id);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decrypt(byId, AddUpSituation.class);
|
2022-03-08 18:10:03 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 详情列表
|
2022-03-09 18:58:30 +08:00
|
|
|
|
*
|
2022-03-08 18:10:03 +08:00
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-03-09 18:58:30 +08:00
|
|
|
|
public List<AddUpSituationRecordDTO> recordList(AddUpSituationQueryParam param) {
|
2022-03-09 16:40:14 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
List<AddUpSituationRecordDTO> addUpSituationRecordDTOS = mapper.recordList(param);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
return encryptUtil.decryptList(addUpSituationRecordDTOS, AddUpSituationRecordDTO.class);
|
2022-03-09 16:40:14 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-08 18:10:03 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchSave(List<AddUpSituation> param) {
|
2022-05-26 13:41:58 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-03-08 18:10:03 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
encryptUtil.encryptList(param, AddUpSituation.class);
|
2022-07-13 09:53:11 +08:00
|
|
|
|
List<List<AddUpSituation>> partition = Lists.partition(param, 50);
|
2022-05-26 13:41:58 +08:00
|
|
|
|
partition.forEach(mapper::insertData);
|
2022-03-09 18:58:30 +08:00
|
|
|
|
sqlSession.commit();
|
2022-03-08 18:10:03 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchUpdate(List<AddUpSituation> param) {
|
2022-05-26 13:41:58 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-03-08 18:10:03 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
2022-12-13 13:34:22 +08:00
|
|
|
|
encryptUtil.encryptList(param, AddUpSituation.class);
|
2022-07-13 09:53:11 +08:00
|
|
|
|
List<List<AddUpSituation>> partition = Lists.partition(param, 50);
|
2022-05-26 13:41:58 +08:00
|
|
|
|
partition.forEach(mapper::updateData);
|
2022-03-08 18:10:03 +08:00
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void handleImportData(List<AddUpSituation> pos) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pos)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
AddUpSituation po = pos.get(0);
|
|
|
|
|
|
// 多条相同人的则以第一条为准,如果逆序排列(用于重复的则以最后一条为准)Collections.reverse(pos);
|
|
|
|
|
|
// 去重(通过记录的唯一条件(申报月份,人员id,个税扣缴义务人id)拼接)
|
|
|
|
|
|
List<AddUpSituation> finalPos = pos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))), ArrayList::new));
|
|
|
|
|
|
// 查询已有数据
|
2022-03-09 18:58:30 +08:00
|
|
|
|
List<AddUpSituation> list = listSome(AddUpSituation.builder().taxYearMonth(po.getTaxYearMonth()).build());
|
2022-03-08 18:10:03 +08:00
|
|
|
|
// 待修改的 本地已存在则更新【交集】
|
|
|
|
|
|
List<AddUpSituation> updateList = list.stream().map(m -> {
|
|
|
|
|
|
Optional<AddUpSituation> optional = finalPos.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
|
|
|
|
|
|
AddUpSituation temp = null;
|
|
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
|
|
temp = optional.get();
|
|
|
|
|
|
// 换成本地库的id
|
|
|
|
|
|
temp.setId(m.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
// 待新增的 导入比本地多,则新增【差集(导入 - local)】
|
|
|
|
|
|
List<AddUpSituation> saveList = finalPos.stream().map(m -> {
|
|
|
|
|
|
Optional<AddUpSituation> optional = list.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
|
|
|
|
|
|
AddUpSituation temp = null;
|
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
|
temp = m;
|
|
|
|
|
|
}
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 修改
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(updateList)) {
|
|
|
|
|
|
batchUpdate(updateList);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 保存
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
|
|
|
|
|
batchSave(saveList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-28 14:08:27 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return void
|
2024-03-14 15:28:14 +08:00
|
|
|
|
* @description 批量删除数据
|
2022-10-28 14:08:27 +08:00
|
|
|
|
* @author Harryxzy
|
|
|
|
|
|
* @date 2022/10/27 22:39
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchDeleteByIDS(List<Long> deleteIds) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(deleteIds)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpSituationMapper mapper = sqlSession.getMapper(AddUpSituationMapper.class);
|
|
|
|
|
|
List<List<Long>> partition = Lists.partition(deleteIds, 100);
|
|
|
|
|
|
partition.forEach(mapper::deleteData);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-08 18:10:03 +08:00
|
|
|
|
}
|