admin
2022-05-19 a44f2c3b5db92069ea2813ecf8cb12a6ab3b2203
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
package com.yeshi.makemoney.app.controller.admin.goldcorn;
 
import com.google.gson.*;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType;
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.BigDecimalUtil;
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.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
 
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornConsumeRecordService;
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornConsumeRecordQuery;
 
@Controller
@RequestMapping("admin/api/goldcorn/consume/record")
public class GoldCornConsumeRecordAdminController {
 
    @Resource
    private GoldCornConsumeRecordService goldCornConsumeRecordService;
 
    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();
 
    @ResponseBody
    @RequestMapping("list")
    public String list(GoldCornConsumeRecordQuery query, int page, int limit) {
        List<GoldCornConsumeRecord> list = goldCornConsumeRecordService.list(query, page, limit);
        long count = goldCornConsumeRecordService.count(query);
        JSONObject data = new JSONObject();
        JSONArray array = JSONArray.fromObject(gson.toJson(list));
        for (int i = 0; i < array.size(); i++) {
            array.optJSONObject(i).put("money", new BigDecimal(array.optJSONObject(i).optLong("money")).divide(new BigDecimal(100), 2, RoundingMode.FLOOR));
        }
 
        data.put("list", array);
        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);
        goldCornConsumeRecordService.delete(idList);
        return JsonUtil.loadTrueResult("");
    }
 
 
    @ResponseBody
    @RequestMapping("get")
    public String get(String id, HttpSession session) {
        GoldCornConsumeRecord entity = goldCornConsumeRecordService.get(id);
        if (entity != null) {
            return JsonUtil.loadTrueResult(entity);
 
        } else {
            return JsonUtil.loadFalseResult("ID不存在");
 
        }
    }
 
    @ResponseBody
    @RequestMapping("getTypeList")
    public String getTypeList(String id, HttpSession session) {
        JSONArray array = new JSONArray();
        for (GoldCornConsumeType type : GoldCornConsumeType.values()) {
            JSONObject data = new JSONObject();
            data.put("key", type.name());
            data.put("value", type.getName());
            array.add(data);
        }
        return JsonUtil.loadTrueResult(array);
    }
 
 
}