From 568e38a95cb6fb20fe16b53d17f610aefc6f744f Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 09 十月 2025 18:29:29 +0800
Subject: [PATCH] 钉钉通知 与钥匙柜开发

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java |  295 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 226 insertions(+), 69 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java
index dc6e28b..fe94066 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSONObject;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.dingTalk.DingTalk;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.haikang.model.HKConstants;
 import com.doumee.core.haikang.model.param.BaseResponse;
@@ -124,6 +125,8 @@
     private SmsEmailMapper smsEmailMapper;
     @Autowired
     private EmayService emayService;
+    @Autowired
+    private DingTalk dingTalk;
     @Override
     public Integer create(Approve approve) {
         approveMapper.insert(approve);
@@ -286,6 +289,7 @@
                                 Constants.equalsInteger(i.getUserId(),memberId)
                                 &&Constants.equalsInteger(i.getStatus(),Constants.ZERO)
                                 &&Constants.equalsInteger(i.getSendacopy(),Constants.ZERO)
+                                        &&StringUtils.equals(i.getParam2(),"0")
                         ).count()
                 );
                 //宸插鐞嗘暟鎹�
@@ -302,7 +306,7 @@
                         noticesJoinMapper.selectCount(new QueryWrapper<Notices>().lambda().eq(Notices::getParam3,memberId))
                 );
                 //鎶勯�佹垜鐨勬暟鎹�
