admin
2022-10-28 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff
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
package com.yeshi.makemoney.app.controller.admin.money;
 
import com.google.gson.*;
import com.yeshi.makemoney.app.entity.money.UserMoneyType;
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.money.UserMoneyRecord;
import com.yeshi.makemoney.app.service.inter.money.UserMoneyRecordService;
import com.yeshi.makemoney.app.service.query.money.UserMoneyRecordQuery;
 
@Controller
@RequestMapping("admin/api/money/record")
public class UserMoneyRecordAdminController {
 
    @Resource
    private UserMoneyRecordService userMoneyRecordService;
 
 
    @ResponseBody
    @RequestMapping("list")
    public String list(UserMoneyRecordQuery query, int page, int limit, String callback) {
        List<UserMoneyRecord> list = userMoneyRecordService.list(query, page, limit);
        long count = userMoneyRecordService.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"));
            }
        }).create();
 
        data.put("list", gson.toJson(list));
        data.put("count", count);
        return JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data));
 
    }
 
    @ResponseBody
    @RequestMapping("delete")
    public String delete(String ids, String callback) {
        Type type = new TypeToken<List<Long>>() {
        }.getType();
        List<Long> idList = new Gson().fromJson(ids, type);
        userMoneyRecordService.delete(idList);
        return JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(""));
 
    }
 
 
    @ResponseBody
    @RequestMapping("get")
    public String get(Long id, HttpSession session, String callback) {
        UserMoneyRecord entity = userMoneyRecordService.get(id);
        if (entity != null) {
            return JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(entity));
 
        } else {
            return JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("ID不存在"));
 
        }
    }
 
    @ResponseBody
    @RequestMapping("getMoneyTypes")
    public String getMoneyTypes() {
 
        JSONArray array = new JSONArray();
        for (UserMoneyType type : UserMoneyType.values()) {
            JSONObject data = new JSONObject();
            data.put("key", type.name());
            data.put("value", type.getName());
            array.add(data);
        }
        return JsonUtil.loadTrueResult(array);
    }
 
 
}