Commit 92e60d34 authored by 刘林's avatar 刘林

fix(cylinder):气瓶区域信息查询

parents 76eab8e2 d1b12488
......@@ -28,8 +28,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- Vastbase G100 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Vastbase G100 -->
<dependency>@
<groupId>cn.com.vastdata</groupId>
<artifactId>vastbase</artifactId>
<version>1.0.0.2</version>
......@@ -156,6 +165,27 @@
<artifactId>jettison</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-core</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-json</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-jsplot</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-excel</artifactId>
<version>0.43.1</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.yeejoin.amos.api.openapi.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderFillingAuditFieldEnum {
sequenceCode(true, true),
fillingExamineId(true, true),
fillingAuditDate(true, false),
fillingAuditUrl(true, false),
fillingAuditname(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderInfoFieldEnum {
creditCode(true, false),
unitName(true, false),
sequenceCode(true, true),
cylinderVariety(true, false),
cylinderVarietyName(true, false),
factoryNum(true, false),
fillingMedia(true, false),
fillingMediaName(true, false),
manufacturingUnit(true, false),
manufacturingDate(true, false),
valveManufacturUnit(true, false),
nominalWorkPressure(true, false),
volume(true, false),
productQualified(true, false),
proofQuality(true, false),
supervisionInspec(true, false),
typeExperiments(true, false),
cylinderStatus(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderInspectionFieldEnum {
sequenceCode(true, true),
inspectionUnit(true, true),
inspectionDate(true, true),
inspectionResult(true, true),
scrapQuantity(true, true),
nextInspectionDate(true, true),
syncDate(true, true),
syncState(true, true);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderTagFieldEnum {
sequenceCode(true, true),
qrCode(true, true),
electronicLabelCode(true, true),
gasCylinderStamp(true, true),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderUnitFieldEnum {
unitId(true, true),
regionCode(true, false),
regionName(true, false),
unitName(true, true),
creditCode(true, true),
address(true, false),
unitPerson(true, false),
personMobilePhone(true, false),
personTelephone(true, false),
securityAdm(true, false),
securityAdmPhone(true, false),
postalCode(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum FillingAfterFieldEnum {
sequenceCode(true, true),
fillingCheckId(true, true),
withinScope(true, false),
sealedState(true, false),
defective(true, false),
abnormaLTemperature(true, false),
warningSign(true, false),
compliance(true, false),
checkResults(true, false),
nonconformances(true, false),
inspector(true, false),
inspectionDate(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum FillingBeforeFieldEnum {
sequenceCode(true, true),
fillingBeforeId(true, true),
creditCode(true, false),
fillingUnitName(true, false),
inspectorUser(true, false),
inspectionDate(true, false),
isValid(true, false),
same(true, false),
isRegulations(true, false),
isComplianceWithGBT(true, false),
haveStillPressure(true, false),
isComplete(true, false),
haveSecurityDocuments(true, false),
fillBeforeItem(true, false),
checkResults(true, false),
nonconformances(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum FillingRecordFieldEnum {
sequenceCode(true, true),
fillingRecordId(true, true),
fillingBeforeId(true, true),
fillingCheckId(true, true),
fillingExamineId(true, true),
fillingStartTime(true, false),
fillingEndTime(true, false),
fillingUser(true, false),
inspectorName(true, false),
fillingQuantity(true, false),
dischargeVolume(true, false),
temperature(true, false),
abnormal(true, false),
syncDate(true, false),
syncState(true, false);
private boolean isRequire;
private boolean isUnique;
public static List<String> getAllRequireKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isRequire).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
public static List<String> getAllUniqueKeys() {
List<String> keys = Arrays.stream(values()).filter(e -> e.isUnique).map(e -> e.name()).collect(Collectors.toList());
return keys;
}
}
package com.yeejoin.amos.api.openapi.face.model;
import lombok.Data;
import java.util.List;
@Data
public class CylinderFillingDataValidationResultModel {
private List<String> beforeErrorData;
private List<String> recordErrorData;
private List<String> afterErrorData;
private String result = "success";
}
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.RegistrationInfo;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Set;
/**
* 特种设备基本信息-注册登记信息 Mapper 接口
......@@ -11,4 +17,7 @@ import com.yeejoin.amos.api.openapi.face.orm.entity.RegistrationInfo;
*/
public interface RegistrationInfoMapper extends BaseMapper<RegistrationInfo> {
@DS("tzs")
@Query("SELECT DISTINCT r.* FROM idx_biz_jg_use_info i, idx_biz_jg_register_info r WHERE i.data_source = 'jg' AND i.RECORD = r.RECORD AND r.EQU_CODE IN :values")
List<RegistrationInfo> getUseInfoByEquipCode(@Param("values") Set<String> sequenceCodes);
}
package com.yeejoin.amos.api.openapi.face.service;
import com.yeejoin.amos.api.openapi.constant.*;
import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.api.openapi.face.orm.dao.RegistrationInfoMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.RegistrationInfo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
* 气瓶数据校验
*/
@Component
public class CylinderFillingDataValidationService {
@Autowired
EnterpriseInfoService enterpriseInfoService;
@Autowired
RegistrationInfoMapper registrationInfoMapper;
/**
* 企业信息校验
* @param unitData
* @return
*/
public boolean validatEcylinderUnit(List<CylinderUnitModel> unitData) {
JSONArray jsonArray = JSONArray.fromObject(unitData);
// 1.必填校验
List<String> errorRows = validateRequired(CylinderUnitFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList())).toString());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(CylinderUnitFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList())).toString());
}
// 3.检查企业统一社会信用代码是否存在
Set<String> creditCodes = getAllData(FillingBeforeFieldEnum.creditCode.name(), jsonArray);
errorRows = getNotExistEnterpriseInfoByCreditCode(creditCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject(errorRows.stream().map(e -> "企业统一社会信用代码不存在:" + e).collect(Collectors.toList())).toString());
}
return true;
}
/**
* 校验气瓶数据
* @param infoData
* @return
*/
public boolean validateCylinderInfo(List<CylinderInfoModel> infoData) {
JSONArray jsonArray = JSONArray.fromObject(infoData);
// 1.必填校验
List<String> errorRows = validateRequired(CylinderInfoFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList())).toString());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(CylinderInfoFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList())).toString());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList())).toString());
}
// 4.检查企业统一社会信用代码是否存在
Set<String> creditCodes = getAllData(FillingBeforeFieldEnum.creditCode.name(), jsonArray);
errorRows = getNotExistEnterpriseInfoByCreditCode(creditCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "企业统一社会信用代码不存在:" + e).collect(Collectors.toList())).toString());
}
return true;
}
public boolean validateCylinderTag(List<CylinderTagsModel> tagData) {
JSONArray jsonArray = JSONArray.fromObject(tagData);
// 1.必填校验
List<String> errorRows = validateRequired(CylinderTagFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList())).toString());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(CylinderTagFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList())).toString());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList())).toString());
}
return true;
}
boolean validateCylinderInspection(List<CylinderInspectionModel> inspectionData) {
JSONArray jsonArray = JSONArray.fromObject(inspectionData);
// 1.必填校验
List<String> errorRows = validateRequired(CylinderInspectionFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList())).toString());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(CylinderInspectionFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList())).toString());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList())).toString());
}
return true;
}
boolean validateCylinderFillingExamineModel(List<CylinderFillingExamineModel> inspectionData) {
JSONArray jsonArray = JSONArray.fromObject(inspectionData);
// 1.必填校验
List<String> errorRows = validateRequired(CylinderFillingAuditFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList())).toString());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(CylinderFillingAuditFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList())).toString());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
throw new BadRequest(JSONArray.fromObject( errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList())).toString());
}
return true;
}
/**
* 验证气瓶充装数据
* @return
*/
public CylinderFillingDataValidationResultModel validateFilling(JSONObject jsonobject) throws ExecutionException, InterruptedException {
CylinderFillingDataValidationResultModel result = new CylinderFillingDataValidationResultModel();
CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检验前数据
return validateFillingBeforeData(jsonobject.getJSONArray("fillingBefore"));
});
CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检填充数据
return validateFillingRecordData(jsonobject.getJSONArray("filling"));
});
CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检填充后数据
return validateFillinAfterData(jsonobject.getJSONArray("fillingAfter"));
});
/**
* 等待校验结果
*/
CompletableFuture.allOf(beforeFuture, recordFuture, afterFuture);
result.setBeforeErrorData(beforeFuture.get());
result.setRecordErrorData(recordFuture.get());
result.setAfterErrorData(afterFuture.get());
return result;
}
/**
* 验证检验前数据
* @param jsonArray
* @return List 异常数据
*/
public List<String> validateFillingBeforeData(JSONArray jsonArray) {
// 1.必填校验
List<String> errorRows = validateRequired(FillingBeforeFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingBeforeFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList());
}
// 4.检查企业统一社会信用代码是否存在
Set<String> creditCodes = getAllData(FillingBeforeFieldEnum.creditCode.name(), jsonArray);
errorRows = getNotExistEnterpriseInfoByCreditCode(creditCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "企业统一社会信用代码不存在:" + e).collect(Collectors.toList());
}
return null;
}
/**
* 验证检验记录数据
* @param jsonArray
* @return List 异常数据
*/
public List<String> validateFillingRecordData(JSONArray jsonArray) {
// 1.必填校验
List<String> errorRows = validateRequired(FillingRecordFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingRecordFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList());
}
// 4.检查企业统一社会信用代码是否存在
Set<String> creditCodes = getAllData(FillingBeforeFieldEnum.creditCode.name(), jsonArray);
errorRows = getNotExistEnterpriseInfoByCreditCode(creditCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "企业统一社会信用代码不存在:" + e).collect(Collectors.toList());
}
return null;
}
/**
* 验证检验后数据
* @param jsonArray
* @return List 异常数据
*/
public List<String> validateFillinAfterData(JSONArray jsonArray) {
// 1.必填校验
List<String> errorRows = validateRequired(FillingAfterFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "必填字段为空::" + e).collect(Collectors.toList());
}
// 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingAfterFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
}
// 3.检查气瓶唯一标识码是否存在
Set<String> sequenceCodes = getAllData(FillingBeforeFieldEnum.sequenceCode.name(), jsonArray);
errorRows = getNotExistSequenceCodes(sequenceCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "气瓶唯一标识码不存在:" + e).collect(Collectors.toList());
}
// 4.检查企业统一社会信用代码是否存在
Set<String> creditCodes = getAllData(FillingBeforeFieldEnum.creditCode.name(), jsonArray);
errorRows = getNotExistEnterpriseInfoByCreditCode(creditCodes);
if (!ObjectUtils.isEmpty(errorRows)) {
return errorRows.stream().map(e -> "企业统一社会信用代码不存在:" + e).collect(Collectors.toList());
}
return null;
}
/**
* 必填校验
* @param keys 需要校验的key
* @param jsonArray 被校验数据
* @return 校验结果 通过为 true,不通过为false
*/
public List<String> validateRequired(List<String> keys, JSONArray jsonArray) {
List<String> errorList = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject row = jsonArray.getJSONObject(i);
for (String key : keys) {
if (!row.containsKey(key) || row.get(key) == null) {
errorList.add(row.toString());
}
}
}
return errorList;
}
/**
* 数据唯一性校验
* @param keys 需要校验的key
* @param jsonArray 被校验数据
* @return 校验结果 通过为 true,不通过为false
*/
public List<String> validateUnique(List<String> keys, JSONArray jsonArray) {
Map<String, Set<Object>> valuesMap = new HashMap<>();
List<String> errorList = new ArrayList<>();
for (String key : keys) {
valuesMap.put(key, new HashSet<>());
}
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject row = jsonArray.getJSONObject(i);
for (String key : keys) {
if (valuesMap.get(key).contains(row.get(key))) {
errorList.add(row.toString());
}
valuesMap.get(key).add(row.get(key));
}
}
return errorList;
}
/**
* 获取指定 key的所有数据
* @param key
* @param jsonArray
* @return
*/
public Set<String> getAllData(String key, JSONArray jsonArray) {
Set<String> sequenceCode = new HashSet<>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject row = jsonArray.getJSONObject(i);
sequenceCode.add(row.get(key).toString());
}
return sequenceCode;
}
/**
* 校验企业唯一信用代码
* @param creditCodes
* @return
*/
public List<String> getNotExistEnterpriseInfoByCreditCode(Set<String> creditCodes) {
List<EnterpriseInfoModel> enterpriseInfos = enterpriseInfoService.getEnterpriseInfoByCreditCode(creditCodes);
if (enterpriseInfos.size() < creditCodes.size()) {
List<String> userCodes = enterpriseInfos.stream().map(e -> e.getUseCode()).collect(Collectors.toList());
return creditCodes.stream().filter(c -> !userCodes.contains(c)).collect(Collectors.toList());
}
return null;
}
/**
* 获取不存在的气瓶编码
* @param sequenceCodes
* @return
*/
public List<String> getNotExistSequenceCodes(Set<String> sequenceCodes) {
List<RegistrationInfo> 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());
}
return null;
}
}
......@@ -53,5 +53,7 @@ public class CylinderFillingService extends BaseService<CylinderFillingModel,Cyl
String tokenKey = Redis.genKey(Constant.TOKEN_PREFIX,RequestContext.getToken());
BizTokenModel bizTokenModel = (BizTokenModel) redisTemplate.opsForValue().get(tokenKey);
return bizTokenModel.getAppId();
}
}
}
package com.yeejoin.amos.api.openapi.face.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.yeejoin.amos.api.openapi.enums.JgFileAttributeEnum;
import com.yeejoin.amos.api.openapi.enums.JgFileObjectEnum;
import com.yeejoin.amos.api.openapi.face.model.EnterpriseInfoModel;
......@@ -16,6 +17,7 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* 企业数据信息 服务类
......@@ -132,4 +134,9 @@ public class EnterpriseInfoService extends AppBaseService<EnterpriseInfoModel, E
throw new BadRequest("使用单位标识码为:"+models.getUseUnitCode()+"的企业,"+"同步状态不能为空!");
}
}
@DS("tzs")
public List<EnterpriseInfoModel> getEnterpriseInfoByCreditCode(Set<String> useCode) {
return this.queryForList("", false, useCode);
}
}
......@@ -2,10 +2,23 @@ spring.application.name=AMOS-API-OPENAPI
server.servlet.context-path=/openapi
server.port=11001
# jdbc_config
spring.datasource.driver-class-name=cn.com.vastbase.Driver
spring.datasource.url=jdbc:vastbase://172.16.10.243:5432/tzs_amos_tzs_biz_init?currentSchema=amos_openapi_cyl
spring.datasource.url=jdbc:vastbase://172.16.10.243:5432/tzs_amos_tzs_biz_init?currentSchema=amos_openapi_cyl&allowMultiQueries=true
spring.datasource.username=admin
spring.datasource.password=Yeejoin@2023
spring.datasource.driver-class-name=cn.com.vastbase.Driver
spring.datasource.dynamic.primary=openapi
#ds tzs
spring.datasource.dynamic.datasource.openapi.url=jdbc:vastbase://172.16.10.243:5432/tzs_amos_tzs_biz_init?currentSchema=amos_openapi_cyl&allowMultiQueries=true
spring.datasource.dynamic.datasource.openapi.username=admin
spring.datasource.dynamic.datasource.openapi.password=Yeejoin@2023
spring.datasource.dynamic.datasource.openapi.driver-class-name=cn.com.vastbase.Driver
#ds cyl
spring.datasource.dynamic.datasource.tzs.url=jdbc:vastbase://172.16.10.243:5432/tzs_amos_tzs_biz_init?currentSchema=amos_openapi_cyl&allowMultiQueries=true
spring.datasource.dynamic.datasource.tzs.username=admin
spring.datasource.dynamic.datasource.tzs.password=Yeejoin@2023
spring.datasource.dynamic.datasource.tzs.driver-class-name=cn.com.vastbase.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5
......
package com.yeejoin.amos.boot.module.cylinder.flc.api.dto;
import io.swagger.annotations.ApiModel;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "CylinderUnitVideoDto", description = "气瓶企业视频信息")
public class CylinderUnitVideoDto extends BaseDto {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*获取token地址
*/
private String tokenUrl;
/**
*获取播放地址
*/
private String url;
/**
*appkey
*/
private String appKey;
/**
*appsecret
*/
private String appSecret;
/**
*设备序列号
*/
private String deviceSerial;
/**
*流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
*/
private String protocol;
/**
* 通道号
*/
private String channelNo;
/**
* 过期时长,单位秒;针对hls/rtmp/flv设置有效期,相对时间;30秒-720天
*/
private Long expireTime;
/**
* 单位ID
*/
private Long unitSeq;
}
package com.yeejoin.amos.boot.module.cylinder.flc.api.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 气瓶企业视频信息
* @author kinky
*
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName("tz_cylinder_unit_video")
public class CylinderUnitVideo extends BaseEntity{/**
*
*/
private static final long serialVersionUID = 1L;
/**
*获取token地址
*/
@TableField("token_url")
private String tokenUrl;
/**
*获取播放地址
*/
@TableField("url")
private String url;
/**
*appkey
*/
@TableField("app_key")
private String appKey;
/**
*appsecret
*/
@TableField("app_secret")
private String appSecret;
/**
*设备序列号
*/
@TableField("device_serial")
private String deviceSerial;
/**
*流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
*/
@TableField("protocol")
private String protocol;
/**
* 通道号
*/
@TableField("channel_no")
private String channelNo;
/**
* 过期时长,单位秒;针对hls/rtmp/flv设置有效期,相对时间;30秒-720天
*/
@TableField("expire_time")
private Long expireTime;
/**
* 单位ID
*/
@TableField("unit_seq")
private Long unitSeq;
}
......@@ -19,28 +19,32 @@ public interface CylinderInfoMapper extends BaseMapper<CylinderInfo> {
/**
* 查询根据公司查询气瓶数量以及过期气瓶数
*
* @param sequenceNbr
* @return
*/
Map<String, String> queryNumAndOutOfDateNum(@Param("sequenceNbr") Long sequenceNbr);
Integer getMonthInfoTotal(@Param("regionCode") String regionCode);
/**
* 获取上个月气瓶总量
*
* @return
*/
Integer getLastMonthInfoTotal(@Param("regionCode") String regionCode);
/**
* 获取上上个月气瓶总量
*
* @return
*/
Integer getMonthBeforeLastInfoTotal(@Param("regionCode") String regionCode);
/**
* 根据regionCode 获取气瓶数量
*
* @param regionCode
* @return
*/
......@@ -49,17 +53,20 @@ public interface CylinderInfoMapper extends BaseMapper<CylinderInfo> {
Double queryIntegirtyByAppId(@Param("appId") String appId);
Integer getWarnNum(String code);
Integer getMonthInfoTotalUnit(@Param("appId") String appId);
/**
* 获取上个月气瓶总量-APPID
*
* @return
*/
Integer getLastMonthInfoTotalUnit(@Param("appId") String appId);
/**
* 获取上上个月气瓶总量-APPID
*
* @return
*/
Integer getMonthBeforeLastInfoTotalUnit(@Param("appId") String appId);
......@@ -70,14 +77,13 @@ public interface CylinderInfoMapper extends BaseMapper<CylinderInfo> {
Page<CylinderInfoDto> queryPageListByEarlyWarningLevel(Page<CylinderInfoDto> page, @Param("earlyWarningLevel") String earlyWarningLevel);
/**
* 查询行政区划下的所有气瓶
*
* @param regionCode
* @return
*/
List<CylinderInfoDto> listWithRegionCode(Integer regionCode);
List<CylinderInfoDto> listWithRegionCode(Integer regionCode);
Page<CylinderInfoDto> cyinderInfoList(Page<CylinderInfoDto> page, CylinderInfoDto cylinderInfoDto, String sort, List<String> appids);
......@@ -88,14 +94,17 @@ public interface CylinderInfoMapper extends BaseMapper<CylinderInfo> {
Integer getInfoTotal();
void updateEsCylinderInfoStatus(@Param("ids")List<String> ids);
void updateEsCylinderInfoStatus(@Param("ids") List<String> ids);
Integer saveOrUpdateBatch(@Param("list") List<CylinderInfo> list);
Page<Map<String,Object>> timeOutList(@Param("page") Page<Map<String, Object>> page, @Param("companyId") String companyId, @Param("regionCode") String regionCode);
Page<Map<String, Object>> timeOutList(@Param("page") Page<Map<String, Object>> page, @Param("companyId") String companyId, @Param("regionCode") String regionCode);
Page<Map<String,Object>> licenceList(@Param("page") Page<Map<String, Object>> page, @Param("companyId") String companyId);
Page<Map<String, Object>> licenceList(@Param("page") Page<Map<String, Object>> page, @Param("companyId") String companyId);
int countNumber(@Param("status") String status, @Param("companyId") String companyId, @Param("regionCode") String regionCode);
Map<String, Object> countFillingTimesAndQuantityByCompany(@Param("companyId") String companyId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
package com.yeejoin.amos.boot.module.cylinder.flc.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnitVideo;
import java.util.List;
/**
* 气瓶企业视频信息 Mapper 接口
*
* @author system_generator
* @date 2021-12-14
*/
public interface CylinderUnitVideoMapper extends BaseMapper<CylinderUnitVideo> {
}
package com.yeejoin.amos.boot.module.cylinder.flc.api.service;
import java.util.List;
/**
* 气瓶企业视频信息接口类
*
* @author system_generator
* @date 2021-12-14
*/
public interface ICylinderUnitVideoService {
List<String> getUnitVideoUrl(Long unitSeq);
}
......@@ -387,6 +387,21 @@
</where>
</select>
<select id="countFillingTimesAndQuantityByCompany" resultType="java.util.Map">
SELECT COUNT(1) AS fillingTimes, SUM(filling_quantity) AS fillingQuantity
FROM tz_cylinder_filling_record AS tcfr
<where>
<if test="companyId != null and companyId != ''">
tcfr."app_id" = #{companyId}
</if>
<if test="startTime != null">
AND DATE_FORMAT(tcfr."filling_starttime",'%Y-%m-%d') <![CDATA[>=]]> #{startTime}
</if>
<if test="endTime != null">
AND DATE_FORMAT(tcfr."filling_endtime",'%Y-%m-%d') <![CDATA[<=]]> #{endTime}
</if>
</where>
</select>
<select id="countNumber" resultType="java.lang.Integer">
SELECT count(DISTINCT(onlyCode))
FROM(
......
......@@ -1344,4 +1344,14 @@ public class CylinderInfoController extends BaseController {
List<CityCylinderInfoDto> result = cylinderInfoServiceImpl.getCityCylinderData(level);
return ResponseHelper.buildResponse(result);
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "GET", value = "某个企业充装次数及累计充装量统计")
@GetMapping(value = "/countFillingTimesAndQuantityByCompany")
public ResponseModel<Map<String,Object>> countFillingTimesAndQuantityByCompany(@RequestParam(value = "companyId") String companyId,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime) {
return ResponseHelper.buildResponse(cylinderInfoServiceImpl.getBaseMapper().countFillingTimesAndQuantityByCompany(companyId, startTime, endTime));
}
}
package com.yeejoin.amos.boot.module.cylinder.flc.biz.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderUnitDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnit;
import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderInfoService;
import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderUnitVideoService;
import com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl.CylinderUnitServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -20,8 +18,6 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -41,7 +37,8 @@ public class CylinderUnitController extends BaseController {
@Autowired
ICylinderInfoService iCylinderInfoService;
@Autowired
ICylinderUnitVideoService icylinderUnitVideoService;
/**
......@@ -124,4 +121,11 @@ public class CylinderUnitController extends BaseController {
return ResponseHelper.buildResponse(cylinderUnitServiceImpl.queryForCylinderUnitPage(page));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getUnitVideoUrl")
@ApiOperation(httpMethod = "GET", value = "根据气瓶企业seq查询视频链接", notes = "根据气瓶企业seq查询视频链接")
public ResponseModel<List<String>> getUnitVideoUrl(@RequestParam Long unitSeq) {
return ResponseHelper.buildResponse(icylinderUnitVideoService.getUnitVideoUrl(unitSeq));
}
}
package com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderUnitVideoDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnitVideo;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderUnitVideoMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderUnitVideoService;
import cn.hutool.http.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
* 气瓶企业信息服务实现类
*
* @author system_generator
* @date 2021-12-14
*/
@Service
public class CylinderUnitVideoServiceImpl extends BaseService<CylinderUnitVideoDto, CylinderUnitVideo, CylinderUnitVideoMapper> implements
ICylinderUnitVideoService {
private static final Logger logger = LoggerFactory.getLogger(CylinderUnitVideoServiceImpl.class);
private static final String CODE_200 = "200";
private static final String CODE_10001 = "10001";
private static final String CODE_10005 = "10005";
private static final String CODE_10017 = "10017";
private static final String CODE_10030 = "10030";
private static final String CODE_49999 = "49999";
private static final String CODE_201 = "201";
private static final String CODE_401 = "401";
private static final String CODE_403= "403";
private static final String CODE_404 = "404";
private static final String CODE_20001 = "20001";
@Override
public List<String> getUnitVideoUrl(Long unitSeq) {
List<String> result = new ArrayList<String>();
LambdaQueryWrapper<CylinderUnitVideo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CylinderUnitVideo::getUnitSeq,unitSeq);
CylinderUnitVideo cylinderUnitVideo = this.getBaseMapper().selectOne(wrapper);
if(null != cylinderUnitVideo){
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("appKey",cylinderUnitVideo.getAppKey());
requestInfo.put("appSecret",cylinderUnitVideo.getAppSecret());
try {
String accessTokenData = HttpUtil.post(cylinderUnitVideo.getTokenUrl(),requestInfo);
JSONObject jsonObject = JSON.parseObject(accessTokenData);
String msg = jsonObject.get("msg").toString();
String code = jsonObject.get("code").toString();
if(CODE_10001.equals(code) || CODE_10005.equals(code) || CODE_10017.equals(code) || CODE_10030.equals(code) || CODE_49999.equals(code)){
String errorMsg = "code:"+code+"msg:"+msg+"appKey:"+cylinderUnitVideo.getAppKey()+"appSecret:"+cylinderUnitVideo.getAppSecret();
logger.info("视频token获取失败errorMsg",errorMsg);
return result;
}
if(CODE_200.equals(code)){
String data = jsonObject.get("data").toString();
JSONObject objTokenJson = JSON.parseObject(data);
String accessToken = objTokenJson.get("accessToken").toString();
System.out.println(accessToken);
String channelNos = cylinderUnitVideo.getChannelNo();
List<String> channelNoList = Arrays.asList(channelNos.split(","));
for (String channelNo : channelNoList) {
HashMap<String, Object> requestVideosInfo = new HashMap<>();
requestVideosInfo.put("accessToken",accessToken);
requestVideosInfo.put("deviceSerial",cylinderUnitVideo.getDeviceSerial());
requestVideosInfo.put("channelNo",channelNo);
requestVideosInfo.put("protocol",cylinderUnitVideo.getProtocol());
requestVideosInfo.put("expireTime",cylinderUnitVideo.getExpireTime());
String videoData = HttpUtil.post(cylinderUnitVideo.getUrl(),requestVideosInfo);
JSONObject videoJsonObject = JSON.parseObject(videoData);
String msgVideo = videoJsonObject.get("msg").toString();
String codeVideo = videoJsonObject.get("code").toString();
if(CODE_201.equals(codeVideo) || CODE_401.equals(codeVideo) || CODE_403.equals(codeVideo) || CODE_404.equals(codeVideo) || CODE_20001.equals(codeVideo)){
String errorMsg = "code:"+codeVideo+"msg:"+msgVideo+"appKey:"+cylinderUnitVideo.getAppKey()+"appSecret:"+cylinderUnitVideo.getAppSecret()+"accessToken:"+accessToken;
logger.info("视频地址获取失败errorMsg",errorMsg);
}
if(CODE_200.equals(codeVideo)){
String dataS = videoJsonObject.get("data").toString();
JSONObject dd = JSON.parseObject(dataS);
String url = dd.get("url").toString();
result.add(url);
}
}
}
}catch (Exception e){
logger.error(e.getMessage());
e.printStackTrace();
}
}
return result;
}
}
\ No newline at end of file
......@@ -11,6 +11,8 @@ import com.yeejoin.amos.boot.module.ymt.api.entity.RegistrationInfo;
import com.yeejoin.amos.boot.module.ymt.api.mapper.RegistrationInfoMapper;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.feign.rule.Rule;
import com.yeejoin.amos.feign.rule.model.FactBaseModel;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,6 +24,9 @@ import org.typroject.tyboot.core.foundation.context.RequestContext;
import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
......@@ -109,7 +114,7 @@ public class InspectionOrgRefreshListener extends EmqxListener {
inspectionEquipInfo.setInspectionType(equipInfoModel.getInspectionType());
inspectionEquipInfo.setRecord(equipInfoModel.getRecord());
inspectionEquipInfo.setBizType(getCategoryByType(JYJCTypeEnum.of(inspectionEquipInfo.getInspectionType())));
touchRule(inspectionEquipInfo);
touchRuleWithApi(inspectionEquipInfo);
}
private RegistrationInfo fetchRegistrationInfo(String record) {
......@@ -119,7 +124,7 @@ public class InspectionOrgRefreshListener extends EmqxListener {
.eq(RegistrationInfo::getRecord, record));
}
private void touchRule(InspectionEquipInfo inspectionEquipInfo) {
private void touchRuleWithMsg(InspectionEquipInfo inspectionEquipInfo) {
if (log.isInfoEnabled()) {
log.info("发送规则的消息对象:{}", toJSONString(inspectionEquipInfo));
}
......@@ -131,7 +136,34 @@ public class InspectionOrgRefreshListener extends EmqxListener {
try {
ruleTrigger.publish(inspectionEquipInfo, ruleName + "/" + inspectionEquipInfo.getBizType(), null);
} catch (Exception e) {
log.error("调用规则触发风险模型失败", e);
log.error("调用规则触发获取报检规则失败", e);
}
}
private void touchRuleWithApi(InspectionEquipInfo inspectionEquipInfo) {
if (log.isInfoEnabled()) {
log.info("发送规则的消息对象:{}", toJSONString(inspectionEquipInfo));
}
try {
RequestContext.setToken(amosRequestContext.getToken());
RequestContext.setAppKey(amosRequestContext.getAppKey());
RequestContext.setProduct(amosRequestContext.getProduct());
HashMap<String, byte[]> factMap = new HashMap<>();
List<Object> factList = new ArrayList<>();
factList.add(inspectionEquipInfo);
for (Object fact : factList) {
factMap.put(fact.getClass().getName(), toJSONString(fact).getBytes());
}
FactBaseModel factBaseModel = new FactBaseModel();
factBaseModel.setFactMap(factMap);
factBaseModel.setPackageId(ruleName + "/" + inspectionEquipInfo.getBizType());
factBaseModel.setProcessIds(null);
if (log.isInfoEnabled()) {
log.info("发送规则的消息对象:{},\n变量对象:{}", toJSONString(factBaseModel), toJSONString(factBaseModel));
}
Rule.ruleClient.fireRule(factBaseModel);
} catch (Exception e) {
log.error("调用规则触发获取报检规则失败", e);
}
}
}
......@@ -16,7 +16,6 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.dao.mapper.DataDictionaryMapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcOpeningApplication;
import com.yeejoin.amos.boot.module.jyjc.api.enums.BizTypeEnum;
......@@ -103,8 +102,6 @@ public class JyjcOpeningApplicationServiceImpl extends BaseService<JyjcOpeningAp
@Value("classpath:/json/bizTypeInfo.json")
private org.springframework.core.io.Resource bizTypeInfo;
@Autowired
private RedisUtils redisUtils;
@Autowired
private TzBaseEnterpriseInfoMapper enterpriseInfoMapper;
......@@ -149,6 +146,11 @@ public class JyjcOpeningApplicationServiceImpl extends BaseService<JyjcOpeningAp
*/
private final static String ZZXM_JYJC_DICT_KEY = "ZZXM_JYJC_ALL";
/**
* 编辑、工作台暂存逻辑
* @param model 对象
* @return JyjcOpeningApplicationModel
*/
@Transactional(rollbackFor = {Exception.class, BaseException.class})
public JyjcOpeningApplicationModel saveOrUpdate(JyjcOpeningApplicationModel model) {
if (model.getSequenceNbr() != null) {
......@@ -173,10 +175,15 @@ public class JyjcOpeningApplicationServiceImpl extends BaseService<JyjcOpeningAp
return this.updateWithModel(model);
}
/**
* 提交、保存并提交逻辑
* @param model 对象
* @return JyjcOpeningApplicationModel
*/
@Transactional(rollbackFor = {Exception.class, BaseException.class})
public JyjcOpeningApplicationModel submitApplication(JyjcOpeningApplicationModel model) {
model.setApplyTime(new Date());
String instanceId = model.getWorkflowProstanceId();
this.setDefaultFieldValue(model);
if (StringUtils.isBlank(instanceId)) {
// 未开启过工作流则进行开启 startProcess
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
......@@ -199,17 +206,45 @@ public class JyjcOpeningApplicationServiceImpl extends BaseService<JyjcOpeningAp
model.setNextTaskId(workflowResultDto.getNextTaskId());
model.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
// 首次提交时删除暂存的待办
taskModelService.deleteTaskModel(model.getSequenceNbr() + "");
this.deleteDraftTask(model);
saveModel(model);
// 创建代办
buildTask(model, workflowResultDto);
// 缓存流程数据
commonService.saveExecuteFlowData2Redis(workflowResultDto.getInstanceId(), this.buildInstanceRuntimeData(model));
return this.updateWithModel(model);
return model;
} else {
// 首次提交时删除暂存的待办
taskModelService.deleteTaskModel(model.getSequenceNbr() + "");
this.deleteDraftTask(model);
// 存在流程,执行
executeOneStep(model);
saveModel(model);
return model;
}
}
private void deleteDraftTask(JyjcOpeningApplicationModel model) {
if (model.getSequenceNbr() != null) {
taskModelService.deleteTaskModel(model.getSequenceNbr() + "");
}
}
private void setDefaultFieldValue(JyjcOpeningApplicationModel model) {
CompanyBo companyBo = commonService.getReginParamsOfCurrentUser().getCompany();
model.setApplyTime(new Date());
model.setUnitCode(companyBo.getCompanyCode());
model.setUnitCodeName(companyBo.getCompanyName());
if (model.getSequenceNbr() == null) {
model.setCreateUserId(RequestContext.getExeUserId());
List<String> codes = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.JY.getCode(), 1).getResult();
model.setApplicationSeq(codes.get(0));
}
}
private JyjcOpeningApplicationModel saveModel(JyjcOpeningApplicationModel model) {
if (model.getSequenceNbr() == null) {
return this.createWithModel(model);
} else {
return this.updateWithModel(model);
}
}
......
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