Administrator
2025-03-05 af0be3243ab0d75e38ae8213de461c4a584652f7
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.taoke.autopay.controller.admin;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.taoke.autopay.dao.WxUserInfoMapper;
import com.taoke.autopay.entity.AdminUser;
import com.taoke.autopay.entity.WxUserInfo;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.factory.WxUserFactory;
import com.taoke.autopay.service.AdminUserService;
import com.taoke.autopay.service.WxUserService;
import com.taoke.autopay.service.WxUserSettingService;
import com.taoke.autopay.utils.TimeUtil;
import com.taoke.autopay.vo.WxUserOrderSettingVO;
import com.taoke.autopay.vo.WxUserVO;
import net.sf.json.JSONObject;
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.NumberUtil;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.*;
 
@Controller
@RequestMapping("/admin/api/wxuser")
public class AdminWxUserController {
 
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
        @Override
        public void write(JsonWriter out, Date value) throws IOException {
            String desc = "";
            if (value != null) {
                // 判断是否是同一天
                desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
                out.value(desc);
            } else {
                out.value("");
            }
        }
 
        @Override
        public Date read(JsonReader in) throws IOException {
            return new Date();
        }
    }).create();
 
    @Resource
    private WxUserService wxUserService;
 
    @Resource
    private WxUserSettingService wxUserSettingService;
 
 
    /**
     * @param key
     * @param keyType 1-用户ID/昵称   2-地域
     * @param page
     * @param limit
     * @return
     */
 
    @ResponseBody
    @RequestMapping("list")
    public String listWxUser(String key, Integer keyType, int page, int limit) {
        //先查询所有的数据
        WxUserInfoMapper.DaoQuery query = new WxUserInfoMapper.DaoQuery();
        query.sortList = Arrays.asList(new String[]{"login_time desc"});
        if (keyType == null) {
            keyType = 1;
        }
        switch (keyType) {
            case 1:
                if (!StringUtil.isNullOrEmpty(key)) {
                    if (NumberUtil.isNumeric(key)) {
                        query.id = Long.parseLong(key);
                    } else {
                        query.searchKey = key;
                    }
                }
                break;
            case 2:
                if (!StringUtil.isNullOrEmpty(key)) {
                    query.searchArea = key;
                }
                break;
 
        }
 
        List<WxUserInfo> userList = wxUserService.list(query, page, limit);
        long count = wxUserService.count(query);
        Map<Long, WxUserSettings> settingsMap = new HashMap<>();
        if (userList.size() > 0) {
            List<Long> uids = new ArrayList<>();
            for (WxUserInfo u : userList) {
                uids.add(u.getId());
            }
            List<WxUserSettings> settings = wxUserSettingService.listByUids(uids);
            for (WxUserSettings setting : settings) {
                settingsMap.put(setting.getId(), setting);
            }
        }
 
        // 转vo
        List<WxUserVO> voList = new ArrayList<>();
        for (WxUserInfo user : userList) {
            voList.add(WxUserFactory.createVO(user, settingsMap.get(user.getId())));
        }
        JSONObject data = new JSONObject();
        data.put("count", count);
        data.put("list", gson.toJson(voList));
        return JsonUtil.loadTrueResult(data);
    }
 
    @ResponseBody
    @RequestMapping("getOrderSettings")
    public String getOrderSettings(Long id) {
        WxUserSettings settings = wxUserSettingService.getUserSettings(id);
        return JsonUtil.loadTrueResult(WxUserFactory.createVO(settings));
    }
 
    @ResponseBody
    @RequestMapping("updateOrderSettings")
    public String updateOrderSettings(WxUserOrderSettingVO vo) {
        WxUserSettings settings = new WxUserSettings();
        settings.setId(vo.getId());
        settings.setTotalOrderCountPerDay(vo.getTotalSubmitCount());
        settings.setDyOrderCountPerDay(vo.getDyPayCount());
        settings.setKsOrderCountPerDay(vo.getKsPayCount());
        wxUserSettingService.add(settings);
        return JsonUtil.loadTrueResult("");
    }
 
    @ResponseBody
    @RequestMapping("getUser")
    public String getUser(Long id) {
        WxUserInfo user = wxUserService.selectById(id);
        return JsonUtil.loadTrueResult(user);
    }
 
    @ResponseBody
    @RequestMapping("updateUser")
    public String updateUser(WxUserInfo user) {
        wxUserService.update(user);
        return JsonUtil.loadTrueResult("");
    }
 
 
}