Browse Source

后端整合模块

detached
huangqizhen 4 months ago
parent
commit
5df74f2d6b
  1. 100
      src/main/java/com/example/demo/Util/BaseDES.java
  2. 2
      src/main/java/com/example/demo/controller/DetailYController.java
  3. 4
      src/main/java/com/example/demo/mapper/DetailYMapper.java
  4. 69
      src/main/java/com/example/demo/serviceImpl/OtherServiceImpl.java
  5. 2
      src/main/java/com/example/demo/sevice/OtherService.java

100
src/main/java/com/example/demo/Util/BaseDES.java

@ -0,0 +1,100 @@
package com.example.demo.Util;
import javax.crypto.Cipher;
import java.security.*;
public class BaseDES {
private static String strDefaultKey = "98hltleg";
private Cipher encryptCipher = null;
private Cipher decryptCipher = null;
public static String byteArr2HexStr(byte[] arrB) throws Exception {
int iLen = arrB.length;
StringBuffer sb = new StringBuffer(iLen * 2);
for (int i = 0; i < iLen; i++) {
int intTmp = arrB[i];
while (intTmp < 0) {
intTmp = intTmp + 256;
}
if (intTmp < 16) {
sb.append("0");
}
sb.append(Integer.toString(intTmp, 16));
}
return sb.toString();
}
public static byte[] hexStr2ByteArr(String strIn) {
byte[] arrB = strIn.getBytes();
int iLen = arrB.length;
byte[] arrOut = new byte[iLen / 2];
for (int i = 0; i < iLen; i = i + 2) {
String strTmp = new String(arrB, i, 2);
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
}
return arrOut;
}
public BaseDES() throws Exception {
this(strDefaultKey);
}
public BaseDES(String strKey) throws Exception {
Key key = getKey(strKey.getBytes());
encryptCipher = Cipher.getInstance("DES");
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
decryptCipher = Cipher.getInstance("DES");
decryptCipher.init(Cipher.DECRYPT_MODE, key);
}
public byte[] encrypt(byte[] arrB) throws Exception {
return encryptCipher.doFinal(arrB);
}
public String encrypt(String strIn) throws Exception {
return byteArr2HexStr(encrypt(strIn.getBytes()));
}
public byte[] decrypt(byte[] arrB) throws Exception {
return decryptCipher.doFinal(arrB);
}
public String decrypt(String strIn) throws Exception {
return new String(decrypt(hexStr2ByteArr(strIn)));
}
private Key getKey(byte[] arrBTmp) {
byte[] arrB = new byte[8];
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
return key;
}
public static void main(String args[]) {
try {
BaseDES d = new BaseDES();
System.out.println("加密字符串:90005179》"+d.encrypt("90005179"));
System.out.println("解密字符串:6aaef5277c050f7ae383f816651098ff》"+d.decrypt("6aaef5277c050f7ae383f816651098ff"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

2
src/main/java/com/example/demo/controller/DetailYController.java

@ -61,7 +61,7 @@ public class DetailYController {
return Result.success(detailYService.searchAll(detailExport));
}
@PostMapping("/ERP")
public Result addERP(@RequestBody ERP erp) {
public Result addERP(@RequestBody ERP erp) throws Exception {
return Result.success(otherService.addERP(erp));
}
}

4
src/main/java/com/example/demo/mapper/DetailYMapper.java

@ -19,9 +19,9 @@ public interface DetailYMapper {
// ",#{refundGoods},#{name},#{username},#{area},#{contactId},#{remark},#{rechargeCoin}" +
// ",#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now(),#{firstRecharge})"
"insert into detail_y \n" +
"(jwcode, order_code, activity_id, recharge_way, product_id, consume_platform, consume_type, refund_type, refund_goods, name, username, area, contact_id, remark, recharge_coin, free_coin, task_coin, admin_id, update_type, detail_flag, create_time, first_recharge)\n" +
"(jwcode, order_code, activity_id, recharge_way, product_id, consume_platform, consume_type, refund_type, refund_goods, name, username, area, contact_id, remark, recharge_coin, free_coin, task_coin, admin_id, update_type, detail_flag, create_time, first_recharge,product_name)\n" +
"values \n" +
"(#{jwcode}, #{orderCode}, #{activityId}, #{rechargeWay}, #{productId}, #{consumePlatform}, #{consumeType}, #{refundType}, #{refundGoods}, #{name}, #{username}, #{area}, #{contactId}, #{remark}, #{rechargeCoin}, #{freeCoin}, #{taskCoin}, #{adminId}, #{updateType}, 1, now(), #{firstRecharge})"
"(#{jwcode}, #{orderCode}, #{activityId}, #{rechargeWay}, #{productId}, #{consumePlatform}, #{consumeType}, #{refundType}, #{refundGoods}, #{name}, #{username}, #{area}, #{contactId}, #{remark}, #{rechargeCoin}, #{freeCoin}, #{taskCoin}, #{adminId}, #{updateType}, 1, now(), #{firstRecharge},#{productName})"
})
@Options(useGeneratedKeys = true,keyColumn = "detaily_id",keyProperty = "detailyId")
int add(DetailY detaily);

69
src/main/java/com/example/demo/serviceImpl/OtherServiceImpl.java

@ -1,5 +1,6 @@
package com.example.demo.serviceImpl;
import com.example.demo.Util.BaseDES;
import com.example.demo.domain.entity.DetailY;
import com.example.demo.domain.vo.ERP;
import com.example.demo.mapper.DetailYMapper;
@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
@ -104,7 +106,7 @@ public class OtherServiceImpl implements OtherService {
}
@Override
public int addERP(ERP erp) {
public int addERP(ERP erp) throws Exception {
DetailY detailY = new DetailY();
String type = erp.getType();
String JwCode = erp.getJwcode();
@ -115,15 +117,59 @@ public class OtherServiceImpl implements OtherService {
String productName = erp.getProductName();
String remark = erp.getReamrk();
String Way = otherMapper.selectWay(type);
//
// // 调用 POST 接口获取 username area
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_JSON);
// HttpEntity<String> entity = new HttpEntity<>(JwCode, headers);
// ResponseEntity<Map> response = restTemplate.exchange(
// "http://example.com/api/getUserDetails", HttpMethod.POST, entity, Map.class);
// String username = (String) response.getBody().get("username");
// String area = (String) response.getBody().get("area");
String country = null;
String name = null;
BaseDES des = new BaseDES();
String desjwcode= des.encrypt(JwCode);
System.out.println("desjwcode:"+desjwcode);
// 创建 JSON 请求体
Map<String, String> requestBody = new HashMap<>();
requestBody.put("jwcode", desjwcode);
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 创建 HttpEntity
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
// 发送 POST 请求
try {
ResponseEntity<Map> response = restTemplate.exchange(
"http://hwapi.rzfwq.com/hwjnApp/hwhc-login/hwhclogin/hc/login/clent/info",
HttpMethod.POST, entity, Map.class);
// 检查响应状态码
if (response.getStatusCode().is2xxSuccessful()) {
Map<String, Object> responseBody = response.getBody();
if (responseBody != null) {
// 获取data部分
Map<String, Object> data = (Map<String, Object>) responseBody.get("data");
if (data != null) {
// 提取name和country
name = (String) data.get("name");
country = (String) data.get("country");
// 打印获取到的数据
System.out.println("Name: " + name);
System.out.println("Country: " + country);
} else {
System.out.println("Data is null");
}
} else {
System.out.println("Response body is null");
}
} else {
System.out.println("Request failed with status code: " + response.getStatusCode());
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
if (typesToUpdateZero.contains(type)) {
detailY.setUpdateType(0);// 设置 updateType 0
@ -138,6 +184,9 @@ public class OtherServiceImpl implements OtherService {
detailY.setProductName(productName);
detailY.setConsumePlatform("ERP系统");
detailY.setRechargeWay(Way);
detailY.setArea(country);
detailY.setUsername(name);

2
src/main/java/com/example/demo/sevice/OtherService.java

@ -3,5 +3,5 @@ package com.example.demo.sevice;
import com.example.demo.domain.vo.ERP;
public interface OtherService {
int addERP(ERP erp);
int addERP(ERP erp) throws Exception;
}
Loading…
Cancel
Save