Helius
2021-03-17 8f9e3814fd49efd763f06305ffbfff6d87012627
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
package com.matrix.system.hive.action;
 
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.*;
import com.matrix.core.tools.excl.ExcelSheetPO;
import com.matrix.core.tools.excl.ExcelUtil;
import com.matrix.core.tools.excl.ExcelVersion;
import com.matrix.system.common.bean.CustomerDataDictionary;
import com.matrix.system.common.bean.SystemDictionary;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.CustomerDataDictionaryDao;
import com.matrix.system.common.service.SystemDictionaryService;
import com.matrix.system.common.service.SysUsersService;
import com.matrix.system.common.tools.ResponseHeadUtil;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.constance.SystemConstance;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.MoneyCardUseDao;
import com.matrix.system.hive.dao.SysVipLabelDao;
import com.matrix.system.hive.dao.VipAnswerDao;
import com.matrix.core.tools.DateUtil;
import com.matrix.system.hive.pojo.RegisterInfo;
import com.matrix.system.hive.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException;
import java.util.*;
 
 
/**
 * @author jyy
 * @description 会员信息管理action
 * @date 2016-07-12
 */
@Controller
@RequestMapping(value = "admin/vipInfo")
public class VipInfoController extends BaseController {
    @Resource
    private SysVipInfoService vipInfoService;
 
    @Resource
    private SysVipLevelService vipLevelService;
 
    @Resource
    private SysUsersService shopstaffInfoService;
 
    @Autowired
    private VipAnswerDao vipAnswerDao;
    @Resource
    private QuestionSerivce questionSerivce;
    @Resource
    private MoneyCardUseService cardUseService;
 
    @Autowired
    private MoneyCardUseDao moneyCardUseDao;
 
    @Autowired
    private SysVipLabelDao sysVipLabelDao;
 
    @Autowired
    private SystemDictionaryService dataDictionaryService;
 
    @Autowired
    private CustomerDataDictionaryDao customerDataDictionaryDao;
    @Resource
    private SysOrderService sysOrderService;
 
 
    @RequestMapping(value = "/showVipLevel")
    public @ResponseBody
    AjaxResult findVipLevel() {
        // 会员卡等级信息
        List<SysVipLevel> vipLevels = vipLevelService.findByModel(null);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipLevels, 0);
    }
 
    /**
     * 显示所有的会员信息
     */
    @RequestMapping(value = "/showVipInfoList")
    public @ResponseBody
    AjaxResult showList(PaginationVO pageVo, SysVipInfo vipInfo) {
 
//        if (!getMe().getShopRole().equals(Dictionary.FLAG_YES_Y)) {
        vipInfo.setShopId(getMe().getShopId());
//        }
        return showList(vipInfoService, vipInfo, pageVo);
    }
 
    /**
     * 门店查看会员信息
     *
     * @author luoyuanhong
     * @date 2016-06-24
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/showVipInfo")
    public @ResponseBody
    AjaxResult findByModel(String keyWord) {
        LinkedList<SysVipInfo> userList = null;
        // 获取最近查询客户
        if (WebUtil.getSession().getAttribute(SystemConstance.HISTORY_CUSTOMER) == null) {
            userList = new LinkedList<SysVipInfo>();
            WebUtil.getSession().setAttribute(SystemConstance.HISTORY_CUSTOMER, userList);
        } else {
            userList = (LinkedList<SysVipInfo>) WebUtil.getSession().getAttribute(SystemConstance.HISTORY_CUSTOMER);
        }
        List<SysVipInfo> vips = vipInfoService.findByVipNoOrTel(keyWord);
        if (vips.size() > 0) {
            // 在session存放当前查询的客户
            vips.get(0).setSysOrder(sysOrderService.findSysOrderTjByVipId(vips.get(0).getId()));
            vips.get(0).setLevelCard(cardUseService.findByVipId(vips.get(0).getId()));
            WebUtil.getSession().setAttribute(SystemConstance.CURRENT_CUSTOMER, vips.get(0));
            // 满20后删除一个
            if (userList.size() == 20) {
                userList.poll();
            }
            // 去重标志
            boolean isNoRepeat = true;
            for (SysVipInfo sysVipInfo : userList) {
                if (vips.get(0).getPhone().equals(sysVipInfo.getPhone())) {
                    isNoRepeat = false;
                }
            }
            if (isNoRepeat) {
                userList.add(vips.get(0));
            }
            vips.get(0).setLabels(sysVipLabelDao.selectByVipId(vips.get(0).getId()));
            vips.get(0).setAge(DateUtil.getAgeForBirthDay(vips.get(0).getBirthday1()));
            vips.get(0).setBalance(moneyCardUseDao.selectVipCardTotalMoney(vips.get(0).getId()));
            AjaxResult result=  new AjaxResult(AjaxResult.STATUS_SUCCESS, vips, 0);
            return result;
        }else{
            return AjaxResult.buildFailInstance("未查到询客户信息");
        }
 
    }
 
 
    /**
     * 通过姓名或者电话号码
     */
    @RequestMapping(value = "/findUserByPhotoOrName")
    public @ResponseBody
    AjaxResult findUserByPhotoOrName(String keyWord) {
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipInfoService.findUserByKey(keyWord), 0);
    }
 
 
    /**
     * 添加或修改会员信息
     */
    @RequestMapping(value = "/addOrModify")
    @RemoveRequestToken
    public @ResponseBody
    AjaxResult addOrModify(SysVipInfo vipInfo) {
        if (vipInfo.getId() != null) {
 
            try {
                if (vipInfo.getPassWord() != null) {
                    vipInfo.setPassWord(EncrypUtil.getMD5(vipInfo.getPassWord()));
                }
            } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            return modify(vipInfoService, vipInfo, "会员信息");
        } else {
 
            try {
                if (StringUtils.isNotBlank(vipInfo.getPassWord())) {
                    vipInfo.setPassWord(EncrypUtil.getMD5(vipInfo.getPassWord()));
                }
                vipInfo.setVipState(Dictionary.VIP_STATE_HY);
            } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
            vipInfo.setShopId(users.getShopId());
            return add(vipInfoService, vipInfo, "会员信息");
        }
    }
 
 
    /**
     * 保存客户的
     *
     * @param vipInfo
     * @return
     */
    @RequestMapping(value = "/modifyVipArchives")
    public @ResponseBody
    AjaxResult modifyVipArchives(@RequestBody SysVipInfo vipInfo) {
        VipAnswer delAnswer = new VipAnswer();
        delAnswer.setVipId(vipInfo.getId());
        vipAnswerDao.deleteByModel(delAnswer);
        if (vipInfo.getVipAnswers() != null && vipInfo.getVipAnswers().size() > 0) {
            vipAnswerDao.batchInsert(vipInfo.getVipAnswers());
        }
        AjaxResult result = new AjaxResult();
        result.setStatus(AjaxResult.STATUS_SUCCESS);
        result.setInfo("档案更新成功");
        return result;
    }
 
 
    /**
     * 删除会员信息
     */
    @RequestMapping(value = "/del")
    public @ResponseBody
    AjaxResult del(String keys) {
 
        return remove(vipInfoService, keys);
    }
 
    /**
     * 弹出框,会员信息
     */
    @RequestMapping(value = "/editForm")
    @SaveRequestToken
    public String editForm(Long id, HttpServletRequest request) {
        SysVipInfo vipInfo;
        // 查询所有美疗师,由于是手动添加,因此不用框架中的下拉框方式
        List<SysUsers> mlslist = new ArrayList<SysUsers>();
 
        if (!getMe().getShopRole().equals(Dictionary.FLAG_YES_Y)) {
            mlslist = shopstaffInfoService.findByRoleName(true, Dictionary.STAFF_POST_MLS);
        } else {
            mlslist = shopstaffInfoService.findByRoleName(false, Dictionary.STAFF_POST_MLS);
        }
 
 
        request.setAttribute("mlslist", mlslist);
 
 
        // vip信息
        if (id != null) {
            vipInfo = vipInfoService.findById(id);
            request.setAttribute("obj", vipInfo);
        }
        return "admin/hive/vip/vipInfo-form";
    }
 
 
    @RequestMapping(value = "/getVipQuestions")
    public @ResponseBody
    AjaxResult getVipQuestions(Long id, HttpServletRequest request) {
        // 获取会员所有的答案,分类型
        List<Question> questions = questionSerivce.findByVipId(id);
        request.setAttribute("questions", questions);
        AjaxResult result = new AjaxResult();
        result.putInMap("questions", questions);
        result.setStatus(AjaxResult.STATUS_SUCCESS);
        return result;
    }
 
 
    /**
     * 编辑会员备注
     */
    @RequestMapping(value = "/editRemarkForm")
    @SaveRequestToken
    public String editRemarkForm(Long id, HttpServletRequest request) {
        SysVipInfo vipInfo;
        vipInfo = vipInfoService.findById(id);
        request.setAttribute("obj", vipInfo);
        return "admin/hive/vip/vipInfo-remark-form";
    }
 
 
    /**
     * 批量修改健康顾问
     */
    @RequestMapping(value = "/updateVipInfos")
    public @ResponseBody
    AjaxResult updateVipInfos(String ids, Long staffId) {
 
        int i = vipInfoService.updateStaffId(ids, staffId);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功修改" + i + "条数据!");
    }
 
    /**
     * 客户到访录入
     */
    @RequestMapping(value = "/toVisitInfo")
    public String toVisitInfo() {
        Long shopId = getMe().getShopId();
 
        SystemDictionary dataDictionary = new SystemDictionary();
        // 获取到店途径
        dataDictionary.setType("到店途径");
        WebUtil.getRequest().setAttribute("ddtj", dataDictionaryService.findByModel(dataDictionary));
        // 业务类型
        dataDictionary.setType("业务类型");
        WebUtil.getRequest().setAttribute("ywlx", dataDictionaryService.findByModel(dataDictionary));
        // 门店信息
        WebUtil.getRequest().setAttribute("shopNmae", getMe().getShopName());
        WebUtil.getRequest().setAttribute("staffName", getMe().getSuName());
        // 登录者门店的美疗师信息
        WebUtil.getRequest().setAttribute("mls", shopstaffInfoService.findByRoleName(true, Dictionary.STAFF_POST_MLS));
        return "admin/hive/mobile/CRM-visit";
    }
 
 
    /**
     * 钉钉点击注册
     */
    @RequestMapping(value = "/toRegister")
    public String toRegister() {
        SystemDictionary dataDictionary = new SystemDictionary();
        // 获取到店途径
        dataDictionary.setType("到店途径");
        WebUtil.getRequest().setAttribute("ddtj", customerDataDictionaryDao.selectByParentCode("DDTJ",getMe().getCompanyId()));
        // 获取生肖
        dataDictionary.setType("生肖");
        WebUtil.getRequest().setAttribute("sx", dataDictionaryService.findByModel(dataDictionary));
        // 获取星座
        dataDictionary.setType("星座");
        WebUtil.getRequest().setAttribute("xz", dataDictionaryService.findByModel(dataDictionary));
        // 获取
        // 获取会员等级
        WebUtil.getRequest().setAttribute("level", vipLevelService.findByModel(null));
        return "admin/hive/mobile/CRM-vip";
    }
 
    /**
     * 会员注册
     */
    @RequestMapping(value = "/registerVipInfo")
    public @ResponseBody
    AjaxResult register(RegisterInfo vipInfo) {
 
        vipInfo.setBirthday1(DateUtil.stringToDate(vipInfo.getVoBirthday(), "yyyy-MM-dd"));
        vipInfo.setVipState(Dictionary.VIP_STATE_HY);
        vipInfo.setStaffId(getMe().getSuId());
        vipInfo.setShopId(getMe().getShopId());
        vipInfo.setVipType(Dictionary.VIP_TYPE_NOCARD);
        vipInfoService.add(vipInfo);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "会员信息注册成功");
    }
 
 
    /**
     * 修改会员信息
     */
    @RequestMapping(value = "/modifyVip")
    public @ResponseBody
    AjaxResult modifyVip(SysVipInfo vipInfo) {
        return modify(vipInfoService, vipInfo, "会员");
    }
 
 
    /**
     * 通过电话号码模糊查询
     */
    @RequestMapping(value = "/findUserByPhoto")
    public @ResponseBody
    AjaxResult findUserByPhoto(String keyWord) {
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipInfoService.findUserByKey(keyWord), 0);
    }
 
    /**
     * 通过Id查询vip信息
     */
    @RequestMapping(value = "/findUserById")
    public @ResponseBody
    AjaxResult findUserById(Long id) {
        SysVipInfo vipInfo = vipInfoService.findById(id);
        vipInfo.setBalance(moneyCardUseDao.selectVipCardTotalMoney(id));
        vipInfo.setLevelCard(cardUseService.findByVipId(vipInfo.getId()));
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(vipInfo), 0);
    }
 
 
    /**
     * 查询会员等级
     */
    @RequestMapping(value = "/findVipLevel")
    public @ResponseBody
    AjaxResult findVipLevel(SysVipLevel sysVipLevel) {
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipLevelService.findByModel(sysVipLevel), 0);
    }
 
    /**
     * 通过电话号码精确查询
     */
    @RequestMapping(value = "/findUserPho")
    public @ResponseBody
    AjaxResult findUserPho(SysVipInfo info) {
        //System.out.println(info.getPhone());
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipInfoService.findByModel1(info), 0);
    }
 
    /**
     * 通过会员编号或者手机号查询会员
     */
    @RequestMapping(value = "/findUserByPhoneOrNo")
    public @ResponseBody
    AjaxResult findUserByPhoneOrNo(String keyWord) {
        LinkedList<SysVipInfo> userList = null;
        // 获取最近查询客户
        if (WebUtil.getSession().getAttribute(SystemConstance.HISTORY_CUSTOMER) == null) {
            userList = new LinkedList<SysVipInfo>();
            WebUtil.getSession().setAttribute(SystemConstance.HISTORY_CUSTOMER, userList);
        } else {
            userList = (LinkedList<SysVipInfo>) WebUtil.getSession().getAttribute(SystemConstance.HISTORY_CUSTOMER);
        }
        List<SysVipInfo> vips = vipInfoService.findByVipNoOrTel(keyWord);
        if (vips.size() > 0) {
            // 在session存放当前查询的客户
            WebUtil.getSession().setAttribute(SystemConstance.CURRENT_CUSTOMER, vips.get(0));
            // 满20后删除一个
            if (userList.size() == 20) {
                userList.poll();
            }
            // 去重标志
            boolean isNoRepeat = true;
            for (SysVipInfo sysVipInfo : userList) {
                if (vips.get(0).getPhone().equals(sysVipInfo.getPhone())) {
                    isNoRepeat = false;
                }
            }
            if (isNoRepeat) {
                userList.add(vips.get(0));
            }
        }
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vips, 0);
 
    }
 
    @RequestMapping(value = "/getBirthday")
    public @ResponseBody
    AjaxResult getBirthday(SysVipInfo info) {
        Calendar c = Calendar.getInstance();
        c.setTime(info.getBirthday1());
        //获取年份
        int year = c.get(Calendar.YEAR);
        //获取月份
        int month = c.get(Calendar.MONTH) + 1;
        //获取日
        int day = c.get(Calendar.DATE);
 
        //星座
        String xz = DateUtil.getConstellation(month, day);
 
 
        SysVipInfo vip = new SysVipInfo();
        vip.setConstell(xz);
        List<SysVipInfo> vipList = new ArrayList<SysVipInfo>();
        vipList.add(vip);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, vipList, 0);
    }
 
    @RequestMapping(value = "/exportExcel")
    public void report(ModelMap model, HttpServletRequest request, HttpServletResponse response,
                       SysVipInfo vipInfo) throws IOException {
 
        if (vipInfo.getVipType() != null && !(vipInfo.getVipType().equals(""))) {
            vipInfo.setVipType(URLDecoder.decode(vipInfo.getVipType(), "UTF-8"));
        }
        if (vipInfo.getVipName() != null && !"".equals(vipInfo.getVipName())) {
            vipInfo.setVipName(URLDecoder.decode(vipInfo.getVipName(), "UTF-8"));
        }
        if (vipInfo.getArrivalWay() != null && !"".equals(vipInfo.getArrivalWay())) {
            vipInfo.setArrivalWay(URLDecoder.decode(vipInfo.getArrivalWay(), "UTF-8"));
        }
        if (vipInfo.getVipState() != null && !"".equals(vipInfo.getVipState())) {
            vipInfo.setVipState(URLDecoder.decode(vipInfo.getVipState(), "UTF-8"));
        }
 
        List<ExcelSheetPO> res = new ArrayList<>();
        ExcelSheetPO orderSheet = new ExcelSheetPO();
        String title = "每日单据明细";
        orderSheet.setSheetName(title);
        orderSheet.setTitle(title);
        String[] header = {"会员编号", "姓名", "性别", "手机号码", "会员类型", "会员活跃度", "到店途径", "健康顾问", "所属门店"};
        orderSheet.setHeaders(header);
        QueryUtil.setQueryLimit(vipInfo);
        List<SysVipInfo> dataList = vipInfoService.findInPage(vipInfo, null);
        List<List<Object>> list = new ArrayList<>();
        if (dataList.size() > 0) {
            for (SysVipInfo item : dataList) {
                List<Object> temp = new ArrayList<>();
                temp.add(item.getVipNo());
                temp.add(item.getVipName());
                temp.add(item.getSex());
                temp.add(item.getPhone());
                temp.add(item.getVipType());
                temp.add(item.getVipState());
                temp.add(item.getArrivalWay());
                temp.add(item.getStaffName());
                temp.add(item.getShopName());
                list.add(temp);
            }
        }
        orderSheet.setDataList(list);
        res.add(orderSheet);
        response = ResponseHeadUtil.setExcelHead(response);
        response.setHeader("Content-Disposition",
                "attachment;filename=" + URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8"));
        OutputStream os = response.getOutputStream();
        ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
 
    }
 
    @RequestMapping(value = "/findAllVipInfo")
    @ResponseBody
    public AjaxResult findAllVipInfo() {
        return showList(vipInfoService, null, null);
    }
 
    @RequestMapping(value = "/findAllVipInfoWithShop")
    @ResponseBody
    public AjaxResult findAllVipInfoWithShop() {
        SysVipInfo info = new SysVipInfo();
        info.setShopId(getMe().getShopId());
        return showList(vipInfoService, info, null);
    }
 
    @RequestMapping(value = "/importVipInfo")
    @ResponseBody
    public AjaxResult importVipInfo(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
 
        String fileName = file.getOriginalFilename();
        String dirPath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH);
//        String dirPath = "C:/Users/wzy19/Desktop/zq";
        File fileDir = new File(dirPath);
        LogUtil.info("#----->{}#", fileDir.exists());
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
 
        File saveFile = new File(dirPath + "/" + fileName);
        file.transferTo(saveFile);
 
        int i = vipInfoService.importVipInfo(saveFile);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "导入成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "导入失败");
        }
    }
 
    @RequestMapping(value = "/toImportForm")
    public String toImportForm() {
        return "admin/hive/vip/vipImport-form";
    }
}