1
zj
2025-06-25 a0361e762fc672d844ef15e18db5971893cce2bf
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
package project.web.api;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.mysql.cj.util.StringUtils;
 
import kernel.exception.BusinessException;
import kernel.web.BaseAction;
import kernel.web.ResultObject;
import project.wallet.rate.ExchangeRate;
import project.wallet.rate.UserRateConfigService;
 
/**
 * API 计价方式
 *
 */
@RestController
@CrossOrigin
public class ExchangeRateUserConfigController extends BaseAction {
 
    private static final Logger logger = LoggerFactory.getLogger(ExchangeRateUserConfigController.class);
 
    @Autowired
    private UserRateConfigService userRateConfigService;
    
    private final String action = "api/exchangerateuserconfig!";
 
    /**
     * 设置计价方式
     */
    @RequestMapping(action + "userSetRate.action")
    public Object userSetRate(HttpServletRequest request) throws IOException {
 
        ResultObject resultObject = new ResultObject();
        resultObject = readSecurityContextFromSession(resultObject);
        if (!"0".equals(resultObject.getCode())) {
            return resultObject;
        }
 
        String partyId = this.getLoginPartyId();
        try {
            String rateId = request.getParameter("rateId");
            if (StringUtils.isNullOrEmpty(rateId)) {
                throw new BusinessException("rateId is null");
            }
            this.userRateConfigService.update(rateId, partyId);
        } catch (BusinessException e) {
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            logger.error("error:", e);
        }
        return resultObject;
    }
 
    /**
     * 获取 汇率
     */
    @RequestMapping(action + "get.action")
    public Object get() throws IOException {
        ResultObject resultObject = new ResultObject();
 
        String partyId = this.getLoginPartyId();
        Map<String, Object> data = new HashMap<String, Object>();
        try {
            ExchangeRate exchangeRate = this.userRateConfigService.findUserConfig(partyId);
            data.put("currency", exchangeRate.getCurrency());
            data.put("name", exchangeRate.getName());
            data.put("currency_symbol", exchangeRate.getCurrency_symbol());
            data.put("rate", exchangeRate.getRata());
            resultObject.setData(data);
        } catch (BusinessException e) {
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            logger.error("error:", e);
        }
        return resultObject;
    }
    
}