Administrator
2025-04-21 a217652d33c75df23202828000d82d0ca8555ac2
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
package com.taoke.autopay.controller.admin.credit;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.taoke.autopay.dao.credit.ExchangeRateMapper;
import com.taoke.autopay.entity.credit.ExchangeRate;
import com.taoke.autopay.service.credit.ExchangeRateService;
import com.taoke.autopay.utils.JsonUtil;
import com.taoke.autopay.utils.TimeUtil;
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 javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
@Controller
@RequestMapping("/admin/api/credit/exchangeRate")
public class CreditExchangeRateAdminController {
 
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
        @Override
        public void write(JsonWriter out, Date value) throws IOException {
            String desc = "";
            if (value != null) {
                // 判断是否是同一天
                desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
                out.value(desc);
            } else {
                out.value("");
            }
        }
 
        @Override
        public Date read(JsonReader in) throws IOException {
            return new Date();
        }
    }).registerTypeAdapter(BigDecimal.class, new TypeAdapter<BigDecimal>() {
        @Override
        public void write(JsonWriter out, BigDecimal value) throws IOException {
            if (value != null) {
                out.value(value.toString());
            } else {
                out.value("");
            }
        }
 
        @Override
        public BigDecimal read(JsonReader in) throws IOException {
            return new BigDecimal("0.00");
        }
    }).create();
 
    @Resource
    private ExchangeRateService exchangeRateService;
 
    /**
     * 获取积分汇率列表
     */
    @ResponseBody
    @RequestMapping("list")
    public String listExchangeRates(int page, int limit) {
        List<ExchangeRate> exchangeRates = exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder()
                        .start((long) (page - 1) * limit)
                        .count(limit)
                .build());
        long count = exchangeRateService.countExchangeRates(ExchangeRateMapper.DaoQuery.builder().build());
        JSONObject root=new JSONObject();
        root.put("list",gson.toJson(exchangeRates));
        root.put("count",count);
        return JsonUtil.loadTrueResult(root);
    }
 
    /**
     * 获取积分汇率详情
     */
    @ResponseBody
    @RequestMapping("getDetail")
    public String getDetail(Long id) {
        ExchangeRate exchangeRate = exchangeRateService.selectById(id);
        if (exchangeRate == null) {
            return JsonUtil.loadFalseResult("积分汇率不存在");
        }
        return JsonUtil.loadTrueResult(gson.toJson(exchangeRate));
    }
 
    /**
     * 更新积分汇率
     */
    @ResponseBody
    @RequestMapping("update")
    public String updateExchangeRate(ExchangeRate exchangeRate) {
        int success = exchangeRateService.updateExchangeRate(exchangeRate);
        if (success>0) {
            return JsonUtil.loadTrueResult("更新成功");
        } else {
            return JsonUtil.loadFalseResult("更新失败");
        }
    }
}