admin
2021-04-07 35a29882f356542dd9c431714c64d277eb7cad40
src/main/java/com/yeshi/buwan/controller/admin/api/VipAdminController.java
@@ -1,12 +1,15 @@
package com.yeshi.buwan.controller.admin.api;
import com.google.gson.*;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.vip.UserVIPInfo;
import com.yeshi.buwan.domain.vip.VIPOrderRecord;
import com.yeshi.buwan.service.inter.LoginUserService;
import com.yeshi.buwan.service.inter.vip.VIPService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
import com.yeshi.buwan.vo.vip.UserVIPInfoVO;
import com.yeshi.buwan.web.tag.PageEntity;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
@@ -16,7 +19,9 @@
import org.yeshi.utils.JsonUtil;
import javax.annotation.Resource;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -27,9 +32,12 @@
    @Resource
    private VIPService vipService;
    @Resource
    private LoginUserService loginUserService;
    private Gson getGson() {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                if (value == null) {
@@ -46,7 +54,7 @@
    @ResponseBody
    @RequestMapping(value = "/vipUserList", method = RequestMethod.POST)
    public String vipUserList(Boolean vip,String uid, int page) {
    public void vipUserList(Boolean vip, String uid, int page, PrintWriter out) {
        Date minDate = null;
        Date maxDate = null;
        if (vip != null) {
@@ -57,19 +65,41 @@
                maxDate = new Date();
            }
        }
        List<UserVIPInfo> list = new ArrayList<>();
        long count = 0;
        if (!StringUtil.isNullOrEmpty(uid)) {
            UserVIPInfo vipInfo = vipService.getVIPInfo(uid);
            if (vipInfo != null) {
                list.add(vipInfo);
                count = 1;
            }
        } else {
            list = vipService.listVIPUser(minDate, maxDate, page, Constant.pageCount);
            count = vipService.countVIPUser(minDate, maxDate);
        }
        List<UserVIPInfo> list = vipService.listVIPUser(minDate, maxDate, page, Constant.pageCount);
        long count = vipService.countVIPUser(minDate, maxDate);
        List<UserVIPInfoVO> voList = new ArrayList<>();
        for (UserVIPInfo vipInfo : list) {
            UserVIPInfoVO vo = new UserVIPInfoVO();
            vo.setCreateTime(vipInfo.getCreateTime());
            vo.setExpireDate(vipInfo.getExpireDate());
            vo.setUpdateTime(vipInfo.getUpdateTime());
            LoginUser loginUser = loginUserService.getLoginUser(vipInfo.getUid());
            vo.setUser(loginUser);
            voList.add(vo);
        }
        JSONObject data = new JSONObject();
        data.put("pageEntity", new PageEntity(page, Constant.pageCount,(int)count));
        data.put("list", getGson().toJson(list));
        return JsonUtil.loadTrueResult(data);
        data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
        data.put("list", getGson().toJson(voList));
        out.print(JsonUtil.loadTrueResult(data));
    }
    @ResponseBody
    @RequestMapping(value = "/vipOrderList", method = RequestMethod.POST)
    public String vipOrderList(Boolean pay, String uid, int page) {
    public void vipOrderList(Boolean pay, String uid, int page, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(uid)) {
            uid = null;
        }
@@ -85,9 +115,9 @@
        List<VIPOrderRecord> list = vipService.listOrderRecord(uid, state, page, Constant.pageCount);
        long count = vipService.countOrderRecord(uid, state);
        JSONObject data = new JSONObject();
        data.put("pageEntity", new PageEntity(page, Constant.pageCount,(int)count));
        data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
        data.put("list", getGson().toJson(list));
        return JsonUtil.loadTrueResult(data);
        out.print(JsonUtil.loadTrueResult(data));
    }