仓储推送到智慧工程逻辑优化

This commit is contained in:
15856 2024-10-16 10:57:34 +08:00
parent 7bd381bb7f
commit 9fc9bfe931
8 changed files with 85 additions and 87 deletions

View File

@ -27,10 +27,10 @@ public class MaMachineIntelligentVO extends BaseEntity {
private String specificationType; private String specificationType;
@ApiModelProperty(value = "生产厂家") @ApiModelProperty(value = "生产厂家")
private String manufacturer; private Integer manufacturer;
@ApiModelProperty(value = "出厂日期") @ApiModelProperty(value = "出厂日期")
private Date factoryDate; private String factoryDate;
@ApiModelProperty(value = "检验证编号") @ApiModelProperty(value = "检验证编号")
private String inspectionCertificateNumber; private String inspectionCertificateNumber;
@ -48,10 +48,10 @@ public class MaMachineIntelligentVO extends BaseEntity {
private Integer source; private Integer source;
@ApiModelProperty(value = "试验日期") @ApiModelProperty(value = "试验日期")
private Date trialDate; private String trialDate;
@ApiModelProperty(value = "有效截止日期") @ApiModelProperty(value = "有效截止日期")
private Date validityDate; private String validityDate;
@ApiModelProperty(value = "使用所属单位ID") @ApiModelProperty(value = "使用所属单位ID")
private String belongUnitId; private String belongUnitId;
@ -66,7 +66,7 @@ public class MaMachineIntelligentVO extends BaseEntity {
private String machineryCode; private String machineryCode;
@ApiModelProperty(value = "操作方式 0:默认新增 1:修改以前推送的数据") @ApiModelProperty(value = "操作方式 0:默认新增 1:修改以前推送的数据")
private Integer operateType; private String operateType;
@ApiModelProperty(value = "存在图片时必填") @ApiModelProperty(value = "存在图片时必填")
private String multipartFiles; private String multipartFiles;

View File

@ -122,6 +122,11 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.6</version>
</dependency>
</dependencies> </dependencies>

View File

@ -8,11 +8,10 @@ import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -37,23 +36,25 @@ public class HttpHelper {
return responseContent; return responseContent;
} }
public static String sendHttpPost(String url, Map<String,String> headerMap, String JSONBody) throws Exception { public static String sendHttpPost(String url,String token,String content,String intelligentAppKey) throws Exception {
System.out.println("JSONBody-=========:" + JSONBody); System.out.println("JSONBody-=========:" + content);
CloseableHttpClient httpClient = HttpClients.createDefault(); try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url); HttpPost post = new HttpPost(url);
httpPost.addHeader("Content-Type", "multipart/form-data; charset=UTF-8"); post.setHeader("token", token);
if (!CollectionUtils.isEmpty(headerMap)) { post.setHeader("appKey", intelligentAppKey);
for (Map.Entry<String, String> entry : headerMap.entrySet()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create();
httpPost.addHeader(entry.getKey(), entry.getValue()); builder.addBinaryBody("params", content.getBytes());
} post.setEntity(builder.build());
CloseableHttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
response.close();
return responseContent;
} catch (IOException e) {
e.printStackTrace();
} }
httpPost.setEntity(new StringEntity(JSONBody,StandardCharsets.UTF_8)); return null;
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
response.close();
httpClient.close();
return responseContent;
} }
public static String doPost(String urlString,String param) { public static String doPost(String urlString,String param) {

View File

@ -609,13 +609,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
} }
/** 生成工器具编码: 类似CSG-A101-2024061900001 */ /** 生成工器具编码: 类似CSG-A101-2024061900001 */
public static String getDeviceCode(String ownerCode, String categoryName, String typeId, Date date, String maId) { public static String getDeviceCode(String ownerCode, String intelligentCode, Date date, String maId) {
int number = Integer.parseInt(maId); int number = Integer.parseInt(maId);
if (number > 30000) { if (number > 30000) {
number = number % 30000; number = number % 30000;
} }
String numberStr = String.format("%05d", number); String numberStr = String.format("%05d", number);
String deviceCode = ownerCode + "-" + CAT_MAP.get(categoryName) + typeId + "-" + DateUtils.getDateTimeString(date) + numberStr; String deviceCode = ownerCode + "-" + intelligentCode + "-" + DateUtils.getDateTimeString(date) + numberStr;
return deviceCode; return deviceCode;
} }

View File

@ -288,5 +288,6 @@ public class TmTask implements Serializable {
private Date thisCheckTime; private Date thisCheckTime;
@ApiModelProperty(value = "工器具编码") @ApiModelProperty(value = "工器具编码")
private String deviceCode; //like CSG-A101-2024061900001 private String deviceCode; //like CSG-A101-2024061900001
@ApiModelProperty(value = "推送智慧工程定义的门类分类机具编码")
private String intelligentCode;
} }

View File

