|
@@ -0,0 +1,338 @@
|
|
|
+package com.care.keeper.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.care.client.vo.MemberInfoVO;
|
|
|
+import com.care.common.cache.RedisKeyConstant;
|
|
|
+import com.care.common.cache.RedisUtil;
|
|
|
+import com.care.common.entity.*;
|
|
|
+import com.care.common.enums.*;
|
|
|
+import com.care.common.exception.BDException;
|
|
|
+import com.care.common.service.*;
|
|
|
+import com.care.common.vo.PageReqVO;
|
|
|
+import com.care.common.vo.device.DeviceVO;
|
|
|
+import com.care.common.vo.event.*;
|
|
|
+import com.care.keeper.vo.DeviceMonitorVO;
|
|
|
+import com.care.keeper.vo.HouseContactVO;
|
|
|
+import com.care.keeper.vo.KeeperInfoVO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
|
+import org.springframework.beans.factory.BeanFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: lilt
|
|
|
+ * @Date: 2021/6/7
|
|
|
+ * @Desc:
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class KeeperApiService {
|
|
|
+ @Resource
|
|
|
+ private CareDeviceService careDeviceService;
|
|
|
+ @Resource
|
|
|
+ private CareMemberInfoService careMemberInfoService;
|
|
|
+ @Resource
|
|
|
+ private CareHouseContactService careHouseContactService;
|
|
|
+ @Resource
|
|
|
+ private CareEventOrderService careEventOrderService;
|
|
|
+ @Resource
|
|
|
+ private CareEventOrderHandleHisService careEventOrderHandleHisService;
|
|
|
+ @Resource
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
+ @Resource
|
|
|
+ private CareHouseService careHouseService;
|
|
|
+ @Resource
|
|
|
+ private CareOrganizationService careOrganizationService;
|
|
|
+ @Resource
|
|
|
+ private CareStationService careStationService;
|
|
|
+ @Resource
|
|
|
+ private CareSysUserService careSysUserService;
|
|
|
+ @Resource
|
|
|
+ private CareEventOrderChambService careEventOrderChambService;
|
|
|
+ @Resource
|
|
|
+ private CareEventOrderOlderService careEventOrderOlderService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CareEventOrderKeyApplyService careEventOrderKeyApplyService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理服务人数
|
|
|
+ * @param keeperInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int queryOlderCount(KeeperInfoVO keeperInfoVO){
|
|
|
+ return this.careSysUserService.queryOlderCountByChambId(keeperInfoVO.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 待处理的工单
|
|
|
+ *
|
|
|
+ * @param pageReqVo
|
|
|
+ * @param chambId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<ChambEventOrderVO> queryTodoEventByChambId(PageReqVO pageReqVo, Long chambId) {
|
|
|
+ return this.careEventOrderChambService.queryTodoEventByChambId(pageReqVo,chambId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 进行中的工单
|
|
|
+ *
|
|
|
+ * @param pageReqVo
|
|
|
+ * @param chambId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<ChambEventOrderVO> queryDoingEventByChambId(PageReqVO pageReqVo, Long chambId) {
|
|
|
+ return this.careEventOrderChambService.queryDoingEventByChambId(pageReqVo,chambId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完成的工单
|
|
|
+ *
|
|
|
+ * @param pageReqVo
|
|
|
+ * @param chambId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<ChambEventOrderVO> queryDoneEventByChambId(PageReqVO pageReqVo, Long chambId) {
|
|
|
+ return this.careEventOrderChambService.queryDoneEventByChambId(pageReqVo,chambId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ChambEventOrderVO getChambOrder(Long id){
|
|
|
+ CareEventOrderChamb orderChamb = this.careEventOrderChambService.getById(id);
|
|
|
+ ChambEventOrderVO chambEventOrderVO = new ChambEventOrderVO();
|
|
|
+ BeanUtil.copyProperties(orderChamb,chambEventOrderVO);
|
|
|
+ return chambEventOrderVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 事件详情
|
|
|
+ * @param orderId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public EventOrderVO getEventInfo(Long orderId){
|
|
|
+ CareEventOrder eventOrder = this.careEventOrderService.getById(orderId);
|
|
|
+ EventOrderVO vo = new EventOrderVO();
|
|
|
+ BeanUtil.copyProperties(eventOrder,vo);
|
|
|
+ vo.setOrderTypeName(OrderTypeEnum.getCodeToName(vo.getOrderType()));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询老人列表
|
|
|
+ * @param orderId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<OrderOlderVO> queryOrderOlderList(Long orderId){
|
|
|
+ List<OrderOlderVO> orderOlderVOList = Lists.newArrayList();
|
|
|
+ QueryWrapper<CareEventOrderOlder> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareEventOrderOlder::getOrderId,orderId);
|
|
|
+ List<CareEventOrderOlder> ceoos = this.careEventOrderOlderService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(ceoos)){
|
|
|
+ ceoos.forEach(item->{
|
|
|
+ OrderOlderVO orderOlderVO = new OrderOlderVO();
|
|
|
+ BeanUtil.copyProperties(item,orderOlderVO);
|
|
|
+ orderOlderVO.setStatusDesc(OrderOlderStatusEnum.getCodeToName(orderOlderVO.getStatus()));
|
|
|
+ orderOlderVOList.add(orderOlderVO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return orderOlderVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询事件紧急联系人
|
|
|
+ * @param orderId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<HouseContactVO> queryContactByOrderId(Long orderId){
|
|
|
+ List<HouseContactVO> vos = Lists.newArrayList();
|
|
|
+ CareEventOrder order = this.careEventOrderService.getById(orderId);
|
|
|
+ QueryWrapper<CareHouseContact> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareHouseContact::getHouseId, order.getHouseId())
|
|
|
+ .orderByAsc(CareHouseContact::getContactLevel);
|
|
|
+ List<CareHouseContact> contacts = this.careHouseContactService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(contacts)){
|
|
|
+ contacts.forEach(item -> {
|
|
|
+ HouseContactVO vo = new HouseContactVO();
|
|
|
+ BeanUtil.copyProperties(item,vo);
|
|
|
+ vos.add(vo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钥匙信息
|
|
|
+ * @param orderId
|
|
|
+ * @param keeperId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public OrderKeyApplyVO getApplyKeyInfo(Long orderId,Long keeperId ){
|
|
|
+ QueryWrapper<CareEventOrderKeyApply> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareEventOrderKeyApply::getOrderId,orderId).eq(CareEventOrderKeyApply::getApplyRole,UserRoleEnum.CHANMB.getValue())
|
|
|
+ .eq(CareEventOrderKeyApply::getApplyUserId,keeperId);
|
|
|
+ List<CareEventOrderKeyApply> datas = this.careEventOrderKeyApplyService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(datas)){
|
|
|
+ OrderKeyApplyVO keyApplyVO = new OrderKeyApplyVO();
|
|
|
+ BeanUtil.copyProperties(datas.get(0),keyApplyVO);
|
|
|
+ return keyApplyVO;
|
|
|
+ }else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 申请钥匙
|
|
|
+ * @param orderId
|
|
|
+ * @param keeperInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean applyKey(Long orderId,KeeperInfoVO keeperInfoVO){
|
|
|
+ String key = RedisKeyConstant.KEY_APPLY_LOCAK+":"+keeperInfoVO.getId();
|
|
|
+ boolean result = redisUtil.tryLock(key,3000);
|
|
|
+ Date date = DateUtil.date();
|
|
|
+ boolean flag =false;
|
|
|
+ try{
|
|
|
+ if (result){
|
|
|
+ CareEventOrder order = this.careEventOrderService.getById(orderId);
|
|
|
+ CareEventOrderKeyApply keyApply = new CareEventOrderKeyApply();
|
|
|
+ keyApply.setOrgId(order.getOrgId());
|
|
|
+ keyApply.setStationId(order.getStationId());
|
|
|
+ keyApply.setHouseId(order.getHouseId());
|
|
|
+ keyApply.setOrderId(orderId);
|
|
|
+ keyApply.setApplyRole(UserRoleEnum.CHANMB.getValue());
|
|
|
+ keyApply.setApplyUserId(keeperInfoVO.getId());
|
|
|
+ keyApply.setApplyUserName(keeperInfoVO.getName());
|
|
|
+ keyApply.setStatus(KeyAuthEnum.TODO.getValue());
|
|
|
+ keyApply.setCreateTime(date);
|
|
|
+ keyApply.setModifyTime(date);
|
|
|
+ keyApply.setRelationTypeDesc(RelationTypeEnum.CHANMB.getName());
|
|
|
+ flag = this.careEventOrderKeyApplyService.save(keyApply);
|
|
|
+ if (flag){
|
|
|
+ CareEventOrderHandleHis his = new CareEventOrderHandleHis();
|
|
|
+ his.setOrgId(keyApply.getOrgId());
|
|
|
+ his.setStationId(keyApply.getStationId());
|
|
|
+ his.setOrderId(keyApply.getOrderId());
|
|
|
+ his.setLogType(LogTypeEnum.KEY.getValue());
|
|
|
+ his.setLogObjectId(keyApply.getApplyUserId());
|
|
|
+ his.setLogObjectName(keyApply.getApplyUserName());
|
|
|
+ his.setLogResult("申请钥匙");
|
|
|
+ his.setOpUserRole(UserRoleEnum.SEAT.getValue());
|
|
|
+ his.setOpUserId(keyApply.getApplyUserId());
|
|
|
+ his.setOpUserName(keyApply.getApplyUserName());
|
|
|
+ his.setCreateTime(date);
|
|
|
+ his.setRelationTypeDesc(RelationTypeEnum.CHANMB.getName());
|
|
|
+ this.careEventOrderHandleHisService.save(his);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BDException("已经申请,请勿重复申请");
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ redisUtil.releaseLock(key);
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 到达确认
|
|
|
+ * @param orderChambId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean daoDaConfirm(Long orderChambId){
|
|
|
+ boolean flag = false;
|
|
|
+ CareEventOrderChamb orderChamb = this.careEventOrderChambService.getById(orderChambId);
|
|
|
+ Date date = DateUtil.date();
|
|
|
+ UpdateWrapper<CareEventOrderChamb> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().eq(CareEventOrderChamb::getId,orderChambId)
|
|
|
+ .set(CareEventOrderChamb::getDaodaTime,date)
|
|
|
+ .set(CareEventOrderChamb::getModifyTime,date);
|
|
|
+ flag = this.careEventOrderChambService.update(updateWrapper);
|
|
|
+ if (flag){
|
|
|
+ //保存日志
|
|
|
+ CareEventOrderHandleHis his = new CareEventOrderHandleHis();
|
|
|
+ his.setOrgId(orderChamb.getOrgId());
|
|
|
+ his.setStationId(orderChamb.getStationId());
|
|
|
+ his.setOrderId(orderChamb.getOrderId());
|
|
|
+ his.setLogType(LogTypeEnum.CHAMB.getValue());
|
|
|
+ his.setLogObjectId(orderChamb.getId());
|
|
|
+ his.setLogObjectName(orderChamb.getChambName());
|
|
|
+ his.setLogResult("已到达");
|
|
|
+ his.setOpUserRole(UserRoleEnum.CHANMB.getValue());
|
|
|
+ his.setOpUserId(orderChamb.getChambId());
|
|
|
+ his.setOpUserName(orderChamb.getChambName());
|
|
|
+ his.setCreateTime(date);
|
|
|
+ his.setRelationTypeDesc(RelationTypeEnum.CHANMB.getName());
|
|
|
+ this.careEventOrderHandleHisService.save(his);
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 离开确认
|
|
|
+ * @param orderChambId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean liKaiConfirm(Long orderChambId,String remark,String scenePic){
|
|
|
+ boolean flag = false;
|
|
|
+ CareEventOrderChamb orderChamb = this.careEventOrderChambService.getById(orderChambId);
|
|
|
+ Date date = DateUtil.date();
|
|
|
+ UpdateWrapper<CareEventOrderChamb> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().eq(CareEventOrderChamb::getId,orderChambId)
|
|
|
+ .set(CareEventOrderChamb::getRemark,remark)
|
|
|
+ .set(CareEventOrderChamb::getScenePic,scenePic)
|
|
|
+ .set(CareEventOrderChamb::getLikaiTime,date)
|
|
|
+ .set(CareEventOrderChamb::getStatus,ChambOrderStatusEnum.COMPLETE.getValue())
|
|
|
+ .set(CareEventOrderChamb::getModifyTime,date);
|
|
|
+ flag = this.careEventOrderChambService.update(updateWrapper);
|
|
|
+ if (flag){
|
|
|
+ //保存日志
|
|
|
+ CareEventOrderHandleHis his = new CareEventOrderHandleHis();
|
|
|
+ his.setOrgId(orderChamb.getOrgId());
|
|
|
+ his.setStationId(orderChamb.getStationId());
|
|
|
+ his.setOrderId(orderChamb.getOrderId());
|
|
|
+ his.setLogType(LogTypeEnum.CHAMB.getValue());
|
|
|
+ his.setLogObjectId(orderChamb.getId());
|
|
|
+ his.setLogObjectName(orderChamb.getChambName());
|
|
|
+ his.setLogResult("已离开");
|
|
|
+ his.setOpUserRole(UserRoleEnum.CHANMB.getValue());
|
|
|
+ his.setOpUserId(orderChamb.getChambId());
|
|
|
+ his.setOpUserName(orderChamb.getChambName());
|
|
|
+ his.setCreateTime(date);
|
|
|
+ his.setRelationTypeDesc(RelationTypeEnum.CHANMB.getName());
|
|
|
+ this.careEventOrderHandleHisService.save(his);
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取处理记录
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<OrderHandleHisVO> queryOrderHandleHis(Long orderId){
|
|
|
+ List<OrderHandleHisVO> result = Lists.newArrayList();
|
|
|
+ QueryWrapper<CareEventOrderHandleHis> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareEventOrderHandleHis::getOrderId,orderId)
|
|
|
+ .orderByDesc(CareEventOrderHandleHis::getCreateTime);
|
|
|
+ List<CareEventOrderHandleHis> datas = this.careEventOrderHandleHisService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(datas)){
|
|
|
+ datas.forEach(item ->{
|
|
|
+ OrderHandleHisVO hisVO = new OrderHandleHisVO();
|
|
|
+ BeanUtil.copyProperties(item,hisVO);
|
|
|
+ result.add(hisVO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|