|  |  | 
 |  |  | package com.matrix.system.hive.service.imp; | 
 |  |  |  | 
 |  |  | import cn.hutool.core.collection.CollUtil; | 
 |  |  | import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
 |  |  | import com.matrix.core.constance.MatrixConstance; | 
 |  |  | import com.matrix.core.exception.GlobleException; | 
 |  |  | 
 |  |  |             SysProjUse sysProjUse = projUseService.findById(sysBeauticianState.getPuseId()); | 
 |  |  |  | 
 |  |  |             ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(sysProjUse.getProjId()); | 
 |  |  |            SysOrderItem item = sysOrderItemService.findById(sysProjUse.getOrderItemId()); | 
 |  |  |            SysOrder orderItem = sysOrderService.findById(item.getOrderId()); | 
 |  |  |             SysOrderItem item = sysOrderItemService.findById(sysProjUse.getOrderItemId()); | 
 |  |  |             SysOrder orderItem = sysOrderService.findById(item.getOrderId()); | 
 |  |  |             if ("购买".equals(sysProjUse.getSource())) { | 
 |  |  |                 // 如果用户有欠款,服务单总价不能超过已付金额 | 
 |  |  |                 if (orderItem!=null && orderItem.getArrears() > 0) { | 
 |  |  | 
 |  |  |             if (beauticianStateDao.checkBeauticianClash(beauticianState) > 0) { | 
 |  |  |                 throw new GlobleException("该美疗师已被占用,请重新分配!"); | 
 |  |  |             } | 
 |  |  | //            beauticianState.setExcTime(beauticianState.getProjInfo().getTimeLength()); | 
 |  |  |             beauticianState.setState(Dictionary.BEATUI_STATE_YYY); | 
 |  |  |             beauticianStateDao.update(beauticianState); | 
 |  |  |  | 
 |  |  | 
 |  |  |         if (!projServices.getState().equals(Dictionary.SERVICE_STATU_FWWC)) { | 
 |  |  |             throw new GlobleException("该服务单状态为" + projServices.getState() + ",不可以进行当前操作!"); | 
 |  |  |         } else { | 
 |  |  |             SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
 |  |  |             if (skipServiceOrderStep(Dictionary.SERVICE_OVER_BEGIN_END)) { | 
 |  |  |                 SysBeauticianState checkBeauticianState = new SysBeauticianState(); | 
 |  |  |                 checkBeauticianState.setServicesId(projServices.getId()); | 
 |  |  |                 checkBeauticianState.setState(Dictionary.BEATUI_STATE_FWJS); | 
 |  |  |                 beauticianStateDao.chengItemState(checkBeauticianState); | 
 |  |  |  | 
 |  |  |                 // 释放床位资源 | 
 |  |  |                 SysBedState checkBedState = sysBedStateDao.selectBySerIdAndBedId(projServices.getId(), projServices.getBedId()); | 
 |  |  |                 if (checkBedState != null) { | 
 |  |  |                     checkBedState.setBedState(Dictionary.BED_STATE_SYJS); | 
 |  |  |                     bedStateDao.update(checkBedState); | 
 |  |  |                 } | 
 |  |  |                 projServices.setEndTime(new Date()); | 
 |  |  |                 // 计算时差 | 
 |  |  |                 long minspace = DateUtil.getDifTimeMin(projServices.getStartTime(), projServices.getEndTime()) - projServices.getTotalTime(); | 
 |  |  |                 // 判断是服务超时还是服务提前结束,如果minspace大于0则是超时服务,小于0则是提前结束服务 | 
 |  |  |                 projServices.setIsOverTime(minspace + ""); | 
 |  |  |                 projServices.setState(Dictionary.SERVICE_STATU_FWWC); | 
 |  |  |                 sysProjServicesDao.update(projServices); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             projServices.setState(Dictionary.SERVICE_STATU_FFJS); | 
 |  |  |             projServices.setConsumeTime(new Date()); | 
 |  |  |             int result=sysProjServicesDao.update(projServices); | 
 |  |  | 
 |  |  |         // 设置服务单状态 | 
 |  |  | //        projServices.setState(Dictionary.SERVICE_STATU_PLWC); | 
 |  |  |  | 
 |  |  |         projServices.setState(Dictionary.SERVICE_STATU_FWWC); | 
 |  |  |         if(projServices.getDevisionId()==null){ | 
 |  |  |             //如果没有设置配料师则默认为操作配料的人为配料师 | 
 |  |  |             projServices.setDevisionId(sysUsers.getSuId()); | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 判断是否跳过开始/结束服务 | 
 |  |  |         if (skipServiceOrderStep(Dictionary.SERVICE_OVER_BEGIN_END)) { | 
 |  |  |             projServices.setStartTime(new Date()); | 
 |  |  |             projServices.setState(Dictionary.SERVICE_STATU_FWWC); | 
 |  |  |         } | 
 |  |  |         // 释放床位资源 | 
 |  |  |         SysBedState checkBedState = sysBedStateDao.selectBySerIdAndBedId(projServices.getBedId(), projServices.getId()); | 
 |  |  |         if (checkBedState != null) { | 
 |  |  |             checkBedState.setBedState(Dictionary.BED_STATE_SYJS); | 
 |  |  |             bedStateDao.update(checkBedState); | 
 |  |  |         } | 
 |  |  |         projServices.setStartTime(new Date()); | 
 |  |  |         projServices.setEndTime(new Date()); | 
 |  |  |         // 计算时差 | 
 |  |  |         long minspace = DateUtil.getDifTimeMin(projServices.getStartTime(), projServices.getEndTime()) | 
 |  |  |                 - projServices.getTotalTime(); | 
 |  |  |         // 判断是服务超时还是服务提前结束,如果minspace大于0则是超时服务,小于0则是提前结束服务 | 
 |  |  |         projServices.setIsOverTime(minspace + ""); | 
 |  |  |         projServices.setState(Dictionary.SERVICE_STATU_FWWC); | 
 |  |  | //        SysBedState checkBedState = sysBedStateDao.selectBySerIdAndBedId(projServices.getBedId(), projServices.getId()); | 
 |  |  | //        if (checkBedState != null) { | 
 |  |  | //            checkBedState.setBedState(Dictionary.BED_STATE_SYJS); | 
 |  |  | //            bedStateDao.update(checkBedState); | 
 |  |  | //        } | 
 |  |  | //        projServices.setStartTime(new Date()); | 
 |  |  | //        projServices.setEndTime(new Date()); | 
 |  |  | //        // 计算时差 | 
 |  |  | //        long minspace = DateUtil.getDifTimeMin(projServices.getStartTime(), projServices.getEndTime()) | 
 |  |  | //                - projServices.getTotalTime(); | 
 |  |  | //        // 判断是服务超时还是服务提前结束,如果minspace大于0则是超时服务,小于0则是提前结束服务 | 
 |  |  | //        projServices.setIsOverTime(minspace + ""); | 
 |  |  | //        projServices.setState(Dictionary.SERVICE_STATU_FWWC); | 
 |  |  |         return sysProjServicesDao.update(projServices); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         SysBeauticianState checkBeauticianState = new SysBeauticianState(); | 
 |  |  |         checkBeauticianState.setServicesId(projServices.getId()); | 
 |  |  |         checkBeauticianState.setState(Dictionary.BEATUI_STATE_FWJS); | 
 |  |  |         checkBeauticianState.setStaffId(users.getSuId()); | 
 |  |  |         int rerunlt = beauticianStateDao.chengItemState(checkBeauticianState); | 
 |  |  |  | 
 |  |  |         // 验证是否是最后一个美疗师结束服务 | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return rerunlt; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |     public int findApiServiceOrderListTotal(ServiceOrderListDto serviceOrderListDto) { | 
 |  |  |         return sysProjServicesDao.selectApiServiceOrderListTotal(serviceOrderListDto); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 跳过服务单某步骤 | 
 |  |  |      */ | 
 |  |  |     private boolean skipServiceOrderStep(String step) { | 
 |  |  |         SysUsers users = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); | 
 |  |  |         ParameterSettings ps = new ParameterSettings(); | 
 |  |  |         ps.setCompanyId(users.getCompanyId()); | 
 |  |  |         ps.setCategory("店务配置"); | 
 |  |  |         List<ParameterSettings> settings = parameterSettingsDao.getByCategory(ps); | 
 |  |  |  | 
 |  |  |         boolean flag = false; | 
 |  |  |         if (CollUtil.isNotEmpty(settings)) { | 
 |  |  |             for (ParameterSettings setting : settings) { | 
 |  |  |                 if (step.equals(setting.getCode()) && Dictionary.FLAG_YES.equals(setting.getUserValue())) { | 
 |  |  |                     flag = true; | 
 |  |  |                     break; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return flag; | 
 |  |  |     } | 
 |  |  | } |