|
@@ -13,6 +13,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
@@ -61,6 +63,10 @@ public class SalaryAttendanceController {
|
|
|
private ISalaryAttendanceHolidayService salaryAttendanceHolidayService;
|
|
|
@Autowired
|
|
|
private ISalaryChangeRecordService salaryChangeRecordService;
|
|
|
+ @Autowired
|
|
|
+ private ISalaryManagementService salaryManagementService;
|
|
|
+ @Autowired
|
|
|
+ private ISalaryManagementExtraService salaryManagementExtraService;
|
|
|
String remarkExcel = "";
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -84,6 +90,149 @@ public class SalaryAttendanceController {
|
|
|
return Result.ok(pageList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ * 福利现金 年终奖
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "导入福利现金或年终奖")
|
|
|
+ @RequestMapping(value = "/importExcelFlNz", method = RequestMethod.POST)
|
|
|
+// @RequiresPermissions("salaryAttendance:importExcel:flj")
|
|
|
+ public Result<?> importExcelFlNz(HttpServletRequest request, HttpServletResponse response, SalaryManagement salaryManagement) throws IOException, InvalidFormatException {
|
|
|
+
|
|
|
+ if (org.apache.commons.lang.StringUtils.isEmpty(salaryManagement.getType())) {
|
|
|
+ return Result.error("参数异常:类型为空!!");
|
|
|
+ }
|
|
|
+ salaryManagement.setYearWithMonth(DateUtils.date_ym());
|
|
|
+// salaryManagement.setYearWithMonth("2024-12");
|
|
|
+
|
|
|
+ if (org.apache.commons.lang.StringUtils.isEmpty(salaryManagement.getId()) || "false".equals(salaryManagement.getId())) {
|
|
|
+
|
|
|
+ QueryWrapper<SalaryManagement> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("del_flag", "0");
|
|
|
+ queryWrapper.eq("year_with_month", salaryManagement.getYearWithMonth());
|
|
|
+ queryWrapper.eq("type", salaryManagement.getType());
|
|
|
+ List<SalaryManagement> list = salaryManagementService.list(queryWrapper);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ return Result.error("系统中已含有" + salaryManagement.getYearWithMonth() + salaryManagement.getType() + ",若要覆盖请选中覆盖上传选项!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("福利现金".equals(salaryManagement.getType())) {
|
|
|
+ QueryWrapper<SalaryManagementExtra> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("del_flag", "0");
|
|
|
+ queryWrapper.eq("year_with_month", salaryManagement.getYearWithMonth());
|
|
|
+ //0福利现金 1年终奖
|
|
|
+ queryWrapper.eq("type", "0");
|
|
|
+ queryWrapper.eq("calculate", "1");
|
|
|
+
|
|
|
+ List<SalaryManagementExtra> list1 = salaryManagementExtraService.list(queryWrapper);
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ return Result.error("系统中" + salaryManagement.getYearWithMonth() + salaryManagement.getType() + "已计算(" + list1.get(0).getCalculateDate() + "),无法覆盖!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果当年12月份工资已计算,则当年12月福利现金不能导入
|
|
|
+ if(DateUtils.formatDate("MM").equals("12")){
|
|
|
+
|
|
|
+ QueryWrapper<SalaryManagement> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("del_flag", "0");
|
|
|
+ queryWrapper2.eq("year_with_month", salaryManagement.getYearWithMonth());
|
|
|
+ queryWrapper2.eq("type", "月度工资单");
|
|
|
+ List<SalaryManagement> list = salaryManagementService.list(queryWrapper2);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ return Result.error("系统中已含有本年度12月月度工资单,无法再生成福利现金!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
+ for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
+ MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(1);
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setNeedSave(false);
|
|
|
+
|
|
|
+ String st = this.ifExist2(file, salaryManagement.getType());
|
|
|
+ if (!"true".equals(st)) {
|
|
|
+ if (st.contains("请")) {
|
|
|
+ return Result.error(st);
|
|
|
+ }
|
|
|
+ return Result.error("未在模板中找到" + st + "字段,请勿增删改导入模板的字段!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ List<SalaryManagementExtra> detailList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<SalaryManagementExtra> list = ExcelImportUtil.importExcel(file.getInputStream(), SalaryManagementExtra.class, params);
|
|
|
+
|
|
|
+ for (SalaryManagementExtra page : list) {
|
|
|
+
|
|
|
+ String name = page.getName();//员工姓名
|
|
|
+ String cardNo = page.getCardNo();//卡号
|
|
|
+ String beforeTaxAmount = page.getBeforeTaxAmount();//税前金额
|
|
|
+
|
|
|
+ if (org.apache.commons.lang.StringUtils.isEmpty(name) || org.apache.commons.lang.StringUtils.isEmpty(cardNo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang.StringUtils.isEmpty(beforeTaxAmount)) {
|
|
|
+ return Result.error("文件导入失败!" + name + "+" + cardNo + "组合,金额(税前)不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ new BigDecimal(beforeTaxAmount);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return Result.error("文件导入失败!" + name + "+" + cardNo + "组合,金额(税前)无转换成数字!");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SalaryChangeRecord> userList = salaryChangeRecordService.selectUserByPar(name.trim(), cardNo.trim());
|
|
|
+ if (userList.size() < 1) {
|
|
|
+ return Result.error("文件导入失败!" + name + "+" + cardNo + "组合,无法在查找到数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SalaryChangeRecord entry = userList.get(0);
|
|
|
+
|
|
|
+ page.setCode(entry.getCode());
|
|
|
+ page.setUserId(entry.getUserId());
|
|
|
+ page.setOrgName(entry.getOrgName());
|
|
|
+ page.setYearWithMonth(salaryManagement.getYearWithMonth());
|
|
|
+
|
|
|
+ if (salaryManagement.getType().equals("福利现金")) {
|
|
|
+ page.setType("0");//福利现金
|
|
|
+ } else {
|
|
|
+ page.setType("1");//年终奖
|
|
|
+ }
|
|
|
+ detailList.add(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detailList.size() > 0) {
|
|
|
+ salaryManagementService.saveMainExtra(salaryManagement, detailList);
|
|
|
+ } else {
|
|
|
+ return Result.error("文件导入失败:导入模板不正确或者导入数据为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.ok("文件导入成功!合法数据行数:" + detailList.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return Result.error("文件导入失败:" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ file.getInputStream().close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.ok("文件导入失败!");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
*
|
|
@@ -267,6 +416,75 @@ public class SalaryAttendanceController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验导入模板是否完整
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String ifExist2(MultipartFile file, String type) throws IOException, InvalidFormatException {
|
|
|
+
|
|
|
+ Workbook workbook = WorkbookFactory.create(file.getInputStream());
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ Iterator<Row> rowIterator = sheet.iterator();
|
|
|
+ List<String> header = new ArrayList<>();
|
|
|
+ List<String> header1 = new ArrayList<>();
|
|
|
+ if (rowIterator.hasNext()) {
|
|
|
+ Row headerRow1 = rowIterator.next();
|
|
|
+ if (rowIterator.hasNext()) {
|
|
|
+ Iterator<Cell> cellIterator = headerRow1.cellIterator();
|
|
|
+ while (cellIterator.hasNext()) {
|
|
|
+ Cell cell = cellIterator.next();
|
|
|
+ try {
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotBlank(cell.getStringCellValue())) {
|
|
|
+ header1.add(cell.getStringCellValue());
|
|
|
+ }
|
|
|
+ } catch (Exception x) {
|
|
|
+ throw new RuntimeException("导入模板中表头字段:" + cell.toString() + "无法与系统匹配!" + x.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Row headerRow = rowIterator.next();
|
|
|
+ if (rowIterator.hasNext()) {
|
|
|
+// headerRow = rowIterator.next();
|
|
|
+ Iterator<Cell> cellIterator = headerRow.cellIterator();
|
|
|
+ while (cellIterator.hasNext()) {
|
|
|
+ Cell cell = cellIterator.next();
|
|
|
+ try {
|
|
|
+ header.add(cell.getStringCellValue());
|
|
|
+ } catch (Exception x) {
|
|
|
+ throw new RuntimeException("导入模板中表头字段:" + cell.toString() + "无法与系统匹配!" + x.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(header1.size() == 0){
|
|
|
+
|
|
|
+ return "请使用正确的导入模板";
|
|
|
+ }
|
|
|
+ if (type.equals("福利现金") && !header1.get(0).equals("福利现金导入模板")) {
|
|
|
+
|
|
|
+ return "请使用福利现金导入模板";
|
|
|
+
|
|
|
+ }
|
|
|
+ if (type.equals("年终奖") && !header1.get(0).equals("年终奖导入模板")) {
|
|
|
+
|
|
|
+ return "请使用年终奖导入模板";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = "姓名,工资卡号,金额";
|
|
|
+ for (String o : fileName.split(",")) {
|
|
|
+ if (!header.contains(o)) {
|
|
|
+ return o;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return "true";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验导入模板是否完整
|
|
|
* @param file
|