jiangping
2024-05-28 d154966cc9492a30c47809aa2824ba61d18e6fef
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java
@@ -1,22 +1,18 @@
package com.doumee.service.business.impl;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.IdcardUtil;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.biz.system.SystemUserBiz;
import com.doumee.config.DataSyncConfig;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.erp.ErpConstants;
import com.doumee.core.erp.ErpTool;
import com.doumee.core.erp.model.openapi.request.VisitListRequest;
import com.doumee.core.erp.model.openapi.request.erp.ApproveAddRequest;
import com.doumee.core.erp.model.openapi.request.erp.UserInfoRequest;
import com.doumee.core.erp.model.openapi.response.VisitEventListResponse;
import com.doumee.core.erp.model.openapi.response.erp.ApproveInfoResponse;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
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;
@@ -28,21 +24,24 @@
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.core.wx.wxPlat.WxPlatNotice;
import com.doumee.dao.admin.response.MemberInfoDTO;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dao.CompanyMapper;
import com.doumee.dao.business.dto.ResetPasswordDTO;
import com.doumee.dao.business.join.DeviceJoinMapper;
import com.doumee.dao.business.join.VisitEventJoinMapper;
import com.doumee.dao.business.join.VisitsJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.dto.ResetSystemUserPwdDTO;
import com.doumee.dao.system.model.SystemUser;
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;
import com.doumee.dao.web.response.VisitRecordVO;
import com.doumee.service.business.ApproveService;
import com.doumee.service.business.InterfaceLogService;
import com.doumee.service.business.SmsEmailService;
import com.doumee.service.business.VisitsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -50,16 +49,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
@@ -92,6 +88,8 @@
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private SystemUserBiz systemUserBiz;
    @Autowired
    private DeviceJoinMapper deviceJoinMapper;
    @Autowired
    private ErpTool erpTool;
@@ -101,6 +99,14 @@
    @Autowired
    private InterfaceLogService interfaceLogService;
    @Autowired
    private DataSyncConfig dataSyncConfig;
    @Autowired
    private SmsEmailService smsEmailService;
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private ApproveService approveService;
    @Override
