admin
2024-07-29 734dfe9eb0a2176103dce8245c69b1194574c68e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.taoke.autopay.controller.admin;
 
import com.google.gson.reflect.TypeToken;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.vo.admin.PayMoneySettingsVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
 
@Controller
@RequestMapping("/admin/api/settings")
public class AdminSettingsController {
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @ResponseBody
    @RequestMapping("getDefaultOrderCount")
    public String getDefaultOrderCount() {
        // 获取默认的
        SystemConfigKeyEnum[] keys = new SystemConfigKeyEnum[]{
                SystemConfigKeyEnum.DY_ORDER_MAX_PAY_COUNT_DEFAULT,
                SystemConfigKeyEnum.KS_ORDER_MAX_PAY_COUNT_DEFAULT,
                SystemConfigKeyEnum.ORDER_MAX_SUBMIT_COUNT_DEFAULT,
                SystemConfigKeyEnum.ALIPAY_KEY_VERIFY
        };
        JSONObject data = new JSONObject();
        for (SystemConfigKeyEnum key : keys) {
            String val = systemConfigService.getValue(key);
            data.put(key.getKey(), val);
        }
        return JsonUtil.loadTrueResult(data);
    }
 
 
    @ResponseBody
    @RequestMapping("setDefaultOrderCount")
    public String setDefaultOrderCount(HttpServletRequest request) {
 
        SystemConfigKeyEnum[] keys = new SystemConfigKeyEnum[]{
                SystemConfigKeyEnum.DY_ORDER_MAX_PAY_COUNT_DEFAULT,
                SystemConfigKeyEnum.KS_ORDER_MAX_PAY_COUNT_DEFAULT,
                SystemConfigKeyEnum.ORDER_MAX_SUBMIT_COUNT_DEFAULT,
                SystemConfigKeyEnum.ALIPAY_KEY_VERIFY
        };
        for (SystemConfigKeyEnum key : keys) {
            String val = request.getParameter(key.getKey());
            if (val != null) {
                systemConfigService.setValue(key, val);
            }
        }
        systemConfigService.clearCache();
        return JsonUtil.loadTrueResult("");
    }
 
 
    @ResponseBody
    @RequestMapping("setPayMoneyAndTime")
    public String setPayMoneyAndTime(String moneys, String startSubmitTime, String endSubmitTime) {
        if(StringUtil.isNullOrEmpty(moneys)){
            return JsonUtil.loadFalseResult("未上传金额");
        }
        if(StringUtil.isNullOrEmpty(startSubmitTime)){
            return JsonUtil.loadFalseResult("未上传开始时间");
        }
        if(StringUtil.isNullOrEmpty(endSubmitTime)){
            return JsonUtil.loadFalseResult("未上传结束时间");
        }
        JSONArray moneyArrays =  JSONArray.fromObject(moneys);
        JSONArray fa=new JSONArray();
        for(int i=0;i<moneyArrays.size();i++){
            // 统一保留2位小数
            double money =  moneyArrays.optDouble(i);
            fa.add(new BigDecimal(money).setScale(2, RoundingMode.HALF_UP).toString());
        }
        systemConfigService.setValue(SystemConfigKeyEnum.PAY_MONEY_LIST, fa.toString());
        // 设置时间,用逗号分隔
        systemConfigService.setValue(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE, startSubmitTime+","+endSubmitTime);
        systemConfigService.clearCache();
        return JsonUtil.loadTrueResult("");
    }
 
 
 
    @ResponseBody
    @RequestMapping("getPayMoneyAndTime")
    public String getPayMoneyAndTime() {
        String value = systemConfigService.getValue(SystemConfigKeyEnum.PAY_MONEY_LIST);
        PayMoneySettingsVO vo=new PayMoneySettingsVO();
        if(StringUtil.isNullOrEmpty(value)){
            vo.setMoneys(new ArrayList<>());
        }else{
            vo.setMoneys(JsonUtil.getSimpleGson().fromJson(value,new TypeToken<List<String>>(){}.getType() ));
        }
        // 设置时间,用逗号分隔
       value = systemConfigService.getValue(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE);
        if(StringUtil.isNullOrEmpty(value)){
            vo.setStartSubmitTime("");
            vo.setEndSubmitTime("");
        }else{
            vo.setStartSubmitTime(value.split(",")[0]);
            vo.setEndSubmitTime(value.split(",")[1]);
        }
        return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(vo));
    }
 
}