admin
2021-09-17 a2c56bd6b79d2b8ca2c4c44a254ad2958fb72bca
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.ks.push.controller.admin;
 
import com.google.gson.*;
import com.ks.push.dao.BPushAppInfoDao;
import com.ks.push.pojo.DO.BPushAppInfo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
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 javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
 
@Controller
@RequestMapping("/admin/api/app")
public class AdminAppController {
 
    @Resource
    private BPushAppInfoDao bPushAppInfoDao;
 
    @ResponseBody
    @RequestMapping("list")
    public String list(String key, int page, int limit) {
        BPushAppInfoDao.DaoQuery daoQuery = new BPushAppInfoDao.DaoQuery();
        daoQuery.name = key;
        daoQuery.start = (page - 1) * limit;
        daoQuery.count = limit;
        List<BPushAppInfo> list = bPushAppInfoDao.list(daoQuery);
        long count = bPushAppInfoDao.count(daoQuery);
        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.loadTrueResult(data);
    }
 
    @ResponseBody
    @RequestMapping("delete")
    public String delete(String ids) {
        JSONArray array = JSONArray.fromObject(ids);
        for (int i = 0; i < array.size(); i++) {
            Query query = new Query();
            query.addCriteria(Criteria.where("appCode").is(array.optString(i)));
            bPushAppInfoDao.delete(query);
        }
        return JsonUtil.loadTrueResult("");
    }
 
 
    @ResponseBody
    @RequestMapping("update")
    public String update(BPushAppInfo app, HttpSession session) {
        if (app.getAppCode() == null) {
            return JsonUtil.loadFalseResult("ID不能为空");
        }
        bPushAppInfoDao.updateSelective(app);
        return JsonUtil.loadTrueResult("");
    }
 
 
    @ResponseBody
    @RequestMapping("add")
    public String add(BPushAppInfo app, HttpSession session) {
        if (app.getAppCode() == null) {
            return JsonUtil.loadFalseResult("appCode不能为空");
        }
        //查询是否存在
        BPushAppInfoDao.DaoQuery daoQuery = new BPushAppInfoDao.DaoQuery();
        daoQuery.appCode = app.getAppCode();
        if (bPushAppInfoDao.count(daoQuery) > 0) {
            return JsonUtil.loadFalseResult("appCode已经存在");
        }
        if (app.getCreateTime() == null) {
            app.setCreateTime(new Date());
        }
 
        bPushAppInfoDao.save(app);
        return JsonUtil.loadTrueResult("");
    }
 
 
}