2022-03-04 10:10:38 +08:00
|
|
|
|
package com.engine.salary.biz;
|
|
|
|
|
|
|
2022-12-12 09:37:15 +08:00
|
|
|
|
import com.engine.salary.encrypt.EncryptUtil;
|
2022-05-31 11:45:43 +08:00
|
|
|
|
import com.engine.salary.encrypt.datacollection.AddUpDeductionEncrypt;
|
|
|
|
|
|
import com.engine.salary.encrypt.datacollection.AddUpDeductionRecordStrDTOEncrypt;
|
|
|
|
|
|
import com.engine.salary.encrypt.datacollection.AddUpDeductionStrDTOEncrypt;
|
2022-03-07 15:08:56 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpDeduction;
|
2022-03-08 18:10:03 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO;
|
2022-03-08 15:40:26 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO;
|
2022-03-04 10:10:38 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam;
|
|
|
|
|
|
import com.engine.salary.mapper.datacollection.AddUpDeductionMapper;
|
2022-05-26 13:41:58 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
2022-03-07 15:08:56 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-03-04 10:10:38 +08:00
|
|
|
|
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 AddUpDeductionBiz extends BaseBean {
|
|
|
|
|
|
|
2022-12-12 09:37:15 +08:00
|
|
|
|
private final EncryptUtil encryptUtil = new EncryptUtil();
|
|
|
|
|
|
|
2022-03-04 10:10:38 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2022-03-07 15:08:56 +08:00
|
|
|
|
* 关联查询查询列表
|
2022-03-04 10:10:38 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-03-08 18:10:03 +08:00
|
|
|
|
public List<AddUpDeductionDTO> list(AddUpDeductionQueryParam param) {
|
2022-03-04 10:10:38 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-06-10 16:43:38 +08:00
|
|
|
|
List<AddUpDeductionDTO> list = mapper.list(param);
|
2022-06-23 14:08:55 +08:00
|
|
|
|
AddUpDeductionStrDTOEncrypt.decryptAddUpDeductionList(list);
|
|
|
|
|
|
return list;
|
2022-03-07 15:08:56 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 条件查询
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<AddUpDeduction> listSome(AddUpDeduction param) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
List<AddUpDeduction> addUpDeductions = mapper.listSome(param);
|
2022-12-12 09:37:15 +08:00
|
|
|
|
return encryptUtil.decryptList(addUpDeductions, AddUpDeduction.class);
|
2022-03-07 15:08:56 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-08 15:40:26 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据id获取
|
2022-03-10 11:09:08 +08:00
|
|
|
|
*
|
2022-03-08 15:40:26 +08:00
|
|
|
|
* @param id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public AddUpDeduction getById(Long id) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
AddUpDeduction byId = mapper.getById(id);
|
|
|
|
|
|
return AddUpDeductionEncrypt.decryptAddUpDeduction(byId);
|
2022-03-08 15:40:26 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 详情列表
|
2022-03-10 11:09:08 +08:00
|
|
|
|
*
|
2022-03-08 15:40:26 +08:00
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2022-03-10 11:09:08 +08:00
|
|
|
|
public List<AddUpDeductionRecordDTO> recordList(AddUpDeductionQueryParam param) {
|
2022-03-08 15:40:26 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-06-10 16:43:38 +08:00
|
|
|
|
List<AddUpDeductionRecordDTO> addUpDeductionRecordStrDTOS = mapper.recordList(param);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
return AddUpDeductionRecordStrDTOEncrypt.decryptAddUpDeductionRecordDTO(addUpDeductionRecordStrDTOS);
|
2022-03-08 15:40:26 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:08:56 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchSave(List<AddUpDeduction> param) {
|
2022-05-26 13:41:58 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-03-07 15:08:56 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
AddUpDeductionEncrypt.encryptAddUpDeductionList(param);
|
2022-05-26 13:41:58 +08:00
|
|
|
|
List<List<AddUpDeduction>> partition = Lists.partition(param, 100);
|
|
|
|
|
|
partition.forEach(mapper::insertData);
|
2022-03-10 11:09:08 +08:00
|
|
|
|
sqlSession.commit();
|
2022-03-07 15:08:56 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchUpdate(List<AddUpDeduction> param) {
|
2022-05-26 13:41:58 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(param)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-03-07 15:08:56 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
AddUpDeductionEncrypt.encryptAddUpDeductionList(param);
|
2022-05-26 13:41:58 +08:00
|
|
|
|
List<List<AddUpDeduction>> partition = Lists.partition(param, 100);
|
|
|
|
|
|
partition.forEach(mapper::updateData);
|
2022-03-07 15:08:56 +08:00
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-10 11:09:08 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 处理导入数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param pos
|
|
|
|
|
|
*/
|
2022-03-07 15:08:56 +08:00
|
|
|
|
public void handleImportData(List<AddUpDeduction> pos) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pos)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
AddUpDeduction po = pos.get(0);
|
|
|
|
|
|
// 多条相同人的则以第一条为准,如果逆序排列(用于重复的则以最后一条为准)Collections.reverse(pos);
|
|
|
|
|
|
// 去重(通过记录的唯一条件(申报月份,人员id,个税扣缴义务人id)拼接)
|
|
|
|
|
|
List<AddUpDeduction> finalPos = pos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getEmployeeId() + "-" + f.getTaxAgentId()))), ArrayList::new));
|
|
|
|
|
|
// 查询已有数据
|
|
|
|
|
|
List<AddUpDeduction> list = listSome(AddUpDeduction.builder().declareMonth(po.getDeclareMonth()).build());
|
|
|
|
|
|
// 待修改的 本地已存在则更新【交集】
|
|
|
|
|
|
List<AddUpDeduction> updateList = list.stream().map(m -> {
|
|
|
|
|
|
Optional<AddUpDeduction> optional = finalPos.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
|
|
|
|
|
|
AddUpDeduction temp = null;
|
|
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
|
|
temp = optional.get();
|
|
|
|
|
|
// 换成本地库的id
|
|
|
|
|
|
temp.setId(m.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
// 待新增的 导入比本地多,则新增【差集(导入 - local)】
|
|
|
|
|
|
List<AddUpDeduction> saveList = finalPos.stream().map(m -> {
|
|
|
|
|
|
Optional<AddUpDeduction> optional = list.stream().filter(p -> (p.getEmployeeId() + "-" + p.getTaxAgentId()).equals(m.getEmployeeId() + "-" + m.getTaxAgentId())).findFirst();
|
|
|
|
|
|
AddUpDeduction 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 记录操作日志
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 13:59:11 +08:00
|
|
|
|
public void batchDeleteByIDS(List<Long> ids) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
List<List<Long>> partition = Lists.partition(ids, 100);
|
|
|
|
|
|
partition.forEach(mapper::deleteData);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-04 10:10:38 +08:00
|
|
|
|
}
|