1.修改产品信息导出json文件

master
MrZhai 3 years ago
parent 16bd9d3810
commit c89df98970

@ -17,6 +17,7 @@ public class BasicProcessStatus {
public static final int EXPORT_EXCEL = 1;
public static final int EXPORT_SMP = 2;
public static final int EXPORT_JSON = 3;
}

@ -116,12 +116,10 @@ public class ThrProductsExportLogController {
//产品信息导出生成Excel并创建生成记录
@PostMapping("/udiwms/thrProducts/importLog/export")
public BaseResponse excelDownload(@RequestBody ThrProductsExportRequest thrProductsExportRequest) {
ThrProductsExportLogEntity thrProductsExportLogEntity = new ThrProductsExportLogEntity();
thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_PROCESS);
String genKey = CustomUtil.getId();
String fileName = "D:\\udiwms\\exportFile\\" + "第三方产品信息" + genKey + ".xls";
String fileName = "D:\\udiwms\\exportFile\\" + "第三方产品信息" + genKey + ".json";
File file = new File(fileName);
if (!file.exists()) {
try {
@ -134,11 +132,13 @@ public class ThrProductsExportLogController {
thrProductsExportLogEntity.setFilePath(fileName);
thrProductsExportLogEntity.setUpdateTime(new Date());
thrProductsExportLogEntity.setDlCount(0);
thrProductsExportLogEntity.setType(BasicProcessStatus.EXPORT_EXCEL);
thrProductsExportLogEntity.setType(BasicProcessStatus.EXPORT_JSON);
thrProductsExportLogService.insertThrProductsExportLog(thrProductsExportLogEntity);
thrProductsDlService.genExcel(genKey, thrProductsExportRequest);
return ResultVOUtils.success("后台正在导出生成excel文件请稍后刷新查看!");
//thrProductsDlService.genExcel(genKey, thrProductsExportRequest);
//修改为导出json文件
thrProductsDlService.genJsonFile(genKey, thrProductsExportRequest);
return ResultVOUtils.success("后台正在导出生成excel文件请稍后刷新查看!");
}

@ -17,4 +17,12 @@ public interface ThrProductsExportLogDao {
boolean updateThrProductsExportLog(ThrProductsExportLogEntity thrProductsExportLogEntity);
boolean deleteById(@Param("id") String id);
/**
*
*
* @param id
* @return
*/
String selectFilePathById(@Param("id") String id);
}

@ -1,5 +1,7 @@
package com.glxp.api.admin.service.thrsys.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.glxp.api.admin.dao.thrsys.ThrProductsExportLogDao;
import com.glxp.api.admin.entity.thrsys.ThrProductsExportLogEntity;
@ -52,6 +54,11 @@ public class ThrProductsExportLogServiceImpl implements ThrProductsExportLogServ
@Override
public boolean deleteById(String id) {
//删除日志同步删除文件
String filePath = thrProductsExportLogDao.selectFilePathById(id);
if (StrUtil.isNotBlank(filePath)) {
FileUtil.del(filePath);
}
return thrProductsExportLogDao.deleteById(id);
}
}

@ -1,12 +1,16 @@
package com.glxp.api.admin.thread;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.admin.config.WebSocketServer;
import com.glxp.api.admin.constant.BasicProcessStatus;
import com.glxp.api.admin.entity.basic.BasicThirdSysDetailEntity;
import com.glxp.api.admin.entity.info.SystemParamConfigEntity;
import com.glxp.api.admin.entity.thrsys.*;
import com.glxp.api.admin.entity.thrsys.ThrProductsEntity;
import com.glxp.api.admin.entity.thrsys.ThrProductsExportLogEntity;
import com.glxp.api.admin.entity.thrsys.ThrProductsImportDetailEntity;
import com.glxp.api.admin.entity.thrsys.ThrProductsImportLogEntity;
import com.glxp.api.admin.httpclient.ErpBasicClient;
import com.glxp.api.admin.req.basic.FilterErpGoodsRequest;
import com.glxp.api.admin.req.basic.FilterUdiIpLogRequest;
@ -422,6 +426,17 @@ public class ThrProductsDlService {
return excelData;
}
public List<ThrProductsEntity> genJsonData(String id, FilterThrProductsRequest filterThrProductsRequest) {
List<ThrProductsEntity> jsonData = new ArrayList<>();
if (id != null) {
ThrProductsEntity thrProductsEntity = thrProductsService.selectById(id);
jsonData.add(thrProductsEntity);
} else {
jsonData = thrProductsService.filterThrProductsRequest(filterThrProductsRequest);
}
return jsonData;
}
public List<List<String>> getRows(List<ThrProductsEntity> thrProductsEntities) {
List<List<String>> excelData = new ArrayList<>();
for (ThrProductsEntity thrProductsEntity : thrProductsEntities) {
@ -437,4 +452,52 @@ public class ThrProductsDlService {
}
return excelData;
}
//导出json文件
@Async
public void genJsonFile(String genKey, ThrProductsExportRequest thrProductsExportRequest) {
ThrProductsExportLogEntity thrProductsExportLogEntity = thrProductsExportLogService.selectByGenKey(genKey);
List<ThrProductsEntity> exportData = new ArrayList<>();
//选中导出
if (thrProductsExportRequest.getThrProductsEntities() != null && thrProductsExportRequest.getThrProductsEntities().size() > 0) {
List<ThrProductsEntity> thrProductsEntities = thrProductsExportRequest.getThrProductsEntities();
exportData.addAll(thrProductsEntities);
} else {//一键导出
BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailService.selectByKey("piQueryUrl", thrProductsExportRequest.getThirdSys());
if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) {
thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
thrProductsExportLogEntity.setRemark("产品信息接口未定义!");
thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity);
return;
}
if (!basicThirdSysDetailEntity.getEnabled()) {
thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
thrProductsExportLogEntity.setRemark("第三方产品信息服务未启用!");
thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity);
return;
}
if (basicThirdSysDetailEntity.getFromType() == 0) {
FilterThrProductsRequest filterThrProductsRequest = new FilterThrProductsRequest();
BeanUtils.copyProperties(thrProductsExportRequest, filterThrProductsRequest);
List<ThrProductsEntity> thrProductsEntities = exportThrProducts(filterThrProductsRequest);
exportData.addAll(thrProductsEntities);
} else {
FilterThrProductsRequest filterThrInvProductsRequest = new FilterThrProductsRequest();
BeanUtils.copyProperties(thrProductsExportRequest, filterThrInvProductsRequest);
List<ThrProductsEntity> jsonData = genJsonData(null, filterThrInvProductsRequest);
exportData.addAll(jsonData);
}
}
FileWriter writer = new FileWriter(thrProductsExportLogEntity.getFilePath());
writer.write(JSONUtil.toJsonStr(exportData));
thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity);
}
}

@ -19,6 +19,9 @@
</where>
ORDER BY updateTime DESC
</select>
<select id="selectFilePathById" resultType="java.lang.String">
select filePath from thr_products_export_log where id = #{id}
</select>
<insert id="insertThrProductsExportLog" keyProperty="id"

Loading…
Cancel
Save