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

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

View File

@ -122,6 +122,11 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.6</version>
</dependency>
</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.HttpPost;
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.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@ -37,23 +36,25 @@ public class HttpHelper {
return responseContent;
}
public static String sendHttpPost(String url, Map<String,String> headerMap, String JSONBody) throws Exception {
System.out.println("JSONBody-=========:" + JSONBody);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "multipart/form-data; charset=UTF-8");
if (!CollectionUtils.isEmpty(headerMap)) {
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
httpPost.addHeader(entry.getKey(), entry.getValue());
}
public static String sendHttpPost(String url,String token,String content,String intelligentAppKey) throws Exception {
System.out.println("JSONBody-=========:" + content);
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPost post = new HttpPost(url);
post.setHeader("token", token);
post.setHeader("appKey", intelligentAppKey);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
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));
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
response.close();
httpClient.close();
return responseContent;
return null;
}
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 */
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);
if (number > 30000) {
number = number % 30000;
}
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;
}

View File

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

View File

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

View File

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