|
@@ -1,13 +1,18 @@
|
|
|
package com.xjrsoft.module.personnel.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
|
import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.personnel.dto.AddBasePersonnelLabourCapitalDto;
|
|
|
import com.xjrsoft.module.personnel.dto.BasePersonnelLabourCapitalMonthPageDto;
|
|
|
import com.xjrsoft.module.personnel.dto.BasePersonnelLabourCapitalYearPageDto;
|
|
|
import com.xjrsoft.module.personnel.entity.BasePersonnelLabourCapital;
|
|
@@ -19,12 +24,24 @@ import com.xjrsoft.module.personnel.mapper.BasePersonnelLabourCapitalTitleMapper
|
|
|
import com.xjrsoft.module.personnel.service.IBasePersonnelLabourCapitalService;
|
|
|
import com.xjrsoft.module.personnel.vo.BasePersonnelLabourCapitalMonthPageVo;
|
|
|
import com.xjrsoft.module.personnel.vo.BasePersonnelLabourCapitalYearPageVo;
|
|
|
+import com.xjrsoft.module.weekly.dto.WeeklyDutySchedulePageDto;
|
|
|
+import com.yomahub.liteflow.util.JsonUtil;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -75,6 +92,165 @@ public class BasePersonnelLabourCapitalServiceImpl extends MPJBaseServiceImpl<Ba
|
|
|
return labourCapitalMapper.getYearPage(page, dto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导入工资条数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean importLabourCapitalData(AddBasePersonnelLabourCapitalDto dto, List<Map<Integer, Object>> excelDataList) throws ParseException {
|
|
|
+ //构造数据
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ BasePersonnelLabourCapital basePersonnelLabourCapital = BeanUtil.toBean(dto, BasePersonnelLabourCapital.class);
|
|
|
+ basePersonnelLabourCapital.setDataRow(4);
|
|
|
+ basePersonnelLabourCapital.setPersonnelNameColumn(3);
|
|
|
+ basePersonnelLabourCapital.setAmountToColumn(4);
|
|
|
+ basePersonnelLabourCapital.setIdTypeColumn(0);
|
|
|
+ basePersonnelLabourCapital.setIdNumberColumn(1);
|
|
|
+ basePersonnelLabourCapital.setJobNumberColumn(2);
|
|
|
+ basePersonnelLabourCapital.setDateOfIssue(sdf.parse(dto.getDateOfIssue()));
|
|
|
+
|
|
|
+ //处理表头数据,目前只支持2行表头
|
|
|
+ List<BasePersonnelLabourCapitalTitle> titleList = initTitleList(excelDataList.get(0), excelDataList.get(1), basePersonnelLabourCapital);
|
|
|
+ //读取表内容数据
|
|
|
+ List<BasePersonnelLabourCapitalData> dataList = initDataList(dto, excelDataList, 2);
|
|
|
+
|
|
|
+ //添加表头数据
|
|
|
+ basePersonnelLabourCapital.setBasePersonnelLabourCapitalTitleList(titleList);
|
|
|
+ basePersonnelLabourCapital.setBasePersonnelLabourCapitalDataList(dataList);
|
|
|
+
|
|
|
+ return this.add(basePersonnelLabourCapital);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean importSocialSecurityData(AddBasePersonnelLabourCapitalDto dto, List<Map<Integer, Object>> excelDataList) throws ParseException {
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ BasePersonnelLabourCapital basePersonnelLabourCapital = BeanUtil.toBean(dto, BasePersonnelLabourCapital.class);
|
|
|
+ basePersonnelLabourCapital.setDataRow(4);
|
|
|
+ basePersonnelLabourCapital.setPersonnelNameColumn(3);
|
|
|
+ basePersonnelLabourCapital.setIdTypeColumn(0);
|
|
|
+ basePersonnelLabourCapital.setIdNumberColumn(1);
|
|
|
+ basePersonnelLabourCapital.setJobNumberColumn(2);
|
|
|
+ basePersonnelLabourCapital.setDateOfIssue(sdf.parse(dto.getDateOfIssue()));
|
|
|
+
|
|
|
+ List<BasePersonnelLabourCapitalTitle> titleList = initTitleList(excelDataList.get(0), new LinkedHashMap<>(), basePersonnelLabourCapital);
|
|
|
+ List<BasePersonnelLabourCapitalData> dataList = initDataList(dto, excelDataList, 1);
|
|
|
+
|
|
|
+ //添加表头数据
|
|
|
+ basePersonnelLabourCapital.setBasePersonnelLabourCapitalTitleList(titleList);
|
|
|
+ basePersonnelLabourCapital.setBasePersonnelLabourCapitalDataList(dataList);
|
|
|
+
|
|
|
+ return this.add(basePersonnelLabourCapital);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理教师工资数据
|
|
|
+ * @param excelDataList 表格数据
|
|
|
+ * @return 返回集合
|
|
|
+ */
|
|
|
+ List<BasePersonnelLabourCapitalData> initDataList(AddBasePersonnelLabourCapitalDto dto, List<Map<Integer, Object>> excelDataList, int titleRowNumber){
|
|
|
+ List<BasePersonnelLabourCapitalData> resultList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < excelDataList.size(); i ++){
|
|
|
+ //跳过表头
|
|
|
+ if(i < titleRowNumber){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Integer, Object> datatMap = excelDataList.get(i);
|
|
|
+ BasePersonnelLabourCapitalData data = new BasePersonnelLabourCapitalData();
|
|
|
+ data.setName(datatMap.get(3) == null?null:datatMap.get(3).toString());
|
|
|
+ data.setIdNumber(datatMap.get(1) == null?null:datatMap.get(1).toString());
|
|
|
+ data.setIdType(datatMap.get(0) == null?null:datatMap.get(0).toString());
|
|
|
+ data.setAmountTo(datatMap.get(4) == null?null:datatMap.get(4).toString());
|
|
|
+ data.setJobNumber(datatMap.get(2) == null?null:datatMap.get(2).toString());
|
|
|
+ for (Integer integer : datatMap.keySet()) {
|
|
|
+ Object o = datatMap.get(integer);
|
|
|
+ if(o != null && o.toString().startsWith("(") && o.toString().endsWith(")")){
|
|
|
+ datatMap.put(integer, "-" + o.toString().replace("(", "").replace(")", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String jsonString = JsonUtil.toJsonString(datatMap);
|
|
|
+ jsonString = jsonString.replaceAll("- 0", "-");
|
|
|
+ data.setExtendJson(jsonString);
|
|
|
+ resultList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理表头数据
|
|
|
+ * @param titleRow1 第一行数据
|
|
|
+ * @param titleRow2 第二行数据
|
|
|
+ * @return 返回集合
|
|
|
+ */
|
|
|
+ List<BasePersonnelLabourCapitalTitle> initTitleList(Map<Integer, Object> titleRow1, Map<Integer, Object> titleRow2, BasePersonnelLabourCapital capital){
|
|
|
+ List<BasePersonnelLabourCapitalTitle> resultList = new ArrayList<>();
|
|
|
+ //识别第一行
|
|
|
+ int mergeColumns = 0, mergeRows = 0;
|
|
|
+ for (Integer column : titleRow1.keySet()) {
|
|
|
+ BasePersonnelLabourCapitalTitle title = new BasePersonnelLabourCapitalTitle();
|
|
|
+ Object value = titleRow1.get(column);
|
|
|
+ if(value == null){
|
|
|
+ mergeColumns = 0;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int i = column + 1; i < titleRow1.size(); i ++){
|
|
|
+ Object mergeValue = titleRow1.get(i);
|
|
|
+ if(mergeValue != null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ mergeColumns ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ Object value2 = titleRow2.get(column);
|
|
|
+ if(value2 == null){
|
|
|
+ mergeRows = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ title.setName(value.toString());
|
|
|
+ title.setColumnNumber(column);
|
|
|
+ title.setRowsNumber(capital.getDataRow() - 1);
|
|
|
+ title.setMergeColumns(mergeColumns);
|
|
|
+ title.setMergeRows(mergeRows);
|
|
|
+ resultList.add(title);
|
|
|
+
|
|
|
+ mergeColumns = 0;
|
|
|
+ mergeRows = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //识别第二行
|
|
|
+ for (Integer column : titleRow2.keySet()) {
|
|
|
+ BasePersonnelLabourCapitalTitle title = new BasePersonnelLabourCapitalTitle();
|
|
|
+ Object value = titleRow2.get(column);
|
|
|
+ if(value == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ title.setName(value.toString());
|
|
|
+ title.setColumnNumber(column);
|
|
|
+ title.setRowsNumber(capital.getDataRow());
|
|
|
+ title.setMergeColumns(mergeColumns);
|
|
|
+ title.setMergeRows(mergeRows);
|
|
|
+ resultList.add(title);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export")
|
|
|
+ @ApiOperation(value = "导出")
|
|
|
+ public ResponseEntity<byte[]> exportData(@Valid WeeklyDutySchedulePageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
|
|
|
+ List<BasePersonnelLabourCapital> list = this.list();
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ EasyExcel.write(bot, BasePersonnelLabourCapital.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(list);
|
|
|
+
|
|
|
+ return RT.fileStream(bot.toByteArray(), "BasePersonnelLabourCapital" + ExcelTypeEnum.XLSX.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private String getBpName(Long labourCapitalId, String columnNumber) {
|
|
|
List<BasePersonnelLabourCapitalTitle> bpTitles = capitalTitleMapper.selectList(
|
|
|
Wrappers.<BasePersonnelLabourCapitalTitle>lambdaQuery()
|