perf:登录导入进度
This commit is contained in:
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.tiesheng.core.pojos.DaoBase;
|
import com.tiesheng.core.pojos.DaoBase;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,6 +37,12 @@ public class CoreLogProcess extends DaoBase {
|
|||||||
@TableField(value = "fail_num")
|
@TableField(value = "fail_num")
|
||||||
private Integer failNum;
|
private Integer failNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败的文件
|
||||||
|
*/
|
||||||
|
@TableField(value = "fail_file")
|
||||||
|
private String failFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型(import-导入,sync-同步)
|
* 类型(import-导入,sync-同步)
|
||||||
*/
|
*/
|
||||||
@@ -120,6 +127,14 @@ public class CoreLogProcess extends DaoBase {
|
|||||||
this.failNum = failNum;
|
this.failNum = failNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFailFile() {
|
||||||
|
return failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailFile(String failFile) {
|
||||||
|
this.failFile = failFile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取类型(import-导入,sync-同步)
|
* 获取类型(import-导入,sync-同步)
|
||||||
*
|
*
|
||||||
@@ -155,4 +170,4 @@ public class CoreLogProcess extends DaoBase {
|
|||||||
public void setStatus(Integer status) {
|
public void setStatus(Integer status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public class ProcessDetailVo {
|
|||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
private String failFile;
|
||||||
|
|
||||||
public Integer getStatus() {
|
public Integer getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -64,4 +66,12 @@ public class ProcessDetailVo {
|
|||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFailFile() {
|
||||||
|
return failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailFile(String failFile) {
|
||||||
|
this.failFile = failFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.tiesheng.core.service;
|
package com.tiesheng.core.service;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
@@ -15,6 +17,7 @@ import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
|||||||
import com.tiesheng.core.pojos.dao.CoreLogProcess;
|
import com.tiesheng.core.pojos.dao.CoreLogProcess;
|
||||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||||
import com.tiesheng.core.pojos.vo.ProcessDetailVo;
|
import com.tiesheng.core.pojos.vo.ProcessDetailVo;
|
||||||
|
import com.tiesheng.core.util.LogProcessConsumer;
|
||||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||||
import com.tiesheng.util.ServletKit;
|
import com.tiesheng.util.ServletKit;
|
||||||
@@ -24,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
@@ -53,38 +57,48 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
|||||||
public CoreLogProcessMapper getCoreLogProcessMapper() {
|
public CoreLogProcessMapper getCoreLogProcessMapper() {
|
||||||
return coreLogProcessMapper;
|
return coreLogProcessMapper;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// 操作日志
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// 导入日志
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加空的过程 返回id 用于更新
|
* 添加空的过程 返回id 用于更新
|
||||||
*
|
*
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @param type 类型 import-导入,sync-同步
|
* @param type 类型 import-导入,sync-同步
|
||||||
* @param total 总数
|
* @param list 要导入的数据
|
||||||
*/
|
*/
|
||||||
public CoreLogProcess addProcess(String title, String type, Integer total) {
|
public <T> CoreLogProcess addProcess(String title, String type, List<T> list, LogProcessConsumer consumer) {
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
throw new ApiException("文件中不存在数据");
|
||||||
|
}
|
||||||
CoreLogProcess coreLogProcess = new CoreLogProcess();
|
CoreLogProcess coreLogProcess = new CoreLogProcess();
|
||||||
coreLogProcess.setTitle(title);
|
coreLogProcess.setTitle(title);
|
||||||
coreLogProcess.setTotal(total);
|
coreLogProcess.setTotal(list.size());
|
||||||
coreLogProcess.setType(type);
|
coreLogProcess.setType(type);
|
||||||
|
coreLogProcess.setSuccessNum(0);
|
||||||
|
coreLogProcess.setFailNum(0);
|
||||||
coreLogProcessMapper.insert(coreLogProcess);
|
coreLogProcessMapper.insert(coreLogProcess);
|
||||||
|
|
||||||
|
ThreadUtil.execute(() -> {
|
||||||
|
CollUtil.split(list, 100).forEach((it) -> {
|
||||||
|
int accept = consumer.accept(coreLogProcess, it);
|
||||||
|
coreLogProcess.setSuccessNum(coreLogProcess.getSuccessNum() + accept);
|
||||||
|
coreLogProcess.setFailNum(coreLogProcess.getFailNum() + 100 - accept);
|
||||||
|
|
||||||
|
if (it.size() != 100) {
|
||||||
|
coreLogProcess.setFailFile(consumer.getFailFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
coreLogProcessMapper.updateById(coreLogProcess);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return coreLogProcess;
|
return coreLogProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新过程
|
|
||||||
*
|
|
||||||
* @param coreLogProcess 过程对象
|
|
||||||
*/
|
|
||||||
public void upProcess(CoreLogProcess coreLogProcess) {
|
|
||||||
if (coreLogProcess == null || coreLogProcess.getId().isEmpty()) {
|
|
||||||
throw new ApiException("更新过程id不能为空");
|
|
||||||
}
|
|
||||||
coreLogProcessMapper.updateById(coreLogProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id 获取过程详情
|
* 根据id 获取过程详情
|
||||||
@@ -96,6 +110,10 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
|||||||
return BeanUtil.copyProperties(coreLogProcess, ProcessDetailVo.class);
|
return BeanUtil.copyProperties(coreLogProcess, ProcessDetailVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// 操作日志
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加操作日志
|
* 添加操作日志
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.tiesheng.core.util;
|
||||||
|
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogProcess;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface LogProcessConsumer {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据
|
||||||
|
*
|
||||||
|
* @param list
|
||||||
|
* @param <T>
|
||||||
|
* @return 返回成功的数量
|
||||||
|
*/
|
||||||
|
<T> int accept(CoreLogProcess process, List<T> list);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取失败的文件路径
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getFailFile();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -61,6 +61,12 @@ CREATE TABLE `core_log_process`
|
|||||||
ALTER TABLE core_log_process
|
ALTER TABLE core_log_process
|
||||||
ADD status int(6) default 0 COMMENT '状态(0-未完成,1-已完成)';
|
ADD status int(6) default 0 COMMENT '状态(0-未完成,1-已完成)';
|
||||||
|
|
||||||
|
ALTER TABLE core_log_process
|
||||||
|
ADD fail_file varchar(500) null default null COMMENT '失败的文件';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for core_log_operation
|
||||||
|
-- ----------------------------
|
||||||
|
|
||||||
CREATE TABLE `core_log_operation`
|
CREATE TABLE `core_log_operation`
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -14,10 +14,11 @@
|
|||||||
<result column="fail_num" jdbcType="INTEGER" property="failNum" />
|
<result column="fail_num" jdbcType="INTEGER" property="failNum" />
|
||||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||||
<result column="status" jdbcType="INTEGER" property="status" />
|
<result column="status" jdbcType="INTEGER" property="status" />
|
||||||
|
<result column="fail_file" jdbcType="VARCHAR" property="failFile" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
<!--@mbg.generated-->
|
<!--@mbg.generated-->
|
||||||
id, create_time, update_time, is_deleted, title, total, success_num, fail_num, `type`,
|
id, create_time, update_time, is_deleted, title, total, success_num, fail_num, `type`,
|
||||||
`status`
|
`status`, fail_file
|
||||||
</sql>
|
</sql>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user