admin
2022-04-07 e1cc0d03fadc2d251d36c0dc3650f75e830d5363
app/src/main/java/com/yeshi/makemoney/app/controller/admin/money/UserMoneyRecordAdminController.java
@@ -1,6 +1,7 @@
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;
@@ -15,9 +16,11 @@
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 {
@@ -26,10 +29,10 @@
    private UserMoneyRecordService userMoneyRecordService;
   @ResponseBody
    @ResponseBody
    @RequestMapping("list")
    public String list(UserMoneyRecordQuery query, int page, int limit, String callback ) {
        List<UserMoneyRecord> list = userMoneyRecordService.list(query,page,limit);
    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>() {
@@ -42,17 +45,18 @@
        data.put("list", gson.toJson(list));
        data.put("count", count);
        return JsonUtil.loadJSONP(callback,JsonUtil.loadTrueResult(data));
        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);
        Type type = new TypeToken<List<Long>>() {
        }.getType();
        List<Long> idList = new Gson().fromJson(ids, type);
        userMoneyRecordService.delete(idList);
        return JsonUtil.loadJSONP(callback,JsonUtil.loadTrueResult(""));
        return JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(""));
    }
@@ -61,16 +65,28 @@
    @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));
        if (entity != null) {
            return JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(entity));
        } else {
            return JsonUtil.loadJSONP(callback,JsonUtil.loadFalseResult("ID不存在"));
            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);
    }
}