fix (farm): 生产计划
- 养殖类租户,打印网箱能力.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo;
|
package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo.vo.*;
|
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.JbyPrintManager;
|
||||||
import cn.iocoder.yudao.module.farm.service.plotinfo.PlotLesseeService;
|
import cn.iocoder.yudao.module.farm.service.plotinfo.PlotLesseeService;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -46,6 +47,8 @@ public class PlotInfoController {
|
|||||||
private PlotInfoService plotInfoService;
|
private PlotInfoService plotInfoService;
|
||||||
@Resource
|
@Resource
|
||||||
private PlotLesseeService plotLesseeService;
|
private PlotLesseeService plotLesseeService;
|
||||||
|
@Resource
|
||||||
|
private JbyPrintManager printManager;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建地块")
|
@Operation(summary = "创建地块")
|
||||||
@@ -129,9 +132,9 @@ public class PlotInfoController {
|
|||||||
@GetMapping("/grid-code/print")
|
@GetMapping("/grid-code/print")
|
||||||
@Operation(summary = "网箱二维码打印")
|
@Operation(summary = "网箱二维码打印")
|
||||||
@Parameter(name = "planNumber", description = "生产计划编号", required = true)
|
@Parameter(name = "planNumber", description = "生产计划编号", required = true)
|
||||||
public CommonResult<Boolean> gridPrint(@RequestParam("planNumber") String planNumber) {
|
public CommonResult<String> gridPrint(@RequestParam("planNumber") String planNumber) {
|
||||||
|
String msg = printManager.printGridCode(planNumber);
|
||||||
return success(true);
|
return success(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.grid.ProductionPlanGridRespVO;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.dto.PrintReqDTO;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.dto.PrintTask;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.utils.JbyPrintUtil;
|
||||||
|
import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 13:50
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class JbyPrintManager {
|
||||||
|
|
||||||
|
private final JbyPrintUtil jbyPrintUtil;
|
||||||
|
private final ProductionPlanService productionPlanService;
|
||||||
|
|
||||||
|
public JbyPrintManager(JbyPrintUtil jbyPrintUtil, ProductionPlanService productionPlanService) {
|
||||||
|
this.jbyPrintUtil = jbyPrintUtil;
|
||||||
|
this.productionPlanService = productionPlanService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String printGridCode(String planNumber) {
|
||||||
|
ProductionPlanGridRespVO gridForPlan = productionPlanService.getGridForPlan(planNumber);
|
||||||
|
List<ProductionPlanGridRespVO.Row> rows = gridForPlan.getRows();
|
||||||
|
List<PrintTask> taskList = rows.stream()
|
||||||
|
.map(e -> new PrintTask(e.getGridCode(), new PrintReqDTO.PlanData(planNumber, e.getGridCode())))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return jbyPrintUtil.batchPrint(taskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.conf;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: TODO
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 14:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "jby")
|
||||||
|
public class PrintConf {
|
||||||
|
|
||||||
|
private String hosts;
|
||||||
|
private String apiKey;
|
||||||
|
private String memberCode;
|
||||||
|
private String templateId;
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.conf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 佳博云打印机
|
||||||
|
* @URL https://dev.poscom.cn/openapi?sendMsg
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 14:30
|
||||||
|
*/
|
||||||
|
public class PrintConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印信息的格式类型。取值范围[2-3] (无空格,如十六进制 0x12 0xAB 0xCD 0xEF,发送内容 12ABCDEF)
|
||||||
|
* mode=2,自由格式打印(推荐使用)
|
||||||
|
* mode=3,十六进制命令集或十六进制字符串打印
|
||||||
|
*/
|
||||||
|
private final String MODE_2 = "2";
|
||||||
|
private final String MODE_3 = "3";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 打印机请求参数
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 14:05
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PrintReqDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前UNIX时间戳。13位,精确到毫秒。
|
||||||
|
*/
|
||||||
|
private String reqTime;
|
||||||
|
private String securityCode;
|
||||||
|
private String memberCode;
|
||||||
|
private String deviceID;
|
||||||
|
private String templetID;
|
||||||
|
private String tData;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码格式,取值范围[1-10] 默认1。
|
||||||
|
* 1: GB18030
|
||||||
|
* 2: GB2312
|
||||||
|
* 3: GBK
|
||||||
|
* 4: UTF-8
|
||||||
|
* 5: Unicode
|
||||||
|
* 6: ISO8859-1
|
||||||
|
* 7: BIG5
|
||||||
|
* 8: EUC-KR
|
||||||
|
* 9: TIS-620
|
||||||
|
* 10: VISCII
|
||||||
|
*/
|
||||||
|
private String charset;
|
||||||
|
/**
|
||||||
|
*业务ID 一般由用户生成,用于跟踪订单状态
|
||||||
|
*/
|
||||||
|
private String msgNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否重新打印。取值范围[0-1] 0:否,1:是。默认值0。
|
||||||
|
* 若是重新打印则系统允许 msgNo 字段重复,但不记录订单
|
||||||
|
*/
|
||||||
|
private String reprint;
|
||||||
|
|
||||||
|
private String times;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class PlanData {
|
||||||
|
private String planNumber;
|
||||||
|
private String gridCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: TODO
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 15:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PrintRespDTO {
|
||||||
|
private Integer code;
|
||||||
|
private String msg;
|
||||||
|
private Object data;
|
||||||
|
private String serverExecTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 15:31
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PrintTask {
|
||||||
|
private String msgNo;
|
||||||
|
private PrintReqDTO.PlanData data;
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.conf.PrintConf;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.dto.PrintReqDTO;
|
||||||
|
import cn.iocoder.yudao.module.farm.manager.printer.dto.PrintTask;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @description
|
||||||
|
* @date 2025/7/18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class JbyPrintUtil {
|
||||||
|
|
||||||
|
private final PrintConf printConf;
|
||||||
|
private final PrintServerHttpClientUtil httpClientUtil;
|
||||||
|
|
||||||
|
public JbyPrintUtil(PrintConf printConf, PrintServerHttpClientUtil httpClientUtil) {
|
||||||
|
this.printConf = printConf;
|
||||||
|
this.httpClientUtil = httpClientUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量打印方法
|
||||||
|
*/
|
||||||
|
public String batchPrint(List<PrintTask> tasks) {
|
||||||
|
if (tasks == null || tasks.isEmpty()) {
|
||||||
|
return buildSuccessResult("无打印任务");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("开始批量打印,任务数量: {}", tasks.size());
|
||||||
|
int successCount = 0;
|
||||||
|
|
||||||
|
for (PrintTask task : tasks) {
|
||||||
|
try {
|
||||||
|
String result = print(
|
||||||
|
task.getMsgNo(),
|
||||||
|
printConf.getDeviceId(),
|
||||||
|
printConf.getTemplateId(),
|
||||||
|
1L,
|
||||||
|
task.getData()
|
||||||
|
);
|
||||||
|
|
||||||
|
// 检查API返回结果
|
||||||
|
if (!isSuccessResult(result)) {
|
||||||
|
log.error("打印API返回错误,停止批量打印: msgNo={}, result={}", task.getMsgNo(), result);
|
||||||
|
return buildErrorResultFromResponse(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
successCount++;
|
||||||
|
log.info("打印任务成功: msgNo={}", task.getMsgNo());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// print方法异常,立即返回
|
||||||
|
log.error("打印任务异常,停止批量打印: msgNo={}", task.getMsgNo(), e);
|
||||||
|
return buildErrorResult("打印系统异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("批量打印全部成功,共{}条任务", successCount);
|
||||||
|
return buildSuccessResult("成功打印" + successCount + "个任务");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条打印
|
||||||
|
*
|
||||||
|
* @param msgNo
|
||||||
|
* @param deviceID
|
||||||
|
* @param templateId
|
||||||
|
* @param times
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String print(String msgNo,
|
||||||
|
String deviceID,
|
||||||
|
String templateId,
|
||||||
|
Long times,
|
||||||
|
PrintReqDTO.PlanData data) {
|
||||||
|
try {
|
||||||
|
String reqTime = String.valueOf(System.currentTimeMillis());
|
||||||
|
|
||||||
|
String securityCode = generateSecurityCode(deviceID, msgNo, reqTime);
|
||||||
|
|
||||||
|
// 构建符合服务商要求的参数Map
|
||||||
|
Map<String, String> params = buildPrintParams(msgNo, deviceID, templateId, times, data, reqTime, securityCode);
|
||||||
|
|
||||||
|
log.info("发送打印请求: msgNo={}, deviceID={}, template={}", msgNo, deviceID, templateId);
|
||||||
|
log.info("请求参数: {}", params);
|
||||||
|
|
||||||
|
// 使用表单格式发送请求
|
||||||
|
String result = httpClientUtil.postForm(printConf.getHosts(), params);
|
||||||
|
|
||||||
|
log.info("打印响应: {}", result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("打印请求失败: msgNo={}, deviceID={}, error={}", msgNo, deviceID, e.getMessage(), e);
|
||||||
|
throw new RuntimeException("打印服务调用失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建符合服务商要求的参数Map
|
||||||
|
*/
|
||||||
|
private Map<String, String> buildPrintParams(String msgNo, String deviceID, String template,
|
||||||
|
Long printTime, PrintReqDTO.PlanData data,
|
||||||
|
String reqTime, String securityCode) {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
||||||
|
// 严格按照服务商示例的参数名和顺序
|
||||||
|
params.put("reqTime", reqTime);
|
||||||
|
params.put("securityCode", securityCode);
|
||||||
|
params.put("memberCode", printConf.getMemberCode());
|
||||||
|
params.put("templetID", template);
|
||||||
|
params.put("deviceID", deviceID != null ? deviceID : "undefined");
|
||||||
|
params.put("token", "");
|
||||||
|
params.put("tData", data != null ? JSON.toJSONString(data) : "");
|
||||||
|
params.put("reprint", "0");
|
||||||
|
params.put("multi", "0"); // 服务商示例中有这个参数
|
||||||
|
params.put("msgNo", msgNo != null ? msgNo : "");
|
||||||
|
params.put("charset", "1");
|
||||||
|
params.put("times", printTime != null ? printTime.toString() : "1");
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成安全码
|
||||||
|
*/
|
||||||
|
private String generateSecurityCode(String deviceID, String msgNo, String reqTime) {
|
||||||
|
String source = printConf.getMemberCode() + deviceID + msgNo + reqTime + printConf.getApiKey();
|
||||||
|
return DigestUtils.md5Hex(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建成功结果
|
||||||
|
*/
|
||||||
|
private String buildSuccessResult(String message) {
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
result.put("code", 0);
|
||||||
|
result.put("msg", message);
|
||||||
|
result.put("success", true);
|
||||||
|
return result.toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建错误结果(自定义错误信息)
|
||||||
|
*/
|
||||||
|
private String buildErrorResult(String errorMessage) {
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
result.put("code", -1);
|
||||||
|
result.put("msg", errorMessage);
|
||||||
|
result.put("success", false);
|
||||||
|
return result.toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从API响应中构建错误结果
|
||||||
|
*/
|
||||||
|
private String buildErrorResultFromResponse(String apiResponse) {
|
||||||
|
try {
|
||||||
|
JSONObject responseJson = JSON.parseObject(apiResponse);
|
||||||
|
Integer code = responseJson.getInteger("code");
|
||||||
|
String msg = responseJson.getString("msg");
|
||||||
|
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
result.put("code", code != null ? code : -1);
|
||||||
|
result.put("msg", msg != null ? msg : "打印服务返回错误");
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("originalResponse", apiResponse); // 保留原始响应
|
||||||
|
|
||||||
|
return result.toJSONString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果解析失败,使用自定义错误信息
|
||||||
|
return buildErrorResult("打印服务返回异常结果: " + apiResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断API响应是否成功
|
||||||
|
*/
|
||||||
|
private boolean isSuccessResult(String result) {
|
||||||
|
try {
|
||||||
|
JSONObject json = JSON.parseObject(result);
|
||||||
|
Integer code = json.getInteger("code");
|
||||||
|
return code != null && code == 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.manager.printer.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 打印机 httpClient 氢气工具
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/11/14 15:22
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class PrintServerHttpClientUtil {
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public PrintServerHttpClientUtil(RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RestTemplate createRestTemplate() {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
// 设置消息转换器
|
||||||
|
restTemplate.setMessageConverters(Arrays.asList(
|
||||||
|
new StringHttpMessageConverter(StandardCharsets.UTF_8),
|
||||||
|
new MappingJackson2HttpMessageConverter()
|
||||||
|
));
|
||||||
|
|
||||||
|
// 设置请求工厂
|
||||||
|
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
||||||
|
factory.setConnectionRequestTimeout(5000);
|
||||||
|
factory.setConnectTimeout(5000);
|
||||||
|
factory.setReadTimeout(10000);
|
||||||
|
restTemplate.setRequestFactory(factory);
|
||||||
|
|
||||||
|
return restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求 - 发送JSON数据
|
||||||
|
*/
|
||||||
|
public <T> T postForObject(String url, Object request, Class<T> responseType) {
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
|
|
||||||
|
HttpEntity<Object> entity = new HttpEntity<>(request, headers);
|
||||||
|
|
||||||
|
return restTemplate.postForObject(url, entity, responseType);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
throw new RuntimeException("HTTP请求失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求 - 发送表单数据(佳博云API需要表单格式)
|
||||||
|
*/
|
||||||
|
public String postForm(String url, Map<String, String> params) {
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
||||||
|
params.forEach(formData::add);
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(formData, headers);
|
||||||
|
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
||||||
|
return response.getBody();
|
||||||
|
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
throw new RuntimeException("HTTP请求失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET请求
|
||||||
|
*/
|
||||||
|
public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) {
|
||||||
|
try {
|
||||||
|
return restTemplate.getForObject(url, responseType, uriVariables);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
throw new RuntimeException("HTTP请求失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET请求 - 带查询参数
|
||||||
|
*/
|
||||||
|
public <T> T getForObject(String url, Class<T> responseType, Map<String, Object> params) {
|
||||||
|
try {
|
||||||
|
if (params != null && !params.isEmpty()) {
|
||||||
|
StringBuilder urlBuilder = new StringBuilder(url);
|
||||||
|
urlBuilder.append("?");
|
||||||
|
params.forEach((key, value) ->
|
||||||
|
urlBuilder.append(key).append("=").append(value).append("&"));
|
||||||
|
url = urlBuilder.substring(0, urlBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
return restTemplate.getForObject(url, responseType);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
throw new RuntimeException("HTTP请求失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带异常处理的POST请求
|
||||||
|
*/
|
||||||
|
public <T> T postWithExceptionHandler(String url, Object request, Class<T> responseType) {
|
||||||
|
try {
|
||||||
|
return postForObject(url, request, responseType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 这里可以记录日志或进行其他异常处理
|
||||||
|
throw new RuntimeException("调用外部服务失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ spring:
|
|||||||
host: ${redis.host}
|
host: ${redis.host}
|
||||||
port: ${redis.port}
|
port: ${redis.port}
|
||||||
database: ${redis.database}
|
database: ${redis.database}
|
||||||
|
username: ${redis.username}
|
||||||
password: ${redis.password}
|
password: ${redis.password}
|
||||||
mongodb:
|
mongodb:
|
||||||
uri: mongodb://mongo_BiKBdR:mongo_KaShrX@223.83.129.121:27017/farming-platform-iot?authSource=farming-platform-iot
|
uri: mongodb://mongo_BiKBdR:mongo_KaShrX@223.83.129.121:27017/farming-platform-iot?authSource=farming-platform-iot
|
||||||
|
|||||||
@@ -345,6 +345,7 @@ spring:
|
|||||||
max-size: 32 # 最大线程数
|
max-size: 32 # 最大线程数
|
||||||
queue-capacity: 1000 # 队列容量
|
queue-capacity: 1000 # 队列容量
|
||||||
keep-alive: 60s # 空闲线程存活时间
|
keep-alive: 60s # 空闲线程存活时间
|
||||||
|
|
||||||
# 万懋wms系统
|
# 万懋wms系统
|
||||||
wms:
|
wms:
|
||||||
hosts: ${wanmao.wms.hosts}
|
hosts: ${wanmao.wms.hosts}
|
||||||
@@ -396,9 +397,17 @@ weather:
|
|||||||
url-1: https://restapi.amap.com/v3/geocode/regeo?location={0},{1}&key={2} # 经纬度逆解析 GET
|
url-1: https://restapi.amap.com/v3/geocode/regeo?location={0},{1}&key={2} # 经纬度逆解析 GET
|
||||||
url-2: https://restapi.amap.com/v3/weather/weatherInfo?city={0}&key={1} # 获取天气信息 GET
|
url-2: https://restapi.amap.com/v3/weather/weatherInfo?city={0}&key={1} # 获取天气信息 GET
|
||||||
|
|
||||||
|
# 公司联系方式
|
||||||
company:
|
company:
|
||||||
contact-number: 40088888
|
contact-number: 40088888
|
||||||
email: weixucz@isoftstone.com
|
email: weixucz@isoftstone.com
|
||||||
address: 江西省南昌市xxx-xxx-C4-1717室
|
address: 江西省南昌市xxx-xxx-C4-1717室
|
||||||
|
|
||||||
|
# 打印机
|
||||||
|
jby:
|
||||||
|
hosts: ${print.jby.hosts}
|
||||||
|
apikey: ${print.jby.api-key}
|
||||||
|
member-code: ${print.jby.member-code}
|
||||||
|
template-id: ${print.jby.template-id}
|
||||||
|
device-id: ${print.jby.device-id}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
#########################
|
#########################
|
||||||
###########wanmao###########
|
# wanmao server
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
mysql.url=jdbc:mysql://223.83.129.121:3360/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
mysql.url=jdbc:mysql://223.83.129.121:3360/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
||||||
#mysql.url=jdbc:mysql://Mysql:3360/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
#mysql.url=jdbc:mysql://Mysql:3306/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
||||||
mysql.username=farming-platform
|
mysql.username=farming-platform
|
||||||
mysql.password=wCM7fBMhFP3zNdJ3
|
mysql.password=wCM7fBMhFP3zNdJ3
|
||||||
|
|
||||||
redis.host= 112.126.60.236
|
redis.host= 112.126.60.236
|
||||||
#redis.host=Redis
|
#redis.host=Redis
|
||||||
redis.port=65532
|
redis.port=65532
|
||||||
redis.database=0
|
redis.database=5
|
||||||
|
redis.username=
|
||||||
redis.password=luxifa970219
|
redis.password=luxifa970219
|
||||||
|
|
||||||
wm.wx.mp.app-id=wx508d9a9ab84f67d0
|
wm.wx.mp.app-id=wx508d9a9ab84f67d0
|
||||||
@@ -27,34 +28,76 @@ wanmao.wms.hosts=https://wms.simple.gltec.cn/prod-api
|
|||||||
# gaode key
|
# gaode key
|
||||||
gaode.weather.webkey=ea0a0486aaea8dbf9f68274df1160df3
|
gaode.weather.webkey=ea0a0486aaea8dbf9f68274df1160df3
|
||||||
|
|
||||||
|
# print
|
||||||
|
print.jby.hosts=http://api.poscom.cn/apisc/templetPrint
|
||||||
|
print.jby.api-key=8KOSGN3SX11QV80IY8N6PYFMNF29R1N9
|
||||||
|
print.jby.member-code=7A7453F04CB067987229F7BBAD888CFF
|
||||||
|
print.jby.template-id=be64feabccf44de189f7019daa0dd7fb
|
||||||
|
print.jby.device-id=00543113467925660
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#========================
|
||||||
|
# wan mao server
|
||||||
|
#========================
|
||||||
|
|
||||||
|
#mysql.url=jdbc:mysql://rm-2ze979o6dt71z2mf6so.mysql.rds.aliyuncs.com:3306/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
||||||
|
#mysql.username=root
|
||||||
|
#mysql.password=Wm@123456
|
||||||
|
#
|
||||||
|
#redis.host=r-2zepgu4tu2ofnhhgzopd.redis.rds.aliyuncs.com
|
||||||
|
#redis.port=6379
|
||||||
|
#redis.database=5
|
||||||
|
#redis.username=yunge
|
||||||
|
#redis.password=Yunge123
|
||||||
|
#
|
||||||
|
#wm.wx.mp.app-id=wx508d9a9ab84f67d0
|
||||||
|
#wm.wx.mp.secret=92c571b9973f9078c11da47a16c4094c
|
||||||
|
#wm.wx.miniapp.app-id=wx508d9a9ab84f67d0
|
||||||
|
#wm.wx.miniapp.secret=92c571b9973f9078c11da47a16c4094c
|
||||||
|
#
|
||||||
|
#wanmao.wms.url_1=getTenantByMobile
|
||||||
|
## prod
|
||||||
|
#wanmao.wms.hosts=https://wms.simple.gltec.cn/prod-api
|
||||||
|
## test
|
||||||
|
##wanmao.wms.hosts=47.111.15.9:8074/prod-api
|
||||||
|
#
|
||||||
|
## gaode key
|
||||||
|
#gaode.weather.webkey=ea0a0486aaea8dbf9f68274df1160df3
|
||||||
|
#
|
||||||
|
## print
|
||||||
|
#print.jby.hosts=http://api.poscom.cn/apisc/templetPrint
|
||||||
|
#print.jby.api-key=8KOSGN3SX11QV80IY8N6PYFMNF29R1N9
|
||||||
|
#print.jby.member-code=7A7453F04CB067987229F7BBAD888CFF
|
||||||
|
#print.jby.template-id=be64feabccf44de189f7019daa0dd7fb
|
||||||
|
#print.jby.device-id=00543113467925660
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#########################
|
|
||||||
###########jishui###########
|
|
||||||
#########################
|
|
||||||
|
#========================
|
||||||
|
# ji shui server
|
||||||
|
#========================
|
||||||
|
|
||||||
#mysql.url=jdbc:mysql://rm-bp10c7f0fou5efc95fo.mysql.rds.aliyuncs.com:3306/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
#mysql.url=jdbc:mysql://rm-bp10c7f0fou5efc95fo.mysql.rds.aliyuncs.com:3306/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
|
||||||
#mysql.username=root
|
#mysql.username=root
|
||||||
#mysql.password=Jsnm2025
|
#mysql.password=Jsnm2025
|
||||||
#
|
|
||||||
#redis.host=r-bp14zubs85fmfuhnw7pd.redis.rds.aliyuncs.com
|
#redis.host=r-bp14zubs85fmfuhnw7pd.redis.rds.aliyuncs.com
|
||||||
#redis.port=6379
|
#redis.port=6379
|
||||||
#redis.database=1
|
#redis.database=1
|
||||||
#redis.password=m&wRPVcyy7Gl
|
#redis.password=m&wRPVcyy7Gl
|
||||||
#
|
|
||||||
#wm.wx.mp.app-id=wxde87f69bb4a2cf5c
|
#wm.wx.mp.app-id=wxde87f69bb4a2cf5c
|
||||||
#wm.wx.mp.secret=a5e114df50a86c2578af255adba1c3e7
|
#wm.wx.mp.secret=a5e114df50a86c2578af255adba1c3e7
|
||||||
#wm.wx.miniapp.app-id=wxde87f69bb4a2cf5c
|
#wm.wx.miniapp.app-id=wxde87f69bb4a2cf5c
|
||||||
#wm.wx.miniapp.secret=a5e114df50a86c2578af255adba1c3e7
|
#wm.wx.miniapp.secret=a5e114df50a86c2578af255adba1c3e7
|
||||||
#
|
|
||||||
#wms.hosts=https://wms.jslstec.cn/prod-api
|
#wms.hosts=https://wms.jslstec.cn/prod-api
|
||||||
#wms.url_1=getTenantByMobile
|
#wms.url_1=getTenantByMobile
|
||||||
#
|
#gaode.weather.webkey=6e867624a911d74e673f5e68c52a61e7
|
||||||
#weather.webkey=6e867624a911d74e673f5e68c52a61e7
|
|
||||||
Reference in New Issue
Block a user