作者 雷海东

工资计算和导入

... ... @@ -257,6 +257,9 @@ public class JeecgController<T, S extends IService<T>> {
long start = System.currentTimeMillis();
service.saveBatch(dataListToSave);
log.info("批量保存消耗时间:" + (System.currentTimeMillis() - start) + "毫秒");
if(dataListToSave.size()<=0){
return Result.error("没有有效的导入数据");
}
return Result.ok("文件导入成功!数据行数:" + dataListToSave.size());
} else {
return Result.error("文件导入失败:没有有效的数据需要保存!");
... ...
... ... @@ -18,9 +18,14 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecgframework.poi.exception.excel.ExcelImportException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
... ... @@ -39,6 +44,7 @@ import java.util.stream.Collectors;
* @Version: 1.0
*/
@Slf4j
public class JeecgController2<T, t, b, V extends IService<t>, S extends IService<T>, B extends IService<b>> {
/**
* issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service
... ... @@ -295,6 +301,7 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
}
//工资导入
protected Result<?> importExcelgz(HttpServletRequest request, HttpServletResponse response, Class<T> clazz, Class<b> base) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
... ... @@ -307,22 +314,22 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
// params.setKeyIndex(1);
params.setNeedSave(true);
int i = 0;
try {
List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
List<T> shuju = new ArrayList<>();
//update-begin-author:taoyan date:20190528 for:批量插入数据
long start = System.currentTimeMillis();
int i = 0;
// 遍历Excel数据
for (T data : list) {
// 遍历Excel数据
for (T data :list) {
// 使用工号和姓名去基本信息表中检查是否存在对应的员工信息
b employeeExists = checkEmployeeExists(data);
if (employeeExists != null) {
// 如果员工存在,则保存这条数据到数据库中
service.save(data);
shuju.add(data);
i++;
} else {
// 如果员工不存在,则跳过这条数据或进行其他相应的处理
... ... @@ -332,24 +339,33 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
}
//400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
//1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
service.saveBatch(shuju);
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
//update-end-author:taoyan date:20190528 for:批量插入数据
return Result.ok("文件导入成功!数据行数:" + i);
if(i==0){
return Result.error("导入的数据不存在基础信息表");
}
return Result.ok("文件导入成功!数据行数:" + shuju.size());
}catch (ExcelImportException e){
return Result.error("文件导入失败,导入数据格式错误");
} catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage();
log.error(msg, e);
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 手动回滚事务
if (msg != null && (msg.indexOf("Duplicate entry") >= 0 || msg.indexOf("java.sql.SQLIntegrityConstraintViolationException: Duplicate entry")>=0)) {
return Result.error("文件导入失败:有重复数据!");
}else if (msg != null && msg.indexOf("Field 'violation_fines' doesn't have a default value") >= 0){
return Result.error("文件导入失败,导入数据不能为空" );
}
else {
}else if (msg!=null && msg.indexOf("Field 'salary_month' doesn't have a default value")>=0) {
return Result.error("文件导入失败,导入月份不能为空");
} else if (msg!=null && msg.indexOf("Field 'day' doesn't have a default value")>=0) {
return Result.error("文件导入失败,导入出勤天数不能为空");
} else if (msg != null && msg.indexOf("Field 'working_hours' doesn't have a default value") >= 0) {
return Result.error("文件导入失败,导入标准工时数不能为空");
} else {
return Result.error("文件导入失败:" + e.getMessage());
}
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally {
}finally {
try {
file.getInputStream().close();
} catch (IOException e) {
... ...
... ... @@ -99,6 +99,9 @@ public class TblProductionGongxuController extends JeecgController<TblProduction
@PutMapping("/updateYan")
public Result<?> updateYan(@RequestBody List<TblProductionGongxu> tblProductionGongxuList){
boolean b = tblProductionGongxuService.updateBatchById(tblProductionGongxuList);
if(b){
}
return Result.ok("修改成功");
}
... ...
... ... @@ -19,8 +19,13 @@
salaries_payable=#{salariesPayable},
personal_tax=#{personalTax},
net_salary=#{netSalary},
house_allowance=#{houseAllowance}
house_allowance=#{houseAllowance},
other_additions=#{otherAdditions},
violation_fines=#{violationFines},
quality_fines=#{qualityFines},
attendance_fines=#{attendanceFines},
deduction=#{deduction},
working_hours=#{workingHours}
where salary_month=#{salaryMonth} and user_name=#{userName} and job_id=#{jobId}
</update>
<update id="selectup">
... ...
... ... @@ -57,12 +57,32 @@ public class TblSalaryCalculationServiceImpl extends ServiceImpl<TblSalaryCalcul
@Override
public void upjisuan(List<TblSalaryCalculation> list) {
BigDecimal zongHours=new BigDecimal(0);
for (TblSalaryCalculation tsc :list){
if(tsc.getJobTitle().equals("WorkshopGeneralWorker")){
zongHours=zongHours.add(tsc.getWorkingHours());
}
}
for (TblSalaryCalculation sc : list) {
if(sc.getOtherAdditions()==null){
sc.setOtherAdditions(new BigDecimal(0));
}
if(sc.getViolationFines()==null){
sc.setViolationFines(new BigDecimal(0));
}
if(sc.getQualityFines()==null){
sc.setQualityFines(new BigDecimal(0));
}
if(sc.getAttendanceFines()==null){
sc.setAttendanceFines(new BigDecimal(0));
}
if(sc.getDeduction()==null){
sc.setDeduction(new BigDecimal(0));
}
TblSalaryBase sb= tblSalaryCalculationMapper.all(sc.getJobId(),sc.getUserName());
if ((sb.getJobTitle().equals("WorkshopDirector") || sb.getJobTitle().equals("WorkshopTechnicalManager") || sb.getJobTitle().equals("WorkshopTechnician") || sb.getJobTitle().equals("WorkshopAuxiliaryPersonnel"))) {
TblSalarySuanfa suan=tblSalaryCalculationMapper.selectbili(sb.getJobTitle());
sc.setWorkingHours(zongHours);
//每月房补
BigDecimal fangbu=sb.getHousePrice().multiply(sc.getDay());
sc.setHouseAllowance(fangbu);
... ...