| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.DateUtil; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.core.tools.*; |
| | | 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.common.dao.SysUsersDao; |
| | | 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.DateUtils; |
| | | 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 org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private SysOrderService sysOrderService; |
| | | @Autowired |
| | | WarehouseDao warehouseDao; |
| | | @Resource |
| | | private ShoppingGoodsService shoppingGoodsService; |
| | | |
| | | @Autowired |
| | | private RabiitMqTemplate rabiitMqTemplate; |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | |
| | | |
| | | /** |
| | | * 新增服务单 jyy |
| | |
| | | sysProjServices.setServiceNo(codeService.getServiceOrderCode()); |
| | | Double hkPrice = 0.0; |
| | | int i = sysProjServicesDao.insert(sysProjServices); |
| | | |
| | | // 计算项目总时长 |
| | | int totalTime = 0; |
| | | //处理订单明细 |
| | |
| | | //本次消费金额 |
| | | Double bcxfje = MoneyUtil.mul(sysProjUse.getPrice(), Double.valueOf(sysBeauticianState.getCount())); |
| | | upProjUse.setBalance(MoneyUtil.sub(sysProjUse.getBalance(), bcxfje)); |
| | | |
| | | // 判断是否第一次使用该项目, 若是则根据商品消耗有效期更新到期时间 |
| | | List<SysBeauticianState> sysBeauticianStates = beauticianStateDao.selectBeauticianStateByPuseIdAndNoStatus(sysBeauticianState.getPuseId(), Dictionary.SERVICE_STATU_YYQX); |
| | | if (CollectionUtils.isEmpty(sysBeauticianStates)) { |
| | | Date useInvalidTime = shoppingGoodsService.calInvalidTime(sysProjInfo, 2, sysProjUse.getFailTime()); |
| | | upProjUse.setFailTime(useInvalidTime); |
| | | } |
| | | |
| | | //更新余次信息 |
| | | sysProjUseDao.updateSurplusCount(upProjUse); |
| | | //如果项目是套餐 中项目则判断套餐是否失效 |
| | |
| | | taocan.setSurplusCount(0); |
| | | taocan.setStatus(Dictionary.TAOCAN_STATUS_WX); |
| | | } else if (Dictionary.FLAG_YES_Y.equals(taocan.getIsCourse())) { |
| | | //任选套餐检查套餐整体剩余次数 |
| | | int tcSurplusCount = taocan.getSurplusCount() - sysProjUse.getDeductionNum(); |
| | | if (tcSurplusCount < 0) { |
| | | throw new GlobleException(taocan.getProjName() + "已经达到最大使用次数"); |
| | | } else { |
| | | taocan.setSurplusCount(tcSurplusCount); |
| | | if (StringUtils.isBlank(taocan.getIsInfinite()) || Dictionary.FLAG_NO_N.equals(taocan.getIsInfinite())) { |
| | | //任选套餐检查套餐整体剩余次数 |
| | | int tcSurplusCount = taocan.getSurplusCount() - sysBeauticianState.getCount(); |
| | | if (tcSurplusCount < 0) { |
| | | throw new GlobleException(taocan.getProjName() + "已经达到最大使用次数"); |
| | | } else { |
| | | taocan.setSurplusCount(tcSurplusCount); |
| | | } |
| | | |
| | | if (tcSurplusCount == 0) { |
| | | taocan.setIsOver(Dictionary.FLAG_YES_Y); |
| | | taocan.setStatus(Dictionary.TAOCAN_STATUS_WX); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 根据套餐内所有项目查询该套餐是否第一次使用,若第一次使用则更新该套餐有效期 |
| | | List<SysBeauticianState> taocanHas = beauticianStateDao.selectByProjUse(taocanProjUses, Dictionary.SERVICE_STATU_YYQX); |
| | | if (CollectionUtils.isEmpty(taocanHas)) { |
| | | ShoppingGoods taocanInfo = shoppingGoodsDao.selectById(taocan.getProjId()); |
| | | Date useInvalidTime = shoppingGoodsService.calInvalidTime(taocanInfo, 2, sysProjUse.getFailTime()); |
| | | taocan.setFailTime(useInvalidTime); |
| | | } |
| | | sysProjUseDao.updateSurplusCount(taocan); |
| | | } |
| | |
| | | // 验证床位排班时间是否正确 |
| | | |
| | | SysBedState sysBedState = projServices.getBedState(); |
| | | sysBedState.setEndTime(DateUtils.getNextNMinute(sysBedState.getStartTime(), projServices.getTotalTime())); |
| | | sysBedState.setEndTime(DateUtil.getNextNMinute(sysBedState.getStartTime(), projServices.getTotalTime())); |
| | | sysBedState.setBedId(projServices.getBedId()); |
| | | sysBedState.setServiceId((projServices.getId())); |
| | | sysBedState.setBedState(Dictionary.BED_STATE_SYZ); |
| | | |
| | | for (SysBeauticianState beauticianState : projServices.getServiceItems()) { |
| | | if (DateUtils.isAffterDate(beauticianState.getEndTime(), beauticianState.getBeginTime())) { |
| | | if (DateUtil.isAffterDate(beauticianState.getEndTime(), beauticianState.getBeginTime())) { |
| | | throw new GlobleException("美疗师的排班结束时间不能晚于美疗师排班的开始时间!"); |
| | | } |
| | | } |
| | |
| | | */ |
| | | private void backProjCount(SysProjServices projServices) { |
| | | List<SysBeauticianState> beauticianStateList = beauticianStateDao.selectBySerIds(projServices.getId()); |
| | | |
| | | Map<Long ,List<SysProjUse>> taocanMap = new HashMap<>(); |
| | | // 回退项目余额 |
| | | for (SysBeauticianState beauticianState : beauticianStateList) { |
| | | // 该修改为 有效日期判断更新所有 |
| | | beauticianState.setState(Dictionary.BEATUI_STATE_YYQX); |
| | | beauticianStateDao.update(beauticianState); |
| | | |
| | | SysProjUse sysProjUse = sysProjUseDao.selectById(beauticianState.getPuseId()); |
| | | if (sysProjUse != null && sysProjUse.getId() != null) { |
| | | sysProjUse = sysProjUseDao.selectById(sysProjUse.getId()); |
| | |
| | | upProjUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); |
| | | if (sysProjUse.getTaocanId() != null) { |
| | | //TODO 更新套餐状态为有效 |
| | | SysProjUse taocanProjUse = sysProjUseDao.selectById(sysProjUse.getTaocanId()); |
| | | taocanProjUse.setIsOver(Dictionary.DELETED_N); |
| | | taocanProjUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); |
| | | |
| | | if (Dictionary.FLAG_YES_Y.equals(taocanProjUse.getIsCourse())) { |
| | | if (StringUtils.isBlank(taocanProjUse.getIsInfinite()) || Dictionary.FLAG_NO_N.equals(taocanProjUse.getIsInfinite())) { |
| | | taocanProjUse.setSurplusCount(taocanProjUse.getSurplusCount() + beauticianState.getCount()); |
| | | } |
| | | } |
| | | sysProjUseDao.update(taocanProjUse); |
| | | } |
| | | } |
| | | int surplus = sysProjUse.getSurplusCount() + beauticianState.getCount(); |
| | | upProjUse.setSurplusCount(surplus); |
| | | upProjUse.setBalance(MoneyUtil.add(sysProjUse.getBalance(), sysProjUse.getPrice())); |
| | | |
| | | // 取消时,判断该项目之前是否有使用过,若使用过则非第一次使用,则不更新有效日期,若未使用表明此次为第一次使用,则更新有效日期为购买日期或统一失效日期 |
| | | List<SysBeauticianState> hasBeautician = beauticianStateDao.selectBeauticianStateByPuseIdAndNoStatus(beauticianState.getPuseId(), Dictionary.BEATUI_STATE_YYQX); |
| | | if (hasBeautician.isEmpty()) { |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(beauticianState.getProjId()); |
| | | Date useInvalidTime = shoppingGoodsService.calInvalidTime(shoppingGoods, 1, null); |
| | | upProjUse.setFailTime(useInvalidTime); |
| | | } |
| | | |
| | | if (sysProjUse.getTaocanId() != null) { |
| | | List<SysProjUse> sysProjUses = taocanMap.get(sysProjUse.getTaocanId()); |
| | | if (CollectionUtils.isEmpty(sysProjUses)) { |
| | | List<SysProjUse> taocanItems = new ArrayList<>(); |
| | | taocanItems.add(sysProjUse); |
| | | taocanMap.put(sysProjUse.getTaocanId(), taocanItems); |
| | | } else { |
| | | sysProjUses.add(sysProjUse); |
| | | taocanMap.put(sysProjUse.getTaocanId(), sysProjUses); |
| | | } |
| | | } |
| | | sysProjUseDao.updateSurplusCount(upProjUse); |
| | | } |
| | | } |
| | | |
| | | if (taocanMap.size() != 0) { |
| | | for (Map.Entry<Long, List<SysProjUse>> entry : taocanMap.entrySet()) { |
| | | List<SysBeauticianState> taocanUse = beauticianStateDao.selectByProjUse(entry.getValue(), Dictionary.BEATUI_STATE_YYQX); |
| | | if (CollectionUtils.isEmpty(taocanUse)) { |
| | | SysProjUse taocan = sysProjUseDao.selectById(entry.getKey()); |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(taocan.getProjId()); |
| | | Date buyInvalidDate = shoppingGoodsService.calInvalidTime(shoppingGoods, 1, null); |
| | | taocan.setFailTime(buyInvalidDate); |
| | | |
| | | sysProjUseDao.update(taocan); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (!projServices.getState().equals(Dictionary.SERVICE_STATU_FWWC)) { |
| | | throw new GlobleException("该服务单状态为" + projServices.getState() + ",不可以进行当前操作!"); |
| | | } else { |
| | | |
| | | projServices.setState(Dictionary.SERVICE_STATU_FFJS); |
| | | projServices.setConsumeTime(new Date()); |
| | | return sysProjServicesDao.update(projServices); |
| | | int result=sysProjServicesDao.update(projServices); |
| | | //发送微信公众号提醒 |
| | | JSONObject param=new JSONObject(); |
| | | param.put("companyId",projServices.getCompanyId()); |
| | | param.put("serviceId",projServices.getId()); |
| | | rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,param.toJSONString()); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | checkprojServices.setEndTime(new Date()); |
| | | // 计算时差 |
| | | long minspace = DateUtils.getDifTimeMin(checkprojServices.getStartTime(), checkprojServices.getEndTime()) |
| | | long minspace = DateUtil.getDifTimeMin(checkprojServices.getStartTime(), checkprojServices.getEndTime()) |
| | | - checkprojServices.getTotalTime(); |
| | | // 判断是服务超时还是服务提前结束,如果minspace大于0则是超时服务,小于0则是提前结束服务 |
| | | checkprojServices.setIsOverTime(minspace + ""); |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ServiceOrderListVo> findApiServiceOrderListInPage(ServiceOrderListDto serviceOrderListDto, PaginationVO pageVo) { |
| | | return sysProjServicesDao.selectApiServiceOrderListInPage(serviceOrderListDto, pageVo); |
| | | } |
| | | |
| | | @Override |
| | | public int findApiServiceOrderListTotal(ServiceOrderListDto serviceOrderListDto) { |
| | | return sysProjServicesDao.selectApiServiceOrderListTotal(serviceOrderListDto); |
| | | } |
| | | } |