修改机构折扣

This commit is contained in:
yuyang 2022-03-25 09:39:19 +08:00
parent 73c8f1816e
commit 88c7918752
9 changed files with 58 additions and 56 deletions

View File

@ -43,7 +43,7 @@ public interface PileOrderService {
* @param orderNo 订单号
* @return
*/
@PostMapping("/chargeOrder/pileEndOrder")
@GetMapping("/chargeOrder/pileEndOrder")
R pileEndOrder(@RequestParam(value = "orderNo") String orderNo);

View File

@ -48,7 +48,7 @@ public interface UserTypeService {
* 获取该机构的折扣比例
*/
@GetMapping("/common/getMechanismDiscount")
R getMechanismDiscount(@RequestParam(value = "userId")Long userId, @RequestParam(value = "userType")Integer userType, @RequestParam(value = "tenantId")String tenantId, @Param("chargingStationId")Long chargingStationId);
R getMechanismDiscount(@RequestParam(value = "userId")Long userId, @RequestParam(value = "userType")Integer userType, @RequestParam(value = "tenantId")String tenantId,@RequestParam(value = "chargingStationId")Long chargingStationId);
}

View File

@ -2,7 +2,6 @@ package com.xhpc.common.api.factory;
import com.xhpc.common.api.UserTypeService;
import com.xhpc.common.core.domain.R;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
@ -33,7 +32,7 @@ public class UserTypeFallbackFactory implements FallbackFactory<UserTypeService>
}
@Override
public R getMechanismDiscount(Long userId, Integer userType, String tenantId, @Param("chargingStationId")Long chargingStationId) {
public R getMechanismDiscount(Long userId, Integer userType, String tenantId,Long chargingStationId) {
return R.fail("机构信息获取失败:" + cause.getMessage());
}
};

View File

@ -5,7 +5,6 @@ import com.xhpc.databigscreen.domain.CoreParam;
import com.xhpc.databigscreen.domain.OrderRatio;
import com.xhpc.databigscreen.domain.OrderTrend;
import com.xhpc.databigscreen.domain.RealtimeOrders;
import org.graalvm.compiler.hotspot.replacements.ObjectCloneNode;
import java.util.List;
import java.util.Map;

View File