-                 internalHomeVO.setNoticeCopyNum(
+                internalHomeVO.setNoticeCopyNum(
                         noticesList.stream().filter(i->Constants.equalsInteger(i.getUserId(),memberId)
                                 &&Constants.equalsInteger(i.getSendacopy(),Constants.ONE)
                                 &&Constants.equalsInteger(i.getReaded(),Constants.ZERO)
@@ -335,6 +339,7 @@
                     noticesList.stream().filter(i->Constants.equalsInteger(i.getUserId(),noticesDTO.getMemberId())
                             &&Constants.equalsInteger(i.getStatus(),Constants.ZERO)
                             &&Constants.equalsInteger(i.getSendacopy(),Constants.ZERO)
+                            &&StringUtils.equals(i.getParam2(),"0")
                     ).count()
             );
             internalHomeVO.setNoticeDealNum(
@@ -364,10 +369,11 @@
      * @param tempType 妯℃澘绫诲瀷  0闈炴柦宸ヤ汉鍛樿瀹㈢敵璇� 1鏂藉伐浜哄憳璁垮鐢宠 2璁垮鎶ュ 3鍏溅甯傚唴鐢ㄨ溅 4鍏溅瀹ゅ鐢ㄨ溅 5甯傚叕鍙哥墿娴佽溅棰勭害
      * @param businessId 涓氬姟涓婚敭 鏍规嵁 tempType
      * @param createMemberId 鎻愪氦娴佺▼浜哄憳
+     * @param applyMember 鐢宠浜哄璞★紙濡傛灉涓虹┖锛岄粯璁や负鎻愪氦浜猴級
      */
     @Override
     @Transactional(rollbackFor = {Exception.class,BusinessException.class})
-    public void createApproveFlow(Integer tempType,Integer businessId,Integer createMemberId){
+    public void createApproveFlow(Integer tempType,Integer businessId,Integer createMemberId,Member applyMember){
         //鏌ヨ澶勭悊妯℃澘
         ApproveTempl approveTempl = approveTemplMapper.selectOne(new QueryWrapper<ApproveTempl>().lambda()
                 .eq(ApproveTempl::getType,tempType)
@@ -394,18 +400,15 @@
         }
         List<ApproveParam> approveCopyList = approveParamAllList.stream().filter(i->i.getType().equals(Constants.ONE)).collect(Collectors.toList());
 
-        Member createMember = memberMapper.selectById(createMemberId);
+        Member createMember =    memberMapper.selectById(createMemberId);
         if(Objects.isNull(createMember)|| Objects.isNull(createMember.getCompanyId())){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鐢宠浜虹粍缁囦俊鎭紓甯�");
         }
         List<Approve> approveList = new ArrayList<>();
-
-        this.organizeApproveData(approveTempl,approveParamList,createMember,businessId,approveList);
-
+        this.organizeApproveData(approveTempl,approveParamList,createMember,applyMember,businessId,approveList);
         if(CollectionUtils.isEmpty(approveList)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀹℃壒娴侀厤缃敊璇�");
         }
-
         //澶勭悊鎶勯�佹暟鎹�
         if(CollectionUtils.isNotEmpty(approveCopyList)){
             this.organizeApproveCopyData(approveTempl,approveCopyList,businessId,approveList);
@@ -417,7 +420,7 @@
 
     @Override
     @Transactional(rollbackFor = {Exception.class,BusinessException.class})
-    public void createApproveForPlatfrom(Integer tempId,Integer businessId,Integer createMemberId){
+    public void createApproveForPlatfrom(Integer tempId,Integer businessId,Integer createMemberId ){
         //鏌ヨ澶勭悊妯℃澘
         ApproveTempl approveTempl = approveTemplMapper.selectById(tempId);
         if(Objects.isNull(approveTempl)){
@@ -446,7 +449,7 @@
         }
         List<Approve> approveList = new ArrayList<>();
 
-        this.organizeApproveData(approveTempl,approveParamList,createMember,businessId,approveList);
+        this.organizeApproveData(approveTempl,approveParamList,createMember,null,businessId,approveList);
 
         if(CollectionUtils.isEmpty(approveList)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀹℃壒娴侀厤缃敊璇�");
@@ -468,15 +471,18 @@
      * @param businessId
      * @param approveList
      */
-    public void organizeApproveData(ApproveTempl approveTempl,List<ApproveParam> approveParamList,Member createMember,Integer businessId,List<Approve> approveList){
+    public void organizeApproveData(ApproveTempl approveTempl,List<ApproveParam> approveParamList,Member createMember,Member applyMember,Integer businessId,List<Approve> approveList){
 
+        if(applyMember ==null){
+            applyMember = createMember;
+        }
         //鍒涘缓榛樿浜轰俊鎭�
         Approve createUserApprove = new Approve();
         createUserApprove.setRemark("鍙戣捣鐢宠");
         createUserApprove.setCreateDate(new Date());
         createUserApprove.setIsdeleted(Constants.ZERO);
         createUserApprove.setTemplatId(approveTempl.getId());
-        createUserApprove.setChekorId(createMember.getId());
+        createUserApprove.setChekorId(applyMember.getId());
         createUserApprove.setCheckDate(createUserApprove.getCreateDate());
         createUserApprove.setStatus(Constants.approveStatus.pass);
         createUserApprove.setTitle("鍙戣捣鐢宠");
@@ -492,7 +498,7 @@
         approveList.add(createUserApprove);
 
         //鏌ヨ鎵�鏈夊緟澶勭悊浜�
-        String token = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode();
+//        String token = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode();
         //瀹℃壒涓氬姟鏁版嵁
         for (int i = 0; i < approveParamList.size(); i++) {
             ApproveParam approveParam = approveParamList.get(i);
@@ -518,22 +524,25 @@
                         title = this.createNoticesData(noticeType,businessId,title,jsonMap);
                     }
                     if(j==0){
-                        //榛樿鐢熸垚涓�鏉� 鐢宠浜虹殑鏁版嵁 鏍囪鍒犻櫎鐘舵�佺敤浜庡鐞嗗埌 浠诲姟涓績锛堟垜鍙戣捣锛変娇鐢�
-                        Notices notices = new Notices();
-                        notices.setCreateDate(new Date());
-                        notices.setIsdeleted(Constants.ONE);
-                        notices.setObjId(businessId);
-                        notices.setObjType(noticeType);
-                        notices.setType(noticeType);
-                        notices.setTitle(title);
-                        notices.setParam1(JSONObject.toJSONString(jsonMap));
-                        notices.setStatus(Constants.ZERO);
-                        notices.setReaded(Constants.ZERO);
-                        notices.setSendacopy(Constants.ZERO);
-                        notices.setParam2("0");
-                        notices.setParam3(createMember.getId().toString());
-                        notices.setInfo("澶勭悊涓�");
-                        noticesJoinMapper.insert(notices);
+                        //璁垮浜哄憳涓嶇敓鎴愭璁板綍
+                       if(!(Constants.equalsInteger(noticeType,Constants.noticesObjectType.visit)&&Constants.equalsInteger(applyMember.getType(),Constants.ONE))){
+                            //榛樿鐢熸垚涓�鏉� 鐢宠浜虹殑鏁版嵁 鏍囪鍒犻櫎鐘舵�佺敤浜庡鐞嗗埌 浠诲姟涓績锛堟垜鍙戣捣锛変娇鐢�
+                            Notices notices = new Notices();
+                            notices.setCreateDate(new Date());
+                            notices.setIsdeleted(Constants.ONE);
+                            notices.setObjId(businessId);
+                            notices.setObjType(noticeType);
+                            notices.setType(noticeType);
+                            notices.setTitle(title);
+                            notices.setParam1(JSONObject.toJSONString(jsonMap));
+                            notices.setStatus(Constants.ZERO);
+                            notices.setReaded(Constants.ZERO);
+                            notices.setSendacopy(Constants.ZERO);
+                            notices.setParam2("0");
+                            notices.setParam3(createMember.getId().toString());
+                            notices.setInfo("澶勭悊涓�");
+                            noticesJoinMapper.insert(notices);
+                        }
                     }
                     if(CollectionUtils.isEmpty(memberList)){
                         throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌瀹℃壒浜轰俊鎭�");
@@ -596,8 +605,7 @@
                             wxPlatNotice.sendPlatformBookTemplateNotice(systemDictDataBiz,
                                     wxNoticeConfigMapper,
                                     platformBooksMapper.selectById(businessId),
-                                    WxPlatConstants.platformBookContent.platformBookWaitAudit,
-                                    token,
+                                    WxPlatConstants.platformBookContent.platformBookWaitAudit, 
                                     Arrays.asList(member.getSystemOpenid().split(",")),
                                     Constants.ONE);
                         }
@@ -613,10 +621,10 @@
                         if(StringUtils.isNotBlank(member.getSystemOpenid())){
                             wxPlatNotice.sendVisitTemplateNotice(systemDictDataBiz,
                                     wxNoticeConfigMapper,visitsMapper.selectById(businessId), WxPlatConstants.visitContent.visitWaitAudit,
-                                    token,
                                     Arrays.asList(member.getSystemOpenid().split(","))
                             );
                         }
+                        
                     }else if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.visitReporting)){
                         //璁垮鎶ュ
                         SmsEmailServiceImpl.sendVisitReportSms(systemDictDataBiz,
@@ -628,7 +636,6 @@
                         if(StringUtils.isNotBlank(member.getSystemOpenid())){
                             wxPlatNotice.sendVisitTemplateNotice(systemDictDataBiz,
                                     wxNoticeConfigMapper,visitsMapper.selectById(businessId), WxPlatConstants.visitReportContent.visitReportWaitAudit,
-                                    token,
                                     Arrays.asList(member.getSystemOpenid().split(","))
                             );
                         }
@@ -650,16 +657,50 @@
                                             wxNoticeConfigMapper,
                                             carUseBookMapper.selectById(businessId),
                                             WxPlatConstants.carUseBookContent.carUseBookWaitAudit,
-                                            token,
                                             Arrays.asList(member.getSystemOpenid().split(",")),
                                             Constants.ONE);
                                 }
                             }
                         }
                     }
+                } 
+            }
+            if(Constants.equalsInteger(i,Constants.ZERO) && CollectionUtils.isNotEmpty(memberList)){
+                //鐢熸垚绗竴鎵归拤閽夊鎵归�氱煡淇℃伅
+                List<String> erpId = memberList.stream().filter(m->StringUtils.isNotBlank(m.getErpId())).map(m->m.getErpId()).collect(Collectors.toList());
+                if(CollectionUtils.isNotEmpty(erpId)){
+                    if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.useCar)){
+                        CarUseBook carUseBook = carUseBookMapper.selectJoinOne(CarUseBook.class,
+                                new MPJLambdaWrapper<CarUseBook>()
+                                        .selectAll(CarUseBook.class)
+                                        .selectAs(Member::getName,CarUseBook::getMemberName)
+                                        .leftJoin(Member.class,Member::getId,CarUseBook::getMemberId)
+                                        .eq(CarUseBook::getId,businessId)
+                                        .last(" limit 1 ")
+                        );
+                        if(Objects.nonNull(carUseBook)){
+                            if(CollectionUtils.isNotEmpty(erpId)){
+                                String ddTalkId = dingTalk.toDoNotice(StringUtils.isNotBlank(carUseBook.getMemberName())?(carUseBook.getMemberName()+"鎻愪氦鐨勫叕鍔$敤杞︾敵璇�"):"鍏姟杞︾敤杞︾敵璇�",
+                                        erpId ,
+                                        dingTalk.getToDoCarUseBookFiledInfo(carUseBook),"pages/staff/vehicle/sendACarDetail?id="+carUseBook.getId());
+                                carUseBookMapper.update(new UpdateWrapper<CarUseBook>().lambda()
+                                        .set(CarUseBook::getDdBelongToUnionId,erpId.get(Constants.ZERO))
+                                        .set(CarUseBook::getDdToDoId,ddTalkId).eq(CarUseBook::getId,carUseBook.getId()));
+                            }
+                        }
+                    }else if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.visit) || Constants.equalsInteger(noticeType,Constants.noticesObjectType.visitReporting)) {
+                        Visits visits = visitsMapper.selectById(businessId);
+                        if (Objects.nonNull(visits)) {
+                            //TODO 缂哄皯鍩熷悕鍓嶇紑鍐呭
+                            String ddTalkId = dingTalk.toDoNotice(visits.getName() + "鐨勮瀹㈢敵璇�",
+                                    erpId,
+                                    dingTalk.getToDoVisitFiledInfo(visits), "pages/appointmentDetails/appointmentDetails?id=" + visits.getId());
+                            visitsMapper.update(new UpdateWrapper<Visits>().lambda()
+                                            .set(Visits::getDdBelongToUnionId,erpId.get(Constants.ZERO))
+                                    .set(Visits::getDdToDoId, ddTalkId).eq(Visits::getId, visits.getId()));
+                        }
+                    }
                 }
