<commit_before>package org.xxpay.mgr.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.xxpay.common.util.DateUtil;
import org.xxpay.common.util.MyLog;
import org.xxpay.dal.dao.model.PayChannel;
import org.xxpay.dal.dao.plugin.PageModel;
import org.xxpay.mgr.service.PayChannelService;

import java.util.List;

@Controller
@RequestMapping("/pay_channel")
public class PayChannelController {

    private final static MyLog _log = MyLog.getLog(PayChannelController.class);

    @Autowired
    private PayChannelService payChannelService;

    @RequestMapping("/list.html")
    public String listInput(ModelMap model) {
        return "pay_channel/list";
    }

    @RequestMapping("/edit.html")
    public String editInput(String id, ModelMap model) {
        PayChannel item = null;
        if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
            item = payChannelService.selectPayChannel(Integer.parseInt(id));
        }
        if(item == null) item = new PayChannel();
        model.put("item", item);
        return "pay_channel/edit";
    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(@ModelAttribute PayChannel payChannel, Integer pageIndex, Integer pageSize) {
        PageModel pageModel = new PageModel();
        int count = payChannelService.count(payChannel);
        if(count <= 0) return JSON.toJSONString(pageModel);
        List<PayChannel> payChannelList = payChannelService.getPayChannelList((pageIndex-1)*pageSize, pageSize, payChannel);
        if(!CollectionUtils.isEmpty(payChannelList)) {
            JSONArray array = new JSONArray();
            for(PayChannel pc : payChannelList) {
                JSONObject object = (JSONObject) JSONObject.toJSON(pc);
                object.put("createTime", DateUtil.date2Str(pc.getCreateTime()));
                array.add(object);
            }
            pageModel.setList(array);
        }
        pageModel.setCount(count);
        pageModel.setMsg("ok");
        pageModel.setRel(true);
        return JSON.toJSONString(pageModel);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String save(@RequestParam String params) {
        JSONObject po = JSONObject.parseObject(params);
        PayChannel payChannel = new PayChannel();
        Integer id = po.getInteger("id");
        payChannel.setChannelId(po.getString("channelId"));
        payChannel.setMchId(po.getString("mchId"));
        payChannel.setChannelName(po.getString("channelName"));
        payChannel.setChannelMchId(po.getString("channelMchId"));
        payChannel.setState((byte) ("on".equalsIgnoreCase(po.getString("state")) ? 1 : 0));
        payChannel.setParam(po.getString("param"));
        payChannel.setRemark(po.getString("remark"));
        int result;
        if(id == null) {
            // 添加
            result = payChannelService.addPayChannel(payChannel);
        }else {
            // 修改
            payChannel.setId(id);
            result = payChannelService.updatePayChannel(payChannel);
        }
        _log.info("保存渠道记录,返回:{}", result);
        return result+"";
    }

    @RequestMapping("/view.html")
    public String viewInput(String id, ModelMap model) {
        PayChannel item = null;
        if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
            item = payChannelService.selectPayChannel(Integer.parseInt(id));
        }
        if(item == null) item = new PayChannel();
        model.put("item", item);
        return "pay_channel/view";
    }

}<commit_msg>修复保存支付宝渠道私钥+号转空格的bug<commit_after>package org.xxpay.mgr.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.DateUtil;
import org.xxpay.common.util.MyLog;
import org.xxpay.dal.dao.model.PayChannel;
import org.xxpay.dal.dao.plugin.PageModel;
import org.xxpay.mgr.service.PayChannelService;

import java.util.List;

@Controller
@RequestMapping("/pay_channel")
public class PayChannelController {

    private final static MyLog _log = MyLog.getLog(PayChannelController.class);

    @Autowired
    private PayChannelService payChannelService;

    @RequestMapping("/list.html")
    public String listInput(ModelMap model) {
        return "pay_channel/list";
    }

    @RequestMapping("/edit.html")
    public String editInput(String id, ModelMap model) {
        PayChannel item = null;
        if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
            item = payChannelService.selectPayChannel(Integer.parseInt(id));
        }
        if(item == null) item = new PayChannel();
        model.put("item", item);
        return "pay_channel/edit";
    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(@ModelAttribute PayChannel payChannel, Integer pageIndex, Integer pageSize) {
        PageModel pageModel = new PageModel();
        int count = payChannelService.count(payChannel);
        if(count <= 0) return JSON.toJSONString(pageModel);
        List<PayChannel> payChannelList = payChannelService.getPayChannelList((pageIndex-1)*pageSize, pageSize, payChannel);
        if(!CollectionUtils.isEmpty(payChannelList)) {
            JSONArray array = new JSONArray();
            for(PayChannel pc : payChannelList) {
                JSONObject object = (JSONObject) JSONObject.toJSON(pc);
                object.put("createTime", DateUtil.date2Str(pc.getCreateTime()));
                array.add(object);
            }
            pageModel.setList(array);
        }
        pageModel.setCount(count);
        pageModel.setMsg("ok");
        pageModel.setRel(true);
        return JSON.toJSONString(pageModel);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String save(@RequestParam String params) {
        JSONObject po = JSONObject.parseObject(params);
        String channelId = po.getString("channelId");
        String param = po.getString("param");
        // 对于配置支付宝参数时,前端将+号转为空格bug处理
        if(PayConstant.PAY_CHANNEL_ALIPAY_MOBILE.equals(channelId) ||
                PayConstant.PAY_CHANNEL_ALIPAY_PC.equals(channelId) ||
                PayConstant.PAY_CHANNEL_ALIPAY_WAP.equals(channelId)) {
            JSONObject paramObj = po.getJSONObject("param");
            paramObj.put("private_key", paramObj.getString("private_key").replaceAll(" ", "+"));
            paramObj.put("public_key", paramObj.getString("public_key").replaceAll(" ", "+"));
            param = paramObj.toJSONString();
        }

        PayChannel payChannel = new PayChannel();
        Integer id = po.getInteger("id");
        payChannel.setChannelId(channelId);
        payChannel.setMchId(po.getString("mchId"));
        payChannel.setChannelName(po.getString("channelName"));
        payChannel.setChannelMchId(po.getString("channelMchId"));
        payChannel.setState((byte) ("on".equalsIgnoreCase(po.getString("state")) ? 1 : 0));
        payChannel.setParam(param);
        payChannel.setRemark(po.getString("remark"));
        int result;
        if(id == null) {
            // 添加
            result = payChannelService.addPayChannel(payChannel);
        }else {
            // 修改
            payChannel.setId(id);
            result = payChannelService.updatePayChannel(payChannel);
        }
        _log.info("保存渠道记录,返回:{}", result);
        return result+"";
    }

    @RequestMapping("/view.html")
    public String viewInput(String id, ModelMap model) {
        PayChannel item = null;
        if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
            item = payChannelService.selectPayChannel(Integer.parseInt(id));
        }
        if(item == null) item = new PayChannel();
        model.put("item", item);
        return "pay_channel/view";
    }

}
{'fraction_non_alphanumeric': 0.12077741786210087, 'fraction_numerical': 0.0016196205460434984, 'mean_word_length': 3.124522900763359, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145912', 'n_tokens_mistral': 2498, 'n_tokens_neox': 2500, 'n_words': 413}