浏览代码

optimize charge coupon

java110 3 年之前
父节点
当前提交
af551e9df1

+ 97 - 0
java110-bean/src/main/java/com/java110/dto/chargeMachineOrderCoupon/ChargeMachineOrderCouponDto.java

@@ -0,0 +1,97 @@
+package com.java110.dto.chargeMachineOrderCoupon;
+
+import com.java110.dto.PageDto;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @ClassName FloorDto
+ * @Description 充电优惠券数据层封装
+ * @Author wuxw
+ * @Date 2019/4/24 8:52
+ * @Version 1.0
+ * add by wuxw 2019/4/24
+ **/
+public class ChargeMachineOrderCouponDto extends PageDto implements Serializable {
+
+    private String couponName;
+private String hours;
+private String orderId;
+private String cmocId;
+private String remark;
+private String state;
+private String couponId;
+private String communityId;
+
+
+    private Date createTime;
+
+    private String statusCd = "0";
+
+
+    public String getCouponName() {
+        return couponName;
+    }
+public void setCouponName(String couponName) {
+        this.couponName = couponName;
+    }
+public String getHours() {
+        return hours;
+    }
+public void setHours(String hours) {
+        this.hours = hours;
+    }
+public String getOrderId() {
+        return orderId;
+    }
+public void setOrderId(String orderId) {
+        this.orderId = orderId;
+    }
+public String getCmocId() {
+        return cmocId;
+    }
+public void setCmocId(String cmocId) {
+        this.cmocId = cmocId;
+    }
+public String getRemark() {
+        return remark;
+    }
+public void setRemark(String remark) {
+        this.remark = remark;
+    }
+public String getState() {
+        return state;
+    }
+public void setState(String state) {
+        this.state = state;
+    }
+public String getCouponId() {
+        return couponId;
+    }
+public void setCouponId(String couponId) {
+        this.couponId = couponId;
+    }
+public String getCommunityId() {
+        return communityId;
+    }
+public void setCommunityId(String communityId) {
+        this.communityId = communityId;
+    }
+
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getStatusCd() {
+        return statusCd;
+    }
+
+    public void setStatusCd(String statusCd) {
+        this.statusCd = statusCd;
+    }
+}

+ 114 - 0
java110-bean/src/main/java/com/java110/po/chargeMachineOrderCoupon/ChargeMachineOrderCouponPo.java