-
-
             }
         }
     }
@@ -719,13 +760,23 @@
             if(Objects.isNull(platformBooks)){
                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌涓氬姟鏁版嵁淇℃伅");
             }
-            title = "[鐗╂祦杞﹀叆鍥绾鐢宠浜�-" + platformBooks.getDriverName();
-            jsonMap.put("inType", "鍏ュ簱绫诲瀷锛�"+(Constants.equalsInteger(platformBooks.getInType(),Constants.ZERO)?"鏁存墭鐩�":"浠剁儫"));
-            jsonMap.put("totalNum", "鎬昏繍杈撻噺锛�"+platformBooks.getTotalNum()+"涓囨敮");
-            jsonMap.put("arriveDate", "鍒板満鏃堕棿锛�" + DateUtil.DateToStr(platformBooks.getArriveDate() , "yyyy-MM-dd HH:mm"));
-            jsonMap.put("carNum", "杞︾墝鐓э細"+platformBooks.getCarCodeFront());
+            title = ApproveServiceImpl.creatPlatformBookNotice(platformBooks,jsonMap);
+//            title = "[鐗╂祦杞﹀叆鍥绾鐢宠浜�-" + platformBooks.getDriverName();
+//            jsonMap.put("inType", "鍏ュ簱绫诲瀷锛�"+(Constants.equalsInteger(platformBooks.getInType(),Constants.ZERO)?"鏁存墭鐩�":"浠剁儫"));
+//            jsonMap.put("totalNum", "鎬昏繍杈撻噺锛�"+platformBooks.getTotalNum()+"涓囨敮");
+//            jsonMap.put("arriveDate", "鍒板満鏃堕棿锛�" + DateUtil.DateToStr(platformBooks.getArriveDate() , "yyyy-MM-dd HH:mm"));
+//            jsonMap.put("carNum", "杞︾墝鐓э細"+platformBooks.getCarCodeFront());
         }
         return title;
