2021与蓝度共同重构项目,服务端
liuhaonan
2022-06-27 048c03f5df43bf0ebc5b2a122e95cfc52cfa23b5
支付配置
已修改3个文件
110 ■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/UsrPayConfigController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/param/WxpayConfigParam.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/UsrPayConfigController.java
@@ -161,7 +161,7 @@
    /**
     * @param poleId
     * @return
     * @return 通过灯杆id获取配置
     */
    @GetMapping("/getWxPayConfigByPoleId/{poleId}")
    public ResponseVO<Object> getWxPayConfigByPoleId(@PathVariable Long poleId) {
@@ -190,6 +190,13 @@
    }
    /**
     * wx配置列表
     *
     * @param baseConditionVO
     * @param keyword
     * @return
     */
    @GetMapping("/WxConfigList")
    public ResponseVO<Object> WxConfigList(BaseConditionVO baseConditionVO
            , @RequestParam(value = "keyword", required = false) String keyword) {
@@ -200,5 +207,16 @@
        return ResponseUtil.success(wxPayConfigService.configList(baseConditionVO, keyword));
    }
    /**
     * wx配置的停用/启用
     */
    @PostMapping("/updateWxPayConfigStatus")
    public ResponseVO<Object> updateWxPayConfigStatus(@RequestBody WxpayConfigParam wxConfigParam) {
        if (!permissionConfig.check(MenuEnum.WECHAT_CONFIG_UPDATE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(wxPayConfigService.updateState(wxConfigParam.getConfigId(), wxConfigParam.getStatus()));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/param/WxpayConfigParam.java
@@ -30,4 +30,10 @@
     */
    private String privateKey;
    /**
     * 状态  1启用 / 0未启用
     */
    private Integer status;
    private Long configId;
}
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
@@ -17,6 +17,7 @@
import com.sandu.ximon.dao.mapper.UsrWxPayConfigMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -39,10 +40,11 @@
            throw new BusinessException("灯杆id错误或灯杆不存在");
        }
        WxConfigEntity config;
        //未设置支付参数,则使用默认支付参数
        if (pole.getClientId() == null) {
            config = getById(0);
        }
        config = getOne(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId()));
        config = getOne(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, pole.getClientId()).eq(WxConfigEntity::getState, 1));
        if (config == null) {
            throw new BusinessException("用户未配置支付配置,请配置后重试");
        }
@@ -60,10 +62,12 @@
        BeanUtil.copyProperties(configParam, config);
        config.setAppid(configParam.getAppId());
        config.setAppappid(configParam.getAppAppId());
        if(SecurityUtils.getClientId()!=null){
        if (SecurityUtils.getClientId() != null) {
            config.setCreateUserId(SecurityUtils.getUserId());
            if(clientService.findClientId()){
            if (clientService.findClientId()) {
                config.setClientId(clientService.getClientId());
            } else {
                config.setClientId(SecurityUtils.getUserId());
            }
        }
        return save(config);
@@ -91,7 +95,7 @@
    }
    public List<WxConfigEntity> configList(BaseConditionVO baseConditionVO,String keyword) {
    public List<WxConfigEntity> configList(BaseConditionVO baseConditionVO, String keyword) {
        LambdaQueryWrapper<WxConfigEntity> wrapper = new LambdaQueryWrapper<>();
        System.out.println("----------------------------" + clientService.findClientId());
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
@@ -107,26 +111,76 @@
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
            wrapper = Wrappers.lambdaQuery(WxConfigEntity.class);
        }
        if(keyword != null&&!keyword.isEmpty()){
           wrapper= wrapper.like(WxConfigEntity::getConfigId,keyword).or(
                    appid->{
                        appid.like(WxConfigEntity::getAppid,keyword);
        if (keyword != null && !keyword.isEmpty()) {
            wrapper = wrapper.like(WxConfigEntity::getConfigId, keyword).or(
                    appid -> {
                        appid.like(WxConfigEntity::getAppid, keyword);
                    }
            ).or(
                    appappid->{
                        appappid.like(WxConfigEntity::getAppappid,keyword);
                    appappid -> {
                        appappid.like(WxConfigEntity::getAppappid, keyword);
                    }
            ).or(
                    mchId->{
                        mchId.like(WxConfigEntity::getMchId,keyword);
                    mchId -> {
                        mchId.like(WxConfigEntity::getMchId, keyword);
                    }
            ).or(
                    privateKey->{
                        privateKey.like(WxConfigEntity::getPrivateKey,keyword);
                    privateKey -> {
                        privateKey.like(WxConfigEntity::getPrivateKey, keyword);
                    }
            );
        }
        return list(wrapper);
        List<WxConfigEntity> list = list(wrapper);
        list.forEach(
                wxConfigEntity -> {
                    //设置支付参数中的appid和appappid  mchId和privateKey中的部分替换为*
                    wxConfigEntity.setAppid(wxConfigEntity.getAppid().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                    wxConfigEntity.setAppappid(wxConfigEntity.getAppappid().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                    wxConfigEntity.setMchId(wxConfigEntity.getMchId().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                    wxConfigEntity.setPrivateKey(wxConfigEntity.getPrivateKey().replaceAll("(?<=.{4}).*(?=.{4})", "*"));
                }
        );
        return list;
    }
    /**
     * 支付参数配置的停用/启用
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean updateState(Long id, Integer state) {
        WxConfigEntity byId = getById(id);
        if (byId == null) {
            throw new BusinessException("配置id错误或配置不存在");
        }
        /**
         * 获取当前用户所有的wx支付配置
         */
        if (SecurityUtils.getClientId() != null) {
            //客户
            List<WxConfigEntity> configList = list(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, SecurityUtils.getUserId())
                    .or(
                            user -> {
                                user.eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId());
                            }
                    ));
            if (configList.size() == 1 && state == 0) {
                throw new BusinessException("当前用户只有一个支付配置,不能停用");
            }
            //设置当前用户所有的支付配置为停用
            configList.forEach(
                    wxConfigEntity -> {
                        wxConfigEntity.setState(0);
                    }
            );
            boolean b = updateBatchById(configList);
            if (!b) {
                throw new BusinessException("更新失败");
            }
        }
        WxConfigEntity config = new WxConfigEntity();
        config.setConfigId(id);
        config.setState(state);
        return updateById(config);
    }
}