| | |
| | | import com.doumee.core.haikang.model.HKTools; |
| | | import com.doumee.core.haikang.model.param.BaseResponse; |
| | | import com.doumee.core.haikang.model.param.request.VisitAppointmentCancelRequest; |
| | | import com.doumee.core.haikang.model.param.request.VisitAppointmentOutRequest; |
| | | import com.doumee.core.haikang.model.param.request.VisitAppointmentRequest; |
| | | import com.doumee.core.haikang.model.param.respose.VisitAppointmentResponse; |
| | | import com.doumee.core.haikang.service.HKService; |
| | |
| | | import com.doumee.dao.business.join.VisitsJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.web.reqeust.AuditApproveDTO; |
| | | import com.doumee.dao.web.reqeust.ErpVisitDTO; |
| | | import com.doumee.dao.web.reqeust.ErpWithVisitDTO; |
| | | import com.doumee.dao.web.reqeust.VisitRecordDTO; |
| | | import com.doumee.dao.web.response.InternalHomeVO; |
| | | import com.doumee.dao.web.response.VisitDetailVO; |
| | |
| | | public class VisitsServiceImpl implements VisitsService { |
| | | |
| | | @Autowired |
| | | private RetentionMapper retentionMapper; |
| | | @Autowired |
| | | private VisitsMapper visitsMapper; |
| | | @Autowired |
| | | private ApproveMapper approveMapper; |
| | |
| | | @Autowired |
| | | private WxPlatNotice wxPlatNotice; |
| | | |
| | | @Autowired |
| | | private InterfaceLogService interfaceLogService; |
| | | |
| | | |
| | | @Override |
| | | public Integer create(Visits visits) { |
| | | visitsMapper.insert(visits); |
| | | return visits.getId(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public void createFKForErp(ErpVisitDTO erpVisitDTO){ |
| | | try { |
| | | |
| | | if (Objects.isNull(erpVisitDTO) |
| | | || StringUtils.isBlank(erpVisitDTO.getName()) |
| | | || StringUtils.isBlank(erpVisitDTO.getPhone()) |
| | | || Objects.isNull(erpVisitDTO.getIdcardType()) |
| | | || StringUtils.isBlank(erpVisitDTO.getIdcardNo()) |
| | | || Objects.isNull(erpVisitDTO.getStarttime()) |
| | | || Objects.isNull(erpVisitDTO.getEndtime()) |
| | | || StringUtils.isBlank(erpVisitDTO.getFaceImg()) |
| | | || Objects.isNull(erpVisitDTO.getReceptMemberId()) |
| | | || Objects.isNull(erpVisitDTO.getErpId()) |
| | | ) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!"); |
| | | } |
| | | if (erpVisitDTO.getEndtime().getTime() <= erpVisitDTO.getStarttime().getTime()) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约结束时间必须大于开始时间!"); |
| | | } |
| | | if (Constants.equalsInteger(Constants.ZERO, erpVisitDTO.getIdcardType()) && erpVisitDTO.getIdcardNo().length() != 18 |
| | | //&&!IdcardUtil.isValidCard(visits.getIdcardNo()) |
| | | ) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证号码有误,请核实后重试!"); |
| | | } |
| | | |
| | | Visits visits = new Visits(); |
| | | //根据被访问人ERP主键查询系统内人员主键信息 |
| | | Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getIsdeleted, Constants.ZERO).eq(Member::getType, Constants.memberType.internal) |
| | | .eq(Member::getErpId, erpVisitDTO.getReceptMemberId()).last("limit 1")); |
| | | if (Objects.isNull(member)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "未查询到被访问人信息"); |
| | | } |
| | | if (Objects.isNull(member.getCanVisit()) || member.getCanVisit().equals(Constants.ZERO)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "当前被访问人无法被访问"); |
| | | } |
| | | BeanUtils.copyProperties(erpVisitDTO, visits); |
| | | //设置内部系统人员主键 |
| | | visits.setReceptMemberId(member.getId()); |
| | | visits.setSourceType(Constants.ONE); |
| | | List<ErpWithVisitDTO> erpWithVisitDTOList = erpVisitDTO.getErpWithVisitDTOList(); |
| | | if (CollectionUtils.isNotEmpty(erpWithVisitDTOList)) { |
| | | List<Visits> visitsList = new ArrayList<>(); |
| | | for (ErpWithVisitDTO erpWithVisitDTO : erpWithVisitDTOList) { |
| | | Visits withVisits = new Visits(); |
| | | BeanUtils.copyProperties(erpWithVisitDTO, withVisits); |
| | | visitsList.add(withVisits); |
| | | } |
| | | visits.setWithUserList(visitsList); |
| | | } |
| | | this.createFk(visits); |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }finally { |
| | | saveInterfaceLog(erpVisitDTO,"/visitBiz/resource/crateVisit",null,Constants.ZERO); |
| | | } |
| | | } |
| | | |
| | | private void saveInterfaceLog(Object param, String path,String result,Integer type) { |
| | | InterfaceLog interfaceLog=new InterfaceLog(); |
| | | interfaceLog.setType(type); |
| | | interfaceLog.setCreateDate(new Date()); |
| | | interfaceLog.setIsdeleted(Constants.ZERO); |
| | | if(param!=null){ |
| | | interfaceLog.setRequest(JSONObject.toJSONString(param)); |
| | | } |
| | | interfaceLog.setPlat(Constants.ONE); |
| | | interfaceLog.setRepose(result); |
| | | interfaceLog.setName(path); |
| | | interfaceLog.setUrl(path); |
| | | interfaceLogService.create(interfaceLog); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 普通访客申请 |
| | |
| | | initVisitInfo(visits,date); |
| | | visitsMapper.insert(visits); |
| | | //发起ERP审批申请 |
| | | String erpId = startSendErpCheck(visits,visitMember); |
| | | if(StringUtils.isNotBlank(erpId)){ |
| | | visits.setErpId(erpId); |
| | | visits.setStatus(Constants.VisitStatus.submitCheck); |
| | | visitsMapper.updateById(visits); |
| | | if(visits.getSourceType().equals(Constants.ZERO)){ |
| | | String erpId = startSendErpCheck(visits,visitMember); |
| | | if(StringUtils.isNotBlank(erpId)){ |
| | | visits.setErpId(erpId); |
| | | visits.setStatus(Constants.VisitStatus.submitCheck); |
| | | visitsMapper.updateById(visits); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,发起拜访审批申请失败!"); |
| | | } |
| | | //发送微信公众号通知 |
| | | wxPlatNotice.sendVisitAuditTemplateNotice(visits, |
| | | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_PREFIX).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_AUDIT_VISIT).getCode()); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,发起拜访审批申请失败!"); |
| | | visits.setStatus(Constants.VisitStatus.pass); |
| | | visitsMapper.updateById(visits); |
| | | } |
| | | initWithVisitInfo(visits); |
| | | updateProblemLog(visits,problemLog,member); |
| | | //创建审批记录 |
| | | // createApprove(visits,visitMember); |
| | | //发送微信公众号通知 |
| | | wxPlatNotice.sendVisitAuditTemplateNotice(visits, |
| | | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_PREFIX).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_AUDIT_VISIT).getCode()); |
| | | |
| | | return visits.getId(); |
| | | } |
| | |
| | | v.setDoors(visits.getDoors()); |
| | | v.setType(visits.getType()); |
| | | v.setVisitType(visits.getVisitType()); |
| | | v.setStatus(Constants.VisitStatus.submitCheck); |
| | | v.setStatus(visits.getStatus()); |
| | | v.setSourceType(visits.getSourceType()); |
| | | } |
| | | //批量插入数据 |
| | | visitsMapper.insertBatchSomeColumn(visits.getWithUserList()); |
| | |
| | | |
| | | private ProblemLog isValidProblemLog(Visits visits) { |
| | | String required = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROBLEM_VISIT_REQUIRED).getCode(); |
| | | if(StringUtils.equals(required,Constants.ONE+"")){ |
| | | if(StringUtils.equals(required,Constants.ONE+"")&&visits.getSourceType()==Constants.ZERO){ |
| | | //如果必须答题,查找答题记录 |
| | | if(visits.getUserAnswerId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题!"); |
| | |
| | | List<DeviceRole> roles = null; |
| | | if(StringUtils.equals(mustSelectDoors,Constants.ZERO+"")){ |
| | | //如果设置不选择门禁,则提供默认门禁组信息 |
| | | |
| | | if(StringUtils.isBlank(visits.getDoors())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择访问门禁!"); |
| | | } |
| | |
| | | if(roles.size() ==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,暂不存在可访问的访客门禁,无法进行申请操作!"); |
| | | } |
| | | |
| | | }else{ |
| | | //如果必须选择门禁,但未选择 |
| | | String[] dIds = visits.getDoors().split(","); |
| | |
| | | if(!visits.getStatus().equals(Constants.VisitStatus.signin)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"访客记录状态错误,请刷新重试"); |
| | | } |
| | | VisitAppointmentOutRequest request = new VisitAppointmentOutRequest(); |
| | | request.setOrderId(visits.getHkId()); |
| | | //调用海康强制签离 |
| | | BaseResponse response = HKService.outVisitAppiontment(request); |
| | | visitsMapper.update(null,new UpdateWrapper<Visits>().lambda().set(Visits::getStatus,Constants.VisitStatus.signout) |
| | | .eq(Visits::getId,visitId)); |
| | | |
| | | //产出在场人员信息 |
| | | retentionMapper.delete(new UpdateWrapper<Retention>().lambda() |
| | | .eq(Retention::getType,Constants.memberType.visitor) |
| | | .eq(Retention::getMemberId,visits.getMemberId())); |
| | | } |
| | | |
| | | } |