+    }
+
+    public static String creatPlatformBookNotice(PlatformBooks platformBooks,Map<String,Object> jsonMap){
+        jsonMap.put("inType", "浣滀笟绫诲瀷锛�"+(Constants.equalsInteger(platformBooks.getInType(),Constants.ZERO)?"鏁存墭鐩�":"浠剁儫"));
+        jsonMap.put("totalNum", "鎬昏繍杈撻噺锛�"+platformBooks.getTotalNum()+"涓囨敮");
+        jsonMap.put("arriveDate", "鍒板満鏃堕棿锛�" + DateUtil.DateToStr(platformBooks.getArriveDate() , "yyyy-MM-dd HH:mm"));
+        jsonMap.put("carNum", "杞︾墝鐓э細"+platformBooks.getCarCodeFront());
+        return  "[鐗╂祦杞﹀叆鍥绾鐢宠浜�-" + platformBooks.getDriverName() ;
+
     }
 
 
@@ -1206,8 +1257,10 @@
                 || Objects.isNull(approveDTO.getLoginUserInfo())){
             throw new BusinessException(ResponseStatus.BAD_REQUEST);
         }
-        if(approveDTO.getStatus().equals(Constants.THREE)&&StringUtils.isBlank(approveDTO.getCheckInfo())){
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇疯緭鍏ユ嫆缁濊鏄�");
+        if(!(Constants.equalsInteger(approveDTO.getObjType(),Constants.THREE)||Constants.equalsInteger(approveDTO.getObjType(),Constants.FOUR))){
+            if(approveDTO.getStatus().equals(Constants.THREE)&&StringUtils.isBlank(approveDTO.getCheckInfo())){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇疯緭鍏ユ嫆缁濊鏄�");
+            }
         }
         Approve approve = approveMapper.selectOne(new QueryWrapper<Approve>()
                 .lambda()
@@ -1271,6 +1324,7 @@
         approveMapper.updateById(approve);
         //鏄惁澶勭悊 涓氬姟鏁版嵁
         Boolean dealBusinessBean = false;
+        Boolean dealDDToDo = false;
         //瀹℃壒椹冲洖鎯呭喌
         if(approveDTO.getStatus().equals(Constants.THREE)){
             dealBusinessBean = true;
@@ -1333,7 +1387,6 @@
                             .in(Approve::getId,approveList.stream().map(m->m.getId()).collect(Collectors.toList())));
                 }
                 /**寮�鍚笅涓�绾у埆鐨勬暟鎹负寰呭鏍�**/
-
                 List<Approve> waitAuditList = approveJoinMapper.selectJoinList(Approve.class,
                         new MPJLambdaWrapper<Approve>()
                                 .selectAll(Approve.class)
@@ -1369,13 +1422,17 @@
 //                }
             }else if(approve.getApproveType().equals(Constants.ONE)){
                 //浼氱 涓旂粓瀹�
+                if(!Constants.equalsInteger(approveList.size(),Constants.ZERO)&&Constants.equalsInteger(approve.getIsEndCheck(),Constants.ZERO)){
+                    //鏍囪閽夐拤閫氱煡鑷繁宸插鐞�
+                    dealDDToDo = true;
+                }
+
                 //鏃犱粬浜哄鎵圭殑鎯呭喌 鍒欎慨鏀规暟鎹姸鎬�
                 if(Constants.equalsInteger(approveList.size(),Constants.ZERO)&&Constants.equalsInteger(approve.getIsEndCheck(),Constants.ONE)){
                     dealBusinessBean = true;
                 }else{
                     if(Constants.equalsInteger(approveList.size(),Constants.ZERO)&&Constants.equalsInteger(approve.getIsEndCheck(),Constants.ZERO)){
                         /**寮�鍚笅涓�绾у埆鐨勬暟鎹负寰呭鏍�**/
-
                         List<Approve> waitAuditList = approveJoinMapper.selectJoinList(Approve.class,
                                 new MPJLambdaWrapper<Approve>()
                                         .selectAll(Approve.class)
@@ -1405,6 +1462,7 @@
                         List<String> memberPhone = waitAuditList.stream().filter(i->StringUtils.isNotBlank(i.getMemberPhone())).map(i->i.getMemberPhone()).collect(Collectors.toList());
                         List<String> openIdList =waitAuditList.stream().filter(i->StringUtils.isNotBlank(i.getSystemOpenid())).map(i->i.getSystemOpenid()).collect(Collectors.toList());
 
+
                         this.sendNextLvSms(approve,approveDTO,memberPhone,openIdList);
 
                     }
@@ -1414,7 +1472,7 @@
 //                    }
                 }
             }
-            this.passNextNotices(dealBusinessBean,notices,approve,approveList,approveCopyList,approveDTO);
+            this.passNextNotices(dealBusinessBean,notices,approve,approveList,approveCopyList,approveDTO,dealDDToDo);
         }
         //澶勭悊涓氬姟鏁版嵁
         if(dealBusinessBean){
@@ -1428,6 +1486,12 @@
     public void sendNextLvSms(Approve approve ,ApproveDTO approveDTO , List<String> memberPhone ,List<String> openIdList){
         WxPlatNotice wxPlatNotice = new WxPlatNotice();
         //鐗╂祦杞﹂绾�
+        List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda()
+                .in(Member::getPhone,memberPhone)
+                .eq(Member::getIsdeleted,Constants.ZERO)
+                .eq(Member::getStatus,Constants.ZERO)
+                .isNotNull(Member::getErpId)
+         );
         if(approveDTO.getObjType().equals(Constants.approveObjectType.reason)){
             SmsEmailServiceImpl.sendPlatformBookSms(systemDictDataBiz,
                     emayService,smsEmailMapper,smsConfigMapper,platformBooksMapper,approveDTO.getObjId(),
@@ -1440,7 +1504,6 @@
                         wxNoticeConfigMapper,
                         platformBooksMapper.selectById(approveDTO.getObjId()),
                         WxPlatConstants.platformBookContent.platformBookWaitAudit,
-                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                         openIdList,
                         Constants.ONE);
             }
@@ -1455,21 +1518,36 @@
                     SmsConstants.carUseBookContent.carUseBookWaitAudit,
                     approveDTO.getCheckInfo(),memberPhone);
             //鍙戦�佸叕浼楀彿閫氱煡
-            if(CollectionUtils.isNotEmpty(openIdList)){
-                CarUseBook carUseBook = carUseBookMapper.selectById(approve.getObjId());
-                if(Objects.nonNull(carUseBook)){
+            CarUseBook carUseBook = carUseBookMapper.selectJoinOne(CarUseBook.class,
+                    new MPJLambdaWrapper<CarUseBook>()
+                            .selectAll(CarUseBook.class)
+                            .selectAs(Member::getName,CarUseBook::getMemberName)
+                            .leftJoin(Member.class,Member::getId,CarUseBook::getMemberId)
+                            .eq(CarUseBook::getId,approve.getObjId())
+                            .last(" limit 1 ")
+            );
+            if(CollectionUtils.isNotEmpty(openIdList)&&Objects.nonNull(carUseBook)){ 
                     SystemUser systemUser = systemUserMapper.selectById(carUseBook.getCreator());
                     if(Objects.nonNull(systemUser)){
                         carUseBook.setMemberName(systemUser.getRealname());
                         //鍙戦�佸井淇″叕浼楀彿閫氱煡
                         wxPlatNotice.sendCarUseBookTemplateNotice(systemDictDataBiz,
                                 wxNoticeConfigMapper,carUseBook,
-                                WxPlatConstants.carUseBookContent.carUseBookWaitAudit,
-                                systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
+                                WxPlatConstants.carUseBookContent.carUseBookWaitAudit, 
                                 openIdList,1);
-                    }
-                }
+                    } 
             }
+            //鍙戦�侀拤閽夊緟鍔� 鍏姟杞︾敵璇�
+            if(Objects.nonNull(carUseBook)&&Objects.nonNull(memberList)){
+                //鏍囪褰撳墠瀹℃壒浜哄凡瀹屾垚
+                dingTalk.updToDoNoticeInfoStatus(carUseBook.getDdBelongToUnionId(),carUseBook.getDdToDoId());
+                //TODO 缂哄皯鍩熷悕鍓嶇紑鍐呭
+                String ddTalkId = dingTalk.toDoNotice(StringUtils.isNotBlank(carUseBook.getMemberName())?(carUseBook.getMemberName()+"鎻愪氦鐨勫叕鍔$敤杞︾敵璇�"):"鍏姟杞︾敤杞︾敵璇�",
+                        memberList.stream().map(i->i.getErpId()).collect(Collectors.toList()) ,
+                        dingTalk.getToDoCarUseBookFiledInfo(carUseBook),"pages/staff/vehicle/sendACarDetail?id="+carUseBook.getId());
+                carUseBookMapper.update(new UpdateWrapper<CarUseBook>().lambda()
+                        .set(CarUseBook::getDdToDoId,ddTalkId).eq(CarUseBook::getId,carUseBook.getId()));
+            } 
         }else
             //璁垮鐢宠/鎶ュ
             if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit)