@@ -0,0 +1,114 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.po.chargeMachineOrderCoupon;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 类表述: Po 数据模型实体对象 基本保持与数据库模型一直 用于 增加修改删除 等时的数据载体
+ * add by 吴学文 at 2023-04-04 10:28:21 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+public class ChargeMachineOrderCouponPo implements Serializable {
+
+    private String couponName;
+    private String hours;
+    private String orderId;
+    private String cmocId;
+    private String remark;
+    private String statusCd = "0";
+    private String state;
+    private String couponId;
+    private String communityId;
+
+    public String getCouponName() {
+        return couponName;
+    }
+
+    public void setCouponName(String couponName) {
+        this.couponName = couponName;
+    }
+
+    public String getHours() {
+        return hours;
+    }
+
+    public void setHours(String hours) {
+        this.hours = hours;
+    }
+
+    public String getOrderId() {
+        return orderId;
+    }
+
+    public void setOrderId(String orderId) {
+        this.orderId = orderId;
+    }
+
+    public String getCmocId() {
+        return cmocId;
+    }
+
+    public void setCmocId(String cmocId) {
+        this.cmocId = cmocId;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getStatusCd() {
+        return statusCd;
+    }
+
+    public void setStatusCd(String statusCd) {
+        this.statusCd = statusCd;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getCouponId() {
+        return couponId;
+    }
+
+    public void setCouponId(String couponId) {
+        this.couponId = couponId;
+    }
+
+    public String getCommunityId() {
+        return communityId;
+    }
+
+    public void setCommunityId(String communityId) {
+        this.communityId = communityId;
+    }
+
+
+}

+ 131 - 0
java110-db/src/main/resources/mapper/common/ChargeMachineOrderCouponV1ServiceDaoImplMapper.xml

@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="chargeMachineOrderCouponV1ServiceDaoImpl">
+
+
+    <!-- 保存充电优惠券信息 add by wuxw 2018-07-03 -->
+    <insert id="saveChargeMachineOrderCouponInfo" parameterType="Map">
+        insert into charge_machine_order_coupon(
+        coupon_name,hours,order_id,cmoc_id,remark,state,coupon_id,community_id
+        ) values (
+        #{couponName},#{hours},#{orderId},#{cmocId},#{remark},#{state},#{couponId},#{communityId}
+        )
+    </insert>
+
+
+    <!-- 查询充电优惠券信息 add by wuxw 2018-07-03 -->
+    <select id="getChargeMachineOrderCouponInfo" parameterType="Map" resultType="Map">
+        select t.coupon_name,t.coupon_name couponName,t.hours,t.order_id,t.order_id orderId,t.cmoc_id,t.cmoc_id
+        cmocId,t.remark,t.status_cd,t.status_cd statusCd,t.state,t.coupon_id,t.coupon_id
+        couponId,t.community_id,t.community_id communityId
+        from charge_machine_order_coupon t
+        where 1 =1
+        <if test="couponName !=null and couponName != ''">
+            and t.coupon_name= #{couponName}
+        </if>
+        <if test="hours !=null and hours != ''">
+            and t.hours= #{hours}
+        </if>
+        <if test="orderId !=null and orderId != ''">
+            and t.order_id= #{orderId}
+        </if>
+        <if test="cmocId !=null and cmocId != ''">
+            and t.cmoc_id= #{cmocId}
+        </if>
+        <if test="remark !=null and remark != ''">
+            and t.remark= #{remark}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="couponId !=null and couponId != ''">
+            and t.coupon_id= #{couponId}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
+
+    </select>
+
+
+    <!-- 修改充电优惠券信息 add by wuxw 2018-07-03 -->
+    <update id="updateChargeMachineOrderCouponInfo" parameterType="Map">
+        update charge_machine_order_coupon t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="couponName !=null and couponName != ''">
+            , t.coupon_name= #{couponName}
+        </if>
+        <if test="hours !=null and hours != ''">
+            , t.hours= #{hours}
+        </if>
+
+        <if test="remark !=null and remark != ''">
+            , t.remark= #{remark}
+        </if>
+        <if test="state !=null and state != ''">
+            , t.state= #{state}
+        </if>
+        <if test="couponId !=null and couponId != ''">
+            , t.coupon_id= #{couponId}
+        </if>
+        where 1=1
+        <if test="cmocId !=null and cmocId != ''">
+            and t.cmoc_id= #{cmocId}
+        </if>
+        <if test="orderId !=null and orderId != ''">
+            and t.order_id= #{orderId}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+
+    </update>
+
+    <!-- 查询充电优惠券数量 add by wuxw 2018-07-03 -->
+    <select id="queryChargeMachineOrderCouponsCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from charge_machine_order_coupon t
+        where 1 =1
+        <if test="couponName !=null and couponName != ''">
+            and t.coupon_name= #{couponName}
+        </if>
+        <if test="hours !=null and hours != ''">
+            and t.hours= #{hours}
+        </if>
+        <if test="orderId !=null and orderId != ''">
+            and t.order_id= #{orderId}
+        </if>
+        <if test="cmocId !=null and cmocId != ''">
+            and t.cmoc_id= #{cmocId}
+        </if>
+        <if test="remark !=null and remark != ''">
+            and t.remark= #{remark}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="couponId !=null and couponId != ''">
+            and t.coupon_id= #{couponId}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+
+
+    </select>
+
+</mapper>

+ 68 - 0
java110-interface/src/main/java/com/java110/intf/common/IChargeMachineOrderCouponV1InnerServiceSMO.java

@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.intf.common;
+
+import com.java110.config.feign.FeignConfiguration;
+import com.java110.dto.chargeMachineOrderCoupon.ChargeMachineOrderCouponDto;
+import com.java110.po.chargeMachineOrderCoupon.ChargeMachineOrderCouponPo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import java.util.List;
+
+/**
+ * 类表述: 服务之前调用的接口类,不对外提供接口能力 只用于接口建调用
+ * add by 吴学文 at 2023-04-04 10:28:20 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+@FeignClient(name = "common-service", configuration = {FeignConfiguration.class})
+@RequestMapping("/chargeMachineOrderCouponV1Api")
+public interface IChargeMachineOrderCouponV1InnerServiceSMO {
+
+
+    @RequestMapping(value = "/saveChargeMachineOrderCoupon", method = RequestMethod.POST)
+    public int saveChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo);
+
+    @RequestMapping(value = "/updateChargeMachineOrderCoupon", method = RequestMethod.POST)
+    public int updateChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo);
+
+    @RequestMapping(value = "/deleteChargeMachineOrderCoupon", method = RequestMethod.POST)
+    public int deleteChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo);
+
+    /**
+     * <p>查询小区楼信息</p>
+     *
+     *
+     * @param chargeMachineOrderCouponDto 数据对象分享
+     * @return ChargeMachineOrderCouponDto 对象数据
+     */
+    @RequestMapping(value = "/queryChargeMachineOrderCoupons", method = RequestMethod.POST)
+    List<ChargeMachineOrderCouponDto> queryChargeMachineOrderCoupons(@RequestBody ChargeMachineOrderCouponDto chargeMachineOrderCouponDto);
+
+    /**
+     * 查询<p>小区楼</p>总记录数
+     *
+     * @param chargeMachineOrderCouponDto 数据对象分享
+     * @return 小区下的小区楼记录数
+     */
+    @RequestMapping(value = "/queryChargeMachineOrderCouponsCount", method = RequestMethod.POST)
+    int queryChargeMachineOrderCouponsCount(@RequestBody ChargeMachineOrderCouponDto chargeMachineOrderCouponDto);
+}

+ 69 - 11
service-common/src/main/java/com/java110/common/charge/ChargeCoreImpl.java

@@ -1,11 +1,13 @@
 package com.java110.common.charge;
 
+import com.alibaba.fastjson.JSONObject;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.dto.account.AccountDto;
 import com.java110.dto.chargeMachine.ChargeMachineDto;
 import com.java110.dto.chargeMachineFactory.ChargeMachineFactoryDto;
 import com.java110.dto.chargeMachineOrder.ChargeMachineOrderDto;
 import com.java110.dto.chargeMachineOrder.NotifyChargeOrderDto;
+import com.java110.dto.chargeMachineOrderCoupon.ChargeMachineOrderCouponDto;
 import com.java110.dto.chargeMachinePort.ChargeMachinePortDto;
 import com.java110.dto.chargeRuleFee.ChargeRuleFeeDto;
 import com.java110.intf.acct.IAccountInnerServiceSMO;
@@ -13,6 +15,7 @@ import com.java110.intf.common.*;
 import com.java110.po.accountDetail.AccountDetailPo;
 import com.java110.po.chargeMachineOrder.ChargeMachineOrderPo;
 import com.java110.po.chargeMachineOrderAcct.ChargeMachineOrderAcctPo;
+import com.java110.po.chargeMachineOrderCoupon.ChargeMachineOrderCouponPo;
 import com.java110.po.chargeMachinePort.ChargeMachinePortPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.factory.ApplicationContextFactory;
@@ -25,9 +28,7 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * 充电核心类
@@ -57,6 +58,9 @@ public class ChargeCoreImpl implements IChargeCore {
     @Autowired
     private IChargeRuleFeeV1InnerServiceSMO chargeRuleFeeV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IChargeMachineOrderCouponV1InnerServiceSMO chargeMachineOrderCouponV1InnerServiceSMOImpl;
+
 
     @Override
     public ResultVo startCharge(ChargeMachineDto chargeMachineDto, ChargeMachinePortDto chargeMachinePortDto, String chargeType, double duration, String orderId) {
@@ -125,11 +129,11 @@ public class ChargeCoreImpl implements IChargeCore {
             return;
         }
 
-        String chargeHours = chargeMachineOrderDtos.get(0).getChargeHours();
-        double cHours = Double.parseDouble(chargeHours);
-        if (999 == cHours) {
-            cHours = 10;
-        }
+//        String chargeHours = chargeMachineOrderDtos.get(0).getChargeHours();
+//        double cHours = Double.parseDouble(chargeHours);
+//        if (999 == cHours) {
+//            cHours = 10;
+//        }
 
         Date startTime = DateUtil.getDateFromStringA(chargeMachineOrderDtos.get(0).getStartTime());
 
@@ -141,6 +145,11 @@ public class ChargeCoreImpl implements IChargeCore {
             usedHours = 0;
         }
 
+        // todo 优惠券抵扣
+        JSONObject result = useCoupon(usedHours, chargeMachineOrderDtos);
+        usedHours = result.getDoubleValue("usedHours");
+        remark += result.getString("remark");
+
         ChargeRuleFeeDto chargeRuleFeeDto = new ChargeRuleFeeDto();
         chargeRuleFeeDto.setRuleId(chargeMachineDto.getRuleId());
         chargeRuleFeeDto.setCommunityId(chargeMachineDto.getCommunityId());
@@ -161,7 +170,7 @@ public class ChargeCoreImpl implements IChargeCore {
 
         String durationPrice = chargeRuleFeeDtos.get(chargeRuleFeeDtos.size() - 1).getDurationPrice();
 
-        BigDecimal usedHoursDec =  new BigDecimal(usedHours).multiply(new BigDecimal(Double.parseDouble(durationPrice))).setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal usedHoursDec = new BigDecimal(usedHours).multiply(new BigDecimal(Double.parseDouble(durationPrice))).setScale(2, BigDecimal.ROUND_HALF_UP);
 
         BigDecimal returnMoneyDec = new BigDecimal(Double.parseDouble(chargeMachineOrderDtos.get(0).getAmount())).subtract(usedHoursDec);
 
@@ -206,7 +215,6 @@ public class ChargeCoreImpl implements IChargeCore {
 
 
         //充电表中加入退款金额
-
         ChargeMachineOrderAcctPo chargeMachineOrderAcctPo = new ChargeMachineOrderAcctPo();
         chargeMachineOrderAcctPo.setAcctDetailId(accountDetailPo.getDetailId());
         chargeMachineOrderAcctPo.setAmount((-1 * returnMoney) + "");
@@ -229,6 +237,56 @@ public class ChargeCoreImpl implements IChargeCore {
         chargeMachineOrderAcctV1InnerServiceSMOImpl.saveChargeMachineOrderAcct(chargeMachineOrderAcctPo);
     }
 
+    /**
+     * 优惠券抵扣 小时
+     *
+     * @param usedHours
+     * @param chargeMachineOrderDtos
+     * @return {
+     * usedHours:'',
+     * remark:''
+     * }
+     */
+    private JSONObject useCoupon(double usedHours, List<ChargeMachineOrderDto> chargeMachineOrderDtos) {
+        double hours = 0;
+        JSONObject useHoursInfo = new JSONObject();
+        ChargeMachineOrderCouponDto chargeMachineOrderCouponDto = new ChargeMachineOrderCouponDto();
+        chargeMachineOrderCouponDto.setOrderId(chargeMachineOrderDtos.get(0).getOrderId());
+        chargeMachineOrderCouponDto.setCommunityId(chargeMachineOrderDtos.get(0).getCommunityId());
+        chargeMachineOrderCouponDto.setState("W");
+        List<ChargeMachineOrderCouponDto> chargeMachineOrderCouponDtos
+                = chargeMachineOrderCouponV1InnerServiceSMOImpl.queryChargeMachineOrderCoupons(chargeMachineOrderCouponDto);
+        if (chargeMachineOrderCouponDtos == null || chargeMachineOrderCouponDtos.size() < 1) {
+            useHoursInfo.put("usedHours", usedHours);
+            useHoursInfo.put("remark", "");
+            return useHoursInfo;
+        }
+        String couponNames = "";
+        for (ChargeMachineOrderCouponDto tmpChargeMachineOrderCouponDto : chargeMachineOrderCouponDtos) {
+            couponNames += ("优惠券名称:" + tmpChargeMachineOrderCouponDto.getCouponName() + "(" + tmpChargeMachineOrderCouponDto.getCouponId() + "),小时:" + tmpChargeMachineOrderCouponDto.getHours() + ";");
+
+            hours += Double.parseDouble(tmpChargeMachineOrderCouponDto.getHours());
+        }
+
+        //将优惠券修改为已使用状态
+        ChargeMachineOrderCouponPo chargeMachineOrderCouponPo = new ChargeMachineOrderCouponPo();
+        chargeMachineOrderCouponPo.setOrderId(chargeMachineOrderDtos.get(0).getOrderId());
+        chargeMachineOrderCouponPo.setCommunityId(chargeMachineOrderDtos.get(0).getCommunityId());
+        chargeMachineOrderCouponPo.setState("C");
+        chargeMachineOrderCouponV1InnerServiceSMOImpl.updateChargeMachineOrderCoupon(chargeMachineOrderCouponPo);
+
+        BigDecimal useDec = new BigDecimal(usedHours).subtract(new BigDecimal(hours)).setScale(2, BigDecimal.ROUND_HALF_UP);
+        usedHours = useDec.doubleValue();
+        if (usedHours < 0) {
+            useHoursInfo.put("usedHours", 0);
+            useHoursInfo.put("remark", couponNames);
+            return useHoursInfo;
+        }
+        useHoursInfo.put("usedHours", usedHours);
+        useHoursInfo.put("remark", couponNames);
+        return useHoursInfo;
+    }
+
     @Override
     public ChargeMachinePortDto getChargePortState(ChargeMachineDto chargeMachineDto, ChargeMachinePortDto chargeMachinePortDto) {
         ChargeMachineFactoryDto chargeMachineFactoryDto = new ChargeMachineFactoryDto();
@@ -316,7 +374,7 @@ public class ChargeCoreImpl implements IChargeCore {
             throw new CmdException("厂家接口未实现");
         }
 
-        chargeFactoryAdapt.workHeartbeat(chargeMachineDtos.get(0),notifyChargeOrderDto.getBodyParam());
+        chargeFactoryAdapt.workHeartbeat(chargeMachineDtos.get(0), notifyChargeOrderDto.getBodyParam());
 
         return new ResultVo(ResultVo.CODE_OK, "成功");
 

+ 50 - 31
service-common/src/main/java/com/java110/common/cmd/chargeMachine/StartChargeCmd.java

@@ -27,6 +27,7 @@ import com.java110.intf.user.IUserV1InnerServiceSMO;
 import com.java110.po.accountDetail.AccountDetailPo;
 import com.java110.po.chargeMachineOrder.ChargeMachineOrderPo;
 import com.java110.po.chargeMachineOrderAcct.ChargeMachineOrderAcctPo;
+import com.java110.po.chargeMachineOrderCoupon.ChargeMachineOrderCouponPo;
 import com.java110.po.chargeMachinePort.ChargeMachinePortPo;
 import com.java110.po.couponPropertyUser.CouponPropertyUserPo;
 import com.java110.utils.exception.CmdException;
@@ -82,6 +83,9 @@ public class StartChargeCmd extends Cmd {
     @Autowired
     private IChargeRuleFeeV1InnerServiceSMO chargeRuleFeeV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IChargeMachineOrderCouponV1InnerServiceSMO chargeMachineOrderCouponV1InnerServiceSMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
         Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
@@ -124,9 +128,9 @@ public class StartChargeCmd extends Cmd {
         if (chargeRuleFeeDtos == null || chargeRuleFeeDtos.size() < 1) {
             throw new CmdException("未设置充值收费");
         }
-        reqJson.put("durationPrice",chargeRuleFeeDtos.get(chargeRuleFeeDtos.size()-1).getDurationPrice());
+        reqJson.put("durationPrice", chargeRuleFeeDtos.get(chargeRuleFeeDtos.size() - 1).getDurationPrice());
 
-        BigDecimal payMoneyDec = new BigDecimal(Double.parseDouble(chargeRuleFeeDtos.get(chargeRuleFeeDtos.size()-1).getDurationPrice()));
+        BigDecimal payMoneyDec = new BigDecimal(Double.parseDouble(chargeRuleFeeDtos.get(chargeRuleFeeDtos.size() - 1).getDurationPrice()));
 
         double payMoney = payMoneyDec.multiply(new BigDecimal(duration)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 
@@ -253,11 +257,11 @@ public class StartChargeCmd extends Cmd {
         resultVo.setData(orderId);
 
         double couponDurationHours = 0.0;
-        //扣款
-        if (reqJson.containsKey("couponIds") && !StringUtil.isEmpty(reqJson.getString("couponIds"))) {
-            //todo 优惠券抵扣
-            couponDurationHours = withholdCoupon(reqJson, chargeMachineDtos, orderId);
-        }
+
+
+        //todo 优惠券抵扣
+        withholdCoupon(reqJson, chargeMachineDtos, orderId);
+
 
         if (durationHours - couponDurationHours > 0) {
             // todo 3.0 账户扣款
@@ -274,10 +278,14 @@ public class StartChargeCmd extends Cmd {
      * @param chargeMachineDtos
      * @param orderId
      */
-    private double withholdCoupon(JSONObject reqJson, List<ChargeMachineDto> chargeMachineDtos, String orderId) {
+    private void withholdCoupon(JSONObject reqJson, List<ChargeMachineDto> chargeMachineDtos, String orderId) {
+        if (!reqJson.containsKey("couponIds") || StringUtil.isEmpty(reqJson.getString("couponIds"))) {
+            return;
+        }
         int flag;
-        double hours = 0;
-        String couponNames = "";
+//        double hours = 0;
+//        String couponNames = "";
+        ChargeMachineOrderCouponPo chargeMachineOrderCouponPo = null;
         for (String couponId : reqJson.getString("couponIds").split(",")) {
             String requestId = DistributedLock.getLockUUID();
             String key = this.getClass().getSimpleName() + reqJson.getString("couponId");
@@ -301,8 +309,6 @@ public class StartChargeCmd extends Cmd {
                     throw new CmdException("核销失败");
                 }
 
-                couponNames += ("优惠券名称:" + couponPropertyUserDtos.get(0).getCouponName() + ",优惠券编号:" + couponId + ";");
-
                 CouponPropertyPoolConfigDto couponPropertyPoolConfigDto = new CouponPropertyPoolConfigDto();
                 couponPropertyPoolConfigDto.setCouponId(couponPropertyUserDtos.get(0).getCppId());
                 couponPropertyPoolConfigDto.setColumnKey("hours");
@@ -311,30 +317,43 @@ public class StartChargeCmd extends Cmd {
                 Assert.listOnlyOne(couponPropertyPoolConfigDtos, "未包含优惠券配置信息");
 
                 double value = Double.parseDouble(couponPropertyPoolConfigDtos.get(0).getColumnValue());
-                hours += value;
+
+                chargeMachineOrderCouponPo = new ChargeMachineOrderCouponPo();
+                chargeMachineOrderCouponPo.setCouponId(couponId);
+                chargeMachineOrderCouponPo.setCouponName(couponPropertyUserDtos.get(0).getCouponName());
+                chargeMachineOrderCouponPo.setOrderId(orderId);
+                chargeMachineOrderCouponPo.setCommunityId(chargeMachineDtos.get(0).getCommunityId());
+                chargeMachineOrderCouponPo.setState("W");
+                chargeMachineOrderCouponPo.setCmocId(GenerateCodeFactory.getGeneratorId("11"));
+                chargeMachineOrderCouponPo.setHours(value + "");
+                chargeMachineOrderCouponV1InnerServiceSMOImpl.saveChargeMachineOrderCoupon(chargeMachineOrderCouponPo);
+
+//                couponNames += ("优惠券名称:" + couponPropertyUserDtos.get(0).getCouponName() + "(" + couponId + "),小时:"+value+";");
+//
+//                hours += value;
             } finally {
                 DistributedLock.releaseDistributedLock(requestId, key);
             }
         }
 
-        hours = Math.ceil(hours);
-
-        ChargeMachineOrderAcctPo chargeMachineOrderAcctPo = new ChargeMachineOrderAcctPo();
-        chargeMachineOrderAcctPo.setAcctDetailId("-1");
-        chargeMachineOrderAcctPo.setAmount("0");
-        chargeMachineOrderAcctPo.setCmoaId(GenerateCodeFactory.getGeneratorId("11"));
-        chargeMachineOrderAcctPo.setOrderId(orderId);
-        chargeMachineOrderAcctPo.setAcctId(reqJson.getString("acctId"));
-        chargeMachineOrderAcctPo.setStartTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
-        chargeMachineOrderAcctPo.setEndTime(DateUtil.getAddHoursStringA(DateUtil.getCurrentDate(), new Double(hours).intValue()));
-        chargeMachineOrderAcctPo.setRemark("优惠券抵扣," + couponNames);
-        chargeMachineOrderAcctPo.setCommunityId(chargeMachineDtos.get(0).getCommunityId());
-        chargeMachineOrderAcctPo.setEnergy("0");
-        chargeMachineOrderAcctPo.setDurationPrice(reqJson.getString("durationPrice"));
-
-        chargeMachineOrderAcctV1InnerServiceSMOImpl.saveChargeMachineOrderAcct(chargeMachineOrderAcctPo);
-
-        return hours;
+//        hours = Math.ceil(hours);
+
+//        ChargeMachineOrderAcctPo chargeMachineOrderAcctPo = new ChargeMachineOrderAcctPo();
+//        chargeMachineOrderAcctPo.setAcctDetailId("-1");
+//        chargeMachineOrderAcctPo.setAmount("0");
+//        chargeMachineOrderAcctPo.setCmoaId(GenerateCodeFactory.getGeneratorId("11"));
+//        chargeMachineOrderAcctPo.setOrderId(orderId);
+//        chargeMachineOrderAcctPo.setAcctId(reqJson.getString("acctId"));
+//        chargeMachineOrderAcctPo.setStartTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+//        chargeMachineOrderAcctPo.setEndTime(DateUtil.getAddHoursStringA(DateUtil.getCurrentDate(), new Double(hours).intValue()));
+//        chargeMachineOrderAcctPo.setRemark("优惠券抵扣," + couponNames);
+//        chargeMachineOrderAcctPo.setCommunityId(chargeMachineDtos.get(0).getCommunityId());
+//        chargeMachineOrderAcctPo.setEnergy("0");
+//        chargeMachineOrderAcctPo.setDurationPrice(reqJson.getString("durationPrice"));
+//
+//        chargeMachineOrderAcctV1InnerServiceSMOImpl.saveChargeMachineOrderAcct(chargeMachineOrderAcctPo);
+
+//        return hours;
     }
 
     /**

+ 77 - 0
service-common/src/main/java/com/java110/common/dao/IChargeMachineOrderCouponV1ServiceDao.java

@@ -0,0 +1,77 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.common.dao;
+
+
+import com.java110.utils.exception.DAOException;
+import com.java110.entity.merchant.BoMerchant;
+import com.java110.entity.merchant.BoMerchantAttr;
+import com.java110.entity.merchant.Merchant;
+import com.java110.entity.merchant.MerchantAttr;
+
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 类表述:
+ * add by 吴学文 at 2023-04-04 10:28:20 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+public interface IChargeMachineOrderCouponV1ServiceDao {
+
+
+    /**
+     * 保存 充电优惠券信息
+     * @param info
+     * @throws DAOException DAO异常
+     */
+    int saveChargeMachineOrderCouponInfo(Map info) throws DAOException;
+
+
+
+
+    /**
+     * 查询充电优惠券信息(instance过程)
+     * 根据bId 查询充电优惠券信息
+     * @param info bId 信息
+     * @return 充电优惠券信息
+     * @throws DAOException DAO异常
+     */
+    List<Map> getChargeMachineOrderCouponInfo(Map info) throws DAOException;
+
+
+
+    /**
+     * 修改充电优惠券信息
+     * @param info 修改信息
+     * @throws DAOException DAO异常
+     */
+    int updateChargeMachineOrderCouponInfo(Map info) throws DAOException;
+
+
+    /**
+     * 查询充电优惠券总数
+     *
+     * @param info 充电优惠券信息
+     * @return 充电优惠券数量
+     */
+    int queryChargeMachineOrderCouponsCount(Map info);
+
+}

+ 112 - 0
service-common/src/main/java/com/java110/common/dao/impl/ChargeMachineOrderCouponV1ServiceDaoImpl.java

@@ -0,0 +1,112 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.common.dao.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.exception.DAOException;
+import com.java110.utils.util.DateUtil;
+import com.java110.core.base.dao.BaseServiceDao;
+import com.java110.common.dao.IChargeMachineOrderCouponV1ServiceDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 类表述:
+ * add by 吴学文 at 2023-04-04 10:28:20 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+@Service("chargeMachineOrderCouponV1ServiceDaoImpl")
+public class ChargeMachineOrderCouponV1ServiceDaoImpl extends BaseServiceDao implements IChargeMachineOrderCouponV1ServiceDao {
+
+    private static Logger logger = LoggerFactory.getLogger(ChargeMachineOrderCouponV1ServiceDaoImpl.class);
+
+
+
+
+
+    /**
+     * 保存充电优惠券信息 到 instance
+     * @param info   bId 信息
+     * @throws DAOException DAO异常
+     */
+    @Override
+    public int saveChargeMachineOrderCouponInfo(Map info) throws DAOException {
+        logger.debug("保存 saveChargeMachineOrderCouponInfo 入参 info : {}",info);
+
+        int saveFlag = sqlSessionTemplate.insert("chargeMachineOrderCouponV1ServiceDaoImpl.saveChargeMachineOrderCouponInfo",info);
+
+        return saveFlag;
+    }
+
+
+    /**
+     * 查询充电优惠券信息(instance)
+     * @param info bId 信息
+     * @return List<Map>
+     * @throws DAOException DAO异常
+     */
+    @Override
+    public List<Map> getChargeMachineOrderCouponInfo(Map info) throws DAOException {
+        logger.debug("查询 getChargeMachineOrderCouponInfo 入参 info : {}",info);
+
+        List<Map> businessChargeMachineOrderCouponInfos = sqlSessionTemplate.selectList("chargeMachineOrderCouponV1ServiceDaoImpl.getChargeMachineOrderCouponInfo",info);
+
+        return businessChargeMachineOrderCouponInfos;
+    }
+
+
+    /**
+     * 修改充电优惠券信息
+     * @param info 修改信息
+     * @throws DAOException DAO异常
+     */
+    @Override
+    public int updateChargeMachineOrderCouponInfo(Map info) throws DAOException {
+        logger.debug("修改 updateChargeMachineOrderCouponInfo 入参 info : {}",info);
+
+        int saveFlag = sqlSessionTemplate.update("chargeMachineOrderCouponV1ServiceDaoImpl.updateChargeMachineOrderCouponInfo",info);
+
+        return saveFlag;
+    }
+
+     /**
+     * 查询充电优惠券数量
+     * @param info 充电优惠券信息
+     * @return 充电优惠券数量
+     */
+    @Override
+    public int queryChargeMachineOrderCouponsCount(Map info) {
+        logger.debug("查询 queryChargeMachineOrderCouponsCount 入参 info : {}",info);
+
+        List<Map> businessChargeMachineOrderCouponInfos = sqlSessionTemplate.selectList("chargeMachineOrderCouponV1ServiceDaoImpl.queryChargeMachineOrderCouponsCount", info);
+        if (businessChargeMachineOrderCouponInfos.size() < 1) {
+            return 0;
+        }
+
+        return Integer.parseInt(businessChargeMachineOrderCouponInfos.get(0).get("count").toString());
+    }
+
+
+}

+ 89 - 0
service-common/src/main/java/com/java110/common/smo/impl/ChargeMachineOrderCouponV1InnerServiceSMOImpl.java

@@ -0,0 +1,89 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.common.smo.impl;
+
+
+import com.java110.common.dao.IChargeMachineOrderCouponV1ServiceDao;
+import com.java110.intf.common.IChargeMachineOrderCouponV1InnerServiceSMO;
+import com.java110.dto.chargeMachineOrderCoupon.ChargeMachineOrderCouponDto;
+import com.java110.po.chargeMachineOrderCoupon.ChargeMachineOrderCouponPo;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.core.base.smo.BaseServiceSMO;
+import com.java110.dto.user.UserDto;
+import com.java110.dto.PageDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 类表述: 服务之前调用的接口实现类,不对外提供接口能力 只用于接口建调用
+ * add by 吴学文 at 2023-04-04 10:28:20 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+@RestController
+public class ChargeMachineOrderCouponV1InnerServiceSMOImpl extends BaseServiceSMO implements IChargeMachineOrderCouponV1InnerServiceSMO {
+
+    @Autowired
+    private IChargeMachineOrderCouponV1ServiceDao chargeMachineOrderCouponV1ServiceDaoImpl;
+
+
+    @Override
+    public int saveChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo) {
+        int saveFlag = chargeMachineOrderCouponV1ServiceDaoImpl.saveChargeMachineOrderCouponInfo(BeanConvertUtil.beanCovertMap(chargeMachineOrderCouponPo));
+        return saveFlag;
+    }
+
+     @Override
+    public int updateChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo) {
+        int saveFlag = chargeMachineOrderCouponV1ServiceDaoImpl.updateChargeMachineOrderCouponInfo(BeanConvertUtil.beanCovertMap(chargeMachineOrderCouponPo));
+        return saveFlag;
+    }
+
+     @Override
+    public int deleteChargeMachineOrderCoupon(@RequestBody  ChargeMachineOrderCouponPo chargeMachineOrderCouponPo) {
+       chargeMachineOrderCouponPo.setStatusCd("1");
+       int saveFlag = chargeMachineOrderCouponV1ServiceDaoImpl.updateChargeMachineOrderCouponInfo(BeanConvertUtil.beanCovertMap(chargeMachineOrderCouponPo));
+       return saveFlag;
+    }
+
+    @Override
+    public List<ChargeMachineOrderCouponDto> queryChargeMachineOrderCoupons(@RequestBody  ChargeMachineOrderCouponDto chargeMachineOrderCouponDto) {
+
+        //校验是否传了 分页信息
+
+        int page = chargeMachineOrderCouponDto.getPage();
+
+        if (page != PageDto.DEFAULT_PAGE) {
+            chargeMachineOrderCouponDto.setPage((page - 1) * chargeMachineOrderCouponDto.getRow());
+        }
+
+        List<ChargeMachineOrderCouponDto> chargeMachineOrderCoupons = BeanConvertUtil.covertBeanList(chargeMachineOrderCouponV1ServiceDaoImpl.getChargeMachineOrderCouponInfo(BeanConvertUtil.beanCovertMap(chargeMachineOrderCouponDto)), ChargeMachineOrderCouponDto.class);
+
+        return chargeMachineOrderCoupons;
+    }
+
+
+    @Override
+    public int queryChargeMachineOrderCouponsCount(@RequestBody ChargeMachineOrderCouponDto chargeMachineOrderCouponDto) {
+        return chargeMachineOrderCouponV1ServiceDaoImpl.queryChargeMachineOrderCouponsCount(BeanConvertUtil.beanCovertMap(chargeMachineOrderCouponDto));    }
+
+}