| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.matrix.biz.bean.BizUser; | 
| import com.matrix.biz.dao.BizUserDao; | 
| import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.common.dao.SysUsersDao; | 
| import com.matrix.system.common.interceptor.HostInterceptor; | 
| import com.matrix.system.common.tools.LocationUtil; | 
| import com.matrix.system.constance.Dictionary; | 
| import com.matrix.system.hive.bean.*; | 
| import com.matrix.system.hive.dao.*; | 
| import com.matrix.system.hive.plugin.message.StringUtil; | 
| import com.matrix.system.hive.plugin.util.CollectionUtils; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.system.hive.service.CodeService; | 
| import com.matrix.system.hive.service.SysProjUseService; | 
| import com.matrix.system.hive.service.SysWorkBeatuistaffService; | 
| import com.matrix.system.hive.service.SysWorktimeService; | 
| import com.matrix.system.shopXcx.bean.ShopProduct; | 
| import com.matrix.system.shopXcx.dao.ShopProductDao; | 
| import com.matrix.system.shopXcx.dto.YYDayOfWeek; | 
| import com.matrix.system.shopXcx.dto.YYmonth; | 
| import com.matrix.system.shopXcx.mqTask.DTO.UserProjInfo; | 
| import com.matrix.system.shopXcx.mqTask.MQTaskRouting; | 
| import com.matrix.system.shopXcx.shopEnum.TemplateMsgType; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.annotation.Resource; | 
| import java.math.BigDecimal; | 
| import java.util.*; | 
|   | 
| /** | 
|  * @author jiangyouyao | 
|  * @description 预约信息action | 
|  * @date 2019-06-06 10:15 | 
|  */ | 
| @CrossOrigin(origins = "*", maxAge = 3600) | 
| @Controller | 
| @RequestMapping(value = "wxapi/yuyue") | 
| public class YuyueAction { | 
|   | 
|     @Autowired | 
|     SysShopInfoDao shopInfoDao; | 
|   | 
|     @Autowired | 
|     private SysVipInfoDao vipDap; | 
|   | 
|     @Autowired | 
|     private OnlinebookingDao onlinebookingDao; | 
|   | 
|     @Autowired | 
|     RedisUserLoginUtils redisUserLoginUtils; | 
|   | 
|     @Autowired | 
|     ShopProductDao productDao; | 
|   | 
|     @Autowired | 
|     SysUsersDao staffInfoDao; | 
|   | 
|     @Autowired | 
|     BizUserDao bizUserDao; | 
|   | 
|     @Autowired | 
|     RabiitMqTemplate rabiitMqTemplate; | 
|   | 
|   | 
|   | 
|     @Autowired | 
|     ShoppingGoodsAssembleDao shoppingGoodsAssembleDao; | 
|   | 
|     @Autowired | 
|     ShoppingGoodsDao shoppingGoodsDao; | 
|   | 
|     @Value("${evn}") | 
|     private String evn; | 
|     /** | 
|      * 获取门店列表 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getShopList/{locX}/{locY}") | 
|     public @ResponseBody | 
|     AjaxResult getShopList(@PathVariable("locX") String locX, @PathVariable("locY") String locY) { | 
|         SysShopInfo sysShopInfo=new SysShopInfo(); | 
|         sysShopInfo.setIsOpenNet(SysShopInfo.OPEN_NET); | 
|         sysShopInfo.setCompanyId(HostInterceptor.getCompanyId()); | 
|         List<SysShopInfo> shopList = shopInfoDao.selectByModel(sysShopInfo); | 
|   | 
|         if ("X".equals(locX) || "Y".equals(locY)) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopList); | 
|         } | 
|   | 
|         Double distance = null; | 
|         SysShopInfo nearestShop = null; | 
|   | 
|         AjaxResult ajaxResult = new AjaxResult("200", shopList); | 
|         if (CollectionUtils.isNotEmpty(shopList)) { | 
|             for (SysShopInfo shopInfo : shopList) { | 
|                 Double shopX = Double.parseDouble(shopInfo.getLongitude()); | 
|                 Double shopY = Double.parseDouble(shopInfo.getLatitude()); | 
|                 Double disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY); | 
|                 shopInfo.setDistance(new BigDecimal(disResult).setScale(1, BigDecimal.ROUND_HALF_UP)); | 
|                 if (distance == null || distance > disResult) { | 
|                     distance = disResult; | 
|                     nearestShop = shopInfo; | 
|                 } | 
|             } | 
|         } | 
|         ajaxResult.putInMap("shopInfo", nearestShop); | 
|         return ajaxResult; | 
|   | 
|     } | 
|   | 
|     @RequestMapping(value = "/findShopInfoById/{id}") | 
|     @ResponseBody | 
|     public AjaxResult findShopInfoById(@PathVariable Long id) { | 
|         SysShopInfo shopInfo = shopInfoDao.selectById(id); | 
|         AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS,"获取成功"); | 
|         ajaxResult.putInMap("shopInfo", shopInfo); | 
|         return ajaxResult; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取预约时间表 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getTimeList") | 
|     public @ResponseBody | 
|     AjaxResult getTimeList() { | 
|         return new AjaxResult("200", YYmonth.buildMonth(3)); | 
|   | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取预约日期 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getYYDayAndWeek") | 
|     public @ResponseBody | 
|     AjaxResult getYYDayAndWeek(String time) { | 
|         Date date = DateUtil.stringToDate(time, DateUtil.DATE_FORMAT_DD); | 
|         List<YYDayOfWeek> yyDayOfWeeks = YYDayOfWeek.build(date, 4); | 
|         return new AjaxResult("200", yyDayOfWeeks); | 
|     } | 
|   | 
|   | 
|     @Resource | 
|     private SysWorkBeatuistaffService sysWorkBeatuistaffService; | 
|     @Resource | 
|     private com.matrix.system.common.service.SysUsersService SysUsersService; | 
|     @Autowired | 
|     private SysWorktimeService sysWorkTimeService; | 
|   | 
|     /** | 
|      * 查询空闲美疗师 | 
|      */ | 
|     @RequestMapping(value = "/getPaiBanBeauticianList") | 
|     public @ResponseBody | 
|     AjaxResult showPaiBanBeauticianList(@RequestBody SysBeauticianState sysBeauticianState) { | 
|         if(StringUtils.isNotBlank(sysBeauticianState.getBbeginTime())&& | 
|         StringUtils.isNotBlank(sysBeauticianState.getEendTime())){ | 
|             sysBeauticianState.setBeginTime(DateUtil.stringToDate(sysBeauticianState.getBbeginTime(), DateUtil.DATE_FORMAT_MM)); | 
|             sysBeauticianState.setEndTime(DateUtil.stringToDate(sysBeauticianState.getEendTime(), DateUtil.DATE_FORMAT_MM)); | 
|             String codes = DateUtil.dateToString(sysBeauticianState.getBeginTime(),DateUtil.DATE_FORMAT_NO_SPLITE_DD); | 
|             List<SysUsers> staffs = SysUsersService.findByCodeBeaStateShop(sysBeauticianState.getShopId(), | 
|                     sysBeauticianState, codes); | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, staffs); | 
|         }else{ | 
|             return  AjaxResult.buildSuccessInstance(""); | 
|         } | 
|   | 
|   | 
|     } | 
|   | 
|     @Resource | 
|     private SysProjUseService projUseService; | 
|   | 
|     /** | 
|      * 获取用户已购项目列表 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getUserPro/{phone}") | 
|     public @ResponseBody | 
|     AjaxResult getUserPro(@PathVariable String phone) { | 
|         SysVipInfo vipInfo = vipDap.selectByPhone(phone); | 
|         // 根据时间获取一段排班码 | 
|         Map<Object, Object> taocanProjMap = new HashMap<>(); | 
|         List<UserProjInfo> userProjInfoList = new ArrayList(); | 
|         SysProjUse sysProjUse = new SysProjUse(); | 
|         sysProjUse.setVipId(vipInfo.getId()); | 
|         sysProjUse.setIsOver(Dictionary.DELETED_N); | 
|         sysProjUse.setIsOver(Dictionary.DELETED_N); | 
|         sysProjUse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
|         // 查询出该会员的所有可消耗的选择 | 
|         List<SysProjUse> sysProjUseList = projUseService.findByModel(sysProjUse); | 
|         for (int i = 0; i < sysProjUseList.size(); i++) { | 
|             if (sysProjUseList.get(i).getTaocanId() != null) { | 
|                 String flag = sysProjUseList.get(i).getPlatformFlag(); | 
|                 if (taocanProjMap.keySet().contains(flag)) { | 
|                     ((UserProjInfo) taocanProjMap.get(flag)).getChildPro().add(coversion(sysProjUseList.get(i))); | 
|                 } else { | 
|                     SysProjUse pru = sysProjUseList.get(i); | 
|                     UserProjInfo taocan = new UserProjInfo(); | 
|                     taocan.setId(pru.getId()); | 
|                     taocan.setName(pru.getProjName()); | 
|                     taocan.setType(pru.getType()); | 
|                     if (pru.getSurplusCount() > 10000) { | 
|                         taocan.setSurplusCount("不限"); | 
|                     } else { | 
|                         taocan.setSurplusCount(pru.getSurplusCount() + ""); | 
|                     } | 
|                     taocan.setChildPro(new ArrayList<UserProjInfo>()); | 
|                     taocan.getChildPro().add(coversion(pru)); | 
|                     taocanProjMap.put(flag, taocan); | 
|                 } | 
|             } else { | 
|                 userProjInfoList.add(coversion(sysProjUseList.get(i))); | 
|             } | 
|         } | 
|         AjaxResult result = new AjaxResult(); | 
|         result.setStatus("200"); | 
|         result.setMapInfo(taocanProjMap); | 
|         result.setRows(userProjInfoList); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     @Autowired | 
|     private CodeService codeService; | 
|   | 
|     /** | 
|      * 创建预约订单 | 
|      * | 
|      * @param onlinebooking | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/createServiceOrder") | 
|     public @ResponseBody | 
|     AjaxResult createServiceOrder(@RequestBody Onlinebooking onlinebooking) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         bizUser = bizUserDao.findByOpenId(bizUser.getOpenId()); | 
|         SysVipInfo vipInfo = vipDap.selectByPhone(bizUser.getPhoneNumber()); | 
|         onlinebooking.setOrderNo(codeService.getServiceOrderCode()); | 
|         onlinebooking.setVipName(vipInfo.getVipName()); | 
|         onlinebooking.setVipId(vipInfo.getId()); | 
|         onlinebooking.setBizUserId(bizUser.getOpenId()); | 
|         onlinebooking.setStatus(Dictionary.ONLINEBOOKING_DFW); | 
|         onlinebooking.setCreateTime(new Date()); | 
|         onlinebooking.setTime(DateUtil.stringToDate(onlinebooking.getTimeStr(), DateUtil.DATE_FORMAT_MM)); | 
|         onlinebookingDao.insert(onlinebooking); | 
|         //发送消息通知 | 
|         JSONObject msg = new JSONObject(); | 
|         msg.put("templateMsgType", TemplateMsgType.APPOINTMENT_SUCCESS.getCode()); | 
|         msg.put("content", onlinebooking.getId()); | 
|         rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_TEMPLATE_MSG+evn, msg.toJSONString()); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, Collections.singletonList(onlinebooking)); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 根据id查询预约订单的详情 | 
|      * | 
|      * @param id | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getServiceOrderById/{id}") | 
|     public @ResponseBody | 
|     AjaxResult getServiceOrderById(@PathVariable Long id) { | 
|   | 
|         Onlinebooking onlinebooking = onlinebookingDao.selectById(id); | 
|         ShopProduct shopProduct = productDao.selectById(onlinebooking.getProductId()); | 
|         onlinebooking.setShopProduct(shopProduct); | 
|         if (onlinebooking.getStaffId() != null) { | 
|             SysUsers shopstaffInfo = staffInfoDao.selectById(Long.parseLong(onlinebooking.getStaffId() + "")); | 
|             onlinebooking.setStaffInfo(shopstaffInfo); | 
|         } | 
|         SysShopInfo shopInfo = shopInfoDao.selectById(onlinebooking.getShopId()); | 
|         onlinebooking.setShopInfo(shopInfo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "查询成功"); | 
|         result.putInMap("serviceOrder", onlinebooking); | 
|         return result; | 
|   | 
|     } | 
|   | 
|     /** | 
|      * 订单列表查询 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getServiceOrderList") | 
|     public @ResponseBody | 
|     AjaxResult getServiceOrderList(@RequestBody Onlinebooking onlinebooking) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         onlinebooking.setBizUserId(bizUser.getOpenId()); | 
|         List<Onlinebooking> list = onlinebookingDao.selectInPageForWx(onlinebooking); | 
|         //相关数据赋值 | 
|         list.stream().forEach(order -> { | 
|             ShopProduct shopProduct = productDao.selectById(order.getProductId()); | 
|             order.setShopProduct(shopProduct); | 
|             if (order.getStaffId() != null) { | 
|                 SysUsers shopstaffInfo = staffInfoDao.selectById(Long.parseLong(order.getStaffId() + "")); | 
|                 order.setStaffInfo(shopstaffInfo); | 
|             } | 
|             SysShopInfo shopInfo = shopInfoDao.selectById(order.getShopId()); | 
|             order.setShopInfo(shopInfo); | 
|         }); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "查询成功"); | 
|         result.setRows(list); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 取消预约订单 | 
|      * | 
|      * @param | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/cancelOrderById") | 
|     public @ResponseBody | 
|     AjaxResult cancelOrderById(@RequestBody Onlinebooking onlinebooking) { | 
|   | 
|         AjaxResult result = new AjaxResult(); | 
|         if (onlinebooking.getId() == null) { | 
|             result.setStatus(AjaxResult.STATUS_FAIL); | 
|             result.setInfo("请求参数错误"); | 
|         } else { | 
|             onlinebooking.setStatus(Dictionary.ONLINEBOOKING_YQX); | 
|             onlinebookingDao.update(onlinebooking); | 
|             result.setStatus(AjaxResult.STATUS_SUCCESS); | 
|             result.setInfo("订单取消成功"); | 
|         } | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 删除订单 | 
|      * | 
|      * @param | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/removeOrderById/{id}") | 
|     public @ResponseBody | 
|     AjaxResult removeOrderById(@PathVariable Long id) { | 
|         onlinebookingDao.deleteById(id); | 
|         AjaxResult result = new AjaxResult(); | 
|         result.setStatus(AjaxResult.STATUS_SUCCESS); | 
|         result.setInfo("删除成功"); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     private UserProjInfo coversion(SysProjUse pUse) { | 
|         UserProjInfo projInfo = new UserProjInfo(); | 
|         projInfo.setId(pUse.getId()); | 
|         projInfo.setName(shoppingGoodsDao.selectById(pUse.getProjId()).getName()); | 
|         projInfo.setSurplusCount(pUse.getSurplusCount() + ""); | 
|         projInfo.setType(pUse.getType()); | 
|         return projInfo; | 
|     } | 
|   | 
|   | 
|     private int dateToCodeInt(Date date) { | 
|         return Integer.parseInt(DateUtil.dateToString(date, DateUtil.HHmm)); | 
|     } | 
|   | 
|   | 
| } |