2022-03-04 10:10:38 +08:00
|
|
|
|
package com.engine.salary.biz;
|
|
|
|
|
|
|
2022-03-07 15:08:56 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpDeduction;
|
|
|
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
2022-03-04 10:10:38 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.dto.AddUpDeductionListDTO;
|
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-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 org.apache.poi.hssf.usermodel.*;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
|
|
|
import weaver.conn.mybatis.MyBatisFactory;
|
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
public class AddUpDeductionBiz extends BaseBean {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-03-07 15:08:56 +08:00
|
|
|
|
* 关联查询查询列表
|
2022-03-04 10:10:38 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<AddUpDeductionListDTO> list(AddUpDeductionQueryParam param) {
|
2022-03-08 13:17:54 +08:00
|
|
|
|
//fixme 入职日期用的创建日期
|
2022-03-04 10:10:38 +08:00
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
2022-03-07 15:08:56 +08:00
|
|
|
|
return mapper.list(param);
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 条件查询
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<AddUpDeduction> listSome(AddUpDeduction param) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
return mapper.listSome(param);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-08 15:40:26 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据id获取
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public AddUpDeduction getById(Long id) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
return mapper.getById(id);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 详情列表
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<AddUpDeductionRecordDTO> recordList(AddUpDeductionQueryParam param){
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
return mapper.recordList(param);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:08:56 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchSave(List<AddUpDeduction> param) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
mapper.insertData(param);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void batchUpdate(List<AddUpDeduction> param) {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
mapper.updateData(param);
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询人员列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<DataCollectionEmployee> listEmployee() {
|
|
|
|
|
|
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class);
|
|
|
|
|
|
return mapper.listEmployee();
|
2022-03-04 10:10:38 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* excel标题
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final static List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人");
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 导出
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public HSSFWorkbook export(AddUpDeductionQueryParam param) {
|
|
|
|
|
|
|
|
|
|
|
|
//获取操作按钮资源
|
|
|
|
|
|
List<List<String>> rowList = getExcelRowList(param);
|
|
|
|
|
|
|
|
|
|
|
|
//获取excel
|
|
|
|
|
|
return getWorkbook(rowList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取excel
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param rowList 行列表
|
|
|
|
|
|
* @return workbook
|
|
|
|
|
|
*/
|
|
|
|
|
|
private HSSFWorkbook getWorkbook(List<List<String>> rowList) {
|
|
|
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置title样式
|
|
|
|
|
|
HSSFCellStyle titleCellStyle = workbook.createCellStyle();
|
|
|
|
|
|
HSSFFont titleFont = workbook.createFont();
|
|
|
|
|
|
titleFont.setFontName("仿宋");
|
|
|
|
|
|
titleFont.setFontHeightInPoints((short) 15);
|
|
|
|
|
|
titleCellStyle.setFont(titleFont);
|
|
|
|
|
|
titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
|
titleCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());//背景色
|
|
|
|
|
|
titleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置主体样式
|
|
|
|
|
|
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
|
|
HSSFFont font = workbook.createFont();
|
|
|
|
|
|
font.setFontName("宋体");
|
|
|
|
|
|
font.setFontHeightInPoints((short) 10);// 设置字体大小
|
|
|
|
|
|
cellStyle.setFont(font);// 选择需要用到的字体格式
|
|
|
|
|
|
cellStyle.setWrapText(true);
|
|
|
|
|
|
|
|
|
|
|
|
HSSFSheet sheet = workbook.createSheet("0");
|
|
|
|
|
|
for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) {
|
|
|
|
|
|
List<String> infoList = rowList.get(rowIndex);
|
|
|
|
|
|
HSSFRow row = sheet.createRow(rowIndex);
|
|
|
|
|
|
for (int cellIndex = 0; cellIndex < infoList.size(); cellIndex++) {
|
|
|
|
|
|
HSSFCell cell = row.createCell(cellIndex);
|
|
|
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
|
|
|
if (rowIndex == 0) {
|
|
|
|
|
|
cell.setCellStyle(titleCellStyle);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
|
|
|
}
|
|
|
|
|
|
cell.setCellValue(infoList.get(cellIndex));
|
|
|
|
|
|
sheet.setColumnWidth(cellIndex, 35 * 256);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return workbook;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取excel数据行
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 导出数据行集合
|
|
|
|
|
|
*/
|
|
|
|
|
|
private List<List<String>> getExcelRowList(AddUpDeductionQueryParam param) {
|
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
List<AddUpDeductionListDTO> list = list(param);
|
|
|
|
|
|
final List<List<String>> dataRowList = Optional.ofNullable(list)
|
|
|
|
|
|
.map(List::stream)
|
|
|
|
|
|
.map(operatorStream -> operatorStream.map(dto -> {
|
|
|
|
|
|
List<String> cellList = new ArrayList<>();
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getUsername()));
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getTaxAgentName()));
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getDepartmentName()));
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getMobile()));
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getJobNum()));
|
|
|
|
|
|
cellList.add(Util.null2String(dto.getIdNo()));
|
2022-03-07 15:08:56 +08:00
|
|
|
|
cellList.add(dto.getHiredate() == null ? "" : formatter.format(dto.getHiredate()));
|
2022-03-04 10:10:38 +08:00
|
|
|
|
cellList.add(String.valueOf(dto.getAddUpChildEducation()));
|
|
|
|
|
|
cellList.add(String.valueOf(dto.getAddUpContinuingEducation()));
|
|
|
|
|
|
cellList.add(String.valueOf(dto.getAddUpHousingLoanInterest()));
|
|
|
|
|
|
cellList.add(String.valueOf(dto.getAddUpHousingRent()));
|
|
|
|
|
|
cellList.add(String.valueOf(dto.getAddUpSupportElderly()));
|
|
|
|
|
|
return cellList;
|
|
|
|
|
|
}).collect(Collectors.toList()))
|
|
|
|
|
|
.orElse(Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
|
|
List<List<String>> rowList = new ArrayList<>();
|
|
|
|
|
|
rowList.add(title);
|
|
|
|
|
|
rowList.addAll(dataRowList);
|
|
|
|
|
|
return rowList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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.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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-04 10:10:38 +08:00
|
|
|
|
}
|