@@ -1491,9 +1569,18 @@
                         wxPlatNotice.sendVisitTemplateNotice(systemDictDataBiz,
                                 wxNoticeConfigMapper,visitsMapper.selectById(approveDTO.getObjId()),
                                 approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)?WxPlatConstants.visitReportContent.visitReportWaitAudit:WxPlatConstants.visitContent.visitWaitAudit,
-                                systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                                 openIdList
                         );
+                    }
+                    if(Objects.nonNull(visits)&&Objects.nonNull(memberList)){
+                        //鏍囪褰撳墠瀹℃壒浜哄凡瀹屾垚
+                        dingTalk.updToDoNoticeInfoStatus(visits.getDdBelongToUnionId(),visits.getDdToDoId());
+                        //TODO 缂哄皯鍩熷悕鍓嶇紑鍐呭
+                        String ddTalkId = dingTalk.toDoNotice(visits.getName()+"鐨勮瀹㈢敵璇�",
+                                memberList.stream().map(i->i.getErpId()).collect(Collectors.toList()) ,
+                                dingTalk.getToDoVisitFiledInfo(visits),"pages/appointmentDetails/appointmentDetails?id="+visits.getId());
+                        visitsMapper.update(new UpdateWrapper<Visits>().lambda()
+                                .set(Visits::getDdToDoId,ddTalkId).eq(Visits::getId,visits.getId()));
                     }
 
                 }
