jiangping
2024-03-01 f6c2b63e7c992b17ea7750e7c20ee3bcdd9428fb
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java
@@ -34,6 +34,8 @@
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;
@@ -94,11 +96,92 @@
    @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);
    }
    /**
     * 普通访客申请
@@ -135,22 +218,27 @@
        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();
    }
@@ -554,7 +642,8 @@
                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());
@@ -833,7 +922,7 @@
    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(), "对不起,请先按要求进行安全知识答题!");