From 5d7b0a0bbcae6844e2296ef53c3f4c88293dacfe Mon Sep 17 00:00:00 2001
From: jinquanOu <1511349576@qq.com>
Date: 星期二, 11 六月 2024 18:18:08 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 zhang-content/src/main/java/com/ruoyi/service/impl/MeetingStatisticServiceImpl.java |  301 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 301 insertions(+), 0 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/MeetingStatisticServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/MeetingStatisticServiceImpl.java
new file mode 100644
index 0000000..fc33ed5
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/MeetingStatisticServiceImpl.java
@@ -0,0 +1,301 @@
+package com.ruoyi.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.EsModel;
+import com.ruoyi.common.utils.MapUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.domain.*;
+import com.ruoyi.mapper.MeetingStatisticMapper;
+import com.ruoyi.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.*;
+
+
+@Slf4j
+@Service
+public class MeetingStatisticServiceImpl extends ServiceImpl<MeetingStatisticMapper, MeetingStatistic> implements MeetingStatisticService {
+
+    @Resource
+    ZInfoUserService zInfoUserService;
+
+    @Resource
+    ZfLogService zfLogService;
+
+    @Resource
+    private RestHighLevelClient restHighLevelClient;
+
+    @Resource
+    private EsService esSer;
+
+    @Resource
+    ZAuthorityService zAuthorityService;
+
+    @Resource
+    private MeetingStatisticService meetingStatisticService;
+
+    private LambdaQueryWrapper<MeetingStatistic> uniqueCondition(MeetingStatistic meetingStatistic){
+        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getUseTime()), MeetingStatistic::getUseTime, meetingStatistic.getUseTime());
+        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getConferenceRoom()), MeetingStatistic::getConferenceRoom, meetingStatistic.getConferenceRoom());
+        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getTitle()), MeetingStatistic::getTitle, meetingStatistic.getTitle());
+//        lqw.eq(meetingStatistic.getFamilyId()!=null,MeetingStatistic::getFamilyId,meeting.getFamilyId());
+        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getApplyPerson()), MeetingStatistic::getApplyPerson, meetingStatistic.getApplyPerson());
+        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getRatifyPerson())), MeetingStatistic::getRatifyPerson, meetingStatistic.getRatifyPerson());
+        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getStatus())), MeetingStatistic::getStatus, meetingStatistic.getStatus());
+        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getFamilyId())), MeetingStatistic::getFamilyId, meetingStatistic.getFamilyId());
+        return lqw;
+    }
+    public static void getDatePoor(Date endDate, Date nowDate, MeetingStatistic meetingStatistic) {
+
+        long nd = 1000 * 24 * 60 * 60;
+        long nh = 1000 * 60 * 60;
+        long nm = 1000 * 60;
+         long ns = 1000;
+        // 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
+        long diff = endDate.getTime() - nowDate.getTime();
+        // 璁$畻宸灏戝ぉ
+//        long day = diff / nd;
+        // 璁$畻宸灏戝皬鏃�
+        long hour = diff % nd / nh;
+        // 璁$畻宸灏戝垎閽�
+        long min = diff % nd % nh / nm;
+        // 璁$畻宸灏戠//杈撳嚭缁撴灉
+         long sec = diff % nd % nh % nm / ns;
+        System.out.println(hour + "灏忔椂" + min + "鍒嗛挓"+ sec + "绉�");
+        meetingStatistic.setUseTime(hour + "灏忔椂" + min + "鍒嗛挓" + sec + "绉�");
+    }
+    private LambdaQueryWrapper<MeetingStatistic> buildCondition(MeetingStatistic meetingStatistic) {
+        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
+        lqw.select(MeetingStatistic::getFamilyId,MeetingStatistic::getCreateTime);
+        return lqw;
+    }
+    @Override
+    public AjaxResult selectDataList(MeetingStatistic meetingStatistic, Integer pageNum, Integer pageSize) {
+        //瑕佹煡鑷繁瀹跺涵鐨�
+        ZInfoUser myself = zInfoUserService.getMyself();
+        if(myself==null)
+        {
+            //   System.out.println("ssssss");
+            return AjaxResult.success("鎮ㄦ病鍔犲叆鍒板搴旂殑瀹跺涵锛岃鑱旂郴绠$悊鍛�");
+        }
+        Long familyId = myself.getFamilyId();
+//        //涔熻鏌ュ埆浜烘巿鏉冪殑
+//        List<ZAuthority> authority = zAuthorityService.getAuthority();
+//        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(DOCTOR_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
+//        //鍔犱笂鑷繁瀹跺涵鐨刬d
+//        idList.add(familyId);
+//        String familyIds = listFamilyIds();
+//        String secondFamilyAuthority = listSecondFamilyIds();
+        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
+//        LambdaQueryWrapper<MeetingStatistic> lqw = buildCondition(meetingStatistic);
+
+
+        Page<MeetingStatistic> meetingStatisticPage = new Page<>(pageNum, pageSize);
+        Page<MeetingStatistic> pageResult = page(meetingStatisticPage, lqw);
+
+        List<MeetingStatistic> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹�
+        System.out.println("-----------鏁版嵁搴�-----------"+beanRecords);
+        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
+        return AjaxResult.success(data);
+    }
+    @Override
+    public AjaxResult DataList(MeetingStatistic meetingStatistic) {
+        LambdaQueryWrapper<MeetingStatistic> lambdaQueryWrapper = buildCondition(meetingStatistic);
+        List<MeetingStatistic> beanRecords = list(lambdaQueryWrapper);
+        log.info("浠庢暟鎹簱涓煡鍒扮殑涓�:{}", beanRecords);
+        return  AjaxResult.success(beanRecords);
+    }
+
+    @Override
+    public AjaxResult updateData(MeetingStatistic meetingStatistic) {
+        ZfLog zfLog = new ZfLog();
+        zfLog.setUpdateTime(LocalDateTime.now());
+        zfLog.setModule("浼氳缁熻");
+        zfLog.setUpdater(zInfoUserService.getMyself().getNickName());
+        zfLogService.save(zfLog);
+        System.out.println("===================================="+meetingStatistic);
+        if(updateById(meetingStatistic)){
+            //鍒版暟鎹簱涓煡璇㈠搴旂殑鏁版嵁
+            MeetingStatistic dataById = getById(meetingStatistic.getId());
+
+            //鍏堝埌es涓煡璇㈠埌瀵瑰簲閭f潯鏁版嵁鍦╡s鐨刬d
+            EsModel esResult = esSer.findByCtId(dataById.getId().intValue(), "浼氳缁熻");
+            System.out.println("===================================="+meetingStatistic);
+            if (esResult == null){
+                return AjaxResult.success();
+            }
+
+            //鎿嶄綔es淇敼鏁版嵁
+            EsModel newModel = new EsModel();
+//            System.out.println(meeting);
+//            System.out.println("=============="+meetingStatistic.getConnPhone());
+
+//           if (meetingStatistic.getUseTime()==null){
+//                if(meetingStatistic.getHappenEndTime()!=null && meetingStatistic.getHappenStartTime() !=null){
+//                  getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
+//                    System.out.println("===============浣跨敤鏃堕棿====================="+meetingStatistic.getUseTime());
+//                    newModel.setBy2(meetingStatistic.getUseTime());
+//                }else {
+//                    newModel.setBy2(dataById.getUseTime());
+//                }
+//            }
+            if (meetingStatistic.getUseTime()==null){
+                if(meetingStatistic.getHappenEndTime()!=null && meetingStatistic.getHappenStartTime() !=null){
+                    getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
+                    newModel.setBy1(meetingStatistic.getUseTime());
+                }
+                else {
+                    newModel.setBy1(dataById.getUseTime());
+                }
+            }else {
+                newModel.setBy1(dataById.getUseTime());
+            }
+//            if(meetingStatistic.getConferenceRoom()!=null){
+//                newModel.setBy3(meetingStatistic.getConferenceRoom());
+//            }else {
+//                newModel.setBy3(dataById.getConferenceRoom());
+//            }
+            if(meetingStatistic.getTitle()!=null){
+                newModel.setBy2(meetingStatistic.getTitle());
+            }else {
+                newModel.setBy2(dataById.getTitle());
+            }
+//            if(meetingStatistic.getApplyPerson()!=null){
+//                newModel.setBy5(meetingStatistic.getApplyPerson());
+//            }else {
+//                newModel.setBy5(dataById.getApplyPerson());
+//            }
+//            if(meetingStatistic.getRatifyPerson() == 0){
+//                newModel.setBy10(meetingStatistic.getRatifyPerson());
+//            }else {
+//                newModel.setBy10(dataById.getRatifyPerson());
+//            }
+//            if(meetingStatistic.getStatus() == 0){
+//                newModel.setBy11(meetingStatistic.getStatus());
+//            }else {
+//                newModel.setBy11(dataById.getStatus());
+//            }
+            UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId());
+            updateRequest.doc(
+                    "by1",newModel.getBy1(),
+                    "by2",newModel.getBy2()
+
+            );
+
+            LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
+            List<MeetingStatistic> beanRecords = list(lqw);
+            log.info("sss浠庢暟鎹簱涓煡鍒扮殑涓�:{}", beanRecords);
+
+            try {
+                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+
+
+            return AjaxResult.success();
+        }else {
+            return AjaxResult.error();
+        }
+    }
+
+    @Override
+    public AjaxResult deleteData(Long[] ids) {
+        List<MeetingStatistic> meetings = listByIds(Arrays.asList(ids));
+        if (meetingStatisticService.removeByIds(Arrays.asList(ids))) {
+            //鍒犻櫎es涓殑鏁版嵁
+            meetings.stream().forEach(meeting -> {
+                EsModel esModel = esSer.findByCtId((meeting.getId().intValue()), "浼氳缁熻");
+                if (esModel != null){
+                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
+                    try {
+                        restHighLevelClient.delete(deleteRequest,RequestOptions.DEFAULT);
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+
+            return AjaxResult.success();
+        }else {
+            return AjaxResult.error();
+        }
+
+    }
+
+    @Override
+    public List<MeetingStatistic> selectByIds(Long[] ids) {
+        List<MeetingStatistic> list = new ArrayList<>();
+        if (ids.length != 0)
+            list = listByIds(Arrays.asList(ids));
+        else
+            list = list();
+        return list;
+
+    }
+    @Override
+    public AjaxResult addData(MeetingStatistic meetingStatistic) {
+
+        ZInfoUser myself = zInfoUserService.getMyself();
+        Long familyId = myself.getFamilyId();
+
+//        if(familyId == null){
+//            throw new RuntimeException("鎮ㄨ繕鏈姞鍏ヤ换浣曞搴�");
+//        }
+//
+//        List<ZAuthority> authority = zAuthorityService.getAuthority();
+//        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList());
+//        familyIdList.add(familyId);
+//
+//        if (meetingStatistic.getFamilyId()!=null && !familyIdList.contains(meetingStatistic.getFamilyId())) {
+//            throw new RuntimeException("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�");
+//        }
+//
+//
+//        if(meetingStatistic.getFamilyId() == null){
+//            //榛樿娣诲姞鑷繁瀹跺涵鐨勬暟鎹�
+//            meetingStatistic.setFamilyId(familyId);
+//        }
+
+        //鍒ゆ柇鏄惁鏈夐噸澶嶆暟鎹�
+        LambdaQueryWrapper<MeetingStatistic> lqw = uniqueCondition(meetingStatistic);
+        List<MeetingStatistic> list = list(lqw);
+
+        if(list.size()>0){
+            throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁");
+        }
+
+        if (save(meetingStatistic)) {
+            EsModel esModel = new EsModel();
+            Long inte = meetingStatistic.getId();
+            String uuid = UUID.randomUUID().toString().replace("-","");
+            esModel.setId(uuid);
+            esModel.setCtId(inte);
+            esModel.setCtTableName("浼氳缁熻");
+            getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
+            System.out.println("===============浣跨敤鏃堕棿2====================="+meetingStatistic.getUseTime());
+            esModel.setBy1(meetingStatistic.getUseTime());
+            esModel.setBy2(meetingStatistic.getTitle());
+//            esModel.setBy5(meetingStatistic.getApplyPerson());
+            //杩欓噷瀛樺偍鏌ヨ璇︽儏鐨勮矾寰�
+            esModel.setBy5("/zMeetingStatistic");
+            esModel.setFid(familyId);
+            esSer.insertTable(esModel);
+
+            return AjaxResult.success();
+        } else {
+            return AjaxResult.error();
+        }
+    }
+}

--
Gitblit v1.9.1