From f6c2b63e7c992b17ea7750e7c20ee3bcdd9428fb Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 01 三月 2024 15:57:15 +0800
Subject: [PATCH] 整理

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java |  151 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 122 insertions(+), 29 deletions(-)

diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java
index a2a4137..7dd65c1 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java
@@ -16,6 +16,7 @@
 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;
@@ -33,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;
@@ -66,6 +69,8 @@
 public class VisitsServiceImpl implements VisitsService {
 
     @Autowired
+    private RetentionMapper retentionMapper;
+    @Autowired
     private VisitsMapper visitsMapper;
     @Autowired
     private ApproveMapper approveMapper;
@@ -91,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);
+    }
+
 
     /**
      * 鏅�氳瀹㈢敵璇�
@@ -132,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();
     }
@@ -551,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());
@@ -686,7 +778,7 @@
     }
 
     private Member getMemberListParam(String cardno, Visits visits, List<Member> addList, List<Member> editList) {
-        if(!StringUtils.isNotBlank(visits.getCarNos())
+        if(StringUtils.isNotBlank(visits.getCarNos())
                 &&Objects.isNull(Constants.getVehiclePlateNo(visits.getCarNos()))
         ){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝杞︾墝鍙枫��"+visits.getCarNos()+"銆戜笉鍚堟硶锛岃鏍稿疄鍚庨噸璇晘");
@@ -694,7 +786,7 @@
         if(Constants.equalsInteger(Constants.ZERO, visits.getIdcardType())&&cardno.length()!=18
             //&&!IdcardUtil.isValidCard(cardno)
         ){
-            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝韬唤璇佸彿鐮佹湁璇紝璇锋牳瀹炲悗閲嶈瘯锛�");
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝韬唤璇併��"+cardno+"銆戝彿鐮佹湁璇紝璇锋牳瀹炲悗閲嶈瘯锛�");
         }
         Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda()
                 .eq(Member::getType,Constants.memberType.visitor)
@@ -730,10 +822,9 @@
         }else{
             if(!Constants.equalsInteger(Constants.ZERO,member.getStatus() )){
                 //濡傛灉鐢ㄦ埛鐘舵�佸紓甯革紝鍒欐彁绀�
-                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝璇ヨ韩浠借瘉鍙疯绂佹璁块棶鐢宠锛屽鏈夌枒闂紝璇疯仈绯绘偍鐨勬嫓璁夸汉杩涜鏍稿疄");
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝韬唤璇佸彿銆�"+cardno+"銆戣绂佹璁块棶鐢宠锛屽鏈夌枒闂紝璇疯仈绯绘偍鐨勬嫓璁夸汉杩涜鏍稿疄");
             }
             //鏍告煡棰勭害鐢ㄦ埛鏄惁瀛樺湪鏈绂荤殑棰勭害璁板綍
-
 //            isExsitNoOutVisisRecord(member);
 
             member.setFaceImg(visits.getFaceImg());
@@ -751,14 +842,10 @@
             member.setErpStatus(Constants.ZERO);
             member.setVisitCompanyName(visits.getCompanyName());
             memberMapper.updateById(member);
-            // 鏇存柊璁垮淇℃伅,
-//            editList.add(member);
         }
         //鏍规嵁鎵嬫満鍙峰拰韬唤璇佸彿鐮佹煡璇� 褰撳墠棰勭害鐨勬椂闂存槸鍚︿笌鍏朵粬棰勭害璁板綍鏈夊啿绐�
         if (visitsMapper.selectCount(new QueryWrapper<Visits>().lambda()
-                        .notIn(Visits::getStatus,Constants.VisitStatus.cancel,Constants.VisitStatus.noPass,Constants.VisitStatus.xfFail)
-//                .and(ms -> ms.eq(Visits::getPhone, visits.getPhone())
-//                        .or().eq(Visits::getIdcardDecode, Constants.getTuominStr(cardno)))
+                        .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.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") + "' ")
@@ -835,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(), "瀵逛笉璧凤紝璇峰厛鎸夎姹傝繘琛屽畨鍏ㄧ煡璇嗙瓟棰橈紒");
@@ -1028,7 +1115,7 @@
         queryWrapper.selectAs(Company::getName,Visits::getReceptMemberDepartment);
         queryWrapper.leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
         queryWrapper.leftJoin(Company.class,Company::getId,Member::getCompanyId);
-        queryWrapper.leftJoin(" member m on m.id=t.MEMBER_ID");
+        queryWrapper.leftJoin(" member m on m.id= t.MEMBER_ID");
 
         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getLevelStatus()),Visits::getStatus,Constants.VisitStatus.signin);
 
@@ -1038,11 +1125,9 @@
         queryWrapper.eq(Visits::getIsdeleted,Constants.ZERO);
         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getType()),Visits::getType,pageWrap.getModel().getType());
         queryWrapper.and(StringUtils.isNotBlank(pageWrap.getModel().getName()),ms->ms.like(Visits::getPhone,pageWrap.getModel().getName())
-                .or().like(Visits::getPhone,pageWrap.getModel().getName()))
-                .eq(StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()),Visits::getIdcardNo,StringUtils.isNotBlank(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(!Objects.nonNull(pageWrap.getModel().getLevelStatus()),Visits::getOutDate);
+                .or().like(Visits::getName,pageWrap.getModel().getName()));
+        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()),Visits::getIdcardNo,StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()));
+        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),Visits::getCompanyName,pageWrap.getModel().getCompanyName());
         queryWrapper.orderByDesc(Visits::getEditDate);
         IPage<Visits> result = visitsJoinMapper.selectJoinPage(page, Visits.class,queryWrapper);
         if(result!=null&&result.getRecords()!=null){
@@ -1080,6 +1165,7 @@
         visitDetailVO.setPhone(visits.getPhone());
         visitDetailVO.setVisitUserName(member.getName());
         visitDetailVO.setVisitReason(visits.getReason());
+        visitDetailVO.setQrcode(visits.getQrcode());
         visitDetailVO.setVisitTime(DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm") + " 鑷� " + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm") );
         //琚浜哄憳閮ㄩ棬
         Company company = companyMapper.selectById(member.getCompanyId());
@@ -1106,7 +1192,7 @@
         }
         visitDetailVO.setWithVisitsList(
                 visitsMapper.selectList(new QueryWrapper<Visits>().lambda()
-                .select(Visits::getName,Visits::getPhone,Visits::getFaceImg,Visits::getImgurl,Visits::getIdcardDecode,Visits::getStatus)
+                .select(Visits::getName,Visits::getPhone,Visits::getQrcode,Visits::getFaceImg,Visits::getImgurl,Visits::getIdcardDecode,Visits::getStatus)
                 .eq(Visits::getParentId,id)));
         return visitDetailVO;
     }
@@ -1158,9 +1244,16 @@
         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()));
     }
 
 }

--
Gitblit v1.9.3