publish 0.0.5
This commit is contained in:
@@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
@RestControllerAdvice
|
||||
public class SpringExceptionHandler {
|
||||
|
||||
@Autowired(required = false)
|
||||
@Autowired
|
||||
TieshengWebConfigurer tieshengWebConfigurer;
|
||||
|
||||
|
||||
@@ -74,10 +74,7 @@ public class SpringExceptionHandler {
|
||||
return ApiResp.respCust(ApiRespEnum.ServerError.getCode(), "IO异常");
|
||||
}
|
||||
|
||||
if (tieshengWebConfigurer != null) {
|
||||
return tieshengWebConfigurer.addExceptionHandler(e);
|
||||
}
|
||||
return ApiResp.respCust(ApiRespEnum.ServerError);
|
||||
return tieshengWebConfigurer.addExceptionHandler(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.tiesheng.core.config.json;
|
||||
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
@@ -29,8 +28,7 @@ public class FastJsonMessageConverter {
|
||||
FastJsonConfig config = new FastJsonConfig();
|
||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty,
|
||||
SerializerFeature.WriteEnumUsingName,
|
||||
SerializerFeature.WriteNullNumberAsZero);
|
||||
SerializerFeature.WriteEnumUsingName);
|
||||
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.tiesheng.core.config.web;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(value = TieshengWebConfigurer.class, ignored = DefaultWebConfigurer.class)
|
||||
public class DefaultWebConfigurer implements TieshengWebConfigurer {
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.tiesheng.core.config.web;
|
||||
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.exception.ApiRespEnum;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* WEB配置
|
||||
*
|
||||
@@ -24,6 +29,7 @@ public interface TieshengWebConfigurer {
|
||||
default CurrentWebUser getCurrentUserName() {
|
||||
CurrentWebUser webUser = new CurrentWebUser();
|
||||
webUser.setId(TsTokenConfig.getWithoutThr().getId());
|
||||
webUser.setName(webUser.getId());
|
||||
return webUser;
|
||||
}
|
||||
|
||||
@@ -34,8 +40,10 @@ public interface TieshengWebConfigurer {
|
||||
* @param e 异常
|
||||
*/
|
||||
default ApiResp<String> addExceptionHandler(Exception e) {
|
||||
LogFactory.get().info(e);
|
||||
return ApiResp.respCust(ApiRespEnum.ServerError);
|
||||
ApiResp<String> apiResp = ApiResp.respCust(ApiRespEnum.ServerError);
|
||||
apiResp.setException(e);
|
||||
LogFactory.get().info(apiResp.getException());
|
||||
return apiResp;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,4 +53,48 @@ public interface TieshengWebConfigurer {
|
||||
default void uploadFileCheck(String fileExt) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置登录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default LoginConfigurer loginConfigurer() {
|
||||
return new LoginConfigurer() {
|
||||
@Override
|
||||
public TokenBean doLogin(CorePlatformUnique platformUnique) {
|
||||
throw new ApiException("请配置TieshengWebConfigurer->loginConfigurer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redirect(TokenBean bean, String extra, HttpServletResponse response) {
|
||||
throw new ApiException("请配置TieshengWebConfigurer->loginConfigurer");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
interface LoginConfigurer {
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
*
|
||||
* @param platformUnique
|
||||
* @return
|
||||
*/
|
||||
TokenBean doLogin(CorePlatformUnique platformUnique);
|
||||
|
||||
|
||||
/**
|
||||
* 登录重定向
|
||||
*
|
||||
* @param bean
|
||||
* @param extra
|
||||
* @param response
|
||||
*/
|
||||
void redirect(TokenBean bean, String extra, HttpServletResponse response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package com.tiesheng.core.controller.log;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||
import com.tiesheng.core.service.CoreLogService;
|
||||
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.login.service.LoginLogService;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -21,12 +20,10 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/manager/log")
|
||||
public class ManagerLogController {
|
||||
public class LogController {
|
||||
|
||||
@Autowired
|
||||
CoreLogService coreLogService;
|
||||
@Autowired(required = false)
|
||||
LoginLogService loginLogService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -63,9 +60,7 @@ public class ManagerLogController {
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
||||
Page<CoreLogLogin> page = dto.pageObj();
|
||||
if (loginLogService != null) {
|
||||
loginLogService.page(page, queryWrapper);
|
||||
}
|
||||
coreLogService.getLogLoginMapper().selectPage(page, queryWrapper);
|
||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.tiesheng.core.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogLogin;
|
||||
|
||||
public interface CoreLogLoginMapper extends BaseMapper<CoreLogLogin> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.tiesheng.core.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
|
||||
public interface CorePlatformUniqueMapper extends BaseMapper<CorePlatformUnique> {
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.tiesheng.core.pojos.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tiesheng.core.pojos.DaoBase;
|
||||
|
||||
/**
|
||||
* 日志-登录
|
||||
*/
|
||||
@TableName(value = "core_log_login")
|
||||
public class CoreLogLogin extends DaoBase {
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField(value = "user_name")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* ip
|
||||
*/
|
||||
@TableField(value = "platform")
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* ip
|
||||
*/
|
||||
@TableField(value = "ip")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
@TableField(value = "address")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 获取用户id
|
||||
*
|
||||
* @return user_id - 用户id
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户id
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ip
|
||||
*
|
||||
* @return ip - ip
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置ip
|
||||
*
|
||||
* @param ip ip
|
||||
*/
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ip地址
|
||||
*
|
||||
* @return address - ip地址
|
||||
*/
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置ip地址
|
||||
*
|
||||
* @param address ip地址
|
||||
*/
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.tiesheng.core.pojos.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tiesheng.core.pojos.DaoBase;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 平台-唯一值
|
||||
*/
|
||||
@TableName(value = "core_platform_unique")
|
||||
public class CorePlatformUnique extends DaoBase {
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
@TableField(value = "app_id")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 唯一值
|
||||
*/
|
||||
@TableField(value = "unique_id")
|
||||
private String uniqueId;
|
||||
|
||||
/**
|
||||
* 平台
|
||||
*/
|
||||
@TableField(value = "platform")
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* 其他参数
|
||||
*/
|
||||
@TableField(value = "info")
|
||||
private String info;
|
||||
|
||||
/**
|
||||
* 获取用户id
|
||||
*
|
||||
* @return user_id - 用户id
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户id
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取appId
|
||||
*
|
||||
* @return app_id - appId
|
||||
*/
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置appId
|
||||
*
|
||||
* @param appId appId
|
||||
*/
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取唯一值
|
||||
*
|
||||
* @return unique_id - 唯一值
|
||||
*/
|
||||
public String getUniqueId() {
|
||||
return uniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置唯一值
|
||||
*
|
||||
* @param uniqueId 唯一值
|
||||
*/
|
||||
public void setUniqueId(String uniqueId) {
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取平台
|
||||
*
|
||||
* @return platform - 平台
|
||||
*/
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置平台
|
||||
*
|
||||
* @param platform 平台
|
||||
*/
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取其他参数
|
||||
*
|
||||
* @return info - 其他参数
|
||||
*/
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置其他参数
|
||||
*
|
||||
* @param info 其他参数
|
||||
*/
|
||||
public void setInfo(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,36 @@
|
||||
package com.tiesheng.core.service;
|
||||
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
||||
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||
import com.tiesheng.core.mapper.CoreLogLoginMapper;
|
||||
import com.tiesheng.core.mapper.CoreLogOperationMapper;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.ip2region.DataBlock;
|
||||
import com.tiesheng.util.ip2region.Ip2Region;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Service
|
||||
public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLogOperation> {
|
||||
|
||||
@Autowired(required = false)
|
||||
@Autowired
|
||||
TieshengWebConfigurer tieshengWebConfigurer;
|
||||
@Autowired
|
||||
CoreLogLoginMapper coreLogLoginMapper;
|
||||
|
||||
public CoreLogLoginMapper getLogLoginMapper() {
|
||||
return coreLogLoginMapper;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 操作日志
|
||||
@@ -28,13 +42,9 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
*/
|
||||
public void addOperationLog(String title, String subject, Object params) {
|
||||
CoreLogOperation operation = new CoreLogOperation();
|
||||
if (tieshengWebConfigurer != null) {
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName();
|
||||
operation.setUserId(currentWebUser.getId());
|
||||
operation.setUserName(currentWebUser.getName());
|
||||
} else {
|
||||
operation.setUserId(TsTokenConfig.getWithoutThr().getId());
|
||||
}
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName();
|
||||
operation.setUserId(currentWebUser.getId());
|
||||
operation.setUserName(currentWebUser.getName());
|
||||
operation.setTitle(title);
|
||||
operation.setSubject(subject);
|
||||
if (params != null) {
|
||||
@@ -43,4 +53,29 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
save(operation);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 登录日志
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 添加登录日志
|
||||
*
|
||||
* @param platformUnique
|
||||
*/
|
||||
public void addLoginLog(CorePlatformUnique platformUnique) {
|
||||
|
||||
HttpServletRequest request = ServletKit.getRequest();
|
||||
String ip = ServletUtil.getClientIP(request);
|
||||
|
||||
CoreLogLogin login = new CoreLogLogin();
|
||||
login.setUserId(platformUnique.getUserId());
|
||||
login.setPlatform(platformUnique.getPlatform());
|
||||
|
||||
login.setIp(ip);
|
||||
DataBlock dataBlock = Ip2Region.getInstance().btreeSearch(ip);
|
||||
login.setAddress(dataBlock.getRegion());
|
||||
coreLogLoginMapper.insert(login);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.tiesheng.core.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
||||
import com.tiesheng.core.mapper.CorePlatformUniqueMapper;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.login.config.TieshengLoginConfigurer;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Service
|
||||
public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueMapper, CorePlatformUnique> implements TieshengLoginConfigurer {
|
||||
|
||||
@Autowired
|
||||
TieshengWebConfigurer tieshengWebConfigurer;
|
||||
@Autowired
|
||||
CoreLogService coreLogService;
|
||||
|
||||
@Override
|
||||
public TokenBean doLogin(String appId, String uniqueId, String platfrom, String info) {
|
||||
|
||||
CorePlatformUnique platformUnique = getByAppAndUnique(appId, uniqueId, platfrom);
|
||||
platformUnique.setInfo(info);
|
||||
TokenBean tokenBean = tieshengWebConfigurer.loginConfigurer().doLogin(platformUnique);
|
||||
if (tokenBean != null) {
|
||||
platformUnique.setUserId(tokenBean.getId());
|
||||
platformUnique.setIsDeleted(0);
|
||||
saveOrUpdate(platformUnique);
|
||||
|
||||
// 添加登录日志
|
||||
coreLogService.addLoginLog(platformUnique);
|
||||
}
|
||||
return tokenBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginRedirect(TokenBean bean, String extra, HttpServletResponse response) {
|
||||
tieshengWebConfigurer.loginConfigurer().redirect(bean, extra, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过appId获取登录对象
|
||||
*
|
||||
* @param appId
|
||||
* @param uniqueId
|
||||
* @return
|
||||
*/
|
||||
private CorePlatformUnique getByAppAndUnique(String appId, String uniqueId, String platform) {
|
||||
QueryWrapper<CorePlatformUnique> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("app_id", appId);
|
||||
queryWrapper.eq("unique_id", uniqueId);
|
||||
queryWrapper.eq("platform", platform);
|
||||
queryWrapper.last("limit 1");
|
||||
CorePlatformUnique platformUnique = getOne(queryWrapper);
|
||||
if (platformUnique == null) {
|
||||
platformUnique = new CorePlatformUnique();
|
||||
platformUnique.setAppId(appId);
|
||||
platformUnique.setUniqueId(uniqueId);
|
||||
platformUnique.setPlatform(platform);
|
||||
}
|
||||
return platformUnique;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class FileUploadService {
|
||||
|
||||
@Autowired(required = false)
|
||||
@Autowired
|
||||
TieshengWebConfigurer tieshengWebConfigurer;
|
||||
|
||||
|
||||
@@ -38,10 +38,8 @@ public class FileUploadService {
|
||||
public String saveMultipartFile(MultipartFile file) {
|
||||
try {
|
||||
|
||||
if (tieshengWebConfigurer != null) {
|
||||
String fileType = FileTypeUtil.getType(file.getInputStream(), file.getOriginalFilename());
|
||||
tieshengWebConfigurer.uploadFileCheck(fileType);
|
||||
}
|
||||
String fileType = FileTypeUtil.getType(file.getInputStream(), file.getOriginalFilename());
|
||||
tieshengWebConfigurer.uploadFileCheck(fileType);
|
||||
|
||||
FileUploadPath filePath = FileUploadPath.random();
|
||||
|
||||
@@ -65,9 +63,7 @@ public class FileUploadService {
|
||||
* @param fileExt
|
||||
*/
|
||||
public void chunkStart(String fileExt) {
|
||||
if (tieshengWebConfigurer != null) {
|
||||
tieshengWebConfigurer.uploadFileCheck(fileExt);
|
||||
}
|
||||
tieshengWebConfigurer.uploadFileCheck(fileExt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,33 +107,33 @@ public class FileUploadService {
|
||||
* 合并块文件
|
||||
*
|
||||
* @param fileMd5
|
||||
* @param fileExt
|
||||
*/
|
||||
public String chunkMerge(String fileMd5) {
|
||||
|
||||
// 1,获取块文件的路径
|
||||
// 1,获取文件块的目录
|
||||
FileUploadPath folder = FileUploadPath.folder(fileMd5);
|
||||
|
||||
// 2,生成保存文件路径
|
||||
// 2,如果目录不存在
|
||||
if (!FileUtil.exist(folder.getAbsolutePath())) {
|
||||
throw new ApiException("请先上传文件块");
|
||||
}
|
||||
|
||||
// 3,生成保存文件的路径
|
||||
FileUploadPath uploadPath = FileUploadPath.random();
|
||||
|
||||
// 3,如果文件不存在
|
||||
if (FileUtil.exist(folder.getAbsolutePath())) {
|
||||
// 4,获取块文件,此列表是已经排好序的列表
|
||||
List<File> chunkFiles = getSortedChunkFiles(new File(folder.getAbsolutePath()));
|
||||
|
||||
// 4,获取块文件,此列表是已经排好序的列表
|
||||
List<File> chunkFiles = getChunkFiles(new File(folder.getAbsolutePath()));
|
||||
|
||||
// 5,合并文件
|
||||
File newFile = FileUtil.newFile(uploadPath.getAbsolutePath());
|
||||
for (File file : chunkFiles) {
|
||||
byte[] bytes = FileUtil.readBytes(file);
|
||||
FileUtil.writeBytes(bytes, newFile, 0, bytes.length, true);
|
||||
}
|
||||
|
||||
// 6,删除块文件目录
|
||||
FileUtil.del(folder.getAbsolutePath());
|
||||
// 5,合并文件
|
||||
File newFile = FileUtil.newFile(uploadPath.getAbsolutePath());
|
||||
for (File file : chunkFiles) {
|
||||
byte[] bytes = FileUtil.readBytes(file);
|
||||
FileUtil.writeBytes(bytes, newFile, 0, bytes.length, true);
|
||||
}
|
||||
|
||||
// 6,删除块文件目录
|
||||
FileUtil.del(folder.getAbsolutePath());
|
||||
|
||||
return uploadPath.getHttpPath();
|
||||
|
||||
}
|
||||
@@ -148,7 +144,7 @@ public class FileUploadService {
|
||||
* @param chunkFileFolder
|
||||
* @return
|
||||
*/
|
||||
private List<File> getChunkFiles(File chunkFileFolder) {
|
||||
private List<File> getSortedChunkFiles(File chunkFileFolder) {
|
||||
|
||||
//获取路径下的所有块文件
|
||||
File[] chunkFiles = chunkFileFolder.listFiles();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for core_log_login
|
||||
-- ----------------------------
|
||||
CREATE TABLE `core_log_login`
|
||||
(
|
||||
`id` varchar(50) NOT NULL,
|
||||
`create_time` datetime NOT NULL,
|
||||
`update_time` datetime NOT NULL,
|
||||
`is_deleted` int(6) NOT NULL DEFAULT '0',
|
||||
`user_id` varchar(50) DEFAULT NULL COMMENT '用户id',
|
||||
`user_name` varchar(255) DEFAULT NULL COMMENT '用户姓名',
|
||||
`platform` varchar(50) DEFAULT NULL COMMENT '登录方式',
|
||||
`ip` varchar(100) DEFAULT NULL COMMENT 'ip',
|
||||
`address` varchar(255) DEFAULT NULL COMMENT 'ip地址',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4 COMMENT ='日志-登录';
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@@ -0,0 +1,22 @@
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for core_platform_unique
|
||||
-- ----------------------------
|
||||
CREATE TABLE `core_platform_unique`
|
||||
(
|
||||
`id` varchar(50) NOT NULL,
|
||||
`create_time` datetime NOT NULL,
|
||||
`update_time` datetime NOT NULL,
|
||||
`is_deleted` int(6) NOT NULL DEFAULT '0',
|
||||
`user_id` varchar(50) DEFAULT NULL COMMENT '用户id',
|
||||
`app_id` varchar(255) DEFAULT NULL COMMENT 'appId',
|
||||
`unique_id` varchar(255) DEFAULT NULL COMMENT '唯一值',
|
||||
`platform` varchar(255) DEFAULT NULL COMMENT '平台',
|
||||
`info` text COMMENT '其他参数',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4 COMMENT ='平台-唯一值';
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tiesheng.core.mapper.CoreLogLoginMapper">
|
||||
<resultMap id="BaseResultMap" type="com.tiesheng.core.pojos.dao.CoreLogLogin">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table core_log_login-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||
<result column="user_id" jdbcType="VARCHAR" property="userId" />
|
||||
<result column="user_name" jdbcType="VARCHAR" property="userName" />
|
||||
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||
<result column="ip" jdbcType="VARCHAR" property="ip" />
|
||||
<result column="address" jdbcType="VARCHAR" property="address" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tiesheng.core.mapper.CorePlatformUniqueMapper">
|
||||
<resultMap id="BaseResultMap" type="com.tiesheng.core.pojos.dao.CorePlatformUnique">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table core_platform_unique-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||
<result column="user_id" jdbcType="VARCHAR" property="userId" />
|
||||
<result column="app_id" jdbcType="VARCHAR" property="appId" />
|
||||
<result column="unique_id" jdbcType="VARCHAR" property="uniqueId" />
|
||||
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||
<result column="info" jdbcType="LONGVARCHAR" property="info" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, user_id, app_id, unique_id, platform, info
|
||||
</sql>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user