Administrator
2024-01-31 3447c6321d90416d86bd6bd6515589bae3911c65
2024-01-31 朱宝民 电子钱包账户消费接口、申请退款接口、审核退款申请接口
1 文件已重命名
8个文件已修改
3个文件已删除
1个文件已添加
439 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeRefundMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeConsume.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeRefund.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeWalletRecharge.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeRefundMapper.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/DtoWallet.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/DtoWalletRecharge.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java 211 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletSv.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/dto/DtoRecharge.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/enums/LastOperateENUM.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/enums/RefundStatusENUM.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeRefundMapper.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pipIrrGlobal.pojoSe.SeRefund;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
 * @author ZhuBaoMin
@@ -24,4 +25,11 @@
    int updateByPrimaryKeySelective(SeRefund record);
    int updateByPrimaryKey(SeRefund record);
    /**
     * 根据钱包ID获取待审核的退款申请对象
     * @param walletId
     * @return
     */
    SeRefund getRefundByWallerId(@Param("walletId") Long walletId);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeConsume.java
@@ -42,7 +42,7 @@
    * 钱包ID
    */
    @Schema(description = "钱包ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "钱包ID不能为空")
    //@NotNull(message = "钱包ID不能为空")
    private Long walletId;
    /**
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeRefund.java
@@ -45,7 +45,6 @@
    * 钱包ID
    */
    @Schema(description = "钱包ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "钱包ID不能为空")
    private Long walletId;
    /**
@@ -67,7 +66,7 @@
    */
    @Schema(description = "退款金额", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Min(value = 0, message = "消退款金额不能小于0")
    @NotNull(message = "退款金额不能为空")
    //@NotNull(message = "退款金额不能为空")
    private Double refundAmount;
    /**
@@ -108,6 +107,6 @@
    * 审核备注
    */
    @Schema(description = "备注", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Length(message = "备注长度小于{max}字", min = 1, max = 200)
    @Length(message = "备注长度小于{max}字", min = 0, max = 200)
    private String remarks;
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeWalletRecharge.java
@@ -42,7 +42,7 @@
     * 钱包ID
     */
    @Schema(description = "钱包ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "钱包ID不能为空")
    //@NotNull(message = "钱包ID不能为空")
    private Long walletId;
    /**
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeRefundMapper.xml
@@ -170,4 +170,12 @@
      remarks = #{remarks,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <!--根据钱包ID获取待审核的退款申请对象-->
  <select id="getRefundByWallerId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
        <include refid="Base_Column_List" />
    from se_refund
    where refund_status = 1 AND wallet_id = ${walletId}
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java
@@ -81,8 +81,15 @@
    CLIENT_ID_CANNOT_BE_NULL(90001, "农户编号不能为空"),
    WALLET_OPEN_ACCOUNT_FAIL(90002, "电子钱包账户注册失败"),
    WALLET_ACCOUNT_EXIST(90003, "该农户已注册电子钱包"),
    NO_ACCOUNT(90005, "您尚未注册电子钱包账户"),
    UPDATE_ACCOUNT_FAIL(90006, "充值失败,电子钱包账户更新失败");
    NO_ACCOUNT(90004, "您尚未注册电子钱包账户"),
    UPDATE_ACCOUNT_FAIL(90005, "充值失败,电子钱包账户更新失败"),
    RECHARGE_FAIL(90006, "充值失败"),
    BALANCE_IS_INSUFFICIENT(90007, "消费失败,余额不足"),
    CONSUME_FAIL(90008, "消费失败"),
    REFUND_AMOUNT_CANNOT_GREATER_THAN_MONEY(90009, "申请退款失败,退款金额不能大于余额"),
    APPLICATION_REFUND_FAIL(900010, "申请退款失败"),
    NO_TO_AUDIT_REFUND(900011, "该电子钱包没有待审核的退款申请"),
    AUDIT_REFUND_FAIL(900012, "审核退款申请失败");
    private final Integer code;
    private final String message;
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/DtoWallet.java
File was deleted
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/DtoWalletRecharge.java
File was deleted
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java
@@ -4,10 +4,13 @@
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoSe.SeConsume;
import com.dy.pipIrrGlobal.pojoSe.SeRefund;
import com.dy.pipIrrGlobal.pojoSe.SeWallet;
import com.dy.pipIrrGlobal.pojoSe.SeWalletRecharge;
import com.dy.pipIrrSell.result.SellResultCode;
import com.dy.pipIrrSell.wallet.dto.DtoRecharge;
import com.dy.pipIrrSell.wallet.enums.LastOperateENUM;
import com.dy.pipIrrSell.wallet.enums.RefundStatusENUM;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -24,6 +27,7 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Optional;
@@ -45,7 +49,7 @@
    /**
     * 注册电子钱包账户
     * 注册钱先验证该农户是否已经注册电子钱包
     * 需要考虑已注册账户的情况
     * @param clientId
     * @return
     */
@@ -84,6 +88,7 @@
    /**
     * 电子钱包账户充值
     * 需要考虑未注册账户的情况
     * @param po
     * @param bindingResult
     * @return
@@ -100,7 +105,7 @@
    @PostMapping(path = "add_recharge", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> addRecharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult){
    public BaseResponse<Boolean> addRecharge(@RequestBody @Valid SeWalletRecharge po, BindingResult bindingResult){
        Long clientId = Optional.ofNullable(po .getClientId()).orElse(0L);
        Double amount = Optional.ofNullable(po.getAmount()).orElse(0.0);
@@ -125,18 +130,200 @@
        }
        // 添加充值记录
        SeWalletRecharge seWalletRecharge = new SeWalletRecharge();
        seWalletRecharge.setWalletId(wallerId);
        seWalletRecharge.setClientId(clientId);
        seWalletRecharge.setMoney(money);
        seWalletRecharge.setAmount(amount);
        seWalletRecharge.setAfterRecharge(afterRrecharge);
        seWalletRecharge.setRechargeTime(new Date());
        Long rec = Optional.ofNullable(walletSv.addRecharge(seWalletRecharge)).orElse(0L);
        po.setWalletId(wallerId);
        po.setClientId(clientId);
        po.setMoney(money);
        po.setAmount(amount);
        po.setAfterRecharge(afterRrecharge);
        po.setRechargeTime(new Date());
        Long rec = Optional.ofNullable(walletSv.addRecharge(po)).orElse(0L);
        if(rec == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.WALLET_OPEN_ACCOUNT_FAIL.getMessage());
            return BaseResponseUtils.buildFail(SellResultCode.RECHARGE_FAIL.getMessage());
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 电子钱包消费
     * 需要考虑未注册账户的情况、余额不足的情况
     * @param po
     * @param bindingResult
     * @return
     */
    @Operation(summary = "电子钱包消费", description = "电子钱包消费")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @PostMapping(path = "add_consume", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> addConsume(@RequestBody @Valid SeConsume po, BindingResult bindingResult){
        Long clientId = po .getClientId();
        Double consumption = po.getConsumption();
        Date vot = po.getVot();
        Date vct = po.getVct();
        // 计算开关阀时间差及用水时长
        Long timeDifference = vct.getTime() - vot.getTime();
        DecimalFormat df = new DecimalFormat("#.00");
        Double duration = Double.parseDouble(df.format((float)timeDifference / (1000 * 60 * 60)));
        // 验证该农户是否已经注册电子钱包账户并取出ID及当前账户余额
        SeWallet seWallet = walletSv.getWalletByClientId(clientId);
        if(seWallet == null) {
            return BaseResponseUtils.buildFail(SellResultCode.NO_ACCOUNT.getMessage());
        }
        Long wallerId = Optional.ofNullable(seWallet.getId()).orElse(0L);
        Double money = Optional.ofNullable(seWallet.getMoney()).orElse(0.0);
        if(money < consumption) {
            return BaseResponseUtils.buildFail(SellResultCode.BALANCE_IS_INSUFFICIENT.getMessage());
        }
        // 计算消费后余额
        Double afterConsume = money - consumption;
        // 修改电子钱包余额、最后操作类型、最后操作时间
        seWallet.setMoney(afterConsume);
        seWallet.setLastOperate(LastOperateENUM.CONSUME.getCode());
        seWallet.setLastOperateTime(new Date());
        Integer rec_updateWaller = Optional.ofNullable(walletSv.updateWallet(seWallet)).orElse(0);
        if(rec_updateWaller == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.UPDATE_ACCOUNT_FAIL.getMessage());
        }
        // 添加消费记录
        po.setWalletId(wallerId);
        po.setMoney(money);
        po.setAfterConsume(afterConsume);
        po.setDuration(duration);
        Long rec = Optional.ofNullable(walletSv.addConsume(po)).orElse(0L);
        if(rec == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.CONSUME_FAIL.getMessage());
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 申请退款
     * 需要考虑申请退款金额大于余额的情况
     * @param po
     * @param bindingResult
     * @return
     */
    @Operation(summary = "电子钱包申请退费", description = "电子钱包申请退费")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @PostMapping(path = "add_refund", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> addRefund(@RequestBody @Valid SeRefund po, BindingResult bindingResult){
        Long clientId = po .getClientId();
        Double refundAmount = po.getRefundAmount();
        // 验证该农户是否已经注册电子钱包账户并取出ID及当前账户余额
        SeWallet seWallet = walletSv.getWalletByClientId(clientId);
        if(seWallet == null) {
            return BaseResponseUtils.buildFail(SellResultCode.NO_ACCOUNT.getMessage());
        }
        Long wallerId = Optional.ofNullable(seWallet.getId()).orElse(0L);
        Double money = Optional.ofNullable(seWallet.getMoney()).orElse(0.0);
        // 验证退款金额是否大于余额
        if(money < refundAmount) {
            return BaseResponseUtils.buildFail(SellResultCode.REFUND_AMOUNT_CANNOT_GREATER_THAN_MONEY.getMessage());
        }
        // 计算消费后余额
        Double afterRefund = money - refundAmount;
        // 修改电子钱包余额、最后操作类型、最后操作时间
        seWallet.setMoney(afterRefund);
        seWallet.setLastOperate(LastOperateENUM.APPLY_REFUND.getCode());
        seWallet.setLastOperateTime(new Date());
        Integer rec_updateWaller = Optional.ofNullable(walletSv.updateWallet(seWallet)).orElse(0);
        if(rec_updateWaller == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.UPDATE_ACCOUNT_FAIL.getMessage());
        }
        // 添加消费记录
        po.setWalletId(wallerId);
        po.setMoney(money);
        po.setAfterRefund(afterRefund);
        po.setApplicationTime(new Date());
        po.setRefundStatus(RefundStatusENUM.NO_REFUND.getCode());
        Long rec = Optional.ofNullable(walletSv.addRefund(po)).orElse(0L);
        if(rec == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.APPLICATION_REFUND_FAIL.getMessage());
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 审核退款申请
     * 需要考虑该电子钱包没有待审核的退款申请的情况
     * @param po
     * @param bindingResult
     * @return
     */
    @Operation(summary = "电子钱包审核退款申请", description = "电子钱包审核退款申请")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @PostMapping(path = "audit_refund", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> auditRefund(@RequestBody @Valid SeRefund po, BindingResult bindingResult){
        Long clientId = po.getClientId();
        Byte refundStatus = po.getRefundStatus();
        Long auditor = po.getAuditor();
        String remarks = po.getRemarks();
        // 验证该农户是否已经注册电子钱包账户并取出ID及当前账户余额
        SeWallet seWallet = walletSv.getWalletByClientId(clientId);
        if(seWallet == null) {
            return BaseResponseUtils.buildFail(SellResultCode.NO_ACCOUNT.getMessage());
        }
        Long wallerId = Optional.ofNullable(seWallet.getId()).orElse(0L);
        Double money = Optional.ofNullable(seWallet.getMoney()).orElse(0.0);
        // 验证该电子钱包是否有待审核的退款申请(根据钱包ID获取待审核的退款申请对象)
        SeRefund seRefund = walletSv.getRefundByWallerId(wallerId);
        if(seRefund == null) {
            return BaseResponseUtils.buildFail(SellResultCode.NO_TO_AUDIT_REFUND.getMessage());
        }
        // 修改电子钱包最后操作类型、最后操作时间
        seWallet.setLastOperate(LastOperateENUM.AUDIT_REFUND.getCode());
        seWallet.setLastOperateTime(new Date());
        Integer rec_updateWaller = Optional.ofNullable(walletSv.updateWallet(seWallet)).orElse(0);
        if(rec_updateWaller == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.UPDATE_ACCOUNT_FAIL.getMessage());
        }
        // 添加消费记录
        seRefund.setRefundStatus(refundStatus);
        seRefund.setAuditor(auditor);
        seRefund.setAuditTime(new Date());
        seRefund.setRemarks(remarks);
        Integer rec = Optional.ofNullable(walletSv.auditRefund(seRefund)).orElse(0);
        if(rec == 0) {
            return BaseResponseUtils.buildFail(SellResultCode.AUDIT_REFUND_FAIL.getMessage());
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletSv.java
@@ -4,6 +4,8 @@
import com.dy.pipIrrGlobal.daoSe.SeRefundMapper;
import com.dy.pipIrrGlobal.daoSe.SeWalletMapper;
import com.dy.pipIrrGlobal.daoSe.SeWalletRechargeMapper;
import com.dy.pipIrrGlobal.pojoSe.SeConsume;
import com.dy.pipIrrGlobal.pojoSe.SeRefund;
import com.dy.pipIrrGlobal.pojoSe.SeWallet;
import com.dy.pipIrrGlobal.pojoSe.SeWalletRecharge;
import lombok.extern.slf4j.Slf4j;
@@ -51,10 +53,6 @@
        return po.getId();
    }
    public Integer updateWallet(SeWallet po) {
        return seWalletMapper.updateByPrimaryKeySelective(po);
    }
    /**
     * 电子钱包充值
     * @param po
@@ -65,4 +63,52 @@
        return po.getId();
    }
    /**
     * 电子钱包消费
     * @param po
     * @return
     */
    public Long addConsume(SeConsume po) {
        seConsumeMapper.insert(po);
        return po.getId();
    }
    /**
     * 添加退款申请
     * @param po
     * @return
     */
    public Long addRefund(SeRefund po) {
        seRefundMapper.insert(po);
        return po.getId();
    }
    /**
     * 根据钱包ID获取待审核的退款申请对象
     * @param walletId
     * @return
     */
    public SeRefund getRefundByWallerId(Long walletId) {
        return seRefundMapper.getRefundByWallerId(walletId);
    }
    /**
     * 审核退款申请
     * @param po
     * @return
     */
    public Integer auditRefund(SeRefund po) {
        return seRefundMapper.updateByPrimaryKeySelective(po);
    }
    /**
     * 修改电子钱包
     * 充值、消费、申请退款、审核退款时需要修改电子钱包的:余额、最后操作、最后操作时间
     * @param po
     * @return
     */
    public Integer updateWallet(SeWallet po) {
        return seWalletMapper.updateByPrimaryKeySelective(po);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/dto/DtoRecharge.java
File was deleted
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/enums/LastOperateENUM.java
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/LastOperateENUM.java
@@ -1,4 +1,4 @@
package com.dy.pipIrrSell.wallet;
package com.dy.pipIrrSell.wallet.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/enums/RefundStatusENUM.java
New file
@@ -0,0 +1,21 @@
package com.dy.pipIrrSell.wallet.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
 * @author ZhuBaoMin
 * @date 2024-01-31 14:19
 * @LastEditTime 2024-01-31 14:19
 * @Description
 */
@Getter
@AllArgsConstructor
public enum RefundStatusENUM {
    NO_REFUND((byte)1, "未退款"),
    REFUNDED((byte)2, "已退款");
    private final Byte code;
    private final String message;
}