198 lines
7.1 KiB
Java
198 lines
7.1 KiB
Java
package com.engine.salary.biz;
|
||
|
||
import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO;
|
||
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.mapper.datacollection.OtherDeductionMapper;
|
||
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 OtherDeductionBiz extends BaseBean {
|
||
|
||
|
||
/**
|
||
* 关联查询查询列表
|
||
*
|
||
* @param param
|
||
* @return
|
||
*/
|
||
public List<OtherDeductionListDTO> list(OtherDeductionQueryParam param) {
|
||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||
try {
|
||
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
|
||
return mapper.list(param);
|
||
|
||
} finally {
|
||
sqlSession.close();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 条件查询
|
||
*
|
||
* @param param
|
||
* @return
|
||
*/
|
||
public List<OtherDeductionPO> listSome(OtherDeductionPO param) {
|
||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||
try {
|
||
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
|
||
return mapper.listSome(param);
|
||
} finally {
|
||
sqlSession.close();
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 根据id获取
|
||
*
|
||
* @param id
|
||
* @return
|
||
*/
|
||
public OtherDeductionPO getById(Long id) {
|
||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||
try {
|
||
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
|
||
return mapper.getById(id);
|
||
} finally {
|
||
sqlSession.close();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 详情列表
|
||
*
|
||
* @param param
|
||
* @return
|
||
*/
|
||
public List<OtherDeductionRecordDTO> recordList(OtherDeductionQueryParam param) {
|
||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||
try {
|
||
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
|
||
return mapper.recordList(param);
|
||
} finally {
|
||
sqlSession.close();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 批量插入
|
||
*
|
||
* @param param
|
||
* @return
|
||
*/
|
||
public void batchSave(List<OtherDeductionPO> param) {
|
||
if(CollectionUtils.isEmpty(param)){
|
||
return;
|
||
}
|
||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||
try {
|
||
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
|
||
List<List<OtherDeductionPO>> partition = Lists.partition(param, 100);
|
||
partition.forEach(mapper::insertData);
|
||
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);
|
||
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) {
|
||
if (CollectionUtils.isEmpty(pos)) {
|
||
return;
|
||
}
|
||
OtherDeductionPO 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<OtherDeductionPO> list = listSome(OtherDeductionPO.builder().declareMonth(po.getDeclareMonth()).build());
|
||
// 待修改的 本地已存在则更新【交集】
|
||
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());
|
||
// 待新增的 导入比本地多,则新增【差集(导入 - 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());
|
||
|
||
// 修改
|
||
if (CollectionUtils.isNotEmpty(updateList)) {
|
||
batchUpdate(updateList);
|
||
}
|
||
// 保存
|
||
if (CollectionUtils.isNotEmpty(saveList)) {
|
||
batchSave(saveList);
|
||
}
|
||
// 记录操作日志
|
||
// saveList.addAll(updateList);
|
||
//
|
||
// if (CollectionUtils.isNotEmpty(saveList)) {
|
||
// LoggerContext loggerContext = new LoggerContext();
|
||
// loggerContext.setTargetId(String.valueOf(IdGenerator.generate()));
|
||
// 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);
|
||
// }
|
||
}
|
||
|
||
|
||
}
|