| | |
| | | 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.validation.BindingResult; |
| | | 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 javax.validation.constraints.NotEmpty; |
| | | import java.lang.reflect.Type; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | | @RequestMapping("/admin/api/app") |
| | | public class AdminAppController { |
| | | |
| | | @Resource |
| | | private BPushAppInfo adminUserManager; |
| | | private BPushAppInfoDao bPushAppInfoDao; |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String list(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, @NotEmpty(message = "验证码不能为空") String code, BindingResult bindingResult, HttpSession session) { |
| | | 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>() { |
| | | |
| | | return null; |
| | | @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(""); |
| | | } |
| | | |
| | | |