package com.ruoyi.chargingPile.tulaidian.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSON;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.ruoyi.chargingPile.api.model.TChargingGun;
|
import com.ruoyi.chargingPile.service.ISiteService;
|
import com.ruoyi.chargingPile.service.TChargingGunService;
|
import com.ruoyi.chargingPile.service.TChargingPileService;
|
import com.ruoyi.chargingPile.tulaidian.domain.ChargeDetail;
|
import com.ruoyi.chargingPile.tulaidian.domain.ChargeRecord;
|
import com.ruoyi.chargingPile.tulaidian.domain.ConnectorStatusInfos;
|
import com.ruoyi.chargingPile.tulaidian.domain.TContent;
|
import com.ruoyi.chargingPile.tulaidian.service.IContentService;
|
import com.ruoyi.chargingPile.tulaidian.util.AesEncryption;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.utils.DateUtils;
|
import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient;
|
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
|
import com.ruoyi.order.api.model.TChargingOrder;
|
import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy;
|
import io.swagger.annotations.Api;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.math.BigDecimal;
|
import java.text.ParseException;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
|
/**
|
* 广告控制器
|
*/
|
@Api
|
@RestController
|
@RequestMapping("/orderCallBack")
|
public class NotifyController {
|
@Autowired
|
private ChargingOrderClient chargingOrderClient;
|
// @Autowired
|
// private IContentService contentService;
|
@Autowired
|
private ChargingOrderAccountingStrategyClient chargingOrderAccountingStrategyClient;
|
@Autowired
|
private IContentService contentService;
|
@Autowired
|
private TChargingGunService chargingGunService;
|
@Autowired
|
private TChargingPileService chargingPileService;
|
@Autowired
|
private ISiteService siteService;
|
private static final String OperatorID = "MA01H3BQ3";
|
private static final String OperatorSecret = "f1331ef0b37c2d2";
|
private static final String SigSecret = "a6fedf0e1b27d6f8";
|
private static final String DataSecret = "50a61b93919c9606";
|
private static final String DataSecretIV = "7c8ac6861661d586";
|
|
private static final String OperatorSecretOther = "f1331ef0b37c2d2";
|
private static final String SigSecretOther = "a6fedf0e1b27d6f8";
|
private static final String DataSecretOther = "50a61b93919c9606";
|
private static final String DataSecretIVOther = "7c8ac6861661d586";
|
|
// 结束充电后 特来电主动 推送充电订单信息
|
@ResponseBody
|
@PostMapping("/notification_charge_order_info")
|
public Map<String, Object> notification_charge_order_info(@RequestBody String json) throws ParseException {
|
TContent tContent = new TContent();
|
tContent.setType(1);
|
tContent.setContent(json);
|
tContent.setCreateTime(new Date());
|
contentService.save(tContent);
|
JSONObject jsonObject1 = JSONObject.parseObject(json);
|
String data = jsonObject1.getString("Data");
|
String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, data);
|
System.err.println(decrypt);
|
JSONObject jsonObject = JSONObject.parseObject(decrypt);
|
System.err.println("结束充电后 特来电主动推送订单信息");
|
ChargeRecord chargeRecord = JSON.parseObject(jsonObject.toJSONString(), ChargeRecord.class);
|
// 新增订单
|
TChargingOrder chargingOrder = new TChargingOrder();
|
chargingOrder.setCode(chargeRecord.getStartChargeSeq());
|
chargingOrder.setOrderSource(2);
|
// TODO 运营商id
|
chargingOrder.setOperatorId(1);
|
chargingOrder.setTripartitePlatformName("途来电");
|
chargingOrder.setStartChargeSeq(chargeRecord.getStartChargeSeq());
|
chargingOrder.setSourceName("途来电");
|
chargingOrder.setStartTime(DateUtils.stringToLocalDateTime(chargeRecord.getStartTime()));
|
chargingOrder.setEndTime(DateUtils.stringToLocalDateTime(chargeRecord.getEndTime()));
|
chargingOrder.setStatus(5);
|
chargingOrder.setEndMode(1);
|
chargingOrder.setElectrovalence(chargeRecord.getTotalElecMoney());
|
chargingOrder.setServiceCharge(chargeRecord.getTotalSeviceMoney());
|
chargingOrder.setTotalElectricity(chargeRecord.getTotalPower());
|
chargingOrder.setPaymentAmount(chargeRecord.getTotalMoney());
|
chargingOrder.setRechargePaymentType(1);
|
chargingOrder.setRechargePaymentStatus(2);
|
chargingOrder.setChargeAmount(chargeRecord.getTotalMoney());
|
chargingOrder.setOrderAmount(chargeRecord.getTotalMoney());
|
chargingOrder.setResidualAmount(BigDecimal.ZERO);
|
chargingOrder.setPaymentAmount(chargeRecord.getTotalMoney());
|
chargingOrder.setPayTime(LocalDateTime.now());
|
// 通过枪编号查询枪
|
TChargingGun chargingGun = chargingGunService.getOne(Wrappers.lambdaQuery(TChargingGun.class)
|
.eq(TChargingGun::getCode, chargeRecord.getConnectorID()));
|
if(Objects.nonNull(chargingGun)){
|
chargingOrder.setChargingGunId(chargingGun.getId());
|
chargingOrder.setChargingPileId(chargingGun.getChargingPileId());
|
chargingOrder.setSiteId(chargingGun.getSiteId());
|
}
|
R<Long> orderIdR = chargingOrderClient.addChargingOrder(chargingOrder);
|
if(orderIdR.getCode() == 200){
|
// 充电明细
|
List<ChargeDetail> chargeDetails = chargeRecord.getChargeDetails();
|
if(!CollectionUtils.isEmpty(chargeDetails)){
|
List<TChargingOrderAccountingStrategy> accountingStrategyList = new ArrayList<>();
|
for (ChargeDetail chargeDetail : chargeDetails) {
|
TChargingOrderAccountingStrategy accountingStrategy = new TChargingOrderAccountingStrategy();
|
accountingStrategy.setChargingOrderId(orderIdR.getData());
|
accountingStrategy.setAccountingStrategyDetailId(232);
|
accountingStrategy.setType(1);
|
accountingStrategy.setStartTime(chargeDetail.getDetailStartTime());
|
accountingStrategy.setEndTime(chargeDetail.getDetailEndTime());
|
accountingStrategy.setElectrovalence(chargeDetail.getElecPrice());
|
accountingStrategy.setServiceCharge(chargeDetail.getSevicePrice());
|
accountingStrategy.setChargingCapacity(chargeDetail.getDetailPower());
|
accountingStrategy.setPeriodElectricPrice(chargeDetail.getDetailElecMoney());
|
accountingStrategy.setPeriodServicePrice(chargeDetail.getDetailSeviceMoney());
|
accountingStrategy.setPeriodOriginalServicePrice(chargeDetail.getDetailSeviceMoney());
|
accountingStrategy.setCreateTime(LocalDateTime.now());
|
accountingStrategyList.add(accountingStrategy);
|
}
|
chargingOrderAccountingStrategyClient.addChargingOrderAccountingStrategy(accountingStrategyList);
|
}
|
}
|
Map<String,Object> map = new HashMap<>();
|
map.put("StartChargeSeq",chargeRecord.getStartChargeSeq());
|
map.put("ConnectorID",chargeRecord.getConnectorID());
|
map.put("ConfirmResult",0);
|
return map;
|
}
|
|
// @ResponseBody
|
// @PostMapping("/notification_equip_charge_status")
|
// public R notification_equip_charge_status(@RequestBody String json) throws ParseException {
|
// TContent tContent = new TContent();
|
// tContent.setType(2);
|
// tContent.setContent(json);
|
// tContent.setCreateTime(new Date());
|
// contentService.save(tContent);
|
// JSONObject jsonObject1 = JSONObject.parseObject(json);
|
// String data = jsonObject1.getString("Data");
|
// String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, data);
|
// System.err.println(decrypt);
|
// JSONObject jsonObject = JSONObject.parseObject(decrypt);
|
// System.err.println("特来电主动推送订单状态");
|
// ChargeStatus chargeStatus = JSON.parseObject(jsonObject.toJSONString(), ChargeStatus.class);
|
// R<TChargingOrder> chargeOrderR = chargingOrderClient.getChargingOrderByStartChargeSeq(chargeStatus.getStartChargeSeq());
|
// TChargingOrder chargingOrder = chargeOrderR.getData();
|
// if (chargingOrder!=null){
|
// // 修改订单状态
|
// chargingOrder.setStatus(chargeStatus.getStartChargeSeqStat());
|
// chargingOrderClient.updateChargingOrder(chargingOrder);
|
// }
|
// return R.ok();
|
// }
|
|
@ResponseBody
|
@PostMapping("/notification_stationStatus")
|
public Map<String,Integer> notification_stationStatus(@RequestBody String json) {
|
TContent tContent = new TContent();
|
tContent.setType(3);
|
tContent.setContent(json);
|
tContent.setCreateTime(new Date());
|
contentService.save(tContent);
|
JSONObject jsonObject1 = JSONObject.parseObject(json);
|
String data = jsonObject1.getString("Data");
|
String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, data);
|
System.err.println(decrypt);
|
JSONObject jsonObject = JSONObject.parseObject(decrypt);
|
System.err.println("特来电主动推送设备状态");
|
ConnectorStatusInfos connectorStatusInfos = JSON.parseObject(jsonObject.toJSONString(), ConnectorStatusInfos.class);
|
TChargingGun chargingGun = chargingGunService.getOne(Wrappers.lambdaQuery(TChargingGun.class)
|
.eq(TChargingGun::getCode, connectorStatusInfos.getConnectorID()));
|
if (Objects.nonNull(chargingGun)){
|
// 修改订单状态
|
switch (connectorStatusInfos.getStatus()){
|
case 0:
|
chargingGun.setStatus(1);
|
break;
|
case 1:
|
chargingGun.setStatus(2);
|
break;
|
case 2:
|
chargingGun.setStatus(3);
|
break;
|
case 3:
|
chargingGun.setStatus(4);
|
break;
|
case 4:
|
chargingGun.setStatus(6);
|
break;
|
case 255:
|
chargingGun.setStatus(7);
|
break;
|
}
|
chargingGunService.updateById(chargingGun);
|
}
|
Map<String,Integer> map = new HashMap<>();
|
map.put("Status",0);
|
return map;
|
}
|
}
|