@@ -1507,15 +1594,15 @@
      * @param dealBusinessBean  鏄惁闇�瑕佽繘琛屾洿鏂颁笟鍔℃暟鎹姸鎬�
      * @param approve  瀹℃壒璁板綍
      * @param approveList  鍚岀骇寰呭鎵规暟鎹�
+     * @param dealDDToDo  鏄惁澶勭悊 褰撳墠瀹℃壒淇℃伅浜虹殑閽夐拤鐨勫伐浣滈�氱煡
+     *
      */
-    public void passNextNotices(Boolean dealBusinessBean,Notices notices,Approve approve,List<Approve> approveList,List<Approve> copyList,ApproveDTO approveDTO){
+    public void passNextNotices(Boolean dealBusinessBean,Notices notices,Approve approve,List<Approve> approveList,List<Approve> copyList,ApproveDTO approveDTO,Boolean dealDDToDo){
         //鏈紑鍚笅涓�绾ф椂锛屾搷浣滃悗鐨勫緟瀹℃壒浜�
         String memberNames =notices.getParam5()
                 .replaceAll(","+notices.getRemark(),"")
                 .replaceAll(notices.getRemark()+",","")
                 .replaceAll(notices.getRemark(),"");
-
-
 
         //1銆佷慨鏀硅嚜宸辩殑鏁版嵁璁板綍
         noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda()
@@ -1596,6 +1683,30 @@
                 }
             }
         }
