package com.ruoyi.integration.barrierGate.server;
|
|
import com.ruoyi.chargingPile.api.feignClient.ParkingLotClient;
|
import com.ruoyi.chargingPile.api.feignClient.ParkingRecordClient;
|
import com.ruoyi.chargingPile.api.model.TParkingLot;
|
import com.ruoyi.chargingPile.api.model.TParkingRecord;
|
import com.ruoyi.chargingPile.api.vo.GetParkingRecord;
|
import com.ruoyi.integration.barrierGate.model.GetCouponReq;
|
import com.ruoyi.integration.barrierGate.model.GetCouponResp;
|
import com.ruoyi.integration.barrierGate.model.Parameter;
|
import com.ruoyi.integration.barrierGate.model.UsedCoupon;
|
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
|
import com.ruoyi.order.api.model.TChargingOrder;
|
import com.ruoyi.order.api.vo.GetChargingOrderByLicensePlate;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2024/9/5 11:11
|
*/
|
@Service
|
public class CouponService {
|
|
@Resource
|
private ParkingLotClient parkingLotClient;
|
|
@Resource
|
private ParkingRecordClient parkingRecordClient;
|
|
@Resource
|
private ChargingOrderClient chargingOrderClient;
|
|
|
|
|
|
/**
|
* 获取优惠券
|
* @param req
|
* @return
|
*/
|
public GetCouponResp getCoupon(GetCouponReq req){
|
//根据车牌查询入场时间,后再根据入场时间和车牌查询是否有充电订单
|
String carNumber = req.getCarNumber();
|
String appKey = req.getAppkey();
|
TParkingLot parkingLot = parkingLotClient.getParkingLotByAppKey(appKey).getData();
|
if(null == parkingLot){
|
return null;
|
}
|
GetParkingRecord query = new GetParkingRecord();
|
query.setStatus(1);
|
query.setLicensePlate(carNumber);
|
TParkingRecord data = parkingRecordClient.getParkingRecord(query).getData();
|
if(null == data){
|
return null;
|
}
|
//入场时间
|
LocalDateTime inParkingTime = data.getInParkingTime();
|
//开始查询充电订单
|
GetChargingOrderByLicensePlate getChargingOrderByLicensePlate = new GetChargingOrderByLicensePlate();
|
getChargingOrderByLicensePlate.setLicensePlate(carNumber);
|
getChargingOrderByLicensePlate.setStartTime(inParkingTime);
|
TChargingOrder tChargingOrder = chargingOrderClient.getChargingOrderByLicensePlate(getChargingOrderByLicensePlate).getData();
|
|
GetCouponResp resp = new GetCouponResp();
|
resp.setRecordId(data.getId());
|
resp.setCarNumber(carNumber);
|
resp.setSysOrgId("MXCD0001");
|
resp.setPosName("明星电力");
|
resp.setLssuer("admin");
|
resp.setType(4);
|
Parameter parameter = new Parameter();
|
parameter.setFreeFlag(false);
|
if(null == tChargingOrder){
|
//按照非充电进行优惠计算
|
resp.setCouponName("普通停车时长优惠");
|
parameter.setTime(parkingLot.getNonChargeFreeDuration());
|
data.setFreeDuration(parkingLot.getNonChargeFreeDuration());
|
parkingRecordClient.updateParkingRecord(data);
|
}else{
|
resp.setCouponName("充电停车时长优惠");
|
parameter.setTime(parkingLot.getChargeFreeDuration());
|
}
|
resp.setParameter(parameter);
|
return resp;
|
}
|
|
|
/**
|
* 使用优惠券
|
* @param req
|
*/
|
public void usedCoupon(UsedCoupon req){
|
TParkingRecord data = parkingRecordClient.getParkingRecordById(Long.valueOf(req.getRecordId())).getData();
|
data.setSerialnumber(req.getSerialnumber());
|
data.setFreeAmount(new BigDecimal(req.getActualFee()));
|
data.setOrderAmount(new BigDecimal(req.getFee()));
|
BigDecimal subtract = data.getOrderAmount().subtract(data.getFreeAmount());
|
if(BigDecimal.ZERO.compareTo(subtract) < 0){
|
data.setTimeoutAmount(subtract);
|
data.setOutParkingType(1);
|
data.setStatus(3);
|
}else{
|
data.setTimeoutAmount(BigDecimal.ZERO);
|
data.setOutParkingType(2);
|
data.setStatus(2);
|
}
|
parkingRecordClient.updateParkingRecord(data);
|
}
|
}
|