Commit 23fbc1ba authored by 吴琼's avatar 吴琼

xiugai

parent 343364b4
...@@ -61,6 +61,7 @@ public class TransactionReceiptRecordRest { ...@@ -61,6 +61,7 @@ public class TransactionReceiptRecordRest {
try{ try{
return transactionReceiptRecordService.importTransactionReceiptRecord(file); return transactionReceiptRecordService.importTransactionReceiptRecord(file);
}catch(Exception e){ }catch(Exception e){
transactionReceiptRecordService.deleteRedis("importTransactionReceiptRecord");
return JsonResult.buildErrorStateResult(e.getMessage()); return JsonResult.buildErrorStateResult(e.getMessage());
} }
} }
...@@ -90,6 +91,7 @@ public class TransactionReceiptRecordRest { ...@@ -90,6 +91,7 @@ public class TransactionReceiptRecordRest {
try{ try{
return transactionReceiptRecordService.exportZipFile(request,response); return transactionReceiptRecordService.exportZipFile(request,response);
}catch(Exception e){ }catch(Exception e){
transactionReceiptRecordService.deleteRedis("exportZipFile");
return JsonResult.buildErrorStateResult("导出文件出现错误"); return JsonResult.buildErrorStateResult("导出文件出现错误");
} }
......
...@@ -24,4 +24,6 @@ public interface ITransactionReceiptRecordService { ...@@ -24,4 +24,6 @@ public interface ITransactionReceiptRecordService {
void generatePDF(TransactionReceiptVO transactionReceiptVO, String filePath); void generatePDF(TransactionReceiptVO transactionReceiptVO, String filePath);
void deleteRedis(String str);
} }
...@@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import sun.misc.IOUtils; import sun.misc.IOUtils;
...@@ -100,6 +101,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -100,6 +101,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
@Value("${customer.transaction.local.file.limit}") @Value("${customer.transaction.local.file.limit}")
private int limit; private int limit;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Override @Override
public JsonResult<Page<TransactionReceiptRecordVO>> findRecordsByQuery(TransactionReceiptRecordQuery query) { public JsonResult<Page<TransactionReceiptRecordVO>> findRecordsByQuery(TransactionReceiptRecordQuery query) {
...@@ -112,12 +116,11 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -112,12 +116,11 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
} }
if (StringUtils.isNotEmpty(query.getImportStatus())) { if (StringUtils.isNotEmpty(query.getImportStatus())) {
predicates.add(criteriaBuilder.equal(root.get("importStatus"), query.getImportStatus())); predicates.add(criteriaBuilder.equal(root.get("importStatus"), query.getImportStatus()));
}else{
predicates.add(criteriaBuilder.equal(root.get("importStatus"), 1));
} }
if (StringUtils.isNotEmpty(query.getExportStatus())) { if (StringUtils.isNotEmpty(query.getExportStatus())) {
predicates.add(criteriaBuilder.equal(root.get("exportStatus"), query.getExportStatus())); predicates.add(criteriaBuilder.equal(root.get("exportStatus"), query.getExportStatus()));
}else{
predicates.add(criteriaBuilder.equal(root.get("exportStatus"), 1));
} }
// 设置查询条件 // 设置查询条件
criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]))); criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()])));
...@@ -146,9 +149,37 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -146,9 +149,37 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
} }
} }
/**
*校验是否有其他人在导入、导出
*/
private String checkRedis(String str){
log.info("redis add TransactionReceiptRecordServiceImpl."+str+".userId", redisTemplate);
String obj = (String) redisTemplate.opsForValue().get("TransactionReceiptRecordServiceImpl."+str+".userId");
if(StringUtils.isBlank(obj)){
redisTemplate.opsForValue().set("TransactionReceiptRecordServiceImpl."+str+"..userId", str);
return "";
}
return obj;
}
/**
* 删除redis中的值
*/
public void deleteRedis(String str){
log.info("redis delete TransactionReceiptRecordServiceImpl."+str+".userId", redisTemplate);
String obj = (String) redisTemplate.opsForValue().get("TransactionReceiptRecordServiceImpl."+str+".userId");
if(StringUtils.isNotBlank(obj)){
redisTemplate.opsForValue().set("TransactionReceiptRecordServiceImpl."+str+"..userId", "");
}
}
@Override @Override
@Transactional @Transactional
public JsonResult importTransactionReceiptRecord(MultipartFile file) throws RuntimeException { public JsonResult importTransactionReceiptRecord(MultipartFile file) throws RuntimeException {
String str = checkRedis("importTransactionReceiptRecord");
if(StringUtils.isNotBlank(str)){
throw new RuntimeException("只能一个人导入,当前有其他人正在导入,请稍后重试");
}
log.info("[TransactionReceiptRecordServiceImpl importTransactionReceiptRecord] end,query={} ", file); log.info("[TransactionReceiptRecordServiceImpl importTransactionReceiptRecord] end,query={} ", file);
//查询未导出数据最大批次号 //查询未导出数据最大批次号
Integer maxBatchNo = transactionReceiptRecordRepo.findMaxBatchNo(0); Integer maxBatchNo = transactionReceiptRecordRepo.findMaxBatchNo(0);
...@@ -163,12 +194,15 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -163,12 +194,15 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
try { try {
readList = read(file.getOriginalFilename(), file.getInputStream()); readList = read(file.getOriginalFilename(), file.getInputStream());
if(CollectionUtils.isEmpty(readList)){ if(CollectionUtils.isEmpty(readList)){
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("文件中没有数据"); throw new RuntimeException("文件中没有数据");
} }
if(readList !=null && readList.size() > fileSize){ if(readList !=null && readList.size() > fileSize){
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("文件太大,最多可以读取"+fileSize+"条数据!"); throw new RuntimeException("文件太大,最多可以读取"+fileSize+"条数据!");
} }
} catch (IOException e) { } catch (IOException e) {
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("读取数据异常"); throw new RuntimeException("读取数据异常");
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
...@@ -187,6 +221,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -187,6 +221,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
List<TransactionReceiptRecord> records = List<TransactionReceiptRecord> records =
transactionReceiptRecordRepo.selectRecordsByOrderNo(record.getOrderNo(),record.getUserId(),record.getUserName()); transactionReceiptRecordRepo.selectRecordsByOrderNo(record.getOrderNo(),record.getUserId(),record.getUserName());
if(CollectionUtils.isNotEmpty(records)){ if(CollectionUtils.isNotEmpty(records)){
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("存在userid为"+record.getUserId()+",姓名为"+record.getUserName()+",交易单号为"+record.getOrderNo()+"数据还未导出,不能再次导入"); throw new RuntimeException("存在userid为"+record.getUserId()+",姓名为"+record.getUserName()+",交易单号为"+record.getOrderNo()+"数据还未导出,不能再次导入");
} }
//保存时如果有其中一项为空则默认为导入失败,其他则默认初始状态 //保存时如果有其中一项为空则默认为导入失败,其他则默认初始状态
...@@ -208,6 +243,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -208,6 +243,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log.info("TransactionReceiptRecordServiceImpl importTransactionReceiptRecord save end"); log.info("TransactionReceiptRecordServiceImpl importTransactionReceiptRecord save end");
return updateTransactionRecordsStatus(); return updateTransactionRecordsStatus();
} }
deleteRedis("importTransactionReceiptRecord");
return JsonResult.buildErrorStateResult("未读取到数据或读取失败"); return JsonResult.buildErrorStateResult("未读取到数据或读取失败");
} }
...@@ -284,12 +320,17 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -284,12 +320,17 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//导出zip压缩包文件 //导出zip压缩包文件
@Transactional @Transactional
public JsonResult exportZipFile(HttpServletRequest request, HttpServletResponse response) throws RuntimeException { public JsonResult exportZipFile(HttpServletRequest request, HttpServletResponse response) throws RuntimeException {
String str = checkRedis("exportZipFile");
if(StringUtils.isNotBlank(str)){
throw new RuntimeException("只能一个人导出,当前有其他人正在导出,请稍后重试");
}
//调用电商接口获取对应数据 //调用电商接口获取对应数据
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile begin]"); log.info("[TransactionReceiptRecordServiceImpl.exportZipFile begin]");
//查询需要导出的数据-导入成功的数据,但未导出成功的数据 //查询需要导出的数据-导入成功的数据,但未导出成功的数据
List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(1,limit); List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(1,limit);
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList] 可导出数据为:",transactionReceiptRecordList.size()); log.info("[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList] 可导出数据为:",transactionReceiptRecordList.size());
if(CollectionUtils.isEmpty(transactionReceiptRecordList)){ if(CollectionUtils.isEmpty(transactionReceiptRecordList)){
deleteRedis("exportZipFile");
return JsonResult.buildErrorStateResult("没有可以导出得数据"); return JsonResult.buildErrorStateResult("没有可以导出得数据");
} }
//查询导入成功数据的导出的最大批次号 //查询导入成功数据的导出的最大批次号
...@@ -326,6 +367,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -326,6 +367,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log.info("调用kdsp查询订单接口返回结果,result:",result); log.info("调用kdsp查询订单接口返回结果,result:",result);
//转换成json 对象 //转换成json 对象
if(StringUtils.isBlank(result)){ if(StringUtils.isBlank(result)){
deleteRedis("exportZipFile");
throw new RuntimeException("未查询到订单数据"); throw new RuntimeException("未查询到订单数据");
} }
JSONObject json = JSONObject.parseObject(result); JSONObject json = JSONObject.parseObject(result);
...@@ -372,6 +414,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -372,6 +414,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
filePathList.add(map); filePathList.add(map);
} }
} catch (Exception e) { } catch (Exception e) {
deleteRedis("exportZipFile");
log.error("[TransactionReceiptRecordServiceImpl][exportZipFile] 网络通讯异常,userId:{},ex:{}", ExceptionUtils.getStackTrace(e)); log.error("[TransactionReceiptRecordServiceImpl][exportZipFile] 网络通讯异常,userId:{},ex:{}", ExceptionUtils.getStackTrace(e));
return JsonResult.buildErrorStateResult(e.getMessage()); return JsonResult.buildErrorStateResult(e.getMessage());
} }
...@@ -381,6 +424,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -381,6 +424,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log.info("[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]",System.currentTimeMillis()); log.info("[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]",System.currentTimeMillis());
//调用签章接口 //调用签章接口
if(filePathList.isEmpty()){ if(filePathList.isEmpty()){
deleteRedis("exportZipFile");
throw new RuntimeException("没有可以导出的数据"); throw new RuntimeException("没有可以导出的数据");
} }
log.info("contractUrl /contract/batch/sign 调用签章接口"); log.info("contractUrl /contract/batch/sign 调用签章接口");
...@@ -394,6 +438,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -394,6 +438,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
String jsonResult = json.getString("data"); String jsonResult = json.getString("data");
String businessCode = json.getString("businessCode"); String businessCode = json.getString("businessCode");
if(!"0000".equals(businessCode)){ if(!"0000".equals(businessCode)){
deleteRedis("exportZipFile");
throw new RuntimeException("签章失败!"); throw new RuntimeException("签章失败!");
} }
JSONObject jsonObject = JSONObject.parseObject(jsonResult); JSONObject jsonObject = JSONObject.parseObject(jsonResult);
...@@ -420,6 +465,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -420,6 +465,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
} }
}else{ }else{
sftpUtil.logout(); sftpUtil.logout();
deleteRedis("exportZipFile");
throw new RuntimeException("签章失败!"); throw new RuntimeException("签章失败!");
} }
//更新数据 //更新数据
...@@ -456,6 +502,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -456,6 +502,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
deleteDirectory(deleteFile1); deleteDirectory(deleteFile1);
return JsonResult.buildSuccessResult("ok",map); return JsonResult.buildSuccessResult("ok",map);
} catch (Exception e) { } catch (Exception e) {
deleteRedis("exportZipFile");
throw new RuntimeException("文件转换失败"); throw new RuntimeException("文件转换失败");
} }
} }
...@@ -593,6 +640,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -593,6 +640,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
JSONObject kJson =JSONObject.parseObject(kResult); JSONObject kJson =JSONObject.parseObject(kResult);
String businessCode = kJson.getString("businessCode"); String businessCode = kJson.getString("businessCode");
if(!"0000".equals(businessCode)){ if(!"0000".equals(businessCode)){
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("调用电商接口报错"); throw new RuntimeException("调用电商接口报错");
} }
log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用商城接口 end"); log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用商城接口 end");
...@@ -616,6 +664,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -616,6 +664,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
failList.add(record); failList.add(record);
} }
}catch(Exception e){ }catch(Exception e){
deleteRedis("importTransactionReceiptRecord");
throw new RuntimeException("调用接口报错"); throw new RuntimeException("调用接口报错");
} }
} }
...@@ -628,6 +677,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -628,6 +677,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
} }
log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 校验更新数据 end"); log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 校验更新数据 end");
} }
deleteRedis("importTransactionReceiptRecord");
return JsonResult.buildSuccessResult("数据导入成功",null); return JsonResult.buildSuccessResult("数据导入成功",null);
} }
......
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