+        if(dealDDToDo){
+            if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit)
+                    ||approveDTO.getObjType().equals(Constants.approveObjectType.constructionVisit)
+                    ||approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)) {
+                Member member = memberMapper.selectById(approve.getChekorId());
+                // 璁垮 涓夌被涓氬姟鏁版嵁
+                Visits visits = visitsMapper.selectById(approveDTO.getObjId());
+                if(Objects.nonNull(member)&&Objects.nonNull(member.getErpId())
+                        &&Objects.nonNull(visits)&&Objects.nonNull(visits.getDdToDoId())&&Objects.nonNull(visits.getDdBelongToUnionId())){
+                    dingTalk.updUserToDoNoticeInfoStatus(visits.getDdBelongToUnionId(),visits.getDdToDoId(),member.getErpId());
+                }
+            }else if(approveDTO.getObjType().equals(Constants.approveObjectType.cityUseCar)||approveDTO.getObjType().equals(
+                    Constants.approveObjectType.unCityUseCar)){
+                Member member = memberMapper.selectById(approve.getChekorId());
+                CarUseBook carUseBook = carUseBookJoinMapper.selectById(approveDTO.getObjId());
+                if(Objects.nonNull(member)&&Objects.nonNull(member.getErpId())
+                        &&Objects.nonNull(carUseBook)&&Objects.nonNull(carUseBook.getDdToDoId())&&Objects.nonNull(carUseBook.getDdBelongToUnionId())){
+                    dingTalk.updUserToDoNoticeInfoStatus(carUseBook.getDdBelongToUnionId(),carUseBook.getDdToDoId(),member.getErpId());
+                }
+            }
+
+
+
+        }
     }
 
 
@@ -1643,11 +1754,13 @@
 
     public void dealBusinessData(ApproveDTO approveDTO,Approve approve){
         WxPlatNotice wxPlatNotice = new WxPlatNotice();
+        Visits visits = new Visits();
+        CarUseBook carUseBook = new CarUseBook();
         if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit)
                 ||approveDTO.getObjType().equals(Constants.approveObjectType.constructionVisit)
                 ||approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)){
             // 璁垮 涓夌被涓氬姟鏁版嵁
-            Visits visits = visitsMapper.selectById(approveDTO.getObjId());
+            visits = visitsMapper.selectById(approveDTO.getObjId());
             if(Objects.isNull(visits)){
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐢宠璁板綍");
             }
@@ -1748,16 +1861,28 @@
                 if(Objects.nonNull(visits) && StringUtils.isNotBlank(visits.getOpenid())){
                     wxPlatNotice.sendVisitTemplateNotice(systemDictDataBiz,
                             wxNoticeConfigMapper,visits, objCode,
-                            systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                             Arrays.asList(visits.getOpenid().split(","))
                     );
                 }
+                //閽夐拤閫氱煡 璁垮琚浜烘垨鎶ュ鎻愪氦浜�
+                Member beVisitMember = memberMapper.selectById(Constants.equalsInteger(visits.getType(),Constants.TWO)?visits.getMemberId():visits.getReceptMemberId());
+                if(Objects.nonNull(beVisitMember)&&StringUtils.isNotBlank(beVisitMember.getDdId())){
+                    dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()),
+                            beVisitMember.getDdId(),
+                            dingTalk.getVisitNoticeMsg(visits,visits.getName()+"鐨�"+(Constants.equalsInteger(visits.getType(),Constants.TWO)?"璁垮鎶ュ":"璁垮鐢宠")+"锛�"+
+                                    (Constants.equalsInteger(approveDTO.getStatus(),Constants.TWO)? "宸插鎵归�氳繃":"宸插鎵归┏鍥�"))
+                    );
+                }
             }
