zqy
2024-11-26 8a3d7199725a52b555d46daae5e95cef914c9ab3
zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java
@@ -17,6 +17,7 @@
import com.ruoyi.mapper.ZfAncestorMapper;
import com.ruoyi.service.*;
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.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
@Service
@@ -45,6 +47,9 @@
    @Resource
    private  ZfClanService zfClanService;
    @Resource
    ZfLogService zfLogService;
    private LambdaQueryWrapper<ZfAncestor> buildCondition(ZfAncestor zfAncestor) {
@@ -274,35 +279,90 @@
    }
    @Override
    public ZfAncestor update(ZfAncestor zfAncestor) {
        LambdaQueryWrapper<ZfAncestor> lqw = uniqueCondition(zfAncestor);
        List<ZfAncestor> list = list(lqw);
    public AjaxResult update(ZfAncestor zfAncestor) {
//        LambdaQueryWrapper<ZfAncestor> lqw = uniqueCondition(zfAncestor);
//        List<ZfAncestor> list = list(lqw);
//        System.out.println(list);
        ZInfoUser updateDate =zInfoUserService.getInfoBysysId(zfAncestor.getSysId());
        ZfAncestor zfAncestor1 = new ZfAncestor();
        ZfAncestor zfAncestor2 = new ZfAncestor();
        zfAncestor1.setId(list.get(0).getId());
        zfAncestor1.setName(zfAncestor.getName());
        System.out.println(updateDate);
//        ZInfoUser updateDate =zInfoUserService.getInfoBysysId(zfAncestor.getSysId());
//        ZfAncestor zfAncestor1 = new ZfAncestor();
//        ZfAncestor zfAncestor2 = new ZfAncestor();
//        zfAncestor1.setId(list.get(0).getId());
//        zfAncestor1.setName(zfAncestor.getName());
//        System.out.println(updateDate);
//        if (zfAncestor.getSex() != null){
//        if(updateDate.getSpouseId() != null && updateDate.getSpouseId() != 0){
//            Long spouseId=updateDate.getSpouseId();
//            if (zInfoUserService.getById(spouseId).getSex().equals(zfAncestor.getSex())){
//
//                Long spouseSysId = zInfoUserService.getById(spouseId).getSysId();
//                zfAncestor2.setSysId(spouseSysId);
//                Integer spId = list(uniqueCondition(zfAncestor2)).get(0).getId();
//                zfAncestor2.setId(spId);
//                zfAncestor2.setSex(zfAncestor.getSex() == 0? 1: 0);
//                System.out.println(zfAncestor2);
//                zfAncestorService.updateById(zfAncestor2);
//            }}
//            zfAncestor1.setSex(zfAncestor.getSex());}
////        System.out.println("1841vdndigrrr"+zfAncestor1);
//
//            zfAncestorService.updateById(zfAncestor1);
        //操作后加入日志
        ZfLog zfLog = new ZfLog();
        zfLog.setUpdateTime(LocalDateTime.now());
        zfLog.setModule("家族修改");
        zfLog.setUpdater(zInfoUserService.getMyself().getNickName());
        zfLogService.save(zfLog);
        System.out.println("===================================="+zfAncestor);
        LambdaQueryWrapper<ZfAncestor> lqw = uniqueCondition(zfAncestor);
        ZfAncestor zfAncestorList = list(lqw).get(0);
        zfAncestor.setId(zfAncestorList.getId());
        System.out.println(zfAncestorList);
        if(updateById(zfAncestor)){
            //到数据库中查询对应的数据
            ZfAncestor dataById = getById(zfAncestor.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esSer.findByCtId(dataById.getId(), "家族");
            if (esResult == null){
                return AjaxResult.success();
            }
            System.out.println("-------------------------"+zfAncestor);
            //操作es修改数据
            EsModel newModel = new EsModel();
//            System.out.println(meeting);
//            System.out.println("=============="+meeting.getConnPhone());
        if (zfAncestor.getSex() != null){
        if(updateDate.getSpouseId() != null && updateDate.getSpouseId() != 0){
            Long spouseId=updateDate.getSpouseId();
            if (zInfoUserService.getById(spouseId).getSex().equals(zfAncestor.getSex())){
                newModel.setBy8(zfAncestor.getSex());
            }else {
                newModel.setBy8(dataById.getSex());
            }
                Long spouseSysId = zInfoUserService.getById(spouseId).getSysId();
                zfAncestor2.setSysId(spouseSysId);
                Integer spId = list(uniqueCondition(zfAncestor2)).get(0).getId();
                zfAncestor2.setId(spId);
                zfAncestor2.setSex(zfAncestor.getSex() == 0? 1: 0);
                System.out.println(zfAncestor2);
                zfAncestorService.updateById(zfAncestor2);
            }}
            zfAncestor1.setSex(zfAncestor.getSex());}
//        System.out.println("1841vdndigrrr"+zfAncestor1);
            if(zfAncestor.getName() != null){
                newModel.setBy2(zfAncestor.getName());
            }else {
                newModel.setBy2(dataById.getName());
            }
            zfAncestorService.updateById(zfAncestor1);
        return zfAncestor2;
            UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId());
            updateRequest.doc(
                    "by1",newModel.getBy8(),
                    "by2",newModel.getBy2()
            );
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
             return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
    @Override