@@ -200,26 +206,25 @@
        //检验拜访人是否合法
        Member visitMember = isValideVisitedUser(visits.getReceptMemberId());
        if(Constants.equalsInteger(Constants.ZERO, visits.getIdcardType())&&visits.getIdcardNo().length()!=18
            //&&!IdcardUtil.isValidCard(visits.getIdcardNo())
//            &&!IdcardUtil.isValidCard(visits.getIdcardNo())
        ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证号码有误,请核实后重试!");
        }
        Date date = new Date();
        //创建时间
        visits.setCreateDate(date);
        //普通访客
        visits.setType(Constants.ONE);
        //随行人员数量
        visits.setMemberNum(CollectionUtils.isNotEmpty(visits.getWithUserList())?visits.getWithUserList().size():0);
        visits.setMemberNum(Constants.ZERO);
        //访客信息(使用身份证号查询是否已存在改普通访客,没有则新增,存在则更新openid等信息),包括随访人员校验和处理
        Member member =dealMemberAndVisits(visits);
        Member member = dealMemberAndVisits(visits);
        visits.setMemberId(member.getId());
        visits.setVisitType(Integer.valueOf(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.MDJ_VISIT_REQUIRED).getCode()));
        //初始化访客信息
        initVisitInfo(visits,date);
        visitsMapper.insert(visits);
        //发起ERP审批申请
        if(visits.getSourceType().equals(Constants.ZERO)){
        if(dataSyncConfig.getVisitorDataOrigin().equals(Constants.ONE)){
            String erpId = startSendErpCheck(visits,visitMember);
            if(StringUtils.isNotBlank(erpId)){
                visits.setErpId(erpId);
@@ -232,9 +237,12 @@
            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{
            visits.setStatus(Constants.VisitStatus.pass);
        }else if(dataSyncConfig.getVisitorDataOrigin().equals(Constants.ZERO)){
            visits.setStatus(Constants.VisitStatus.waitCheck);
            visitsMapper.updateById(visits);
            approveService.createApproveFlow(visits.getType(),visits.getId(),visits.getReceptMemberId());
        }else{
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,发起拜访审批申请失败!");
        }
        initWithVisitInfo(visits);
        updateProblemLog(visits,problemLog,member);
@@ -243,6 +251,33 @@
        return visits.getId();
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer visitReporting(Visits visits) {
        isValidBaseParam(visits);
        //检验被拜访人是否合法
        Member visitMember = isValideVisitedUser(visits.getMemberId());
        Date date = new Date();
        //创建时间
        visits.setCreateDate(date);
        //访客报备
        visits.setType(Constants.TWO);
        visits.setReceptMemberId(visitMember.getId());
        visits.setStatus(Constants.VisitStatus.waitCheck);
        visits.setVisitType(Integer.valueOf(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.MDJ_VISIT_REQUIRED).getCode()));
        visits.setIdcardNo(DESUtil.decrypt(Constants.EDS_PWD, visitMember.getIdcardNo()));
        //初始化访客信息
        initVisitInfo(visits,date);
        visitsMapper.insert(visits);
        return visits.getId();
    }
    /**
@@ -270,7 +305,7 @@
            approve.setIsEndCheck(Constants.ZERO);
            approve.setType(Constants.ZERO);
            approve.setLevel(Constants.ONE);
            approve.setVisitId(visits.getId());
            approve.setObjId(visits.getId());
            approveMapper.insert(approve);
            if(!CollectionUtils.isNotEmpty(approveIds)){
                approve.setIsEndCheck(Constants.ONE);
@@ -305,7 +340,7 @@
        if(approve.getStatus().equals(Constants.approveStatus.wait)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批记录已处理!");
        }
        Visits visits = visitsMapper.selectById(approve.getVisitId());
        Visits visits = visitsMapper.selectById(approve.getObjId());
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
@@ -327,7 +362,7 @@
            if(approve.getApproveType().equals(Constants.ONE)){
                //会签 查询是否是最后一条记录 如果是最后一条记录 则生成下级审批记录 如果是最后一级,则进行审批确认
                if(approveMapper.selectCount(new QueryWrapper<Approve>().lambda()
                        .eq(Approve::getVisitId,visits.getId())
                        .eq(Approve::getObjId,visits.getId())
                        .eq(Approve::getLevel,approve.getLevel())
                        .ne(Approve::getId,approve.getId())
                )<=Constants.ZERO){
@@ -348,7 +383,7 @@
                        .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                        .set(Approve::getEditDate,new Date())
                        .set(Approve::getCheorId,auditApproveDTO.getMemberId())
                        .eq(Approve::getVisitId,visits.getId())
                        .eq(Approve::getObjId,visits.getId())
                        .eq(Approve::getStatus,Constants.approveStatus.wait)
                        .ne(Approve::getId,approve.getId())
                        .eq(Approve::getLevel,approve.getLevel())
@@ -375,7 +410,7 @@
                    .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                    .set(Approve::getEditDate,new Date())
                    .set(Approve::getCheorId,auditApproveDTO.getMemberId())
                    .eq(Approve::getVisitId,visits.getId())
                    .eq(Approve::getObjId,visits.getId())
                    .eq(Approve::getStatus,Constants.approveStatus.wait)
                    .ne(Approve::getId,approve.getId())
                    .eq(Approve::getLevel,approve.getLevel())
@@ -413,7 +448,7 @@
                approve.setTemplatId(approveParam.getId());
                approve.setChekorId(Integer.valueOf(id));
                approve.setType(Constants.ONE);
                approve.setVisitId(visitId);
                approve.setObjId(visitId);
                approveList.add(approve);
            }
            approveMapper.insertBatchSomeColumn(approveList);
@@ -440,7 +475,7 @@
                approve.setApproveType(approveParam.getApproveType());
                approve.setChekorId(id);
                approve.setType(Constants.ONE);
                approve.setVisitId(visitId);
                approve.setObjId(visitId);
                approveList.add(approve);
            }
            approveMapper.insertBatchSomeColumn(approveList);
@@ -459,7 +494,6 @@
                .eq(ApproveParam::getMemberType,Constants.ZERO)
                .last("limit 1"));
         return  Objects.isNull(approveParam)?null:approveParam.getId();
    }
@@ -574,16 +608,29 @@
                ||  StringUtils.isBlank( visits.getPhone())
                ||  StringUtils.isBlank( visits.getCompanyName())
                ||  visits.getIdcardType() == null
                ||  Objects.isNull(visits.getType())
//                ||  StringUtils.isBlank( visits.getFaceImg() )
                ||  StringUtils.isBlank( visits.getIdcardNo() )
                || visits.getReceptMemberId() == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
        }
        //访客报备
        if(visits.getType().equals(Constants.TWO)
            && (StringUtils.isBlank( visits.getName())
                ||  StringUtils.isBlank( visits.getPhone())
                ||  StringUtils.isBlank( visits.getCompanyName()))
                ||  StringUtils.isBlank( visits.getCarNos())
        ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
        }else if(visits.getType().equals(Constants.ONE) && StringUtils.isBlank(visits.getConstructionReason())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未填写施工事由!");
        }
        if(visits.getEndtime().getTime() < System.currentTimeMillis()){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约结束时间必须大于当前时间!");//
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,入厂时间必须大于当前时间!");//
        }
        if(visits.getEndtime().getTime() <= visits.getStarttime().getTime()){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约结束时间必须大于开始时间!");//
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,离厂时间必须大于入厂时间!");//
        }
        if(visits.getSourceType().equals(Constants.ZERO)){
            String code = systemDictDataBiz.queryByCode(Constants.VISIT_CONFIG,Constants.VALIDATE_VISIT).getCode();
@@ -594,7 +641,6 @@
            }
            if(StringUtils.isNotBlank(code)&&!StringUtils.equals(code,"0")){
//                Integer betweenDays = Math.toIntExact(cn.hutool.core.date.DateUtil.between(visits.getEndtime(), visits.getStarttime(), DateUnit.DAY));
                int betweenDays = DateUtil.daysBetweenDates11(visits.getEndtime(), visits.getStarttime())+1;
                if( betweenDays > codenum){
                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约总天数不能超过["+code+"天]!");
@@ -781,17 +827,6 @@
                model.setMemberId(visitsMember.getId());
            }
        }
//        if(CollectionUtils.isNotEmpty(addList)){
//            memberMapper.insertBatchSomeColumn(addList);
//        }
//        if(CollectionUtils.isNotEmpty(editList)){
//            editList.forEach(i->{
//                memberMapper.updateById(i);
//            });
//
//        }
        return  m;
    }
@@ -863,13 +898,20 @@
        }
        //根据手机号和身份证号码查询 当前预约的时间是否与其他预约记录有冲突
        if (visitsMapper.selectCount(new QueryWrapper<Visits>().lambda()
                        .notIn(Visits::getStatus,Constants.VisitStatus.cancel,Constants.VisitStatus.noPass,Constants.VisitStatus.xfFail,Constants.VisitStatus.signout,Constants.VisitStatus.invalid)
                        .notIn(Visits::getStatus,Constants.VisitStatus.cancel
                                ,Constants.VisitStatus.noPass
                                ,Constants.VisitStatus.xfFail
                                ,Constants.VisitStatus.signout
                                ,Constants.VisitStatus.invalid)
                .eq(Visits::getIdcardDecode, Constants.getTuominStr(cardno))
                .and(ms -> ms.eq(Visits::getPhone, visits.getPhone())
                        .or().eq(Visits::getIdcardDecode, Constants.getTuominStr(cardno)))
                .and(ms -> ms.apply(" visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                        .or().apply(" visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                )) > Constants.ZERO) {
                        .or().apply(" visits.STARTTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                        .or().apply(" visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                )
        ) > Constants.ZERO) {
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,手机号【"+member.getPhone()+"】或身份证【"+ member.getIdcardDecode() +"】存在预约时间冲突,无法申请哦!");
        }
        return  member;
@@ -945,7 +987,7 @@
    private ProblemLog isValidProblemLog(Visits visits) {
        String required = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROBLEM_VISIT_REQUIRED).getCode();
        if(StringUtils.equals(required,Constants.ONE+"")&&visits.getSourceType()==Constants.ZERO){
        if(StringUtils.equals(required,Constants.ONE+"")&&visits.getSourceType()==Constants.ZERO&&!visits.getType().equals(Constants.TWO)){
            //如果必须答题,查找答题记录
            if(visits.getUserAnswerId() == null){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题!");
@@ -1088,7 +1130,7 @@
  
    @Override
    public PageData<Visits> findPage(PageWrap<Visits> pageWrap) {
        IPage<Visits> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
         IPage<Visits> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Visits.class);
@@ -1099,13 +1141,17 @@
        queryWrapper.leftJoin(Company.class,Company::getId,Member::getCompanyId);
        queryWrapper.eq(Visits::getIsdeleted,Constants.ZERO);
        queryWrapper.eq(pageWrap.getModel().getType()!=null,Visits::getType,pageWrap.getModel().getType());
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getType()),Visits::getType,pageWrap.getModel().getType());
        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getOpenid()),Visits::getOpenid,pageWrap.getModel().getOpenid());
        queryWrapper.eq(StringUtils.isBlank(pageWrap.getModel().getOpenid()),"1","2");
        queryWrapper.and(StringUtils.isNotBlank(pageWrap.getModel().getName()),ms->ms.like(Visits::getName,pageWrap.getModel().getName())
                .or().like(Visits::getPhone,pageWrap.getModel().getName()))
                .eq(StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()),Visits::getIdcardNo,DESUtil.encrypt(Constants.EDS_PWD, pageWrap.getModel().getIdcardNo()))
                .eq(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),Visits::getCompanyName,pageWrap.getModel().getCompanyName())
                .eq(Objects.nonNull(pageWrap.getModel().getStatus()),Visits::getStatus,pageWrap.getModel().getStatus());
        queryWrapper.isNull(Visits::getParentId);
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getMemberId()),Visits::getMemberId,pageWrap.getModel().getMemberId());
        queryWrapper.orderByDesc(Visits::getCreateDate);
        IPage<Visits> result = visitsJoinMapper.selectJoinPage(page, Visits.class,queryWrapper);
@@ -1171,7 +1217,7 @@
    @Override
    public VisitDetailVO getVisitDetail(Integer id){
    public VisitDetailVO getVisitDetail(Integer id,Integer memberId){
        Visits visits = visitsMapper.selectById(id);
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
@@ -1194,12 +1240,14 @@
            visitDetailVO.setVisitUserCompany(company.getName());
        }
        visitDetailVO.setName(visits.getName());
            visitDetailVO.setCompanyName(visits.getCompanyName());
            visitDetailVO.setFaceImg(visits.getFaceImg());
            visitDetailVO.setImgUrl(visits.getImgurl());
            visitDetailVO.setIdCardDecode(visits.getIdcardDecode());
            visitDetailVO.setPrefix(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() +
                    systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode());
        visitDetailVO.setCompanyName(visits.getCompanyName());
        visitDetailVO.setFaceImg(visits.getFaceImg());
        visitDetailVO.setType(visits.getType());
        visitDetailVO.setConstructionReason(visits.getConstructionReason());
        visitDetailVO.setImgUrl(visits.getImgurl());
        visitDetailVO.setIdCardDecode(visits.getIdcardDecode());
        visitDetailVO.setPrefix(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() +
                systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode());
        if(StringUtils.isNotBlank(visits.getDoors())){
            List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                            .select(DeviceRole::getName)
@@ -1215,6 +1263,15 @@
                visitsMapper.selectList(new QueryWrapper<Visits>().lambda()
                .select(Visits::getName,Visits::getPhone,Visits::getQrcode,Visits::getFaceImg,Visits::getImgurl,Visits::getIdcardDecode,Visits::getStatus)
                .eq(Visits::getParentId,id)));
        if(Objects.nonNull(memberId)){
            visitDetailVO.setApproveDateVO(
                    approveService.arrangeApprovedData(id,
                            visits.getType(),
                            memberId)
            );
        }
        return visitDetailVO;
    }
@@ -1297,4 +1354,26 @@
                .eq(Retention::getMemberId,visits.getMemberId()));
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void resetPassword(ResetPasswordDTO resetPasswordDTO){
        if(Objects.isNull(resetPasswordDTO)
            || StringUtils.isBlank(resetPasswordDTO.getPassword())
            || StringUtils.isBlank(resetPasswordDTO.getValidCode())
            || StringUtils.isBlank(resetPasswordDTO.getPhone())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SystemUser systemUser = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda().eq(SystemUser::getMobile,resetPasswordDTO.getPhone()).eq(SystemUser::getDeleted,Constants.ZERO).last(" limit 1"));
        if(Objects.isNull(systemUser)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到手机号所属账户");
        }
        smsEmailService.validateCode(resetPasswordDTO.getValidCode(),resetPasswordDTO.getPhone());
        ResetSystemUserPwdDTO dto = new ResetSystemUserPwdDTO();
        dto.setPassword(resetPasswordDTO.getPassword());
        dto.setId(systemUser.getId());
        dto.setOperaUserId(systemUser.getId());
        systemUserBiz.resetPwd(dto);
    }
}