|
|
@@ -1,14 +1,21 @@
|
|
|
|
|
|
package org.sky.scientific.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.sky.core.excel.util.ExcelUtil;
|
|
|
import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.mp.base.BaseServiceImpl;
|
|
|
+import org.sky.core.mp.support.Condition;
|
|
|
+import org.sky.core.mp.support.Query;
|
|
|
import org.sky.core.tool.utils.*;
|
|
|
import org.sky.scientific.excel.SalaryExcel;
|
|
|
import org.sky.scientific.mapper.SalaryMapper;
|
|
|
@@ -24,9 +31,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
* 每月工资信息 服务实现类
|
|
|
@@ -48,70 +56,45 @@ public class SalaryServiceImpl extends BaseServiceImpl<SalaryMapper, SalaryEntit
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
List<SalaryVO> voList = baseMapper.selectSalaryPage(page, salary);
|
|
|
- //如果数据空,则查询该年度整体是否有数据
|
|
|
-// if (voList.isEmpty()) {
|
|
|
-// LambdaQueryWrapper<SalaryEntity> wrapper = Wrappers.<SalaryEntity>query ().lambda()
|
|
|
-// .eq(SalaryEntity::getYearAndMonth, salary.getYearAndMonth())
|
|
|
-// .eq(SalaryEntity::getTenantId, AuthUtil.getTenantId())
|
|
|
-// .eq(SalaryEntity::getIsDeleted, 0);
|
|
|
-// if (baseMapper.selectCount(wrapper) == 0) {
|
|
|
-// //将本年度技术人员基础数据插入工资表,工资数据为空
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
+
|
|
|
return page.setRecords(voList);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@Override
|
|
|
- public List<SalaryExcel> exportSalary(Wrapper<SalaryEntity> queryWrapper) {
|
|
|
- List<SalaryExcel> salaryList = baseMapper.exportSalary(queryWrapper);
|
|
|
- //salaryList.forEach(salary -> {
|
|
|
- // salary.setTypeName(DictCache.getValue(DictEnum.YES_NO, Salary.getType()));
|
|
|
- //});
|
|
|
- return salaryList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean saveSalary(SalaryEntity salary) {
|
|
|
-
|
|
|
- Integer affectNum = 0;
|
|
|
- if (StringUtil.isBlank(salary.getYearAndMonth())) {
|
|
|
- salary.setYearAndMonth(DateUtil.format(DateUtil.now(), DateUtil.PATTERN_YYYY));
|
|
|
+ public void exportSalary(HttpServletResponse response, SalaryDTO dto){
|
|
|
+
|
|
|
+ Query query = new Query().setCurrent(1).setSize(Integer.MAX_VALUE);
|
|
|
+ List<SalaryVO> assetVOList = this.selectSalaryPage(Condition.getPage(query), dto).getRecords();
|
|
|
+
|
|
|
+ AtomicInteger i = new AtomicInteger(1);
|
|
|
+ assetVOList.forEach(temp -> {
|
|
|
+ temp.setXh(i.getAndIncrement()+"");
|
|
|
+ temp.setTotal(temp.getPensionInsurance().add(temp.getMedicalInsurance()).add(temp.getUnemploymentInsurance()).add(temp.getInjuryInsurance()).add(temp.getMaternityInsurance()));
|
|
|
+ });
|
|
|
+
|
|
|
+ InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/每月工资信息.xls");
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("每月工资信息.xls", Charsets.UTF_8));
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream())
|
|
|
+ .withTemplate((templateFileName))
|
|
|
+ .excelType(ExcelTypeEnum.XLS)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ //设置list集合数据
|
|
|
+ excelWriter.fill(assetVOList, writeSheet);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("year", dto.getYearAndMonth().substring(0,4));
|
|
|
+ map.put("month", dto.getYearAndMonth().substring(4));
|
|
|
+ excelWriter.fill(map, writeSheet);
|
|
|
+ excelWriter.finish();
|
|
|
+ if (templateFileName != null) {
|
|
|
+ templateFileName.close();
|
|
|
}
|
|
|
-// //从技术人员花名册中根据年份和人员信息,查询人员是否存在
|
|
|
-// TechnicianEntity technician = new TechnicianEntity();
|
|
|
-// technician.setYearAndMonth(salary.getYearAndMonth());
|
|
|
-// technician.setNumber(salary.getNumber());
|
|
|
-// technician.setIdentityCard(salary.getIdentityCard());
|
|
|
-// technician.setTenantId(AuthUtil.getTenantId());
|
|
|
-// Integer countWithTechnician = technicianMapper.selectPrimaryByDateAndNumberOrIdentityCard(technician);
|
|
|
-// //不存在则抛出异常
|
|
|
-// if(countWithTechnician == 0){
|
|
|
-// throw new ServiceException("[" + salary.getYearAndMonth() + "]年度内无人员[" + salary.getName() + "、" + salary.getNumber() + "、" + salary.getIdentityCard() + "]");
|
|
|
-// }else {
|
|
|
-// //存在则根据年份和人员信息查询工资是否存在
|
|
|
-// LambdaQueryWrapper<SalaryEntity> wrapper = Wrappers.<SalaryEntity>query().lambda()
|
|
|
-// .eq(SalaryEntity::getYearAndMonth, salary.getYearAndMonth())
|
|
|
-// .eq(SalaryEntity::getNumber, salary.getNumber())
|
|
|
-// .eq(SalaryEntity::getIdentityCard, salary.getIdentityCard())
|
|
|
-// .eq(SalaryEntity::getTenantId, AuthUtil.getTenantId())
|
|
|
-// .eq(SalaryEntity::getIsDeleted, 0);
|
|
|
-// //存在则覆盖
|
|
|
-// if (baseMapper.selectCount(wrapper) > 0) {
|
|
|
-// LambdaUpdateWrapper<SalaryEntity> updateWrapper = Wrappers.<SalaryEntity>update().lambda()
|
|
|
-// .eq(SalaryEntity::getYearAndMonth, salary.getYearAndMonth())
|
|
|
-// .eq(SalaryEntity::getNumber, salary.getNumber())
|
|
|
-// .eq(SalaryEntity::getIdentityCard, salary.getIdentityCard())
|
|
|
-// .eq(SalaryEntity::getTenantId, AuthUtil.getTenantId())
|
|
|
-// .eq(SalaryEntity::getIsDeleted, 0);
|
|
|
-// affectNum = baseMapper.update(salary, updateWrapper);
|
|
|
-// }else {
|
|
|
-// //不存在则新增
|
|
|
-// affectNum = baseMapper.insert(salary);
|
|
|
-// }
|
|
|
-// }
|
|
|
- return affectNum > 0;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -228,7 +211,7 @@ public class SalaryServiceImpl extends BaseServiceImpl<SalaryMapper, SalaryEntit
|
|
|
|
|
|
for (SalaryExcel excel : data) {
|
|
|
if(StringUtil.isAllBlank(excel.getNumber(), excel.getIdCard())){
|
|
|
- throw new ServiceException("序号为["+excel.getSerialNumber()+"]的工号和身份证不能都为空");
|
|
|
+ throw new ServiceException("序号为["+excel.getXh()+"]的工号和身份证不能都为空");
|
|
|
}
|
|
|
//根据工号或者身份证查询technicianId
|
|
|
LambdaQueryWrapper<TechnicianEntity> wrapper = Wrappers.<TechnicianEntity>lambdaQuery()
|
|
|
@@ -236,7 +219,7 @@ public class SalaryServiceImpl extends BaseServiceImpl<SalaryMapper, SalaryEntit
|
|
|
.and(t -> t.eq(TechnicianEntity::getNumber, excel.getNumber()).or().eq(TechnicianEntity::getIdCard, excel.getIdCard()));
|
|
|
TechnicianEntity dbTechnician = technicianMapper.selectOne(wrapper);
|
|
|
if(dbTechnician == null){
|
|
|
- throw new ServiceException("序号为["+excel.getSerialNumber()+"]的工号和者身份证都不存在");
|
|
|
+ throw new ServiceException("序号为["+excel.getXh()+"]的工号和者身份证都不存在");
|
|
|
}
|
|
|
|
|
|
//非本月实际参研人员,提示“某某非本月实际参研人员,请核对数据”
|
|
|
@@ -249,7 +232,7 @@ public class SalaryServiceImpl extends BaseServiceImpl<SalaryMapper, SalaryEntit
|
|
|
.eq(SalaryEntity::getYearAndMonth, yearAndMonth)
|
|
|
.eq(SalaryEntity::getUnicode, dbTechnician.getUnicode());
|
|
|
if(baseMapper.selectCount(queryWrapper) > 0){
|
|
|
- throw new ServiceException("序号为["+excel.getSerialNumber()+"]的工资数据已存在, 导入失败");
|
|
|
+ throw new ServiceException("序号为["+excel.getXh()+"]的工资数据已存在, 导入失败");
|
|
|
}
|
|
|
|
|
|
SalaryEntity entity = Objects.requireNonNull(BeanUtil.copyProperties(excel, SalaryDTO.class));
|