package com.matrix.system.shopXcx.api.action; import com.matrix.system.hive.bean.SysVipInfo; import com.matrix.system.hive.dao.SysVipInfoDao; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.redis.RedisUserLoginUtils; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.pojo.VerifyResult; import com.matrix.core.tools.DateUtil; import com.matrix.core.tools.StringUtils; import com.matrix.system.app.mapper.SysProjUseMapper; import com.matrix.system.app.vo.*; 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.util.CollectionUtils; import com.matrix.system.hive.service.*; import com.matrix.system.shopXcx.api.dto.ErpServiceCommentDto; import com.matrix.system.shopXcx.api.dto.ErpServiceOrderListDto; import com.matrix.system.shopXcx.api.vo.ErpServiceOrderListVo; import com.matrix.system.shopXcx.dao.ShopProductDao; import com.matrix.system.shopXcx.dao.ShopSkuDao; import com.matrix.system.shopXcx.dto.YYDayOfWeek; import com.matrix.system.shopXcx.dto.YYmonth; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; 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 vipInfoDao; @Autowired private OnlinebookingDao onlinebookingDao; @Autowired private SysProjServicesService projServicesService; @Autowired private SysProjServicesDao projServicesDao; @Autowired private SysBeauticianStateService sysBeauticianStateService; @Autowired RedisUserLoginUtils redisUserLoginUtils; @Autowired ShopProductDao productDao; @Autowired SysUsersDao staffInfoDao; @Autowired SysVipInfoDao sysVipInfoDao; @Autowired RabiitMqTemplate rabiitMqTemplate; @Autowired SysProjUseDao projUseDao; @Autowired ShopSkuDao skuDao; @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 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 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 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}") @ResponseBody public AjaxResult getUserPro(@PathVariable String phone) { SysVipInfo vipInfo = vipInfoDao.selectByPhone(phone); if (vipInfo == null) { throw new GlobleException("会员不存在"); } ServiceProductListVo productListVo = new ServiceProductListVo(); productListVo.setName(vipInfo.getVipName()); productListVo.setVipId(vipInfo.getId()); SysProjUse queryUse = new SysProjUse(); queryUse.setVipId(vipInfo.getId()); queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); queryUse.setTaocanId(-1L); queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX); queryUse.setIsOver(Dictionary.FLAG_NO_N); List projList = projUseService.findInPage(queryUse, null); List serviceProjVos = SysProjUseMapper.INSTANCE.entityListToProjVoList(projList); queryUse.setTaocanId(null); queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_TC); List taoCanList = projUseService.findInPage(queryUse, null); List serviceTcVos = SysProjUseMapper.INSTANCE.entityListToTcVoList(taoCanList); if (CollectionUtils.isNotEmpty(serviceTcVos)) { serviceTcVos.forEach(item -> { List sysProjUses = projUseService.selectTaocanProjUse(item.getId(), queryUse.getStatus()); List taocanProj = SysProjUseMapper.INSTANCE.entityListToProjVoList(sysProjUses); item.setProj(taocanProj); }); } productListVo.setProj(serviceProjVos); productListVo.setComposeProj(serviceTcVos); AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); ajaxResult.putInMap("proj", productListVo); return ajaxResult; } @Autowired private CodeService codeService; /** * 创建预约订单 * * @param onlinebooking * @return */ @RequestMapping(value = "/createServiceOrder") public @ResponseBody AjaxResult createServiceOrder(@RequestBody Onlinebooking onlinebooking) { SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); SysVipInfo vipInfo = vipInfoDao.selectByPhone(sysVipInfo.getPhone()); SysProjUse sysProjUse = projUseDao.selectById(Long.parseLong(onlinebooking.getProductId() + "")); Date yyTime = DateUtil.stringToDate(onlinebooking.getTimeStr(), DateUtil.DATE_FORMAT_MM); SysProjServices sysProjServices = new SysProjServices(); sysProjServices.setCompanyId(vipInfo.getCompanyId()); sysProjServices.setShopId(onlinebooking.getShopId()); sysProjServices.setVipId(vipInfo.getId()); sysProjServices.setYyTime(yyTime); sysProjServices.setRemark(onlinebooking.getRemark()); List sysBeauticianStates = new ArrayList<>(); SysBeauticianState sysBeauticianState = new SysBeauticianState(); sysBeauticianState.setPuseId(sysProjUse.getId()); sysBeauticianState.setProjUse(sysProjUse); sysBeauticianState.setCount(1); sysBeauticianState.setBeginTime(yyTime); int timeLength=30; if(sysProjUse.getTimeLength()!=null){ timeLength=sysProjUse.getTimeLength(); } sysBeauticianState.setEndTime(DateUtil.getDateAfterMinute(yyTime, timeLength)); if(onlinebooking.getStaffId()!=null){ sysBeauticianState.setStaffId(Long.parseLong(onlinebooking.getStaffId()+"")); } sysBeauticianStates.add(sysBeauticianState); sysProjServices.setServiceItems(sysBeauticianStates); //检测欠款 VerifyResult arrearsVerifyResult = projServicesService.checkArrears(sysProjServices); if (arrearsVerifyResult.isError()) { return new AjaxResult(AjaxResult.STATUS_FAIL, arrearsVerifyResult.getMsg()); } //检测余次 VerifyResult balanceverifyResult = projServicesService.checkBalance(sysProjServices); if (balanceverifyResult.isError()) { return new AjaxResult(AjaxResult.STATUS_FAIL, balanceverifyResult.getMsg()); } sysProjServices.setState(Dictionary.SERVICE_STATU_DQR); SysProjServices newSysProjServices = projServicesService.addSysProjServices(sysProjServices); if (newSysProjServices != null) { return AjaxResult.buildSuccessInstance("下单成功"); } else { return new AjaxResult(AjaxResult.STATUS_FAIL, "下单失败!"); } } /** * 根据id查询预约订单的详情 * * @param id * @return */ @ApiOperation(value = " 根据id查询预约订单的详情", notes = " 根据id查询预约订单的详情") @ApiResponses({ @ApiResponse(code = 200, message = "ok", response = ErpServiceOrderListVo.class) }) @RequestMapping(value = "/getServiceOrderById/{id}") public @ResponseBody AjaxResult getServiceOrderById(@PathVariable("id") Long id) { SysProjServices projServices = projServicesService.findById(id); if (projServices == null) { return AjaxResult.buildFailInstance("服务单不存在"); } ErpServiceOrderListVo serviceOrder = projServicesDao.findWxServiceOrderById(id); AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); ajaxResult.putInMap("detail", serviceOrder); return ajaxResult; } /** * 查询服务单 * @param orderListDto * @return */ @ApiOperation(value = "查询服务单列表", notes = "查询服务单列表") @ApiResponses({ @ApiResponse(code = 200, message = "ok", response = ErpServiceOrderListVo.class) }) @PostMapping(value = "/getServiceOrderList") @ResponseBody public AjaxResult findServiceOrderList(@RequestBody @Validated ErpServiceOrderListDto orderListDto) { SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); SysVipInfo vipInfo= vipInfoDao.selectByPhone(sysVipInfo.getPhone()); orderListDto.setVipId(vipInfo.getId()); List apiServiceOrderListInPage = projServicesDao.findWxServiceOrderList(orderListDto); return AjaxResult.buildSuccessInstance(apiServiceOrderListInPage,"查询成功"); } /** * 取消预约订单 * * @param * @return */ @ApiOperation(value = "取消预约", notes = "取消预约") @GetMapping(value = "/cancelOrderById/{id}") public @ResponseBody AjaxResult cancelOrderById(@PathVariable Long id) { SysProjServices services = new SysProjServices(); services.setId(id); int i = projServicesService.modifyCancelProjServices(services); if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, "取消预约成功"); } else { return new AjaxResult(AjaxResult.STATUS_FAIL, "取消预约失败"); } } @ApiOperation(value = "服务单评论", notes = "服务单评论") @PostMapping(value = "/commentService") public @ResponseBody AjaxResult commentService(@RequestBody @Validated ErpServiceCommentDto commentDto) { SysProjServices services = new SysProjServices(); services.setId(commentDto.getId()); services.setComment(commentDto.getComment()); int i = projServicesDao.update(services); if (i > 0) { return new AjaxResult(AjaxResult.STATUS_SUCCESS, "评论成功"); } else { return new AjaxResult(AjaxResult.STATUS_FAIL, "评论失败"); } } }