mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.sinata.modular.member.controller;
 
import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sinata.common.enums.EnumCityRole;
import com.sinata.common.enums.EnumIsDelete;
import com.sinata.common.enums.EnumIsLock;
import com.sinata.common.enums.EnumMemberGrade;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.common.annotion.BussinessLog;
import com.sinata.core.common.annotion.Permission;
import com.sinata.core.common.constant.factory.PageFactory;
import com.sinata.core.shiro.ShiroKit;
import com.sinata.core.shiro.ShiroUser;
import com.sinata.core.util.Convert;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import com.sinata.modular.member.model.MemUser;
import com.sinata.modular.member.service.IMemUserService;
import com.sinata.modular.system.model.TCityRegion;
import com.sinata.modular.system.service.ITCityRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 会员用户信息控制器
 *
 * @author goku
 */
@Slf4j
@Controller
@RequestMapping("/memUser")
public class MemUserController extends BaseController {
 
    private String PREFIX = "/member/memUser/";
 
    @Autowired
    private IMemUserService memUserService;
 
    @Autowired
    private ITCityRegionService cityRegionService;
 
    /**
     * 跳转到会员用户信息首页
     */
    @RequestMapping("")
    public String index(Model model) {
        return PREFIX + "memUser.html";
    }
 
    /**
     * 获取会员用户信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String nickName, String phone, Integer isLock) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
 
        List<Map<String, Object>> list = wrapperList(page, beginTime, endTime, nickName, phone, isLock);
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    public List<Map<String, Object>> wrapperList(Page<Map<String, Object>> page, String beginTime, String endTime, String nickName, String phone, Integer isLock) {
        Wrapper wrapper = new EntityWrapper<MemUser>()
                .le("member_grade_id", EnumMemberGrade.G_2.index)
                .orderBy("o.id", false);
        wrapper.eq("o.is_delete", EnumIsDelete.EXISTED.index);
 
        if (!StringUtils.isEmpty(nickName)) {
            wrapper.like("nick_name", nickName);
        }
        if (!StringUtils.isEmpty(phone)) {
            wrapper.like("phone", phone);
        }
        if (!StringUtils.isEmpty(isLock) && isLock != -1) {
            wrapper.eq("o.is_lock", isLock);
        }
 
        // 时间搜索
        if (!StringUtils.isEmpty(beginTime)) {
            wrapper.ge("o.create_time", beginTime + " 00:00:00");
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.le("o.create_time", endTime + " 23:59:59");
        }
 
        try {
            // 【城市管理员】数据查询
            ShiroUser shiroUser = ShiroKit.getUser();
            if (shiroUser.getRoleList().contains(EnumCityRole.PROVINCE_ROLE.index)) {
                // 省级城市管理员
                wrapper.like("o.city_code", shiroUser.getCityCode().substring(0, 2), SqlLike.RIGHT);
            } else if (shiroUser.getRoleList().contains(EnumCityRole.CITY_ROLE.index)) {
                // 市级城市管理员
                wrapper.like("o.city_code", shiroUser.getCityCode().substring(0, 4), SqlLike.RIGHT);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        // 查询数据列表
        List<Map<String, Object>> list;
        if (page != null) {
            list = memUserService.getMapList(page, wrapper);
        } else {
            list = memUserService.getMapList(wrapper);
        }
 
        // 获取所有城市
        List<TCityRegion> cityAll = cityRegionService.getCityNameCodeAll();
 
        // 封装数据
        for (Map<String, Object> map : list) {
            map.put("cityCode",
                    cityRegionService.getProvinceCityCountyNameByAll(cityAll, Convert.toStr(map.get("city_code"))).stream()
                            .map(TCityRegion::getName)
                            .collect(Collectors.joining("-"))
            );
        }
        return list;
    }
 
    /**
     * 导出用户列表
     */
    @ResponseBody
    @RequestMapping(value = "/export")
    public void bonuSharesExport(String beginTime, String endTime, String nickName, String phone, Integer isLock, HttpServletResponse response) {
        List<Map<String, Object>> list = this.wrapperList(null, beginTime, endTime, nickName, phone, isLock);
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("注册时间");
        shellList.add("用户昵称");
        shellList.add("所在城市");
        shellList.add("性别");
        shellList.add("生日");
        shellList.add("联系电话");
        shellList.add("职级");
        shellList.add("积分");
        shellList.add("状态");
        dataList.add(shellList);
 
        // 详细数据列【封装】
        for (Map<String, Object> map : list) {
            shellList = new ArrayList<>();
            shellList.add(map.get("create_time"));
            shellList.add(map.get("nick_name"));
            shellList.add(map.get("cityCode"));
            shellList.add(map.get("sex"));
            shellList.add(map.get("birthday"));
            shellList.add(map.get("phone"));
            shellList.add(EnumMemberGrade.getMarkByIndex(Convert.toInt(map.get("member_grade_id"))));
            shellList.add(map.get("integral"));
            shellList.add(EnumIsLock.getMarkByIndex(Convert.toInt(map.get("is_lock"))));
            dataList.add(shellList);
        }
        try {
            String title = "用户信息";
            // 调用工具类进行导出
            ExcelExportUtil.easySheet(title + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), title, dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Permission
    @BussinessLog(value = "用户管理-冻结/解冻")
    @ResponseBody
    @RequestMapping(value = "/updateState")
    public Object updateState(String memUserIds, Integer state, String remark) {
        if (state.intValue() == 1) {
            memUserService.updateForSet("is_lock = " + state + ",remark='" + remark + "'", new EntityWrapper<MemUser>().in("id", memUserIds.split(",")));
 
        } else {
            memUserService.updateForSet("is_lock = " + state + ",remark=null", new EntityWrapper<MemUser>().in("id", memUserIds.split(",")));
 
        }
        return SUCCESS_TIP;
    }
 
 
    @RequestMapping("/getUserList")
    @ResponseBody
    public Object mallGoodsList() {
        Wrapper wrapper = new EntityWrapper<MemUser>().eq("is_delete", 0).orderBy("id", false);
 
        List<MemUser> userList =  memUserService.selectList(wrapper);
        List<HashMap<String, Object>> userMapList= userList.stream().map(user->{
            HashMap<String,Object> goodMap = new HashMap<>();
            //商品编号
            goodMap.put("showId",user.getShowId());
            goodMap.put("phone",user.getPhone());
            goodMap.put("nickName",user.getNickName());
            goodMap.put("id",user.getId());
            goodMap.put("agentLevel",user.getMemberGradeId());
            String agentLevelName ="";
            switch (user.getMemberGradeId()){
                case 2:
                    agentLevelName = "VIP会员";
                    break;
                case 3:
                    agentLevelName = "黄金营销员";
                    break;
                case 4:
                    agentLevelName = "城市合伙人";
                    break;
                case 5:
                    agentLevelName = "市场总监";
                    break;
                default:
                    agentLevelName = "普通会员";
                    break;
            }
            goodMap.put("agentLevelName",agentLevelName);
            return goodMap;
        }).collect(Collectors.toList());
        return  new HashMap<String, Object>(){{
            put( "code", 200);
            put( "value", userMapList);
        }};
    }
 
}