admin
2022-04-07 e1cc0d03fadc2d251d36c0dc3650f75e830d5363
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.yeshi.makemoney.app.controller.admin.goldcorn;
 
import com.google.gson.*;
import com.yeshi.makemoney.app.aop.AdminApiFilter;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
import com.yeshi.makemoney.app.vo.AcceptAdminData;
import com.yeshi.makemoney.app.vo.admin.goldcorn.GoldCornGetFrequencyAdminVO;
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.TimeUtil;
import com.google.gson.reflect.TypeToken;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
 
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetFrequencyConfig;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetFrequencyConfigService;
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetFrequencyConfigQuery;
 
@Controller
@RequestMapping("admin/api/goldcorn/getfrequency")
public class GoldCornGetFrequencyConfigAdminController {
 
    @Resource
    private GoldCornGetFrequencyConfigService goldCornGetFrequencyConfigService;
 
 
    @ResponseBody
    @RequestMapping("list")
    public String list(GoldCornGetFrequencyConfigQuery query, int page, int limit) {
        List<GoldCornGetFrequencyConfig> list = goldCornGetFrequencyConfigService.list(query, page, limit);
        long count = goldCornGetFrequencyConfigService.count(query);
        JSONObject data = new JSONObject();
        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
 
            @Override
            public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
                return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm"));
            }
        }).registerTypeAdapter(GoldCornGetType.class, new JsonSerializer<GoldCornGetType>() {
 
            @Override
            public JsonElement serialize(GoldCornGetType date, Type type, JsonSerializationContext jsonSerializationContext) {
                return date == null ? new JsonPrimitive("") : new JsonPrimitive(date.getName());
            }
        }).registerTypeAdapter(GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.class, new JsonSerializer<GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit>() {
 
            @Override
            public JsonElement serialize(GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit date, Type type, JsonSerializationContext jsonSerializationContext) {
                return date == null ? new JsonPrimitive("") : new JsonPrimitive(date.getName());
            }
        }).create();
 
        data.put("list", gson.toJson(list));
        data.put("count", count);
        return JsonUtil.loadTrueResult(data);
 
    }
 
    @ResponseBody
    @RequestMapping("delete")
    public String delete(String ids) {
        Type type = new TypeToken<List<String>>() {
        }.getType();
        List<String> idList = new Gson().fromJson(ids, type);
        goldCornGetFrequencyConfigService.delete(idList);
        return JsonUtil.loadTrueResult("");
    }
 
    @ResponseBody
    @RequestMapping("add")
    public String add(GoldCornGetFrequencyAdminVO vo, AcceptAdminData acceptAdminData) {
        try {
            goldCornGetFrequencyConfigService.add(vo.toEntity(acceptAdminData.getSystem()));
            return JsonUtil.loadTrueResult("");
        } catch (Exception e) {
            return JsonUtil.loadFalseResult(e.getMessage());
 
        }
    }
 
    @ResponseBody
    @RequestMapping("get")
    public String get(String id, HttpSession session) {
        GoldCornGetFrequencyConfig entity = goldCornGetFrequencyConfigService.get(id);
        if (entity != null) {
            return JsonUtil.loadTrueResult(GoldCornGetFrequencyAdminVO.create(entity));
 
        } else {
            return JsonUtil.loadFalseResult("ID不存在");
 
        }
    }
 
 
    @ResponseBody
    @RequestMapping("update")
    public String update(GoldCornGetFrequencyAdminVO vo, HttpSession session) {
        if (vo.getId() == null) {
            return JsonUtil.loadFalseResult("ID不能为空");
 
        }
        try {
            goldCornGetFrequencyConfigService.update(vo.toEntity(null));
        } catch (Exception e) {
            return JsonUtil.loadFalseResult(e.getMessage());
 
        }
        return JsonUtil.loadTrueResult("");
 
    }
 
 
    @ResponseBody
    @RequestMapping("getTimeUnits")
    public String getTimeUnits() {
        JSONArray array = new JSONArray();
        for (GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit unit : GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.values()) {
            JSONObject data = new JSONObject();
            data.put("key", unit.name());
            data.put("value", unit.getName());
            array.add(data);
        }
        return JsonUtil.loadTrueResult(array);
    }
 
 
}