作者 雷海东

工资计算和导入

@@ -257,6 +257,9 @@ public class JeecgController<T, S extends IService<T>> { @@ -257,6 +257,9 @@ public class JeecgController<T, S extends IService<T>> {
257 long start = System.currentTimeMillis(); 257 long start = System.currentTimeMillis();
258 service.saveBatch(dataListToSave); 258 service.saveBatch(dataListToSave);
259 log.info("批量保存消耗时间:" + (System.currentTimeMillis() - start) + "毫秒"); 259 log.info("批量保存消耗时间:" + (System.currentTimeMillis() - start) + "毫秒");
  260 + if(dataListToSave.size()<=0){
  261 + return Result.error("没有有效的导入数据");
  262 + }
260 return Result.ok("文件导入成功!数据行数:" + dataListToSave.size()); 263 return Result.ok("文件导入成功!数据行数:" + dataListToSave.size());
261 } else { 264 } else {
262 return Result.error("文件导入失败:没有有效的数据需要保存!"); 265 return Result.error("文件导入失败:没有有效的数据需要保存!");
@@ -18,9 +18,14 @@ import org.jeecgframework.poi.excel.entity.ExportParams; @@ -18,9 +18,14 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
18 import org.jeecgframework.poi.excel.entity.ImportParams; 18 import org.jeecgframework.poi.excel.entity.ImportParams;
19 import org.jeecgframework.poi.excel.entity.enmus.ExcelType; 19 import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
20 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; 20 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
  21 +import org.jeecgframework.poi.exception.excel.ExcelImportException;
21 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.beans.factory.annotation.Value; 23 import org.springframework.beans.factory.annotation.Value;
  24 +import org.springframework.transaction.TransactionStatus;
  25 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  26 +import org.springframework.transaction.annotation.Transactional;
23 import org.springframework.transaction.interceptor.TransactionAspectSupport; 27 import org.springframework.transaction.interceptor.TransactionAspectSupport;
  28 +import org.springframework.transaction.support.DefaultTransactionDefinition;
24 import org.springframework.web.multipart.MultipartFile; 29 import org.springframework.web.multipart.MultipartFile;
25 import org.springframework.web.multipart.MultipartHttpServletRequest; 30 import org.springframework.web.multipart.MultipartHttpServletRequest;
26 import org.springframework.web.servlet.ModelAndView; 31 import org.springframework.web.servlet.ModelAndView;
@@ -39,6 +44,7 @@ import java.util.stream.Collectors; @@ -39,6 +44,7 @@ import java.util.stream.Collectors;
39 * @Version: 1.0 44 * @Version: 1.0
40 */ 45 */
41 @Slf4j 46 @Slf4j
  47 +
42 public class JeecgController2<T, t, b, V extends IService<t>, S extends IService<T>, B extends IService<b>> { 48 public class JeecgController2<T, t, b, V extends IService<t>, S extends IService<T>, B extends IService<b>> {
43 /** 49 /**
44 * issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service 50 * issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service
@@ -295,6 +301,7 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -295,6 +301,7 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
295 } 301 }
296 302
297 //工资导入 303 //工资导入
  304 +
298 protected Result<?> importExcelgz(HttpServletRequest request, HttpServletResponse response, Class<T> clazz, Class<b> base) { 305 protected Result<?> importExcelgz(HttpServletRequest request, HttpServletResponse response, Class<T> clazz, Class<b> base) {
299 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; 306 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
300 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); 307 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
@@ -307,22 +314,22 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -307,22 +314,22 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
307 314
308 // params.setKeyIndex(1); 315 // params.setKeyIndex(1);
309 params.setNeedSave(true); 316 params.setNeedSave(true);
  317 + int i = 0;
310 try { 318 try {
311 List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params); 319 List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
312 320
313 - 321 + List<T> shuju = new ArrayList<>();
314 //update-begin-author:taoyan date:20190528 for:批量插入数据 322 //update-begin-author:taoyan date:20190528 for:批量插入数据
315 long start = System.currentTimeMillis(); 323 long start = System.currentTimeMillis();
316 - int i = 0;  
317 - // 遍历Excel数据  
318 - for (T data : list) {  
319 324
  325 + // 遍历Excel数据
  326 + for (T data :list) {
320 // 使用工号和姓名去基本信息表中检查是否存在对应的员工信息 327 // 使用工号和姓名去基本信息表中检查是否存在对应的员工信息
321 b employeeExists = checkEmployeeExists(data); 328 b employeeExists = checkEmployeeExists(data);
322 329
323 if (employeeExists != null) { 330 if (employeeExists != null) {
324 // 如果员工存在,则保存这条数据到数据库中 331 // 如果员工存在,则保存这条数据到数据库中
325 - service.save(data); 332 + shuju.add(data);
326 i++; 333 i++;
327 } else { 334 } else {
328 // 如果员工不存在,则跳过这条数据或进行其他相应的处理 335 // 如果员工不存在,则跳过这条数据或进行其他相应的处理
@@ -332,24 +339,33 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -332,24 +339,33 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
332 } 339 }
333 //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒 340 //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
334 //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒 341 //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
  342 + service.saveBatch(shuju);
335 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); 343 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
336 //update-end-author:taoyan date:20190528 for:批量插入数据 344 //update-end-author:taoyan date:20190528 for:批量插入数据
337 - return Result.ok("文件导入成功!数据行数:" + i); 345 + if(i==0){
  346 + return Result.error("导入的数据不存在基础信息表");
  347 + }
  348 + return Result.ok("文件导入成功!数据行数:" + shuju.size());
  349 + }catch (ExcelImportException e){
  350 + return Result.error("文件导入失败,导入数据格式错误");
338 } catch (Exception e) { 351 } catch (Exception e) {
339 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 352 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
340 String msg = e.getMessage(); 353 String msg = e.getMessage();
341 log.error(msg, e); 354 log.error(msg, e);
342 - if (msg != null && msg.indexOf("Duplicate entry") >= 0) {  
343 - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 手动回滚事务 355 + if (msg != null && (msg.indexOf("Duplicate entry") >= 0 || msg.indexOf("java.sql.SQLIntegrityConstraintViolationException: Duplicate entry")>=0)) {
344 return Result.error("文件导入失败:有重复数据!"); 356 return Result.error("文件导入失败:有重复数据!");
345 - }else if (msg != null && msg.indexOf("Field 'violation_fines' doesn't have a default value") >= 0){  
346 - return Result.error("文件导入失败,导入数据不能为空" );  
347 - }  
348 - else { 357 + }else if (msg!=null && msg.indexOf("Field 'salary_month' doesn't have a default value")>=0) {
  358 + return Result.error("文件导入失败,导入月份不能为空");
  359 + } else if (msg!=null && msg.indexOf("Field 'day' doesn't have a default value")>=0) {
  360 + return Result.error("文件导入失败,导入出勤天数不能为空");
  361 + } else if (msg != null && msg.indexOf("Field 'working_hours' doesn't have a default value") >= 0) {
  362 + return Result.error("文件导入失败,导入标准工时数不能为空");
  363 + } else {
  364 +
349 return Result.error("文件导入失败:" + e.getMessage()); 365 return Result.error("文件导入失败:" + e.getMessage());
350 } 366 }
351 //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 367 //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
352 - } finally { 368 + }finally {
353 try { 369 try {
354 file.getInputStream().close(); 370 file.getInputStream().close();
355 } catch (IOException e) { 371 } catch (IOException e) {
@@ -99,6 +99,9 @@ public class TblProductionGongxuController extends JeecgController<TblProduction @@ -99,6 +99,9 @@ public class TblProductionGongxuController extends JeecgController<TblProduction
99 @PutMapping("/updateYan") 99 @PutMapping("/updateYan")
100 public Result<?> updateYan(@RequestBody List<TblProductionGongxu> tblProductionGongxuList){ 100 public Result<?> updateYan(@RequestBody List<TblProductionGongxu> tblProductionGongxuList){
101 boolean b = tblProductionGongxuService.updateBatchById(tblProductionGongxuList); 101 boolean b = tblProductionGongxuService.updateBatchById(tblProductionGongxuList);
  102 + if(b){
  103 +
  104 + }
102 return Result.ok("修改成功"); 105 return Result.ok("修改成功");
103 } 106 }
104 107
@@ -19,8 +19,13 @@ @@ -19,8 +19,13 @@
19 salaries_payable=#{salariesPayable}, 19 salaries_payable=#{salariesPayable},
20 personal_tax=#{personalTax}, 20 personal_tax=#{personalTax},
21 net_salary=#{netSalary}, 21 net_salary=#{netSalary},
22 - house_allowance=#{houseAllowance}  
23 - 22 + house_allowance=#{houseAllowance},
  23 + other_additions=#{otherAdditions},
  24 + violation_fines=#{violationFines},
  25 + quality_fines=#{qualityFines},
  26 + attendance_fines=#{attendanceFines},
  27 + deduction=#{deduction},
  28 + working_hours=#{workingHours}
24 where salary_month=#{salaryMonth} and user_name=#{userName} and job_id=#{jobId} 29 where salary_month=#{salaryMonth} and user_name=#{userName} and job_id=#{jobId}
25 </update> 30 </update>
26 <update id="selectup"> 31 <update id="selectup">
@@ -57,12 +57,32 @@ public class TblSalaryCalculationServiceImpl extends ServiceImpl<TblSalaryCalcul @@ -57,12 +57,32 @@ public class TblSalaryCalculationServiceImpl extends ServiceImpl<TblSalaryCalcul
57 57
58 @Override 58 @Override
59 public void upjisuan(List<TblSalaryCalculation> list) { 59 public void upjisuan(List<TblSalaryCalculation> list) {
  60 + BigDecimal zongHours=new BigDecimal(0);
  61 + for (TblSalaryCalculation tsc :list){
  62 + if(tsc.getJobTitle().equals("WorkshopGeneralWorker")){
  63 + zongHours=zongHours.add(tsc.getWorkingHours());
  64 + }
  65 + }
60 for (TblSalaryCalculation sc : list) { 66 for (TblSalaryCalculation sc : list) {
61 - 67 + if(sc.getOtherAdditions()==null){
  68 + sc.setOtherAdditions(new BigDecimal(0));
  69 + }
  70 + if(sc.getViolationFines()==null){
  71 + sc.setViolationFines(new BigDecimal(0));
  72 + }
  73 + if(sc.getQualityFines()==null){
  74 + sc.setQualityFines(new BigDecimal(0));
  75 + }
  76 + if(sc.getAttendanceFines()==null){
  77 + sc.setAttendanceFines(new BigDecimal(0));
  78 + }
  79 + if(sc.getDeduction()==null){
  80 + sc.setDeduction(new BigDecimal(0));
  81 + }
62 TblSalaryBase sb= tblSalaryCalculationMapper.all(sc.getJobId(),sc.getUserName()); 82 TblSalaryBase sb= tblSalaryCalculationMapper.all(sc.getJobId(),sc.getUserName());
63 if ((sb.getJobTitle().equals("WorkshopDirector") || sb.getJobTitle().equals("WorkshopTechnicalManager") || sb.getJobTitle().equals("WorkshopTechnician") || sb.getJobTitle().equals("WorkshopAuxiliaryPersonnel"))) { 83 if ((sb.getJobTitle().equals("WorkshopDirector") || sb.getJobTitle().equals("WorkshopTechnicalManager") || sb.getJobTitle().equals("WorkshopTechnician") || sb.getJobTitle().equals("WorkshopAuxiliaryPersonnel"))) {
64 TblSalarySuanfa suan=tblSalaryCalculationMapper.selectbili(sb.getJobTitle()); 84 TblSalarySuanfa suan=tblSalaryCalculationMapper.selectbili(sb.getJobTitle());
65 - 85 + sc.setWorkingHours(zongHours);
66 //每月房补 86 //每月房补
67 BigDecimal fangbu=sb.getHousePrice().multiply(sc.getDay()); 87 BigDecimal fangbu=sb.getHousePrice().multiply(sc.getDay());
68 sc.setHouseAllowance(fangbu); 88 sc.setHouseAllowance(fangbu);