-
+            if(StringUtils.isNotBlank(visits.getDdBelongToUnionId())
+                    && StringUtils.isNotBlank(visits.getDdToDoId())){
+                //鏍囪褰撳墠閽夐拤瀹℃壒宸插畬鎴�
+                dingTalk.updToDoNoticeInfoStatus(visits.getDdBelongToUnionId(),visits.getDdToDoId());
+            }
         }else if(approveDTO.getObjType().equals(Constants.approveObjectType.cityUseCar)||approveDTO.getObjType().equals(
                 Constants.approveObjectType.unCityUseCar)){
             this.updDriver(approveDTO,approve,true);
-            CarUseBook carUseBook = carUseBookJoinMapper.selectById(approveDTO.getObjId());
+            carUseBook = carUseBookJoinMapper.selectById(approveDTO.getObjId());
             if(Objects.nonNull(carUseBook)){
                 SystemUser systemUser = systemUserMapper.selectById(carUseBook.getCreator());
                 //鍙戦�侀�氱煡鐭伅
@@ -1775,9 +1900,22 @@
                     wxPlatNotice.sendCarUseBookTemplateNotice(systemDictDataBiz,
                             wxNoticeConfigMapper,carUseBook,
                             Constants.equalsInteger(approveDTO.getStatus(),Constants.TWO)?WxPlatConstants.carUseBookContent.carUseBookAuditSuccess: WxPlatConstants.carUseBookContent.carUseBookAuditFail,
-                            systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                             Arrays.asList(systemUser.getOpenid().split(",")),0);
                 }
+            }
+            //閽夐拤閫氱煡鍙戣捣浜�
+            Member creatMember = memberMapper.selectById(carUseBook.getMemberId());
+            if(Objects.nonNull(creatMember)&&StringUtils.isNotBlank(creatMember.getDdId())){
+                dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()),
+                        creatMember.getErpId(),
+                                dingTalk.getCarUseNoticeMsg(carUseBook,carUseBook.getMemberName() + "鎻愪氦鐨勫叕鍔$敤杞︼紝"+
+                                        (Constants.equalsInteger(approveDTO.getStatus(),Constants.TWO)? "宸插鎵归�氳繃":"宸插鎵归┏鍥�"))
+                );
+            }
+            if(StringUtils.isNotBlank(carUseBook.getDdBelongToUnionId())
+                && StringUtils.isNotBlank(carUseBook.getDdToDoId())){
+                //鏍囪褰撳墠閽夐拤瀹℃壒宸插畬鎴�
+                dingTalk.updToDoNoticeInfoStatus(carUseBook.getDdBelongToUnionId(),carUseBook.getDdToDoId());
             }
 
         }else if(approveDTO.getObjType().equals(Constants.approveObjectType.reason)){
@@ -1846,7 +1984,6 @@
                 wxPlatNotice.sendPlatformBookTemplateNotice(systemDictDataBiz,
                         wxNoticeConfigMapper, platformBooks,
                         Constants.equalsInteger(approveDTO.getStatus(),Constants.TWO)?WxPlatConstants.platformBookContent.platformBookAuditSuccess: WxPlatConstants.platformBookContent.platformBookAuditFail,
-                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                         Arrays.asList(driver.getOpenid().split(",")),0);
             }
 
@@ -1854,13 +1991,33 @@
             throw new BusinessException(ResponseStatus.BAD_REQUEST);
         }
         if(Constants.equalsInteger(approveDTO.getStatus(),Constants.TWO)){
-            //澶勭悊閫氳繃 鏄剧ず鎵�鏈夌殑鎶勯�佽褰�
-            approveMapper.update(null,new UpdateWrapper<Approve>().lambda().set(Approve::getStatus,Constants.TWO)
-                    .set(Approve::getCheckDate,new Date())
-                    .eq(Approve::getObjId,approve.getObjId())
+            List<Approve> approveList = approveMapper.selectList(new QueryWrapper<Approve>().lambda().eq(Approve::getObjId,approve.getObjId())
                     .eq(Approve::getObjType,approve.getObjType())
-                    .eq(Approve::getType,Constants.ONE)
-            );
+                    .eq(Approve::getType,Constants.ONE));
+            if(CollectionUtils.isNotEmpty(approveList)){
+                //澶勭悊閫氳繃 鏄剧ず鎵�鏈夌殑鎶勯�佽褰�
+                approveMapper.update(null,new UpdateWrapper<Approve>().lambda().set(Approve::getStatus,Constants.TWO)
+                        .set(Approve::getCheckDate,new Date())
+                        .eq(Approve::getObjId,approve.getObjId())
+                        .eq(Approve::getObjType,approve.getObjType())
+                        .eq(Approve::getType,Constants.ONE)
+                );
+                List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda()
+                        .eq(Member::getIsdeleted,Constants.ZERO)
+                        .eq(Member::getStatus,Constants.ZERO)
+                        .isNotNull(Member::getDdId)
+                        .in(Member::getId,approveList.stream().map(i->i.getChekorId()).collect(Collectors.toList())));
+                if(CollectionUtils.isNotEmpty(memberList)){
+                    if(Objects.nonNull(visits)||Objects.nonNull(carUseBook)){
+                        dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()),
+                                StringUtils.join(memberList.stream().map(i->i.getDdId()).collect(Collectors.toList()),","),
+                                Objects.nonNull(visits)?
+                                        dingTalk.getVisitNoticeMsg(visits,visits.getName()+"鐨�"+(Constants.equalsInteger(visits.getType(),Constants.TWO)?"璁垮鎶ュ":"璁垮鐢宠")+"锛屾妱閫佺粰鎮紝璇风煡鏅�"):
+                                        dingTalk.getCarUseNoticeMsg(carUseBook,carUseBook.getMemberName() + "鎻愪氦鐨勫叕鍔$敤杞︼紝鎶勯�佺粰鎮紝璇风煡鏅�")
+                        );
+                    }
+                }
+            }
         }
     }
 

--
Gitblit v1.9.3