@ -21,10 +21,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.Date;
@ -247,7 +244,7 @@ public class XhpcPileOrderController extends BaseController {
* 桩订单结束回调
*/
@Transactional
@PostMapping("/chargeOrder/pileEndOrder")
@GetMapping(value = "/chargeOrder/pileEndOrder")
public R pileEndOrder(@RequestParam(value = "orderNo") String orderNo) {
logger.info("桩订单结束回调>>>>>orderNo"+orderNo);
try{

View File

@ -447,49 +447,52 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
if ( !UserTypeUtil.INTERNET_TYPE.equals(source)) {
if(UserTypeUtil.COMMUNIT_TYPE.equals(source) || UserTypeUtil.CUSTOMERS_TYPE.equals(source)){
//折扣机构用户没有活动时计算
R mechanismDiscount = userTypeService.getMechanismDiscount(userId, source, xhpcChargeOrder.getTenantId(),xhpcChargeOrder.getChargingStationId());
if(mechanismDiscount !=null && mechanismDiscount.getData() !=null) {
Map<String, Object> userDiscount = (Map<String, Object>) mechanismDiscount.getData();
if (userDiscount != null && userDiscount.get("commissionType") != null && userDiscount.get("servicePreferential") != null) {
String commissionType = userDiscount.get("commissionType").toString();
BigDecimal servicePreferential =new BigDecimal(userDiscount.get("servicePreferential").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
if(xhpcChargeOrder.getChargingStationId()!=null){
R mechanismDiscount = userTypeService.getMechanismDiscount(userId, source, xhpcChargeOrder.getTenantId(),xhpcChargeOrder.getChargingStationId());
if(servicePreferential.compareTo(new BigDecimal(0))==1){
if("0".equals(commissionType) || "1".equals(commissionType) || "2".equals(commissionType)){
BigDecimal decimal1 = surplusPowerPrice.multiply(servicePreferential).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal decimal2 = surplusServicePrice.multiply(servicePreferential).setScale(2, BigDecimal.ROUND_HALF_UP);
if("0".equals(commissionType)){
//总金额
actPrice =actPrice.subtract(decimal1.add(decimal2));
//折扣的钱
promotionDiscount = decimal1.add(decimal2);
surplusPowerPrice = surplusPowerPrice.subtract(decimal1);
surplusServicePrice= surplusServicePrice.subtract(decimal2);
}else if("1".equals(commissionType)){
//服务费
if(surplusServicePrice.compareTo(decimal2) > -1){
surplusServicePrice =surplusServicePrice.subtract(decimal2);
actPrice =actPrice.subtract(decimal2);
if(mechanismDiscount !=null && mechanismDiscount.getData() !=null) {
Map<String, Object> userDiscount = (Map<String, Object>) mechanismDiscount.getData();
if (userDiscount != null && userDiscount.get("commissionType") != null && userDiscount.get("servicePreferential") != null) {
String commissionType = userDiscount.get("commissionType").toString();
BigDecimal servicePreferential =new BigDecimal(userDiscount.get("servicePreferential").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
if(servicePreferential.compareTo(new BigDecimal(0))==1){
if("0".equals(commissionType) || "1".equals(commissionType) || "2".equals(commissionType)){
BigDecimal decimal1 = surplusPowerPrice.multiply(servicePreferential).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal decimal2 = surplusServicePrice.multiply(servicePreferential).setScale(2, BigDecimal.ROUND_HALF_UP);
if("0".equals(commissionType)){
//总金额
actPrice =actPrice.subtract(decimal1.add(decimal2));
//折扣的钱
promotionDiscount = decimal1.add(decimal2);
surplusPowerPrice = surplusPowerPrice.subtract(decimal1);
surplusServicePrice= surplusServicePrice.subtract(decimal2);
}else if("1".equals(commissionType)){
//服务费
if(surplusServicePrice.compareTo(decimal2) > -1){
surplusServicePrice =surplusServicePrice.subtract(decimal2);
actPrice =actPrice.subtract(decimal2);
}else{
promotionDiscount = surplusServicePrice;
actPrice =actPrice.subtract(surplusServicePrice);
surplusServicePrice =new BigDecimal(0);
}
}else{
promotionDiscount = surplusServicePrice;
actPrice =actPrice.subtract(surplusServicePrice);
surplusServicePrice =new BigDecimal(0);
}
}else{
//电量抽成
BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree();
//电量的钱
promotionDiscount = chargingDegree.multiply(new BigDecimal(userDiscount.get("servicePreferential").toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
logger.info("=============电量优惠==="+promotionDiscount);
logger.info("=============服务费==="+surplusServicePrice);
//当电量的折扣大于服务费时电量==服务费
if(surplusServicePrice.compareTo(promotionDiscount)>-1){
surplusServicePrice= surplusServicePrice.subtract(promotionDiscount);
actPrice =actPrice.subtract(promotionDiscount);
}else{
promotionDiscount = surplusServicePrice;
actPrice =actPrice.subtract(surplusServicePrice);
surplusServicePrice =new BigDecimal(0);
//电量抽成
BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree();
//电量的钱
promotionDiscount = chargingDegree.multiply(new BigDecimal(userDiscount.get("servicePreferential").toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
logger.info("=============电量优惠==="+promotionDiscount);
logger.info("=============服务费==="+surplusServicePrice);
//当电量的折扣大于服务费时电量==服务费
if(surplusServicePrice.compareTo(promotionDiscount)>-1){
surplusServicePrice= surplusServicePrice.subtract(promotionDiscount);
actPrice =actPrice.subtract(promotionDiscount);
}else{
promotionDiscount = surplusServicePrice;
actPrice =actPrice.subtract(surplusServicePrice);
surplusServicePrice =new BigDecimal(0);
}
}
}
}

View File

@ -462,6 +462,8 @@
from xhpc_community co
join xhpc_mechanism me on me.mechanism_id = co.community_id and me.source = 0 and me.del_flag =0
where co.community_id = (select community_id from xhpc_community_personnel where community_personnel_id=#{userId} and tenant_id=#{tenantId} and del_flag =0)
and me.charging_station_id=#{chargingStationId}
<if test="chargingStationId !=null">
and me.charging_station_id=#{chargingStationId}
</if>
</select>
</mapper>

View File

@ -459,6 +459,8 @@
from xhpc_customers co
join xhpc_mechanism me on me.mechanism_id = co.customers_id and me.source = 1 and me.del_flag =0
where co.customers_id = (select customers_id from xhpc_customers_personnel where customers_personnel_id=#{userId} and tenant_id=#{tenantId} and del_flag =0)
and me.charging_station_id=#{chargingStationId}
<if test="chargingStationId !=null">
and me.charging_station_id=#{chargingStationId}
</if>
</select>
</mapper>

View File

@ -355,13 +355,13 @@
order by totalPrice desc) us on xaus.app_user_id = us.appUserId
where xaus.del_flag = 0
<if test="activity !=null">
and activity &gt;= #{activity}
and us.activity &gt;= #{activity}
</if>
<if test="frequency !=null">
and frequency &gt;= #{frequency}
and us.number &gt;= #{frequency}
</if>
<if test="amount !=null">
and amount &gt;= #{amount}
and us.amount &gt;= #{amount}
</if>
<if test="tenantId !=null and tenantId !=''">
and xaus.tenant_id =#{tenantId}