Commit a9ce7ee1 authored by wanghao's avatar wanghao

2 液化石油气-配送记录 外部接口开发。

parent 57f14343
......@@ -12,7 +12,6 @@ import com.zehong.system.mapper.TEnterpriseInfoMapper;
import com.zehong.system.service.*;
import com.zehong.web.controller.tool.DESEncoder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -69,6 +68,12 @@ public class lpgGasController {
@Resource
private ITYehuaqiUserService tYehuaqiUserService;
/**
* 配送记录
*/
@Resource
private ITLpgDeliveryRecordService itLpgDeliveryRecordService;
@Resource
DecryptService decryptService;
......@@ -1768,9 +1773,279 @@ public class lpgGasController {
/**
* 封装一个 失败的接口对象
* 创建 配送记录接口
* @return r
*/
@PostMapping("/createLpgDeliveryRecord")
public AjaxResult createLpgDeliveryRecord(@RequestBody Encryption encryption) {
keyInformation selectkey = decryptService.selectkey(encryption.getQybm());
if (selectkey == null) {
return AjaxResult.error("企业编码不存在!!!");
}
DESEncoder desEncoder = new DESEncoder();
String data = encryption.getData();
String decrypt = desEncoder.decrypt(data, selectkey.getSecretKey());
TEnterpriseInfo tEnterpriseInfo = tEnterpriseInfoMapper.selectTEnterpriseInfoById(selectkey.getEnterpriseId());
if (tEnterpriseInfo == null) {
return AjaxResult.error("监管平台配置企业信息不存在!!!");
}
int successNum = 0;
int errorNum = 0;
if (StringUtils.isNotBlank(decrypt)) {
JSONArray jsonArray = JSON.parseArray(decrypt);
String js = JSONObject.toJSONString(jsonArray, SerializerFeature.WriteClassName);
List<JSONObject> list = JSONObject.parseArray(js, JSONObject.class);
if (list.size() > 500) {
return AjaxResult.error("每次最多处理500条数据");
}
List<TLpgDeliveryRecord> lpgDeliveryRecords = new ArrayList<>();
// 液化气表里面有的userOwnId
List<TLpgDeliveryRecord> yehuaqiLpgDeliveryRecords = new ArrayList<>();
// 液化气表里面有的userOwnId
List<TLpgDeliveryRecord> userOwnIdNotBlackLpgDeliveryRecords = new ArrayList<>();
TLpgDeliveryRecord lpgDeliveryRecord;
String dateFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
// 接口保存记录
List<TLpgThirdPartyDockingInterfaceRecord> lpgThirdPartyDockingInterfaceRecords = new ArrayList<>();
TLpgThirdPartyDockingInterfaceRecord lpgThirdPartyDockingInterfaceRecord;
for (JSONObject object : list) {
lpgDeliveryRecord = new TLpgDeliveryRecord();
JSONObject jsonObject = object;
// 气瓶条码不许为空
String bottleCode = jsonObject.getString("bottleCode");
if (StringUtils.isBlank(bottleCode)) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"气瓶条码不许为空!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
if (bottleCode.length() > 255) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"气瓶条码不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 用户自有编号 可以为空 为空时 就不关联 燃气用户了
String userOwnId = jsonObject.getString("userOwnId") == null ? "" : jsonObject.getString("userOwnId");
if (userOwnId.length() > 50) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"用户自有编号不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 储备站 可以为空
String stationName = jsonObject.getString("stationName") == null ? "" : jsonObject.getString("stationName");
if (stationName.length() > 64) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"储备站不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 配送人员 可以为空
String deliveryPerson = jsonObject.getString("deliveryPerson") == null ? "" : jsonObject.getString("deliveryPerson");
if (deliveryPerson.length() > 20) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"储备站不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 车辆代码 可以为空
String vehicleCode = jsonObject.getString("vehicleCode") == null ? "" : jsonObject.getString("vehicleCode");
if (vehicleCode.length() > 50) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"车辆代码不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 用户类型 可以为空
String gasUserType = jsonObject.getString("gasUserType") == null ? "" : jsonObject.getString("gasUserType");
if (gasUserType.length() > 2) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"用户类型不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
if (gasUserType.length() > 0 && !"0".equals(gasUserType) && !"1".equals(gasUserType)) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"用户类型不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 配送地址 可以为空
String deliveryAddress = jsonObject.getString("deliveryAddress") == null ? "" : jsonObject.getString("deliveryAddress");
if (deliveryAddress.length() > 50) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"配送地址不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
// 配送时间 可以为空
String deliveryDate = jsonObject.getString("deliveryDate") == null ? "" : jsonObject.getString("deliveryDate");
if (deliveryDate.length() > 0 && !isValidDate(sdf, deliveryDate)) {
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", jsonObject.toJSONString(),
"配送时间不符合要求!!!", encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
continue;
}
lpgDeliveryRecord.setBottleCode(bottleCode);
lpgDeliveryRecord.setUserOwnId(userOwnId);
lpgDeliveryRecord.setStationName(stationName);
lpgDeliveryRecord.setDeliveryPerson(deliveryPerson);
lpgDeliveryRecord.setVehicleCode(vehicleCode);
lpgDeliveryRecord.setGasUserType(gasUserType);
lpgDeliveryRecord.setDeliveryAddress(deliveryAddress);
lpgDeliveryRecord.setDeliveryDate(DateUtils.parseDate(deliveryDate));
lpgDeliveryRecords.add(lpgDeliveryRecord);
}
if (lpgDeliveryRecords.size() > 0) {
// 1 先过滤下 气瓶条码 符不符合 监管平台
List<String> collect = lpgDeliveryRecords.stream().map(TLpgDeliveryRecord::getBottleCode).collect(Collectors.toList());
List<TLpgGasBottleFiles> lpgGasBottleFiles = tLpgGasBottleFilesService.queryAllByQrcodeAndEnterpriseList(collect, tEnterpriseInfo.getEnterpriseId());
Map<String, List<TLpgGasBottleFiles>> collect1 = lpgGasBottleFiles.stream().collect(Collectors.groupingBy(TLpgGasBottleFiles::getQrcode));
for (TLpgDeliveryRecord deliveryRecord : lpgDeliveryRecords) {
List<TLpgGasBottleFiles> lpgGasBottleFiles1 = collect1.get(deliveryRecord.getBottleCode());
if (lpgGasBottleFiles1 != null && lpgGasBottleFiles1.size() > 0) {
yehuaqiLpgDeliveryRecords.add(deliveryRecord);
} else {
String sb = "气瓶条码为:" + deliveryRecord.getBottleCode() + "的信息在监管平台不存在";
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", deliveryRecord.toString(),
sb, encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
}
}
// 2 过滤完 气瓶条码后 判断 userOwnId 如果不为空,看看 监管平台有没有。
if(yehuaqiLpgDeliveryRecords.size() > 0) {
List<TLpgDeliveryRecord> userOwnIdNotBlankList = yehuaqiLpgDeliveryRecords.stream().filter(item -> StringUtils.isNotBlank(item.getUserOwnId())).collect(Collectors.toList());
List<TLpgDeliveryRecord> userOwnIdBlankList = yehuaqiLpgDeliveryRecords.stream().filter(item -> StringUtils.isBlank(item.getUserOwnId())).collect(Collectors.toList());
// userOwnId 不为空的
if (userOwnIdNotBlankList.size() > 0) {
List<String> collect3 = userOwnIdNotBlankList.stream().map(TLpgDeliveryRecord::getUserOwnId).collect(Collectors.toList());
List<TYehuaqiUser> yehuaqiUsers = tYehuaqiUserService.queryByUserOwnIdsAndEnterpriseId(collect3, tEnterpriseInfo.getEnterpriseId());
if (yehuaqiUsers.size() > 0) {
Map<String, List<TYehuaqiUser>> collect2 = yehuaqiUsers.stream().collect(Collectors.groupingBy(TYehuaqiUser::getUserOwnId));
for (TLpgDeliveryRecord tLpgDeliveryRecord : userOwnIdNotBlankList) {
List<TYehuaqiUser> yehuaqiUsers1 = collect2.get(tLpgDeliveryRecord.getUserOwnId());
if (yehuaqiUsers1 != null && yehuaqiUsers1.size() > 0) {
userOwnIdNotBlackLpgDeliveryRecords.add(tLpgDeliveryRecord);
lpgThirdPartyDockingInterfaceRecord = successRecord("createLpgDeliveryRecord", tLpgDeliveryRecord.toString(), encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
successNum++;
}else {
String sb = "userOwnId为:" + tLpgDeliveryRecord.getUserOwnId() + "的信息在监管平台不存在";
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", tLpgDeliveryRecord.toString(),
sb, encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
}
}
// 说明 监管平台没有这些 userOwnIds 则 都是错误数据
} else {
for (TLpgDeliveryRecord tLpgDeliveryRecord : userOwnIdNotBlankList) {
String sb = "userOwnId为:" + tLpgDeliveryRecord.getUserOwnId() + "的信息在监管平台不存在";
lpgThirdPartyDockingInterfaceRecord = errorRecord("createLpgDeliveryRecord", tLpgDeliveryRecord.toString(),
sb, encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
errorNum++;
}
}
}
// userOwnId 都为空,都为空的话,直接插入,就不关联 燃气用户数据了。
if (userOwnIdBlankList.size() > 0){
itLpgDeliveryRecordService.insertBatch(userOwnIdBlankList);
for (TLpgDeliveryRecord yehuaqiLpgDeliveryRecord : userOwnIdBlankList) {
lpgThirdPartyDockingInterfaceRecord = successRecord("createLpgDeliveryRecord", yehuaqiLpgDeliveryRecord.toString(), encryption.getQybm());
lpgThirdPartyDockingInterfaceRecords.add(lpgThirdPartyDockingInterfaceRecord);
successNum++;
}
}
}
}
// 这些是 判断了 气瓶 并且 也 判断了 userownid的正确数据
if (userOwnIdNotBlackLpgDeliveryRecords.size() > 0) {
itLpgDeliveryRecordService.insertBatch(userOwnIdNotBlackLpgDeliveryRecords);
}
// 接口记录直接插入
if (lpgThirdPartyDockingInterfaceRecords.size() > 0) {
lpgThirdPartyDockingInterfaceRecordService.insertBatch(lpgThirdPartyDockingInterfaceRecords);
}
}
StringBuilder sb = new StringBuilder();
if (errorNum > 0) {
sb.append("成功:").append(successNum).append("条;失败:").append(errorNum).append("条");
return AjaxResult.success(sb.toString());
}
sb.append("成功:").append(successNum).append("条");
return AjaxResult.success(sb.toString());
}
/**
* 封装一个 失败的接口对象
* @return r
*/
private TLpgThirdPartyDockingInterfaceRecord errorRecord(String interfaceName,String receiveData,
String failureReason,String qybm){
......
......@@ -160,54 +160,24 @@ public class DESEncoder {
String lpggasdata = "[\n" +
" {\n" +
" \"bottleCode\": \"32323\",\n" +
" \"userOwnId\": \"1\",\n" +
" \"stationName\": \"储备站01-接口来的-01\",\n" +
" \"gasUser\": \"用户名01-接口来的-01\",\n" +
" \"telNum\": \"电话01-接口来的-01\",\n" +
" \"gasUserAddress\": \"用户地址01-接口来的-01\",\n" +
" \"gasUserType\": \"0\",\n" +
" \"safeCheckDate\": \"2024-12-16\",\n" +
" \"safeCheckPerson\": \"安检人-接口来的-01\",\n" +
" \"bottleNum\": \"15\",\n" +
" \"checkInStatus\": \"0\",\n" +
" \"stoveCheckStatus\": \"0\",\n" +
" \"hoseCheckStatus\": \"0\",\n" +
" \"valveCheckStatus\": \"0\",\n" +
" \"bottleCheckStatus\": \"0\",\n" +
" \"alarmCheckStatus\": \"0\",\n" +
" \"placeCheckStatus\": \"0\",\n" +
"\n" +
" \"stoveCheckPic\": \"0\",\n" +
" \"hoseCheckPic\": \"0\",\n" +
" \"valveCheckPic\": \"0\",\n" +
" \"bottleCheckPic\": \"0\",\n" +
" \"alarmCheckPic\": \"0\",\n" +
" \"placeCheckPic\": \"0\",\n" +
" \"stationName\": \"储备站-接口来的-01\",\n" +
" \"deliveryPerson\": \"配送人-接口来的-01\",\n" +
" \"vehicleCode\": \"车辆代码-接口来的-01\",\n" +
" \"gasUserType\": \"1\",\n" +
" \"deliveryAddress\": \"配送地址-接口来的-01\",\n" +
" \"deliveryDate\": \"2024-12-21 23:12:20\"\n" +
" },\n" +
" {\n" +
" \"userOwnId\": \"2\",\n" +
" \"stationName\": \"储备站01-接口来的-01\",\n" +
" \"gasUser\": \"用户名01-接口来的-01\",\n" +
" \"telNum\": \"电话01-接口来的-01\",\n" +
" \"gasUserAddress\": \"用户地址01-接口来的-01\",\n" +
" \"gasUserType\": \"用户类型-接口来的-01\",\n" +
" \"safeCheckDate\": \"2024-12-16\",\n" +
" \"safeCheckPerson\": \"安检人-接口来的-01\",\n" +
" \"bottleNum\": \"设定净重-接口来的-01\",\n" +
" \"checkInStatus\": \"入户状态01-接口来的-01\",\n" +
" \"stoveCheckStatus\": \"0\",\n" +
" \"hoseCheckStatus\": \"0\",\n" +
" \"valveCheckStatus\": \"0\",\n" +
" \"bottleCheckStatus\": \"0\",\n" +
" \"alarmCheckStatus\": \"0\",\n" +
" \"placeCheckStatus\": \"0\",\n" +
"\n" +
" \"stoveCheckPic\": \"0\",\n" +
" \"hoseCheckPic\": \"0\",\n" +
" \"valveCheckPic\": \"0\",\n" +
" \"bottleCheckPic\": \"0\",\n" +
" \"alarmCheckPic\": \"0\",\n" +
" \"placeCheckPic\": \"0\",\n" +
" \"bottleCode\": \"222222\",\n" +
" \"userOwnId\": \"89\",\n" +
" \"stationName\": \"储备站-接口来的-01\",\n" +
" \"deliveryPerson\": \"配送人-接口来的-01\",\n" +
" \"vehicleCode\": \"车辆代码-接口来的-01\",\n" +
" \"gasUserType\": \"0\",\n" +
" \"deliveryAddress\": \"配送地址-接口来的-01\",\n" +
" \"deliveryDate\": \"2024-12-21 23:12:21\"\n" +
" }\n" +
"]\n" +
"\n";
......
......@@ -57,6 +57,11 @@ public class TLpgDeliveryRecord extends BaseEntity
private Long userId;
/**
* 用户自有编号 第三方对接时接收下数据先
*/
private String userOwnId;
public void setDeliveryRecordId(Long deliveryRecordId)
{
this.deliveryRecordId = deliveryRecordId;
......@@ -156,6 +161,13 @@ public class TLpgDeliveryRecord extends BaseEntity
this.userId = userId;
}
public String getUserOwnId() {
return userOwnId;
}
public void setUserOwnId(String userOwnId) {
this.userOwnId = userOwnId;
}
@Override
public String toString() {
......
......@@ -51,6 +51,14 @@ public interface ITLpgDeliveryRecordService
*/
public int insertTLpgDeliveryRecord(TLpgDeliveryRecord tLpgDeliveryRecord);
/**
* 批量插入
* @param tLpgDeliveryRecords t
* @return r
*/
public int insertBatch(List<TLpgDeliveryRecord> tLpgDeliveryRecords);
/**
* 修改液化石油配送记录
*
......
......@@ -157,6 +157,11 @@ public class TLpgDeliveryRecordServiceImpl implements ITLpgDeliveryRecordService
return tLpgDeliveryRecordMapper.insertTLpgDeliveryRecord(tLpgDeliveryRecord);
}
@Override
public int insertBatch(List<TLpgDeliveryRecord> tLpgDeliveryRecords) {
return tLpgDeliveryRecordMapper.insertBatch(tLpgDeliveryRecords);
}
/**
* 修改液化石油配送记录
*
......
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