Commit 62e75e42 authored by tianbo's avatar tianbo

bugfix:cyl对接气瓶编号唯一校验

parent 00ebf8c6
......@@ -2,38 +2,24 @@ package com.yeejoin.amos.api.openapi.controller;
import com.yeejoin.amos.api.common.restful.utils.ResponseHelper;
import com.yeejoin.amos.api.common.restful.utils.ResponseModel;
import com.yeejoin.amos.api.openapi.constant.Constant;
import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.api.openapi.face.service.*;
import com.yeejoin.amos.boot.module.cylinder.api.dto.CylinderFillingMessage;
import com.yeejoin.amos.boot.module.cylinder.api.dto.CylinderFillingMessageModel;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.component.cache.Redis;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.event.RestEventTrigger;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
......@@ -69,6 +55,9 @@ public class CylinderController {
@Autowired
private TmCylinderOffloadingService cylinderOffloadingService;
@Autowired
private CylinderService cylinderService;
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
......@@ -80,6 +69,7 @@ public class CylinderController {
return ResponseHelper.buildResponse(cylinderUnitService.createCylinderUnit(unitData));
}
@Deprecated
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "气瓶基础数据")
@PostMapping(value = "/info")
......@@ -113,80 +103,88 @@ public class CylinderController {
@PostMapping(value = "/filling")
@RestEventTrigger(value = "openapiLogEventHandler")
public ResponseModel<String> cylinderFillingInfo(@RequestBody String fillingData) throws Exception {
String token = RequestContext.getToken();
AgencyUserModel me = Privilege.agencyUserClient.getme().getResult();
String tokenKey = Redis.genKey(Constant.TOKEN_PREFIX, token);
BizTokenModel bizTokenModel = (BizTokenModel)this.redisTemplate.opsForValue().get(tokenKey);
JSONObject jsonobject = JSONObject.fromObject(fillingData);
CylinderFillingDataValidationResultModel validateResult = null;
CylinderFillingMessage cylinderFillingMessage = new CylinderFillingMessage();
cylinderFillingMessage.setTime(simpleDateFormat.format(new Date()));
cylinderFillingMessage.setFillingCompanyName(me.getCompanys().get(0).getCompanyName());
cylinderFillingMessage.setAppId(bizTokenModel.getAppId());
try {
validateResult = cylinderFillingDataValidationService.validateFilling(jsonobject);
} catch (Exception e) {
e.printStackTrace();
logger.error("液化气体气瓶充装信息上报,数据校验失败");
cylinderFillingMessage.setMessage(e.getMessage());
}
if (!ObjectUtils.isEmpty(validateResult)) {
cylinderFillingMessage.setCylinderNumber(validateResult.getCylinderNumber());
List<String> message = new ArrayList<>();
Integer errorNumber = 0;
JSONObject error = new JSONObject();
if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) {
errorNumber += validateResult.getBeforeErrorData().size();
error.put("充装前检查错误数据:", validateResult.getBeforeErrorData());
message.add("充装前检查数据异常气瓶数:" + validateResult.getBeforeErrorCylinderNumber());
}
if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) {
errorNumber += validateResult.getRecordErrorData().size();
error.put("填充错误数据:", validateResult.getRecordErrorData());
message.add("充装记录数据异常气瓶数:" + validateResult.getRecordErrorCylinderNumber());
}
if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) {
errorNumber += validateResult.getAfterErrorData().size();
error.put("充装后错误数据:", validateResult.getAfterErrorData());
message.add("充装后复查数据异常气瓶数:" + validateResult.getAfterErrorCylinderNumber());
}
if (errorNumber <= 0) {
message.add("液化气体气瓶充装信息成功数:" + validateResult.getSuccessCylinderNumber() + "条");
} else {
cylinderFillingMessage.setMessage(String.join("条; ", message));
CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
throw new BadRequest(error.toString());
}
} else {
throw new BadRequest("数据校验失败!!!");
}
TmCylinderFillingModelList cylinderFillingModelList = com.alibaba.fastjson.JSONObject.parseObject(fillingData, TmCylinderFillingModelList.class);
List<TmCylinderFillingModel> fillingBeforeList = cylinderFillingModelList.getFillingBefore();
List<TmCylinderFillingRecordModel> fillingList = cylinderFillingModelList.getFilling();
List<TmCylinderFillingCheckModel> fillingAfterList = cylinderFillingModelList.getFillingAfter();
if (ValidationUtil.isEmpty(fillingBeforeList) && ValidationUtil.isEmpty(fillingList) && ValidationUtil.isEmpty(fillingAfterList)) {
throw new BadRequest("液化气体气瓶充装信息-充装前检查信息、液化气体气瓶充装信息-充装记录信息、液化气体气瓶充装信息-充装后复查信息为空.");
}
cylinderFillingService.createCylinderFillingBefore(fillingBeforeList);
cylinderFillingRecordService.createCylinderFilling(fillingList);
cylinderFillingCheckService.createCylinderFillingAfter(fillingAfterList);
CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
cylinderFillingMessageModel.setAppId(bizTokenModel.getAppId());
cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
cylinderService.cylinderFillingHandler(fillingData);
// String token = RequestContext.getToken();
// AgencyUserModel me = Privilege.agencyUserClient.getme().getResult();
// String tokenKey = Redis.genKey(Constant.TOKEN_PREFIX, token);
// BizTokenModel bizTokenModel = (BizTokenModel)this.redisTemplate.opsForValue().get(tokenKey);
//
// JSONObject jsonobject = JSONObject.fromObject(fillingData);
// CylinderFillingDataValidationResultModel validateResult = null;
// CylinderFillingMessage cylinderFillingMessage = new CylinderFillingMessage();
// cylinderFillingMessage.setTime(simpleDateFormat.format(new Date()));
// cylinderFillingMessage.setFillingCompanyName(me.getCompanys().get(0).getCompanyName());
// cylinderFillingMessage.setAppId(bizTokenModel.getAppId());
// try {
// validateResult = cylinderFillingDataValidationService.validateFilling(jsonobject);
// } catch (Exception e) {
// e.printStackTrace();
// logger.error("液化气体气瓶充装信息上报,数据校验失败");
// cylinderFillingMessage.setMessage(e.getMessage());
// }
//
// if (!ObjectUtils.isEmpty(validateResult)) {
// cylinderFillingMessage.setCylinderNumber(validateResult.getCylinderNumber());
// List<String> message = new ArrayList<>();
// Integer errorNumber = 0;
// JSONObject error = new JSONObject();
// if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) {
// errorNumber += validateResult.getBeforeErrorData().size();
// error.put("充装前检查错误数据:", validateResult.getBeforeErrorData());
// message.add("充装前检查数据异常气瓶数:" + validateResult.getBeforeErrorCylinderNumber());
// }
//
// if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) {
// errorNumber += validateResult.getRecordErrorData().size();
// error.put("填充错误数据:", validateResult.getRecordErrorData());
// message.add("充装记录数据异常气瓶数:" + validateResult.getRecordErrorCylinderNumber());
// }
//
// if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) {
// errorNumber += validateResult.getAfterErrorData().size();
// error.put("充装后错误数据:", validateResult.getAfterErrorData());
// message.add("充装后复查数据异常气瓶数:" + validateResult.getAfterErrorCylinderNumber());
// }
//
// if (!org.springframework.util.ObjectUtils.isEmpty(validateResult.getSeqCodeErrorData())) {
// errorNumber += validateResult.getSeqCodeErrorData().size();
// error.put("气瓶信息不存在:", validateResult.getSeqCodeErrorData());
// message.add("气瓶信息不存在数量:" + validateResult.getSeqCodeErrorData().size());
// }
//
// if (errorNumber <= 0) {
// message.add("液化气体气瓶充装信息成功数:" + validateResult.getSuccessCylinderNumber() + "条");
// } else {
// cylinderFillingMessage.setMessage(String.join("条; ", message) + "个");
// CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
// BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
// cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
// emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
//
// throw new BadRequest(error.toString());
// }
// } else {
// throw new BadRequest("数据校验失败!!!");
// }
//
// TmCylinderFillingModelList cylinderFillingModelList = com.alibaba.fastjson.JSONObject.parseObject(fillingData, TmCylinderFillingModelList.class);
//
// List<TmCylinderFillingModel> fillingBeforeList = cylinderFillingModelList.getFillingBefore();
// List<TmCylinderFillingRecordModel> fillingList = cylinderFillingModelList.getFilling();
// List<TmCylinderFillingCheckModel> fillingAfterList = cylinderFillingModelList.getFillingAfter();
// if (ValidationUtil.isEmpty(fillingBeforeList) && ValidationUtil.isEmpty(fillingList) && ValidationUtil.isEmpty(fillingAfterList)) {
// throw new BadRequest("液化气体气瓶充装信息-充装前检查信息、液化气体气瓶充装信息-充装记录信息、液化气体气瓶充装信息-充装后复查信息为空.");
// }
// cylinderFillingService.createCylinderFillingBefore(fillingBeforeList);
// cylinderFillingRecordService.createCylinderFilling(fillingList);
// cylinderFillingCheckService.createCylinderFillingAfter(fillingAfterList);
//
// CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
// BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
// cylinderFillingMessageModel.setAppId(bizTokenModel.getAppId());
// cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
// emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
// Double a = (double) (1/0);
return ResponseHelper.buildResponse("OK");
}
......
......@@ -15,6 +15,7 @@ public class CylinderFillingDataValidationResultModel {
private List<String> beforeErrorData;
private List<String> recordErrorData;
private List<String> afterErrorData;
private List<String> seqCodeErrorData;
private String result = "success";
}
......@@ -3,8 +3,8 @@ package com.yeejoin.amos.api.openapi.face.orm.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.MidEquipRegistrationInfo;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Set;
......@@ -18,6 +18,17 @@ import java.util.Set;
public interface MidEquipRegistrationInfoMapper extends BaseMapper<MidEquipRegistrationInfo> {
@DS("tzs")
@Query("SELECT DISTINCT r.* FROM idx_biz_jg_use_info i, idx_biz_jg_register_info r WHERE i.data_source like 'jg%' AND i.RECORD = r.RECORD AND r.EQU_CODE IN :values")
List<MidEquipRegistrationInfo> getUseInfoByEquipCode(@Param("values") Set<String> sequenceCodes);
@Select("<script>" +
"SELECT DISTINCT sequenceCode FROM " +
"(SELECT concat ( fi.\"PRODUCE_UNIT_CREDIT_CODE\", '-', fi.\"FACTORY_NUM\" ) sequenceCode " +
"FROM idx_biz_jg_factory_info fi, idx_biz_jg_other_info oi " +
"WHERE oi.\"RECORD\" = fi.\"RECORD\" " +
" AND oi.\"CLAIM_STATUS\" = '已认领' " +
" AND fi.\"PRODUCE_UNIT_CREDIT_CODE\" IS NOT NULL " +
" AND fi.\"FACTORY_NUM\" IS NOT NULL) WHERE sequenceCode in " +
"<foreach item='item' index='index' collection='sequenceCodes' open='(' separator=',' close=')'>" +
" #{item}" +
"</foreach>" +
"</script>")
List<String> getUsedCountBySeqCodes(@Param("sequenceCodes") Set<String> sequenceCodes);
}
......@@ -5,7 +5,6 @@ import cn.hutool.core.collection.ConcurrentHashSet;
import com.yeejoin.amos.api.openapi.enums.*;
import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.api.openapi.face.orm.dao.MidEquipRegistrationInfoMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.MidEquipRegistrationInfo;
import com.yeejoin.amos.boot.module.cylinder.api.dto.TzBaseEnterpriseInfoDto;
import net.sf.json.JSONArray;
import net.sf.json.JSONNull;
......@@ -193,7 +192,7 @@ public class CylinderFillingDataValidationService {
Set<String> afterErrorCylinderSet = new ConcurrentHashSet<>();
CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检验前数据
// 异步校验充装前数据
JSONArray fillingBefore = jsonobject.getJSONArray("fillingBefore");
if (!ObjectUtils.isEmpty(fillingBefore)) {
for (int i = 0; i < fillingBefore.size(); i++) {
......@@ -204,7 +203,7 @@ public class CylinderFillingDataValidationService {
return validateFillingBeforeData(fillingBefore, beforeErrorCylinderSet);
});
CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检填充数据
// 异步校验检充装时数据
JSONArray filling = jsonobject.getJSONArray("filling");
if (!ObjectUtils.isEmpty(filling)) {
for (int i = 0; i < filling.size(); i++) {
......@@ -216,7 +215,7 @@ public class CylinderFillingDataValidationService {
});
CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检填充后数据
// 异步校验充装后数据
JSONArray fillingAfter = jsonobject.getJSONArray("fillingAfter");
if (!ObjectUtils.isEmpty(fillingAfter)) {
for (int i = 0; i < fillingAfter.size(); i++) {
......@@ -224,7 +223,7 @@ public class CylinderFillingDataValidationService {
cylinderCodeSet.add(row.getString("sequenceCode"));
}
}
return validateFillinAfterData(jsonobject.getJSONArray("fillingAfter"), afterErrorCylinderSet);
return validateFillingAfterData(fillingAfter, afterErrorCylinderSet);
});
/**
......@@ -236,12 +235,20 @@ public class CylinderFillingDataValidationService {
result.setAfterErrorData(afterFuture.get());
result.setCylinderNumber(cylinderCodeSet.size());
result.setBeforeErrorCylinderNumber(beforeErrorCylinderSet.size());
result.setRecordErrorCylinderNumber(recordErrorCylinderSet.size());
result.setAfterErrorCylinderNumber(afterErrorCylinderSet.size());
cylinderCodeSet.removeAll(beforeErrorCylinderSet);
cylinderCodeSet.removeAll(recordErrorCylinderSet);
cylinderCodeSet.removeAll(afterErrorCylinderSet);
if (!ObjectUtils.isEmpty(cylinderCodeSet)) {
// 检查气瓶唯一标识码在系统是否存在
List<String> errorRows = getNotExistSequenceCodes(cylinderCodeSet);
result.setSeqCodeErrorData(errorRows);
}
result.setSuccessCylinderNumber(cylinderCodeSet.size());
return result;
}
......@@ -330,7 +337,7 @@ public class CylinderFillingDataValidationService {
* @param jsonArray
* @return List 异常数据
*/
public List<String> validateFillinAfterData(JSONArray jsonArray, Set<String> errorCylinderSet) {
public List<String> validateFillingAfterData(JSONArray jsonArray, Set<String> errorCylinderSet) {
// 1.必填校验
List<String> errorRows = validateRequired(FillingAfterFieldEnum.getAllRequireKeys(), jsonArray);
......@@ -445,10 +452,9 @@ public class CylinderFillingDataValidationService {
* @return
*/
public List<String> getNotExistSequenceCodes(Set<String> sequenceCodes) {
List<MidEquipRegistrationInfo> useInfos = registrationInfoMapper.getUseInfoByEquipCode(sequenceCodes);
if (useInfos.size() < sequenceCodes.size()) {
List<String> equipCodes = useInfos.stream().map(e -> e.getEquCode()).collect(Collectors.toList());
return sequenceCodes.stream().filter(c -> !equipCodes.contains(c)).collect(Collectors.toList());
List<String> usedSeqCodeList = registrationInfoMapper.getUsedCountBySeqCodes(sequenceCodes);
if (usedSeqCodeList.size() < sequenceCodes.size()) {
return sequenceCodes.stream().filter(c -> !usedSeqCodeList.contains(c)).collect(Collectors.toList());
}
return null;
}
......
......@@ -10,7 +10,6 @@ import com.yeejoin.amos.api.openapi.service.MyBaseServiceImpl;
import com.yeejoin.amos.api.openapi.util.MultiFieldKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.Bean;
import java.util.Date;
......@@ -29,10 +28,16 @@ import java.util.List;
@Component
public class TmCylinderFillingService extends MyBaseServiceImpl<TmCylinderFillingModel, TmCylinderFilling, TmCylinderFillingMapper> {
private final SyncCylinderDataService syncCylinderDataService;
@Autowired
private SyncCylinderDataService syncCylinderDataService;
private TmCylinderFillingService self;
public TmCylinderFillingService(SyncCylinderDataService syncCylinderDataService) {
this.syncCylinderDataService = syncCylinderDataService;
}
@DSTransactional
@DSTransactional
public void createCylinderFillingBefore(List<TmCylinderFillingModel> model) {
Date now = new Date();
String appId = getAppId();
......@@ -45,7 +50,7 @@ public class TmCylinderFillingService extends MyBaseServiceImpl<TmCylinderFillin
// 同步至气瓶业务库
syncCylinderFillingBefore(model);
this.saveOrUpdateBatchByUniqueFields(
self.saveOrUpdateBatchByUniqueFields(
tmCylinderFillingList,
tmCylinderFilling -> new LambdaQueryWrapper<TmCylinderFilling>()
.eq(TmCylinderFilling::getAppId, tmCylinderFilling.getAppId())
......
......@@ -9,4 +9,5 @@ public class CylinderFillingMessage {
private Integer cylinderNumber;
private String message;
private String appId;
private String orgCode;
}
......@@ -26,7 +26,6 @@ import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
import com.yeejoin.amos.boot.module.ymt.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.ymt.biz.dao.ESElavtorRepository;
import com.yeejoin.amos.boot.module.ymt.biz.utils.JsonUtils;
import com.yeejoin.amos.boot.module.ymt.biz.utils.StringUtils;
import com.yeejoin.amos.boot.module.ymt.flc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.ymt.flc.api.feign.PrivilegeFeginService;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
......
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