|  |  |  | 
|---|
|  |  |  | package com.matrix.system.hive.service.imp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import com.matrix.core.exception.GlobleException; | 
|---|
|  |  |  | import com.matrix.core.pojo.PaginationVO; | 
|---|
|  |  |  | import com.matrix.core.pojo.VerifyResult; | 
|---|
|  |  |  | import com.matrix.core.tools.*; | 
|---|
|  |  |  | import com.matrix.core.tools.DateUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.LogUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.core.tools.WebUtil; | 
|---|
|  |  |  | import com.matrix.system.app.dto.ServiceOrderListDto; | 
|---|
|  |  |  | import com.matrix.system.app.vo.ServiceOrderListVo; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.matrix.system.constance.Dictionary; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.*; | 
|---|
|  |  |  | import com.matrix.system.hive.dao.*; | 
|---|
|  |  |  | import com.matrix.core.tools.DateUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.plugin.util.MoneyUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.pojo.MyBeauticianCount; | 
|---|
|  |  |  | import com.matrix.system.hive.service.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; | 
|---|
|  |  |  | import com.matrix.system.wechart.templateMsg.UniformMsgParam; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public VerifyResult checkArrears(SysProjServices sysProjServices) { | 
|---|
|  |  |  | //检测欠款 | 
|---|
|  |  |  | /* for (SysBeauticianState sysBeauticianState : sysProjServices.getServiceItems()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检测欠款 | 
|---|
|  |  |  | for (SysBeauticianState sysBeauticianState : sysProjServices.getServiceItems()) { | 
|---|
|  |  |  | SysProjUse sysProjUse = projUseService.findById(sysBeauticianState.getPuseId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(sysProjUse.getProjId()); | 
|---|
|  |  |  | SysOrderItem orderItem = sysOrderItemService.findById(sysProjUse.getOrderItemId()); | 
|---|
|  |  |  | SysOrderItem item = sysOrderItemService.findById(sysProjUse.getOrderItemId()); | 
|---|
|  |  |  | SysOrder orderItem = sysOrderService.findById(item.getOrderId()); | 
|---|
|  |  |  | if ("购买".equals(sysProjUse.getSource())) { | 
|---|
|  |  |  | // 如果用户有欠款,服务单总价不能超过已付金额 | 
|---|
|  |  |  | if (orderItem!=null && orderItem.getArrears() > 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  | double money = MoneyUtil.sub((bj - orderItem.getArrears()), (yxfje + bcxfje)); | 
|---|
|  |  |  | // 如果 已付金额  - (已消费金额+本次消费金额)<0 则不能再消费 | 
|---|
|  |  |  | if (money < 0) { | 
|---|
|  |  |  | return new VerifyResult(true, shoppingGoods.getName() + "存在欠款" + orderItem.getArrears() + "元 , 订单编号[ " + sysOrderService.findById(orderItem.getOrderId()).getOrderNo() + " ] "); | 
|---|
|  |  |  | return new VerifyResult(true, shoppingGoods.getName() + "存在欠款" + orderItem.getArrears() + "元 , 订单编号[ " + orderItem.getOrderNo() + " ] "); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if ("赠送".equals(sysProjUse.getSource())) { | 
|---|
|  |  |  | if (orderItem!=null &&orderItem.getArrears() > 0) { | 
|---|
|  |  |  | return new VerifyResult(true, shoppingGoods.getName() + "存在欠款" + orderItem.getArrears() + "元 , 不能消费赠送项目,订单编号[ " + sysOrderService.findById(orderItem.getOrderId()).getOrderNo() + " ] "); | 
|---|
|  |  |  | return new VerifyResult(true, shoppingGoods.getName() + "存在欠款" + orderItem.getArrears() + "元 , 不能消费赠送项目,订单编号[ " + orderItem.getOrderNo() + " ] "); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new VerifyResult(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (beauticianStateDao.checkBeauticianClash(beauticianState) > 0) { | 
|---|
|  |  |  | throw new GlobleException("该美疗师已被占用,请重新分配!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            beauticianState.setExcTime(beauticianState.getProjInfo().getTimeLength()); | 
|---|
|  |  |  | beauticianState.setState(Dictionary.BEATUI_STATE_YYY); | 
|---|
|  |  |  | beauticianStateDao.update(beauticianState); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置成功状态 | 
|---|
|  |  |  | projServices.setState(Dictionary.SERVICE_STATU_YYCG); | 
|---|
|  |  |  | projServices.setState(Dictionary.SERVICE_STATU_XPL); | 
|---|
|  |  |  | // 判断当前门店是否有历史美疗师 | 
|---|
|  |  |  | LastestWorkBeatuistaff lastWorkStaff = new LastestWorkBeatuistaff(); | 
|---|
|  |  |  | lastWorkStaff.setShopId(checkProjServices.getShopId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | achieveNewService.addAchieveByServiceOrder(projServices); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //发送微信公众号提醒 | 
|---|
|  |  |  | UniformMsgParam uniformMsgParam=new UniformMsgParam(projServices.getCompanyId(),UniformMsgParam.GZH_FWWC); | 
|---|
|  |  |  | uniformMsgParam.put("serviceId",projServices.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int modifyPLProjServices(SysProjServices projServicesVo) throws GlobleException { | 
|---|
|  |  |  | SysProjServices projServices = sysProjServicesDao.selectById(projServicesVo.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | if (!projServices.getState().equals(Dictionary.SERVICE_STATU_XPL)) { | 
|---|
|  |  |  | throw new GlobleException("该服务单状态为" + projServices.getState() + ",不可以进行当前操作!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if(projServices.getDevisionId()!=null){ | 
|---|
|  |  |  | outStore.setStaffId(projServices.getDevisionId()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | outStore.setStaffId(sysUsers.getSuId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | outStore.setServiceId(projServices.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | double sum = stores.stream().mapToDouble(item2 -> item2.getStoreTotal()).sum(); | 
|---|
|  |  |  | Double needAmount = MoneyUtil.div(item.getAmount(), Double.valueOf(shoppingGoods.getVolume())); | 
|---|
|  |  |  | if (sum < needAmount) { | 
|---|
|  |  |  | throw new GlobleException("出库失败:【" + shoppingGoods.getName() + "库存不足】"); | 
|---|
|  |  |  | throw new GlobleException("出库失败:【" + shoppingGoods.getName()+"-"+shoppingGoods.getCode()+  "库存不足】"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //循环获取所有批次产品,并扣减库存 | 
|---|
|  |  |  | for (SysStoreInfo storeInfo : stores) { | 
|---|
|  |  |  | 
|---|
|  |  |  | sysOutStoreItem.setStoreId(storeInfo.getId()); | 
|---|
|  |  |  | sysOutStoreItem.setAmount(oldStoreTotal - storeInfo.getStoreTotal()); | 
|---|
|  |  |  | realOutStoreItemList.add(sysOutStoreItem); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | storeInfoDao.update(storeInfo); | 
|---|
|  |  |  | //扣除后剩余库存大于0则跳出扣除,否则剩余数量的负数的绝对值就是再次扣减的数量 | 
|---|
|  |  |  | if (surplus > 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  | LogUtil.debug("未选择配料跳过sku={},amount={}", item.getSkuId(), item.getAmount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sysOutStoreItemDao.batchInsert(realOutStoreItemList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 设置服务单状态 | 
|---|
|  |  |  | //        projServices.setState(Dictionary.SERVICE_STATU_PLWC); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(projServices.getDevisionId()==null){ | 
|---|
|  |  |  | //如果没有设置配料师则默认为操作配料的人为配料师 | 
|---|
|  |  |  | projServices.setDevisionId(sysUsers.getSuId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置服务单状态 | 
|---|
|  |  |  | projServices.setState(Dictionary.SERVICE_STATU_PLWC); | 
|---|
|  |  |  | // 设置服务单操作流水 | 
|---|
|  |  |  | // TODO 本功能待完善记录最新的排班员工 | 
|---|
|  |  |  | /*   List<LastestWorkBeatuistaff> lastList = LastestWorkBeatuistaffDao.selectByModel(null); | 
|---|
|  |  |  | LastestWorkBeatuistaff lastWork = new LastestWorkBeatuistaff(); | 
|---|
|  |  |  | if (lastList.size() > 0) { | 
|---|
|  |  |  | lastWork.setChangeDate(new Date()); | 
|---|
|  |  |  | lastWork.setStaffId(projServices.getBeauticianId()); | 
|---|
|  |  |  | LastestWorkBeatuistaffDao.insert(lastWork); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 有bug集合为零了 | 
|---|
|  |  |  | LastestWorkBeatuistaff modifyObj = lastList.get(0); | 
|---|
|  |  |  | modifyObj.setChangeDate(new Date()); | 
|---|
|  |  |  | modifyObj.setStaffId(projServices.getBeauticianId()); | 
|---|
|  |  |  | LastestWorkBeatuistaffDao.update(modifyObj); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断是否跳过开始/结束服务 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|