Commit 7552d20c authored by hongguangwu's avatar hongguangwu

MVP1.7.0 优化

parent 142af468
......@@ -27,6 +27,7 @@ import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
......@@ -68,4 +69,14 @@ public class TArchivesExportLimit extends BaseEntity {
@ExcelProperty("类型:1预入职导出;2完整度监控导出")
private Integer type;
@Length(max = 64, message = "进度条不能超过64个字符")
@Schema(description = "进度条")
private String progressBar;
@ExcelAttribute(name = "导出最大值(按类型)", isNotEmpty = true, errorInfo = "导出最大值(按类型)不能为空")
@NotBlank(message = "导出最大值(按类型)不能为空")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty("导出最大值(按类型)")
private Integer maxNum;
}
......@@ -22,8 +22,6 @@ import com.yifu.cloud.plus.v1.yifu.archives.entity.TArchivesExportLimit;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 薪资导入、删除锁定表(锁定后不可导入删除,除非清理掉数据)
*
......@@ -32,9 +30,5 @@ import java.util.List;
*/
@Mapper
public interface TArchivesExportLimitMapper extends BaseMapper<TArchivesExportLimit> {
/**
* 查询是否有锁
*/
List<TArchivesExportLimit> getLimitList(@Param("tArchivesExportLimit") TArchivesExportLimit tArchivesExportLimit);
Integer getLimitMaxNum(@Param("type") Integer type);
}
......@@ -63,4 +63,12 @@ public interface TCompleteMonitorService extends IService<TCompleteMonitor> {
// 导出全量
void exportAll(HttpServletResponse response, TCompleteMonitorSearchVo searchVo);
/**
* @Description: 返回异常提示的文件
* @Author: hgw
* @Date: 2024/10/29 10:24
* @return: void
**/
void exportError(HttpServletResponse response, String errorMessage);
}
......@@ -16,15 +16,13 @@ import com.yifu.cloud.plus.v1.yifu.archives.mapper.TEmployeeProjectMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.*;
import com.yifu.cloud.plus.v1.yifu.archives.utils.ExcelStyle;
import com.yifu.cloud.plus.v1.yifu.archives.vo.*;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.*;
import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprUpmsProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.HttpDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.salary.vo.ExportErrorVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.compress.utils.Lists;
......@@ -39,6 +37,7 @@ import java.net.URL;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 档案完整度监控
......@@ -81,6 +80,8 @@ public class TCompleteMonitorServiceImpl extends ServiceImpl<TCompleteMonitorMap
private final OSSUtil ossUtil;
private final AtomicInteger atomicInteger = new AtomicInteger(0);
/**
* 档案完整度监控简单分页查询
* @param tCompleteMonitor 档案完整度监控
......@@ -269,29 +270,74 @@ public class TCompleteMonitorServiceImpl extends ServiceImpl<TCompleteMonitorMap
return exportfieldsName;
}
@Override
public void exportAll(HttpServletResponse response, TCompleteMonitorSearchVo searchVo) {
Integer maxLimit = tArchivesExportLimitMapper.getLimitMaxNum(CommonConstants.TWO_INT);
if (Common.isEmpty(maxLimit)) {
maxLimit = 2;
}
if (atomicInteger.incrementAndGet() <= maxLimit) {
try {
exportAllCore(response, searchVo);
} catch (Exception e) {
log.error("导出异常:", e);
} finally {
atomicInteger.decrementAndGet();
}
} else {
// 前面做了+1(atomicInteger.incrementAndGet())这里也要-1
atomicInteger.decrementAndGet();
log.error("超出阈值:" + ResultConstants.FILE_DOWN_LOAD_DATA);
exportError(response, ResultConstants.FILE_DOWN_LOAD_DATA);
}
}
@Override
public void exportError(HttpServletResponse response, String errorMessage) {
String fileName = "导出异常" + DateUtil.getThisTime() + CommonConstants.XLSX;
//获取要导出的列表
List<ExportErrorVo> list = new ArrayList<>();
list.add(new ExportErrorVo(errorMessage));
ServletOutputStream out = null;
try {
out = response.getOutputStream();
response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
response.setCharacterEncoding("utf-8");
response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, "UTF-8"));
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcelFactory.write(out, ExportErrorVo.class).build();
int index = 0;
WriteSheet writeSheet = EasyExcelFactory.writerSheet("异常信息" + index).build();
excelWriter.write(list, writeSheet);
if (Common.isNotNull(list)) {
list.clear();
}
out.flush();
excelWriter.finish();
} catch (Exception e) {
log.error("执行异常", e);
} finally {
try {
if (null != out) {
out.close();
}
} catch (IOException e) {
log.error("执行异常", e);
}
}
}
/**
* 预入职导出全量
*
* @return
*/
@Override
public void exportAll(HttpServletResponse response, TCompleteMonitorSearchVo searchVo) {
private void exportAllCore(HttpServletResponse response, TCompleteMonitorSearchVo searchVo) {
YifuUser user = SecurityUtils.getUser();
if (user != null) {
TArchivesExportLimit exportLimit = new TArchivesExportLimit();
exportLimit.setCreateBy(user.getId());
exportLimit.setType(CommonConstants.TWO_INT);
List<TArchivesExportLimit> limitList = tArchivesExportLimitMapper.getLimitList(exportLimit);
boolean myExport = false;
if (limitList != null) {
for (TArchivesExportLimit limit1 : limitList) {
if (limit1.getCreateBy().equals(user.getId())) {
myExport = true;
break;
}
}
}
exportLimit.setCreateBy(user.getId());
String name = "档案完整度监控详情";
String fileName = name + DateUtil.getThisTime() + ".xlsx";
//获取要导出的列表
......@@ -306,23 +352,13 @@ public class TCompleteMonitorServiceImpl extends ServiceImpl<TCompleteMonitorMap
ExcelWriter excelWriter = null;
if (count > 200000) {
//if (count > CommonConstants.EXCEL_EXPORT_LIMIT)
List<List<String>> strList = new ArrayList<>();
/*List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"数据超过20万条,请联系管理员后端导出!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("数据超限").doWrite(strList);
} else if (myExport) {
List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"您正在导出,请耐心等待10分钟后再导出!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("您正在导出完整度").doWrite(strList);
} else if (limitList != null && limitList.size() > 2) {
List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"多人正在导出,请耐心等待10分钟后再导出!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("多人正在导出完整度").doWrite(strList);
EasyExcelFactory.write(out).head(headList).sheet("数据超限")
.registerConverter(new DictConverter(null, null)).doWrite(strList);*/
exportError(response, "数据超过20万条,请联系管理员后端导出");
} else {
exportLimit.setDeleteFlag(CommonConstants.ZERO_INT);
exportLimit.setCreateName(user.getNickname());
......@@ -450,7 +486,8 @@ public class TCompleteMonitorServiceImpl extends ServiceImpl<TCompleteMonitorMap
List<String> empIdList;
for (int i = 0; i <= count; i += limitNum) {
System.out.println("进度:"+i+"/"+count);
exportLimit.setProgressBar("导出完整度进度:"+i+"/"+count);
tArchivesExportLimitMapper.updateById(exportLimit);
empIdList = new ArrayList<>();
// 获取实际记录
searchVo.setLimitStart(i);
......
......@@ -41,10 +41,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.mapper.TPreEmpMainMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.*;
import com.yifu.cloud.plus.v1.yifu.archives.utils.ExcelStyle;
import com.yifu.cloud.plus.v1.yifu.archives.vo.*;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.*;
import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.common.core.util.alisms.AliSmsResult;
import com.yifu.cloud.plus.v1.yifu.common.core.util.alisms.SmsUtil;
......@@ -58,6 +55,7 @@ import com.yifu.cloud.plus.v1.yifu.common.dapr.util.HttpDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryEmployee;
import com.yifu.cloud.plus.v1.yifu.salary.vo.ExportErrorVo;
import com.yifu.cloud.plus.v1.yifu.salary.vo.ListStringVo;
import com.yifu.cloud.plus.v1.yifu.salary.vo.TBankNameMapVo;
import lombok.AllArgsConstructor;
......@@ -79,6 +77,7 @@ import java.net.URL;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 预入职-主表
......@@ -159,6 +158,8 @@ public class TPreEmpMainServiceImpl extends ServiceImpl<TPreEmpMainMapper, TPreE
private final RedisUtil redisUtil;
private final AtomicInteger preAtomicInteger = new AtomicInteger(0);
/**
* 预入职-主表简单分页查询
*
......@@ -2377,29 +2378,75 @@ public class TPreEmpMainServiceImpl extends ServiceImpl<TPreEmpMainMapper, TPreE
return Arrays.asList(strArr);
}
@Override
public void exportAll(HttpServletResponse response, TPreEmpMainSearchVo searchVo) {
Integer preMaxLimit = tArchivesExportLimitMapper.getLimitMaxNum(CommonConstants.ONE_INT);
if (Common.isEmpty(preMaxLimit)) {
preMaxLimit = 2;
}
if (preAtomicInteger.incrementAndGet() <= preMaxLimit) {
try {
exportAllCore(response, searchVo);
} catch (Exception e) {
log.error("导出异常:", e);
} finally {
preAtomicInteger.decrementAndGet();
}
} else {
// 前面做了+1(atomicInteger.incrementAndGet())这里也要-1
preAtomicInteger.decrementAndGet();
log.error("预入职导出超出阈值:" + ResultConstants.FILE_DOWN_LOAD_DATA);
exportError(response, ResultConstants.FILE_DOWN_LOAD_DATA);
}
}
private void exportError(HttpServletResponse response, String errorMessage) {
String fileName = "导出异常" + DateUtil.getThisTime() + CommonConstants.XLSX;
//获取要导出的列表
List<ExportErrorVo> list = new ArrayList<>();
list.add(new ExportErrorVo(errorMessage));
ServletOutputStream out = null;
try {
out = response.getOutputStream();
response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
response.setCharacterEncoding("utf-8");
response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, "UTF-8"));
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcelFactory.write(out, ExportErrorVo.class).build();
int index = 0;
WriteSheet writeSheet = EasyExcelFactory.writerSheet("异常信息" + index).build();
excelWriter.write(list, writeSheet);
if (Common.isNotNull(list)) {
list.clear();
}
out.flush();
excelWriter.finish();
} catch (Exception e) {
log.error("执行异常", e);
} finally {
try {
if (null != out) {
out.close();
}
} catch (IOException e) {
log.error("执行异常", e);
}
}
}
/**
* 预入职导出全量
*
* @return
*/
@Override
public void exportAll(HttpServletResponse response, TPreEmpMainSearchVo searchVo) {
private void exportAllCore(HttpServletResponse response, TPreEmpMainSearchVo searchVo) {
YifuUser user = SecurityUtils.getUser();
if (user != null) {
TArchivesExportLimit exportLimit = new TArchivesExportLimit();
exportLimit.setCreateBy(user.getId());
exportLimit.setType(CommonConstants.ONE_INT);
List<TArchivesExportLimit> limitList = tArchivesExportLimitMapper.getLimitList(exportLimit);
boolean myExport = false;
if (limitList != null) {
for (TArchivesExportLimit limit1 : limitList) {
if (limit1.getCreateBy().equals(user.getId())) {
myExport = true;
break;
}
}
}
exportLimit.setCreateBy(user.getId());
String name = "预入职导出全量";
String fileName = name + DateUtil.getThisTime() + ".xlsx";
//获取要导出的列表
......@@ -2414,23 +2461,12 @@ public class TPreEmpMainServiceImpl extends ServiceImpl<TPreEmpMainMapper, TPreE
ExcelWriter excelWriter = null;
if (count > 200000) {
//if (count > CommonConstants.EXCEL_EXPORT_LIMIT)
List<List<String>> strList = new ArrayList<>();
/*List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"数据超过20万条,请联系管理员后端导出!!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("数据超限").doWrite(strList);
} else if (myExport) {
List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"您正在导出,请耐心等待10分钟后再导出!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("您正在导出预入职").doWrite(strList);
} else if (limitList != null && limitList.size() > 2) {
List<List<String>> strList = new ArrayList<>();
strList.add(this.getNewArrayList(new String[]{"多人正在导出,请耐心等待10分钟后再导出!"}));
List<List<String>> headList = Lists.newArrayList();
headList.add(this.getNewArrayList(new String[]{"提示"}));
EasyExcelFactory.write(out).head(headList).sheet("多人正在导出预入职").doWrite(strList);
EasyExcelFactory.write(out).head(headList).sheet("数据超限").doWrite(strList);*/
exportError(response, "数据超过20万条,请联系管理员后端导出预入职");
} else {
exportLimit.setDeleteFlag(CommonConstants.ZERO_INT);
exportLimit.setCreateName(user.getNickname());
......@@ -2554,6 +2590,8 @@ public class TPreEmpMainServiceImpl extends ServiceImpl<TPreEmpMainMapper, TPreE
TPreMainExportAllVO temp;
List<String> preMainIdList;
for (int i = 0; i <= count; i += limitNum) {
exportLimit.setProgressBar("导出预入职进度:"+i+"/"+count);
tArchivesExportLimitMapper.updateById(exportLimit);
preMainIdList = new ArrayList<>();
// 获取实际记录
searchVo.setLimitStart(i);
......
......@@ -32,19 +32,20 @@
<result property="createTime" column="CREATE_TIME"/>
<result property="updateBy" column="UPDATE_BY"/>
<result property="updateTime" column="UPDATE_TIME"/>
<result property="progressBar" column="PROGRESS_BAR"/>
<result property="maxNum" column="MAX_NUM"/>
</resultMap>
<sql id="Base_Column_List">
a
.
id
,
a.id,
a.type,
a.delete_flag,
a.CREATE_BY,
a.CREATE_NAME,
a.CREATE_TIME,
a.UPDATE_BY,
a.UPDATE_TIME
a.UPDATE_TIME,
a.PROGRESS_BAR,
a.MAX_NUM
</sql>
<sql id="tArchivesExportLimit_where">
<if test="tArchivesExportLimit != null">
......@@ -61,14 +62,11 @@
</sql>
<!--tArchivesExportLimit查询-->
<select id="getLimitList" resultMap="tArchivesExportLimitMap">
<select id="getLimitMaxNum" resultType="java.lang.Integer">
SELECT
<include refid="Base_Column_List"/>
max(a.MAX_NUM)
FROM t_archives_export_limit a
<where>
a.DELETE_FLAG = 0 and a.create_time > DATE_SUB(NOW(),INTERVAL 10 MINUTE)
<include refid="tArchivesExportLimit_where"/>
</where>
where a.type = #{type}
</select>
</mapper>
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