@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -1386,28 +1387,24 @@ public class TmTaskServiceImpl implements TmTaskService {
if (CollectionUtils.isEmpty(tmTasks)){ if (CollectionUtils.isEmpty(tmTasks)){
throw new ServiceException(String.format(ExceptionDict.PARAM_IS_NULL_ERROR_MSG,"maMachineList"), ExceptionDict.PARAM_IS_NULL_ERROR); throw new ServiceException(String.format(ExceptionDict.PARAM_IS_NULL_ERROR_MSG,"maMachineList"), ExceptionDict.PARAM_IS_NULL_ERROR);
} else { } else {
//组装请求报文
makeIntelligentVOList(tmTasks, intelVOList); makeIntelligentVOList(tmTasks, intelVOList);
} }
if (!CollectionUtils.isEmpty(intelVOList)) { if (!CollectionUtils.isEmpty(intelVOList)) {
try { try {
String content = JSONObject.toJSONString(intelVOList); MaMachineIntelligentVO maMachineIntelligentVO = intelVOList.get(0);
Map<String, String> bodyMap = new HashMap<>(); String content = JSONObject.toJSONString(maMachineIntelligentVO);
//如果以后文件就添加进去 //获取token
bodyMap.put("files", ""); String token = GetTokenByAppKey.getToken(intelligentAppKey, intelligentAesKey);
bodyMap.put("params", content); log.info("token-=========:" + token);
String body = JSONObject.toJSONString(bodyMap); //调用推送的方法
Map<String, String> headerMap = new HashMap<>(); String data = HttpHelper.sendHttpPost(intelligentUrl, token,content,intelligentAppKey);
headerMap.put("appKey", /*intelligentAppKey*/"abc123");
String token = GetTokenByAppKey.getToken(/*intelligentAppKey*/"abc123", /*intelligentAesKey*/"abcdefghijklmnop");
headerMap.put("token", token);
String data = HttpHelper.sendHttpPost(/*intelligentUrl+*/"https://sit.zhgkxt.com/api/clientapi/public/externalApi/acceptExternalMechanical", headerMap, body);
log.info("dataString-=========:" + data); log.info("dataString-=========:" + data);
resultDataHandler(data); resultDataHandler(data);
} catch (Exception e) { } catch (Exception e) {
log.error("请求失败!{}", e); log.error("请求失败!{}", e);
return AjaxResult.error("请求失败!{}", e.getMessage()); return AjaxResult.error("请求失败!{}", e.getMessage());
} }
log.info("推送成功!修改状态");
//更改推送的状态 //更改推送的状态
for (TmTask tmTask:tmTasks) { for (TmTask tmTask:tmTasks) {
LeaseRecord leaseRecord = new LeaseRecord(); LeaseRecord leaseRecord = new LeaseRecord();
@ -1419,7 +1416,9 @@ public class TmTaskServiceImpl implements TmTaskService {
return AjaxResult.success("请求成功!"); return AjaxResult.success("请求成功!");
} }
public static void main(String[] args) { /* public static void main(String[] args) {
String aa = "A101";
System.out.println(aa.charAt(0));
List<TmTask> tmTasks = new ArrayList<>(); List<TmTask> tmTasks = new ArrayList<>();
TmTask tmTask= new TmTask(); TmTask tmTask= new TmTask();
tmTask.setId("622"); tmTask.setId("622");
@ -1429,69 +1428,56 @@ public class TmTaskServiceImpl implements TmTaskService {
tmTask.setManageType("0"); tmTask.setManageType("0");
tmTask.setPartNum(5); tmTask.setPartNum(5);
tmTask.setProName("核打击保密单位"); tmTask.setProName("核打击保密单位");
tmTask.setMaStatus("15");
tmTasks.add(tmTask); tmTasks.add(tmTask);
TmTaskServiceImpl tm = new TmTaskServiceImpl(); TmTaskServiceImpl tm = new TmTaskServiceImpl();
tm.pushToIntelligentProject( tmTasks); tm.pushToIntelligentProject( tmTasks);
} }*/
private void makeIntelligentVOList(List<TmTask> tmTasks, List<MaMachineIntelligentVO> intelVOList) { private void makeIntelligentVOList(List<TmTask> tmTasks, List<MaMachineIntelligentVO> intelVOList) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
for (TmTask task : tmTasks) { for (TmTask task : tmTasks) {
// List<TmTask> subTasks = tmTaskMapper.getLeaseOutDetails(task); List<TmTask> subTasks = tmTaskMapper.getLeaseOutDetails(task);
// for (TmTask subTask : subTasks) { for (TmTask subTask : subTasks) {
MaMachineIntelligentVO intelVO = new MaMachineIntelligentVO(); MaMachineIntelligentVO intelVO = new MaMachineIntelligentVO();
intelVO.setSocialCreditCode(/*loginUser.getSysUser().getDept().getSocialCreditCode()*/"9134010039449847XC"); //getIntelligentCode 值为例A101 获取门类码
intelVO.setAffiliatedUnitName(task.getUnitName()); intelVO.setCategoryCode(subTask.getIntelligentCode().substring(0,1));
intelVO.setBelongUnitId(String.valueOf(task.getUnitId())); //获取分类码
intelVO.setCategoryCode(task.getTypeId()); intelVO.setClassifyCode(subTask.getIntelligentCode().substring(1,2));
intelVO.setClassifyCode(task.getTypeId()); //获取机具码
intelVO.setDelReason("不是报废"); intelVO.setMachineryCode(subTask.getIntelligentCode().substring(2));
intelVO.setInspectorUnitName("123"); intelVO.setInspectorUnitName("123");
intelVO.setInspectionCertificateNumber("123"); intelVO.setInspectionCertificateNumber("123");
intelVO.setManufacturer("123"); //生产厂家
intelVO.setMultipartFiles("123"); intelVO.setManufacturer(0);
intelVO.setOperateType(1); //0:默认新增 1:修改以前推送的数据 intelVO.setOperateType("0"); //0:默认新增 1:修改以前推送的数据
intelVO.setRemarks("123"); //intelVO.setSource(2); //1:智慧工程系统 2:第三方数据
intelVO.setSource(2); //1:智慧工程系统 2:第三方数据
intelVO.setStatus("15".equals(task.getMaStatus()) ? 0 : 1); //0:有效 1:无效 intelVO.setStatus("15".equals(task.getMaStatus()) ? 0 : 1); //0:有效 1:无效
intelVO.setSpecificationType("123"); intelVO.setSpecificationType("123");
intelVO.setValidityDate(new Date()); intelVO.setValidityDate(DateUtils.getDate());
//每个设备不同点的设置 //每个设备不同点的设置
// String ownerCode = loginUser.getSysUser().getDept().getEnterpriseOwnershipCode(); String ownerCode = loginUser.getSysUser().getDept().getEnterpriseOwnershipCode();
//intelVO.setDeviceCode(StringUtils.getDeviceCode(ownerCode, subTask.getTypeName(), subTask.getTypeId(), subTask.getCreateTime(), subTask.getMaId())); if (StringUtils.isEmpty(ownerCode)){
intelVO.setDeviceCode("CSG-A101-2024061950001"); ownerCode = "CSG";
/* intelVO.setFactoryDate(subTask.getOutFacTime()); }
intelVO.setMachineryCode(subTask.getMaId()); intelVO.setDeviceCode(StringUtils.getDeviceCode(ownerCode, subTask.getIntelligentCode(), subTask.getCreateTime(), subTask.getMaId()));
intelVO.setTrialDate(subTask.getThisCheckTime());*/ intelVO.setFactoryDate(DateUtils.getDate());
intelVO.setFactoryDate(new Date()); intelVO.setTrialDate(DateUtils.getDate());
intelVO.setMachineryCode("123");
intelVO.setTrialDate(new Date());
//组成list //组成list
intelVOList.add(intelVO); intelVOList.add(intelVO);
// } }
} }
} }
private void resultDataHandler(String data) throws Exception { private String resultDataHandler(String data) throws Exception {
JSONObject object = JSONObject.parseObject(data); JSONObject object = JSONObject.parseObject(data);
System.err.println(data); System.err.println(data);
String code = object.getString("code"); String code = object.getString("code");
if ("0".equals(code)) { Integer status = BigDecimal.ZERO.intValue();
String dataResultString = object.getString("data"); if (status.equals(code)) {
// 数据解密 String dataResultString = object.getString("result");
String dataArrayString = RsaUtil.decryptByPrivateKey(dataResultString, Constants.publicKey); return dataResultString;
log.info("dataArrayString-=========:" + dataArrayString);
JSONArray dataArray = JSONArray.parseArray(dataArrayString);
if (dataArray != null && dataArray.size() > 0) {
}else {
}
} else {
} }
throw new Exception("推送失败");
} }
} }

View File

@ -26,14 +26,18 @@ spring:
# 共享配置 # 共享配置
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 禁用Actuator端点的未经身份验证的访问
management:
endpoint:
env:
enabled: false
# 多站点特殊配置 # 多站点特殊配置
sgzb: sgzb:
site: cq site: cq
job: job:
settlementJobDay: 21 settlementJobDay: 21
settlementJobCron: "0 0 1 21 * ?" settlementJobCron: "0 0 1 21 * ?"
zlptUrl: zlptUrl: http://test-rental.zhgkxt.com/proxy/item-center/supply/item/pushNotifications
intelligentUrl: intelligentUrl: http://www.zhgkxt.com/api/clientapi/public/externalApi
intelligentAppKey: intelligentAppKey: abc123
intelligentAesKey: intelligentAesKey: abcdefghijklmnop

View File

@ -1184,7 +1184,8 @@
mam.this_check_time as thisCheckTime, mam.this_check_time as thisCheckTime,
mam.create_time as createTime, mam.create_time as createTime,
mt.type_id, mt.type_id,
mt3.type_name as typeName mt3.type_name as typeName,
mt1.intelligent_code as intelligentCode
from lease_out_details lod from lease_out_details lod
left join ma_machine mam on mam.ma_id = lod.ma_id left join ma_machine mam on mam.ma_id = lod.ma_id
left join ma_type mt on mam.type_id = mt.type_id left join ma_type mt on mam.type_id = mt.type_id