From 56cd9a53cb4110b0c214f9b66a993eec7e57b4e5 Mon Sep 17 00:00:00 2001
From: nidapeng <jp@doumee.com>
Date: 星期四, 11 四月 2024 11:47:48 +0800
Subject: [PATCH] 最新版本

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/VisitsServiceImpl.java |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 8 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 e387803..cd7243c 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
@@ -1,5 +1,6 @@
 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;
@@ -54,9 +55,11 @@
 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;
 
@@ -110,10 +113,10 @@
     @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())
+                    || StringUtils.isBlank(erpVisitDTO.getCompanyName())
                     || Objects.isNull(erpVisitDTO.getIdcardType())
                     || StringUtils.isBlank(erpVisitDTO.getIdcardNo())
                     || Objects.isNull(erpVisitDTO.getStarttime())
@@ -155,19 +158,17 @@
                 for (ErpWithVisitDTO erpWithVisitDTO : erpWithVisitDTOList) {
                     Visits withVisits = new Visits();
                     BeanUtils.copyProperties(erpWithVisitDTO, withVisits);
+                    withVisits.setCompanyName(visits.getCompanyName());
+                    withVisits.setReason(visits.getReason());
                     visitsList.add(withVisits);
                 }
                 visits.setWithUserList(visitsList);
             }
             this.createFk(visits,true);
-        }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) {
+    @Transactional(propagation = Propagation.NOT_SUPPORTED)
+    void saveInterfaceLog(Object param, String path, String result, Integer type) {
         InterfaceLog interfaceLog=new InterfaceLog();
         interfaceLog.setType(type);
         interfaceLog.setCreateDate(new Date());
@@ -568,9 +569,10 @@
     private void isValidBaseParam(Visits visits) {
         if(visits.getEndtime() == null
                 || visits.getStarttime() == null
-//                ||  StringUtils.isBlank(visits.getReason())
+                ||  StringUtils.isBlank(visits.getReason())
                 ||  StringUtils.isBlank( visits.getName())
                 ||  StringUtils.isBlank( visits.getPhone())
+                ||  StringUtils.isBlank( visits.getCompanyName())
                 ||  visits.getIdcardType() == null
 //                ||  StringUtils.isBlank( visits.getFaceImg() )
                 ||  StringUtils.isBlank( visits.getIdcardNo() )
@@ -582,6 +584,15 @@
         }
         if(visits.getEndtime().getTime() <= visits.getStarttime().getTime()){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝棰勭害缁撴潫鏃堕棿蹇呴』澶т簬寮�濮嬫椂闂达紒");//
+        }
+        if(visits.getSourceType().equals(Constants.ZERO)){
+            String code = systemDictDataBiz.queryByCode(Constants.VISIT_CONFIG,Constants.VALIDATE_VISIT).getCode();
+            if(StringUtils.isNotBlank(code)&&!StringUtils.equals(code,"0")){
+                Integer betweenDays = Math.toIntExact(cn.hutool.core.date.DateUtil.between(visits.getEndtime(), visits.getStarttime(), DateUnit.DAY));
+                if(Integer.compare(betweenDays,Integer.valueOf(code))>0){
+                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝棰勭害鎬诲ぉ鏁颁笉鑳借秴杩嘯"+code+"澶锛�");
+                }
+            }
         }
     }
     private void isValidWithVisitParam(Visits visits,  List<Member> addList,  List<Member> updateList) {
@@ -847,6 +858,8 @@
         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)
                 .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) {
@@ -916,6 +929,9 @@
         }
         if(!Constants.equalsInteger(Constants.ONE, member.getCanVisit())){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝璇ユ嫓璁夸汉鏆傛椂涓嶈兘鎺ュ彈鎮ㄧ殑鎷滆鐢宠~");
+        }
+        if(StringUtils.isBlank(member.getHkId())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝璇ユ嫓璁夸汉鏈笅鍙戞殏鏃朵笉鑳芥帴鍙楁偍鐨勬嫓璁跨敵璇穨");
         }
         return  member;
     }
@@ -1253,5 +1269,25 @@
                 .eq(Retention::getType,Constants.memberType.visitor)
                 .eq(Retention::getMemberId,visits.getMemberId()));
     }
+    @Override
+    public void  visitCancel(Integer visitId){
+        Visits visits = visitsMapper.selectById(visitId);
+        if(Objects.isNull(visits)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(!visits.getStatus().equals(Constants.VisitStatus.xfSuccess)){
+            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