| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import cn.hutool.core.util.IdcardUtil; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DESUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.DeviceRoleMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.ProblemLogMapper; |
| | | import com.doumee.dao.business.VisitsMapper; |
| | | import com.doumee.dao.business.model.DeviceRole; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.ProblemLog; |
| | | import com.doumee.dao.business.model.Visits; |
| | | import com.doumee.service.business.VisitsService; |
| | | 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 org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private VisitsMapper visitsMapper; |
| | | @Autowired |
| | | private DeviceRoleMapper deviceRoleMapper; |
| | | @Autowired |
| | | private ProblemLogMapper problemLogMapper ; |
| | | @Autowired |
| | | private MemberMapper memberMapper ; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Override |
| | | public Integer create(Visits visits) { |
| | | visitsMapper.insert(visits); |
| | | return visits.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 普通访客申请 |
| | | * @param visits |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer createFk(Visits visits) { |
| | | if(visits.getStarttime() == null |
| | | || visits.getEndtime() == null |
| | | || StringUtils.isBlank(visits.getReason()) |
| | | || StringUtils.isBlank( visits.getName()) |
| | | || StringUtils.isBlank( visits.getPhone()) |
| | | || visits.getIdcardType() == null |
| | | || StringUtils.isBlank( visits.getFaceImg() ) |
| | | || StringUtils.isBlank( visits.getIdcardNo() ) |
| | | || visits.getReceptMemberId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!"); |
| | | } |
| | | //检查是否必须答题,并且符合答题要求 |
| | | ProblemLog problemLog = isValidProblemLog(visits); |
| | | //获取申请的海康访问门禁组信息 |
| | | String[] hkIds = getHkDeviceRoles(visits); |
| | | //检验拜访人是否合法 |
| | | isValideVisitedUser(visits.getReceptMemberId()); |
| | | //检查随访人员是否合法,生成随访人员新增集合 |
| | | List<Member> withUsers = isValideWithUsers(visits.getWithUserList()); |
| | | |
| | | if(Constants.equalsInteger(Constants.ZERO, visits.getIdcardType()) &&!IdcardUtil.isValidCard(visits.getIdcardNo())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证号码有误,请核实后重试!"); |
| | | } |
| | | Date date = new Date(); |
| | | |
| | | visits.setBirthday(Constants.getBirthdyByCardNo(visits.getIdcardNo())); |
| | | //身份证号存储密文 |
| | | visits.setIdcardNo(DESUtil.encrypt(Constants.EDS_PWD, visits.getIdcardNo()));//身份证号加密 |
| | | visits.setIdcardDecode(Constants.getTuominStr(visits.getIdcardNo()));//脱敏手机号 |
| | | visits.setCreateDate(date); |
| | | |
| | | //访客信息(使用身份证号查询是否已存在改普通访客,没有则新增,存在则更新openid等信息) |
| | | Member member = getMemberByIdcardno(visits); |
| | | visitsMapper.insert(visits); |
| | | |
| | | |
| | | updateProblemLog(visits,problemLog,member); |
| | | |
| | | return visits.getId(); |
| | | } |
| | | |
| | | private Member getMemberByIdcardno(Visits idcardNo) { |
| | | Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda() |
| | | // .eq(Member::getType,Constants.MEMBER_TYPE) |
| | | .eq(Member::getIdcardNo,idcardNo.getIdcardNo()) |
| | | ); |
| | | return null; |
| | | } |
| | | |
| | | private List<Member> isValideWithUsers(List<Visits> withUserList) { |
| | | if(withUserList!= null && withUserList .size()>0){ |
| | | for(Visits model:withUserList){ |
| | | |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 如果有答题记录,更新答题记录关联数据 |
| | | * @param visits |
| | | * @param problemLog |
| | | * @param member |
| | | */ |
| | | |
| | | private void updateProblemLog(Visits visits, ProblemLog problemLog,Member member) { |
| | | if(problemLog!=null){ |
| | | problemLog.setEditDate(visits.getCreateDate()); |
| | | problemLog.setName(visits.getName()); |
| | | problemLog.setUserId(member.getId()); |
| | | problemLog.setPhone(member.getPhone()); |
| | | problemLog.setLogId(visits.getId()); |
| | | problemLogMapper.updateById(problemLog); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查访人是否合法 |
| | | * @param receptMemberId |
| | | */ |
| | | private Member isValideVisitedUser(Integer receptMemberId) { |
| | | Member member = memberMapper.selectById(receptMemberId); |
| | | if(member == null || Constants.equalsInteger(Constants.ZERO,member.getIsdeleted())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请!"); |
| | | } |
| | | if(!Constants.equalsInteger(member.getStatus(), Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请."); |
| | | } |
| | | if(!Constants.equalsInteger(Constants.ONE, member.getCanVisit())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请~"); |
| | | } |
| | | return member; |
| | | } |
| | | |
| | | private ProblemLog isValidProblemLog(Visits visits) { |
| | | String required = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROBLEM_VISIT_REQUIRED).getCode(); |
| | | if(StringUtils.equals(required,Constants.ONE+"")){ |
| | | //如果必须答题,查找答题记录 |
| | | if(visits.getUserAnswerId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题!"); |
| | | } |
| | | ProblemLog log = problemLogMapper.selectById(visits.getUserAnswerId()); |
| | | if(log == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题."); |
| | | } |
| | | if(log.getLogId() !=null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题~"); |
| | | } |
| | | return log; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取申请的海康访问门禁组信息 |
| | | * @param visits |
| | | * @return |
| | | */ |
| | | private String[] getHkDeviceRoles(Visits visits) { |
| | | String mustSelectDoors = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SELECT_DOORS_VISIT_REQUIRED).getCode(); |
| | | List<DeviceRole> roles = null; |
| | | if(StringUtils.equals(mustSelectDoors,Constants.ZERO+"")){ |
| | | //如果必须选择门禁,但未选择 |
| | | if(StringUtils.isBlank(visits.getDoors())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择访问门禁!"); |
| | | } |
| | | //校验门禁组信息是否正确 |
| | | String[] dIds = visits.getDoors().split(","); |
| | | roles = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda() |
| | | .eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getType,Constants.DeviceRoleType.fk) |
| | | .in(DeviceRole::getId, Arrays.asList(dIds))); |
| | | if(roles == null || roles.size()==0 || roles.size() != dIds.length){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择有效访问门禁!"); |
| | | } |
| | | }else{ |
| | | //如果设置不选择门禁,则提供默认门禁组信息 |
| | | String[] dIds = visits.getDoors().split(","); |
| | | roles = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda() |
| | | .eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getIsDefault,Constants.ZERO) |
| | | .eq(DeviceRole::getType,Constants.DeviceRoleType.fk)); |
| | | if(roles.size() ==0){ |
| | | |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,暂不存在可访问的访客门禁,无法进行申请操作!"); |
| | | } |
| | | } |
| | | String[] ids =new String[roles.size()]; |
| | | for (int i = 0; i < roles.size(); i++) { |
| | | ids[i] = roles.get(i).getHkId(); |
| | | } |
| | | return ids; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | visitsMapper.deleteById(id); |