Commit 4562d71f authored by Fuzy's avatar Fuzy

修改通用导入和对照方法

parent bc395282
......@@ -26,8 +26,8 @@ public class WagesCompilationController {
* @return
*/
@PostMapping("/excel")
public AjaxResult readExcel(@RequestParam("file") MultipartFile file) {
wagesCompilationService.readExcel(file);
public AjaxResult readExcel(@RequestParam("file") MultipartFile file, String type, String mineId) {
wagesCompilationService.readExcel(file, type, mineId);
return AjaxResult.success();
}
......
package com.ruoyi.system.mapper;
import com.ruoyi.system.model.wages.dao.WagesDetailsOriginalExcelDAO;
import com.ruoyi.system.model.wages.dao.WagesOverviewOriginalExcelDAO;
import com.ruoyi.system.model.wages.dao.WagesSalaryProof;
import com.ruoyi.system.model.wages.dao.*;
import com.ruoyi.system.model.wages.vo.WagesOverviewOriginalDataVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -30,4 +28,6 @@ public interface WagesMapper {
void deleteOverviewToDate(@Param("date") String date);
void deleteDetailsToDate(@Param("date") String date);
WagesCompilationExcelDAO selectComparationToVersionId(String s);
}
package com.ruoyi.system.mapper;
import com.ruoyi.system.model.wages.dao.WagesVersionDAO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -11,4 +12,12 @@ import java.util.List;
public interface WagesVersionMapper {
List<WagesVersionDAO> selectByVersionId();
List<String> selectByVersionIdToMineId(String mineId);
void updateByWagesVersionToTypeAndMineId(@Param("type") String type, @Param("mineId") String mineId);
void insertWagesVersion(@Param("type") String type, @Param("id") String mineId);
String selectByWagesVersionToTypeAndMineId(@Param("type") String type, @Param("id") String mineId);
}
......@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
/**
* @author haiwe
......@@ -464,5 +466,16 @@ public class WagesCompilationExcelDAO {
*/
private Integer versionId;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WagesCompilationExcelDAO that = (WagesCompilationExcelDAO) o;
return comparisonId == that.comparisonId && Objects.equals(a1, that.a1) && Objects.equals(a2, that.a2) && Objects.equals(a3, that.a3) && Objects.equals(a4, that.a4) && Objects.equals(a5, that.a5) && Objects.equals(a6, that.a6) && Objects.equals(a7, that.a7) && Objects.equals(a8, that.a8) && Objects.equals(a9, that.a9) && Objects.equals(a10, that.a10) && Objects.equals(a11, that.a11) && Objects.equals(a12, that.a12) && Objects.equals(a13, that.a13) && Objects.equals(a14, that.a14) && Objects.equals(a15, that.a15) && Objects.equals(a16, that.a16) && Objects.equals(a17, that.a17) && Objects.equals(a18, that.a18) && Objects.equals(a19, that.a19) && Objects.equals(a20, that.a20) && Objects.equals(a21, that.a21) && Objects.equals(a22, that.a22) && Objects.equals(a23, that.a23) && Objects.equals(a24, that.a24) && Objects.equals(a25, that.a25) && Objects.equals(a26, that.a26) && Objects.equals(a27, that.a27) && Objects.equals(a28, that.a28) && Objects.equals(a29, that.a29) && Objects.equals(a30, that.a30) && Objects.equals(a31, that.a31) && Objects.equals(a32, that.a32) && Objects.equals(a33, that.a33) && Objects.equals(a34, that.a34) && Objects.equals(a35, that.a35) && Objects.equals(a36, that.a36) && Objects.equals(a37, that.a37) && Objects.equals(a38, that.a38) && Objects.equals(a39, that.a39) && Objects.equals(a40, that.a40) && Objects.equals(a41, that.a41) && Objects.equals(a42, that.a42) && Objects.equals(a43, that.a43) && Objects.equals(a44, that.a44) && Objects.equals(a45, that.a45) && Objects.equals(a46, that.a46) && Objects.equals(a47, that.a47) && Objects.equals(a48, that.a48) && Objects.equals(a49, that.a49) && Objects.equals(a50, that.a50) && Objects.equals(a51, that.a51) && Objects.equals(a52, that.a52) && Objects.equals(a53, that.a53) && Objects.equals(a54, that.a54) && Objects.equals(a55, that.a55) && Objects.equals(a56, that.a56) && Objects.equals(a57, that.a57) && Objects.equals(a58, that.a58) && Objects.equals(a59, that.a59) && Objects.equals(a60, that.a60) && Objects.equals(a61, that.a61) && Objects.equals(a62, that.a62) && Objects.equals(a63, that.a63) && Objects.equals(a64, that.a64) && Objects.equals(a65, that.a65) && Objects.equals(a66, that.a66) && Objects.equals(a67, that.a67) && Objects.equals(a68, that.a68) && Objects.equals(a69, that.a69) && Objects.equals(a70, that.a70) && Objects.equals(a71, that.a71) && Objects.equals(a72, that.a72) && Objects.equals(a73, that.a73) && Objects.equals(a74, that.a74) && Objects.equals(a75, that.a75) && Objects.equals(a76, that.a76) && Objects.equals(a77, that.a77) && Objects.equals(a78, that.a78) && Objects.equals(a79, that.a79) && Objects.equals(a80, that.a80) && Objects.equals(a81, that.a81) && Objects.equals(a82, that.a82) && Objects.equals(a83, that.a83) && Objects.equals(a84, that.a84) && Objects.equals(a85, that.a85) && Objects.equals(a86, that.a86) && Objects.equals(a87, that.a87) && Objects.equals(a88, that.a88) && Objects.equals(a89, that.a89) && Objects.equals(a90, that.a90) && Objects.equals(a91, that.a91) && Objects.equals(a92, that.a92) && Objects.equals(a93, that.a93) && Objects.equals(a94, that.a94) && Objects.equals(a95, that.a95) && Objects.equals(a96, that.a96) && Objects.equals(a97, that.a97) && Objects.equals(a98, that.a98) && Objects.equals(a99, that.a99) && Objects.equals(a100, that.a100) && Objects.equals(a101, that.a101) && Objects.equals(a102, that.a102) && Objects.equals(a103, that.a103) && Objects.equals(a104, that.a104) && Objects.equals(a105, that.a105) && Objects.equals(a106, that.a106) && Objects.equals(a107, that.a107) && Objects.equals(a108, that.a108) && Objects.equals(a109, that.a109) && Objects.equals(a110, that.a110) && Objects.equals(a111, that.a111) && Objects.equals(a112, that.a112) && Objects.equals(a113, that.a113) && Objects.equals(a114, that.a114) && Objects.equals(a115, that.a115) && Objects.equals(a116, that.a116) && Objects.equals(a117, that.a117) && Objects.equals(a118, that.a118) && Objects.equals(a119, that.a119) && Objects.equals(a120, that.a120) && Objects.equals(a121, that.a121) && Objects.equals(a122, that.a122) && Objects.equals(a123, that.a123) && Objects.equals(a124, that.a124) && Objects.equals(a125, that.a125) && Objects.equals(a126, that.a126) && Objects.equals(a127, that.a127) && Objects.equals(a128, that.a128) && Objects.equals(a129, that.a129) && Objects.equals(a130, that.a130) && Objects.equals(a131, that.a131) && Objects.equals(a132, that.a132) && Objects.equals(a133, that.a133) && Objects.equals(a134, that.a134) && Objects.equals(a135, that.a135) && Objects.equals(a136, that.a136) && Objects.equals(a137, that.a137) && Objects.equals(a138, that.a138) && Objects.equals(a139, that.a139) && Objects.equals(a140, that.a140) && Objects.equals(a141, that.a141) && Objects.equals(a142, that.a142) && Objects.equals(a143, that.a143) && Objects.equals(a144, that.a144) && Objects.equals(a145, that.a145) && Objects.equals(a146, that.a146) && Objects.equals(a147, that.a147) && Objects.equals(a148, that.a148) && Objects.equals(a149, that.a149) && Objects.equals(a150, that.a150) && Objects.equals(a151, that.a151) && Objects.equals(a152, that.a152) && Objects.equals(a153, that.a153) && Objects.equals(a154, that.a154) && Objects.equals(a155, that.a155) && Objects.equals(a156, that.a156) && Objects.equals(a157, that.a157) && Objects.equals(a158, that.a158) && Objects.equals(a159, that.a159) && Objects.equals(a160, that.a160) && Objects.equals(a161, that.a161) && Objects.equals(a162, that.a162) && Objects.equals(a163, that.a163) && Objects.equals(a164, that.a164) && Objects.equals(a165, that.a165) && Objects.equals(a166, that.a166) && Objects.equals(a167, that.a167) && Objects.equals(a168, that.a168) && Objects.equals(a169, that.a169) && Objects.equals(a170, that.a170) && Objects.equals(a171, that.a171) && Objects.equals(a172, that.a172) && Objects.equals(a173, that.a173) && Objects.equals(a174, that.a174) && Objects.equals(a175, that.a175) && Objects.equals(a176, that.a176) && Objects.equals(a177, that.a177) && Objects.equals(a178, that.a178) && Objects.equals(a179, that.a179) && Objects.equals(a180, that.a180) && Objects.equals(mineId, that.mineId) && Objects.equals(type, that.type) && Objects.equals(versionId, that.versionId);
}
@Override
public int hashCode() {
return Objects.hash(comparisonId, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64, a65, a66, a67, a68, a69, a70, a71, a72, a73, a74, a75, a76, a77, a78, a79, a80, a81, a82, a83, a84, a85, a86, a87, a88, a89, a90, a91, a92, a93, a94, a95, a96, a97, a98, a99, a100, a101, a102, a103, a104, a105, a106, a107, a108, a109, a110, a111, a112, a113, a114, a115, a116, a117, a118, a119, a120, a121, a122, a123, a124, a125, a126, a127, a128, a129, a130, a131, a132, a133, a134, a135, a136, a137, a138, a139, a140, a141, a142, a143, a144, a145, a146, a147, a148, a149, a150, a151, a152, a153, a154, a155, a156, a157, a158, a159, a160, a161, a162, a163, a164, a165, a166, a167, a168, a169, a170, a171, a172, a173, a174, a175, a176, a177, a178, a179, a180, mineId, type, versionId);
}
}
......@@ -16,7 +16,7 @@ public interface WagesCompilationService {
* 读取表头数据到数据
* @param file
*/
void readExcel(MultipartFile file);
void readExcel(MultipartFile file, String type, String mineId);
List<WagesCompilationExcelDAO> list();
......
......@@ -9,6 +9,7 @@ import com.ruoyi.system.model.wages.dao.WagesCompilationExcelDAO;
import com.ruoyi.system.service.WagesCompilationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
......@@ -18,6 +19,7 @@ import java.util.List;
/**
* @author haiwe
* @date 2024/6/7
* 对照表
*/
@RequiredArgsConstructor
@Service
......@@ -25,29 +27,24 @@ public class WagesCompilationServiceImpl implements WagesCompilationService {
private final WagesCompilationMapper wagesCompilationMapper;
private final WagesVersionMapper wagesVersionMapper;
@Override
public void readExcel(MultipartFile file) {
@Transactional
/**
* 导入对照表及生产版本,只读sheet1,不支持同时导入多个版本
*/
public void readExcel(MultipartFile file, String type, String mineId) {
try {
wagesVersionMapper.updateByWagesVersionToTypeAndMineId(type, mineId);
wagesVersionMapper.insertWagesVersion(type, mineId);
String vId = wagesVersionMapper.selectByWagesVersionToTypeAndMineId(type, mineId);
InputStream inputStream = file.getInputStream();
List<WagesCompilationExcelDAO> wagesList = EasyExcelFactory.read(inputStream, WagesCompilationExcelDAO.class, new ExcelListener<WagesCompilationExcelDAO>()).sheet(0).headRowNumber(1).doReadSync();
inputStream.close();
InputStream inputStream1 = file.getInputStream();
List<WagesCompilationExcelDAO> financeWagesList = EasyExcelFactory.read(inputStream1, WagesCompilationExcelDAO.class, new ExcelListener<WagesCompilationExcelDAO>()).sheet(1).headRowNumber(1).doReadSync();
inputStream1.close();
WagesCompilationExcelDAO wagesHeader = wagesList.get(0);
WagesCompilationExcelDAO financeWagesHeader = financeWagesList.get(0);
wagesHeader.setMineId("011704");
wagesHeader.setType("0");
financeWagesHeader.setMineId("011704");
financeWagesHeader.setType("1");
wagesHeader.setMineId(mineId);
wagesHeader.setType(type);
wagesHeader.setVersionId(Integer.valueOf(vId));
wagesCompilationMapper.insertBatch(wagesHeader);
wagesCompilationMapper.insertBatch(financeWagesHeader);
} catch (IOException e) {
throw new RuntimeException(e);
}
......
......@@ -2,7 +2,6 @@ package com.ruoyi.system.service.impl;
import com.ruoyi.system.mapper.WagesConversionMapper;
import com.ruoyi.system.model.wages.dao.WagesConversionData;
import com.ruoyi.system.model.wages.dto.WagesConversionDataDto;
import com.ruoyi.system.model.wages.dto.WagesParamsDto;
import com.ruoyi.system.model.wages.vo.WagesConversionDataVO;
import com.ruoyi.system.service.WagesConversionService;
......
......@@ -10,6 +10,7 @@ import com.ruoyi.system.listener.ExcelListener;
import com.ruoyi.system.mapper.WagesDetailsMapper;
import com.ruoyi.system.mapper.WagesMapper;
import com.ruoyi.system.mapper.WagesSalaryProofMapper;
import com.ruoyi.system.mapper.WagesVersionMapper;
import com.ruoyi.system.model.doc.CustomDocRequestModel;
import com.ruoyi.system.model.wages.dao.*;
import com.ruoyi.system.model.wages.vo.WagesOverviewOriginalDataVO;
......@@ -17,6 +18,10 @@ import com.ruoyi.system.service.WagesService;
import com.ruoyi.system.utils.WagesUtils;
import com.ruoyi.system.yyinterface.VoucherUtils;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,6 +33,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -45,6 +51,7 @@ public class WagesServiceImpl implements WagesService {
private final WagesDetailsMapper wagesDetailsMapper;
private final WagesDetailsMapper detailsMapper;
private final WagesUtils wagesUtils;
private final WagesVersionMapper wagesVersionMapper;
@Transactional
@Override
......@@ -218,30 +225,65 @@ public class WagesServiceImpl implements WagesService {
}
@Override
/**
* 通用导入
*/
public String linXiExcelAnalysisWages(MultipartFile file, String date, String mineId) {
try {
Integer comparisonId = wagesUtils.getComparisonId(mineId, "0");
detailsMapper.deleteBatch(mineId, date, comparisonId);
comparisonId = wagesUtils.getComparisonId(mineId, "1");
detailsMapper.deleteBatch(mineId, date, comparisonId);
// 查询有效(启用)的版本id
List<String> list = wagesVersionMapper.selectByVersionIdToMineId(mineId);
// 查询所有有效的对照信息
List<WagesCompilationExcelDAO> lists = new ArrayList<>();
List<WagesCompilationExcelDAO> listsCopy = new ArrayList<>();
for (String s : list) {
lists.add(wagesMapper.selectComparationToVersionId(s));
listsCopy.add(wagesMapper.selectComparationToVersionId(s));
}
// 判断有效的sheet页
InputStream inputStream2 = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream2);
int numberOfSheets = workbook.getNumberOfSheets();
// 计数器
int a = 0;
for (int i = 0; i < numberOfSheets; i++) {
Sheet sheetAt = workbook.getSheetAt(i);
Row row = sheetAt.getRow(1);
if (row != null) {
a++;
}
}
numberOfSheets = a;
inputStream2.close();
// 按sheet页顺序给对应的对照表id排序
LinkedList<Integer> idList = new LinkedList<>();
for (int i = 0; i < numberOfSheets; i++) {
InputStream inputStream = file.getInputStream();
WagesCompilationExcelDAO wages = (WagesCompilationExcelDAO) EasyExcelFactory.read(inputStream, WagesCompilationExcelDAO.class, new ExcelListener<WagesCompilationExcelDAO>()).sheet(i).headRowNumber(1).doReadSync().get(0);
Integer[] j = {0};
lists.stream().forEach(v -> {
idList.add(listsCopy.get(j[0]).getComparisonId());
j[0]++;
v.setMineId(null);
v.setComparisonId(0);
v.setType(null);
v.setVersionId(null);
if (!v.equals(wages)) idList.removeLast();
});
}
// 添加
List<String> filterList = Arrays.asList("小计", "合计", "总计");
InputStream inputStream = file.getInputStream();
List<WagesDetailsExcelDAO> wagesList = EasyExcelFactory.read(inputStream, WagesDetailsExcelDAO.class, new ExcelListener<WagesDetailsExcelDAO>()).sheet(0).headRowNumber(2).doReadSync();
inputStream.close();
Integer comparisonId1 = wagesUtils.getComparisonId(mineId, "0");
InputStream inputStream1 = file.getInputStream();
List<WagesDetailsExcelDAO> financeWagesList = EasyExcelFactory.read(inputStream1, WagesDetailsExcelDAO.class, new ExcelListener<WagesDetailsExcelDAO>()).sheet(1).headRowNumber(2).doReadSync();
inputStream1.close();
Integer comparisonId2 = wagesUtils.getComparisonId(mineId, "1");
wagesList = wagesList.parallelStream()
.filter(v -> !filterList.contains(v.getA1()))
.peek(v -> v.setComparisonId(comparisonId1)).collect(Collectors.toList());
financeWagesList = financeWagesList.parallelStream()
.filter(v -> !filterList.contains(v.getA1()))
.peek(v -> v.setComparisonId(comparisonId2)).collect(Collectors.toList());
wagesDetailsMapper.insertBatch(date, wagesList, mineId);
wagesDetailsMapper.insertBatch(date, financeWagesList, mineId);
} catch (IOException e) {
for (int i = 0; i < idList.size(); i++) {
Integer integer = idList.get(i);
detailsMapper.deleteBatch(mineId, date, integer);
InputStream inputStream = file.getInputStream();
List<WagesDetailsExcelDAO> wagesList = EasyExcelFactory.read(inputStream, WagesDetailsExcelDAO.class, new ExcelListener<WagesDetailsExcelDAO>()).sheet(i).headRowNumber(2).doReadSync();
inputStream.close();
wagesList = wagesList.parallelStream()
.filter(v -> !filterList.contains(v.getA1()))
.peek(v -> v.setComparisonId(integer)).collect(Collectors.toList());
wagesDetailsMapper.insertBatch(date, wagesList, mineId);
}
} catch (Exception e) {
e.printStackTrace();
}
return "完成";
......
......@@ -117,4 +117,26 @@
total_salary_disbursement as totalSalaryDisbursement
from wages_details_original_data
</select>
<select id="selectComparationToVersionId"
resultType="com.ruoyi.system.model.wages.dao.WagesCompilationExcelDAO">
select comparison_id as comparisonId
, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25,
a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38,
a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51,
a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64,
a65, a66, a67, a68, a69, a70, a71, a72, a73, a74, a75, a76, a77,
a78, a79, a80, a81, a82, a83, a84, a85, a86, a87, a88, a89, a90,
a91, a92, a93, a94, a95, a96, a97, a98, a99, a100, a101, a102, a103,
a104, a105, a106, a107, a108, a109, a110, a111, a112, a113, a114,
a115, a116, a117, a118, a119, a120, a121, a122, a123, a124, a125,
a126, a127, a128, a129, a130, a131, a132, a133, a134, a135, a136,
a137, a138, a139, a140, a141, a142, a143, a144, a145, a146, a147,
a148, a149, a150, a151, a152, a153, a154, a155, a156, a157, a158,
a159, a160, a161, a162, a163, a164, a165, a166, a167, a168, a169,
a170, a171, a172, a173, a174, a175, a176, a177, a178, a179, a180
,mine_id as mineId, type, version_id as versionId
from wages_comparation_vertical
where version_id = #{s}
</select>
</mapper>
\ No newline at end of file
......@@ -8,16 +8,33 @@
<result property="versionId" column="version_id" />
<result property="version" column="version" />
<result property="openOrClose" column="open_or_close" />
<result property="beginTime" column="begin_time" />
<result property="endTime" column="end_time" />
</resultMap>
<sql id="selectWagesVersionVo">
select version_id, version, open_or_close, begin_time, end_time, create_time from wages_version
select version_id, version, open_or_close, create_time from wages_version
</sql>
<insert id="insertWagesVersion">
insert into wages_version (open_or_close, mine_id, type)
values ('1', #{id}, #{type});
</insert>
<update id="updateByWagesVersionToTypeAndMineId">
update wages_version
set open_or_close = '0'
where type = #{type} and mine_id = #{mindId};
</update>
<select id="selectByVersionId" resultMap="WagesVersionResult">
<include refid="selectWagesVersionVo"/>
</select>
<select id="selectByVersionIdToMineId" resultType="java.lang.String">
select version_id
from wages_version
where mine_id = #{mindId} and open_or_close = '1'
</select>
<select id="selectByWagesVersionToTypeAndMineId" resultType="java.lang.String">
select version_id
from wages_version
where mine_id = #{id} and open_or_close = '1' and type = #{type}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment