| package com.matrix.system.hiveErp.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.DateUtil; | 
| import com.matrix.core.tools.EncrypUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.core.tools.WebUtil; | 
| 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.SysUsers; | 
| import com.matrix.system.common.bean.SystemDictionary; | 
| import com.matrix.system.common.service.SysUsersService; | 
| import com.matrix.system.common.service.SystemDictionaryService; | 
| import com.matrix.system.common.tools.ResponseHeadUtil; | 
| import com.matrix.system.constance.Dictionary; | 
| import com.matrix.system.hive.action.BaseController; | 
| import com.matrix.system.hive.action.util.QueryUtil; | 
| import com.matrix.system.hive.bean.Question; | 
| import com.matrix.system.hive.bean.SysVipInfo; | 
| import com.matrix.system.hive.bean.SysVipLevel; | 
| import com.matrix.system.hive.bean.VipAnswer; | 
| import com.matrix.system.hive.dao.MoneyCardUseDao; | 
| import com.matrix.system.hive.dao.VipAnswerDao; | 
| import com.matrix.system.hive.pojo.RegisterInfo; | 
| import com.matrix.system.hive.service.MoneyCardUseService; | 
| import com.matrix.system.hive.service.QuestionSerivce; | 
| import com.matrix.system.hive.service.SysVipInfoService; | 
| import com.matrix.system.hive.service.SysVipLevelService; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.io.IOException; | 
| import java.io.OutputStream; | 
| import java.io.UnsupportedEncodingException; | 
| import java.net.URLEncoder; | 
| import java.security.NoSuchAlgorithmException; | 
| import java.util.ArrayList; | 
| import java.util.Arrays; | 
| import java.util.Calendar; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * @author jyy | 
|  * @description 会员信息管理action | 
|  * @date 2016-07-12 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "hiveErp/vipInfo") | 
| public class ErpVipInfoController extends BaseController { | 
|     @Resource | 
|     private SysVipInfoService vipInfoService; | 
|   | 
|     @Resource | 
|     private SysVipLevelService vipLevelService; | 
|   | 
|     @Resource | 
|     private SysUsersService shopstaffInfoService; | 
|   | 
|     @Autowired | 
|     private MoneyCardUseDao moneyCardUseDao; | 
|     @Autowired | 
|     private VipAnswerDao vipAnswerDao; | 
|     @Resource | 
|     private QuestionSerivce questionSerivce; | 
|     @Resource | 
|     private MoneyCardUseService cardUseService; | 
|     @Autowired | 
|     private SystemDictionaryService dataDictionaryService; | 
|   | 
|     @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) { | 
|   | 
|         QueryUtil.setQueryLimitCom(vipInfo); | 
|         List<SysVipInfo> dataList = vipInfoService.findInPage(vipInfo, pageVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, vipInfoService.findTotal(vipInfo)); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 门店查看会员信息 | 
|      * | 
|      * @author luoyuanhong | 
|      * @date 2016-06-24 | 
|      */ | 
|     @SuppressWarnings("unchecked") | 
|     @RequestMapping(value = "/showVipInfo") | 
|     public @ResponseBody | 
|     AjaxResult findByModel(String keyWord) { | 
|         List<SysVipInfo> vips = vipInfoService.findByVipNoOrTel(keyWord); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, vips, 0); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 通过姓名或者电话号码 | 
|      */ | 
|     @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(); | 
|             } | 
|             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) { | 
|         // 获取会员所有的答案,分类型 | 
|         SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); | 
|         List<Question> questions=questionSerivce.findByVipId(id,user.getCompanyId()); | 
|         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", dataDictionaryService.findByModel(dataDictionary)); | 
|         // 获取生肖 | 
|         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.setCompanyId(getMe().getCompanyId()); | 
|         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); | 
|     } | 
|   | 
|     /** | 
|      * 通过电话号码模糊查询 | 
|      */ | 
|     @RequestMapping(value = "/findUserById") | 
|     public @ResponseBody | 
|     AjaxResult findUserById(Long id) { | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(vipInfoService.findById(id)), 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) { | 
|         List<SysVipInfo> vips = vipInfoService.findByVipNoOrTel(keyWord); | 
|         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(HttpServletResponse response, | 
|                        SysVipInfo vipInfo) | 
|             throws IOException { | 
|   | 
|         QueryUtil.setQueryLimitCom(vipInfo ); | 
|   | 
|   | 
|         List<ExcelSheetPO> res = new ArrayList<>(); | 
|         ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|         String title = "会员资料"; | 
|         orderSheet.setSheetName(title); | 
|         orderSheet.setTitle(title); | 
|         String[] header = {"会员编号", "姓名", "性别", "手机号码", "会员类型", "会员活跃度", "到店途径", "健康顾问", "所属门店"}; | 
|         orderSheet.setHeaders(header); | 
|   | 
|         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); | 
|   | 
|     } | 
|   | 
| } |