task调整

master
wj 2 years ago
parent e70b41d58c
commit 1eb7afe25e

@ -21,7 +21,7 @@ import javax.sql.DataSource;
@Configuration
// 扫描 Mapper 接口并容器管理
@MapperScan(basePackages = {"com.glxp.sale.admin.dao","com.glxp.sale.admin.*.dao"}, sqlSessionFactoryRef = "masterSqlSessionFactory")
@MapperScan(basePackages = {"com.glxp.sale.admin.dao", "com.glxp.sale.admin.*.dao"}, sqlSessionFactoryRef = "masterSqlSessionFactory")
public class MasterDataSourceConfig {//TODO Mapper
// 精确到 master 目录,以便跟其他数据源隔离
@ -43,8 +43,9 @@ public class MasterDataSourceConfig {//TODO Mapper
@Configuration
@ConfigurationProperties(prefix = "mybatis-plus.configuration")
public class CusMybatisConfiguration extends MybatisConfiguration{
public class CusMybatisConfiguration extends MybatisConfiguration {
}
@Configuration
@ConfigurationProperties(prefix = "mybatis-plus.global-config")
public class CusGlobalConfig extends GlobalConfig {
@ -56,7 +57,8 @@ public class MasterDataSourceConfig {//TODO Mapper
throws Exception {
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(masterDataSource);
sessionFactory.setConfiguration((MybatisConfiguration) configuration);
configuration.setMapUnderscoreToCamelCase(false);
sessionFactory.setConfiguration(configuration);
sessionFactory.setGlobalConfig(globalConfig);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(MasterDataSourceConfig.MAPPER_LOCATION));

@ -14,9 +14,18 @@ import com.glxp.sale.common.res.BaseResponse;
import com.glxp.sale.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@ -101,4 +110,108 @@ public class BasicDataSyncStatusController {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
@GetMapping("/spssync/basic/udiinfo/uploadInfoByStatus")
public void uploadInfoByStatus(HttpServletResponse response, String id) throws IOException {
if (StrUtil.isBlank(id)) {
throw new RuntimeException("缺少唯一标识");
}
BasicUploadStatusEntity info = basicUploadService.getById(id);
if (info == null) {
throw new RuntimeException("数据不存在");
}
if (StrUtil.isBlank(info.getCacheFilePath())) {
throw new RuntimeException("文件未生成");
}
File file = new File(info.getCacheFilePath());
if (!file.exists()) {
throw new RuntimeException("文件丢失");
}
String[] split = info.getCacheFilePath().split("/");
String enFileName = URLEncoder.encode(split[split.length - 1], StandardCharsets.UTF_8);
// 设值返回文件属性,浏览器会根据属性调用下载文件方法
response.addHeader("Content-Disposition", "attachment;filename=" + enFileName);
// 前端获取文件名,需要解码
response.addHeader("downLoadName", enFileName);
// 定义输出流
ServletOutputStream outputStream = null;
FileInputStream fileInputStream = null;
try {
outputStream = response.getOutputStream();
// 定义输出类型为二进制流输出
response.setContentType("application/octet-stream");
fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
// 把流写入response
outputStream.write(bytes);
// flush落盘
outputStream.flush();
// 关闭输出流
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (outputStream != null) {
outputStream.close();
}
if (fileInputStream != null) {
fileInputStream.close();
}
}
}
@GetMapping("/spssync/basic/udiinfo/infoByStatus")
public void infoByStatus(HttpServletResponse response, String id) throws IOException {
if (StrUtil.isBlank(id)) {
throw new RuntimeException("缺少唯一标识");
}
BasicExportStatusEntity info = basicExportService.getById(id);
if (info == null) {
throw new RuntimeException("数据不存在");
}
if (StrUtil.isBlank(info.getCacheFilePath())) {
throw new RuntimeException("文件未生成");
}
File file = new File(info.getCacheFilePath());
if (!file.exists()) {
throw new RuntimeException("文件丢失");
}
String[] split = info.getCacheFilePath().split("/");
String enFileName = URLEncoder.encode(split[split.length - 1], StandardCharsets.UTF_8);
// 设值返回文件属性,浏览器会根据属性调用下载文件方法
response.addHeader("Content-Disposition", "attachment;filename=" + enFileName);
// 前端获取文件名,需要解码
response.addHeader("downLoadName", enFileName);
// 定义输出流
ServletOutputStream outputStream = null;
FileInputStream fileInputStream = null;
try {
outputStream = response.getOutputStream();
// 定义输出类型为二进制流输出
response.setContentType("application/octet-stream");
fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
// 把流写入response
outputStream.write(bytes);
// flush落盘
outputStream.flush();
// 关闭输出流
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (outputStream != null) {
outputStream.close();
}
if (fileInputStream != null) {
fileInputStream.close();
}
}
}
}

@ -281,7 +281,7 @@ public class SpsSyncDataController {
}
@PostMapping("/spssync/basic/udiinfo/finishTask")
@PostMapping("/spssync/udiinfo/finishTask")
public BaseResponse finishTask(@RequestBody BasicExportStatusEntity basicExportStatusEntity) {
if (StrUtil.isBlank(basicExportStatusEntity.getId())) {
@ -295,6 +295,7 @@ public class SpsSyncDataController {
.eq(BasicExportStatusEntity::getId, basicExportStatusEntity.getId())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
);
spGetHttp.receiveTask(basicExportStatusEntity.getId());
if (b)
return ResultVOUtils.success("更新成功!");
else
@ -343,10 +344,11 @@ public class SpsSyncDataController {
basicUploadStatusEntity.setIdDatas(exportType.getKey());
basicUploadStatusEntity.setType(exportType.getRemark());
basicUploadStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicUploadService.insertDownloadStatus(basicUploadStatusEntity);
FileUtils.makeDirectory(filePath + "upload/");
String fileName = filePath + "upload/" + exportType.getRemark() + "-" + taskId + ".udi";
FileUtils.SaveFileAs(content, fileName);
basicUploadStatusEntity.setCacheFilePath(fileName);
basicUploadService.insertDownloadStatus(basicUploadStatusEntity);
}
@Async

@ -1,5 +1,6 @@
package com.glxp.sale.admin.dao.sync;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.sale.admin.entity.sync.BasicUploadStatusEntity;
import com.glxp.sale.admin.req.sync.BasicUploadRequest;
import org.apache.ibatis.annotations.Mapper;
@ -8,7 +9,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface BasicUploadDao {
public interface BasicUploadDao extends BaseMapper<BasicUploadStatusEntity> {
List<BasicUploadStatusEntity> filterUploadStatus(BasicUploadRequest basicDownloadRequest);

@ -1,5 +1,6 @@
package com.glxp.sale.admin.entity.sync;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@ -8,6 +9,7 @@ import java.util.Date;
*
*/
@Data
@TableName("basic_upload_status")
public class BasicUploadStatusEntity {
private String id;
private String taskId;

@ -331,7 +331,13 @@ public class SpGetHttp {
public void finishTask(String id) {
String result = UHttpClient.postJson(getSpmsUrl() + "/spssync/basic/udiinfo/finishTask"
String result = UHttpClient.postJson(getSpmsUrl() + "/spssync/udiinfo/finishTask"
, Map.of("id", id), getHeaders());
}
public void receiveTask(String id) {
String result = UHttpClient.postJson(getSpmsUrl() + "/spssync/udiinfo/receiveTask"
, Map.of("id", id), getHeaders());
}

@ -1,11 +1,12 @@
package com.glxp.sale.admin.service.sync;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.sale.admin.entity.sync.BasicUploadStatusEntity;
import com.glxp.sale.admin.req.sync.BasicUploadRequest;
import java.util.List;
public interface BasicUploadService {
public interface BasicUploadService extends IService<BasicUploadStatusEntity> {
BasicUploadStatusEntity findByData(String idDatas, Integer status);

@ -1,6 +1,7 @@
package com.glxp.sale.admin.service.sync.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.sale.admin.dao.sync.BasicUploadDao;
import com.glxp.sale.admin.entity.sync.BasicUploadStatusEntity;
@ -15,7 +16,7 @@ import java.util.List;
@Slf4j
@Service
public class BasicUploadServiceImpl implements BasicUploadService {
public class BasicUploadServiceImpl extends ServiceImpl<BasicUploadDao,BasicUploadStatusEntity> implements BasicUploadService {
@Resource
private BasicUploadDao basicUploadDao;

@ -27,7 +27,7 @@
and scheduleType = #{scheduleType}
</if>
</where>
order by updateTime desc
order by startTime desc
</select>

Loading…
Cancel
Save