| | |
| | | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.domain.ZInfoUser; |
| | | import com.ruoyi.domain.ZfAncestor; |
| | | import com.ruoyi.domain.ZfClan; |
| | | import com.ruoyi.common.utils.MapUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.domain.*; |
| | | import com.ruoyi.domain.dto.AncestorClan; |
| | | 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; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | |
| | | @Resource |
| | | private EsService esSer; |
| | | |
| | | @Resource |
| | | private ZfAncestorMapper zfAncestorMapper; |
| | | @Resource |
| | | ZInfoUserService zInfoUserService; |
| | | |
| | |
| | | @Resource |
| | | private ZfClanService zfClanService; |
| | | |
| | | @Resource |
| | | ZfLogService zfLogService; |
| | | |
| | | |
| | | private LambdaQueryWrapper<ZfAncestor> buildCondition(ZfAncestor zfAncestor) { |
| | | LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.orderByDesc(ZfAncestor::getId); |
| | | lqw.eq(zfAncestor.getClanId() !=null , ZfAncestor::getClanId, zfAncestor.getClanId()); |
| | | lqw.eq(zfAncestor.getName()!=null, ZfAncestor::getName,zfAncestor.getName()); |
| | | |
| | | return lqw; |
| | | } |
| | |
| | | return AjaxResult.success(members); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult selectDataList(ZfAncestor zfAncestor, Integer pageNo, Integer pageSize) { |
| | | QueryWrapper<Object> queryWrapper = new QueryWrapper<>(); |
| | | |
| | | queryWrapper.eq(zfAncestor.getClanId() !=null , " zf_ancestor.clan_id", zfAncestor.getClanId()); |
| | | queryWrapper.eq(zfAncestor.getSysId() !=null , " zf_ancestor.sys_id ", zfAncestor.getSysId()); |
| | | queryWrapper.like(StringUtils.isNotEmpty(zfAncestor.getName()),"zf_ancestor.name",zfAncestor.getName()); |
| | | |
| | | Page<AncestorClan> info = zfAncestorMapper.selectInfo(new Page<>(pageNo, pageSize),queryWrapper); |
| | | //page(pa, wrapper); |
| | | // List<AncestorClan> orders = page(pa, wrapper); |
| | | List<AncestorClan> list =info.getRecords(); |
| | | HashMap<String, Object> data = MapUtils.getResult(info, list); |
| | | return AjaxResult.success(data); |
| | | } |
| | | |
| | | @Override |
| | | public List<AncestorClan> selectByCondition(ZfAncestor zfAncestor) { |
| | | QueryWrapper<Object> lqw = new QueryWrapper<>(); |
| | | lqw.eq(zfAncestor.getClanId() !=null , " zf_ancestor.clan_id", zfAncestor.getClanId()); |
| | | |
| | | lqw.like(StringUtils.isNotEmpty(zfAncestor.getName()),"zf_ancestor.name",zfAncestor.getName()); |
| | | |
| | | List<AncestorClan> lis = zfAncestorMapper.selectAllInfo(lqw); |
| | | |
| | | return lis; |
| | | } |
| | | |
| | | @Override |
| | | public List<AncestorClan> selectByIds(Long[] ids) { |
| | | List<AncestorClan> list = new ArrayList<>(); |
| | | QueryWrapper<Object> lqw = new QueryWrapper<>(); |
| | | // lqw.like(StringUtils.isNotEmpty(zfAncestor.getName()),"zf_ancestor.name",zfAncestor.getName()); |
| | | |
| | | // if(ids.length!=0) |
| | | // list = listByIds(Arrays.asList(ids)); |
| | | //else |
| | | list = zfAncestorMapper.selectAllInfo(lqw); |
| | | // System.out.println(list.size()); |
| | | // System.out.println("---------+++++++++---------"); |
| | | |
| | | List tmp = new ArrayList<>(Arrays.asList(ids)); |
| | | List res = new ArrayList(); |
| | | if(ids.length!=0) |
| | | { |
| | | for(AncestorClan ast : list) |
| | | { |
| | | if(tmp.contains(ast.getId().longValue())) |
| | | { |
| | | res.add(ast); |
| | | } |
| | | } |
| | | return res; |
| | | } |
| | | else |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Long addData(ZfAncestor zfAncestor) { |
| | | LambdaQueryWrapper<ZfAncestor> lqw = buildCondition(zfAncestor); |
| | | List<ZfAncestor> list = list(lqw); |
| | | Long sysID = 0L; |
| | | if(list.size()>2){ |
| | | throw new RuntimeException("请勿重复添加祖先"); |
| | | } |
| | | else if (list.size() == 1){ |
| | | if (list.get(0).getSex().equals(zfAncestor.getSex())){ |
| | | throw new RuntimeException("两位祖先不能为同性"); |
| | | } |
| | | // LambdaQueryWrapper<ZfAncestor> lqw = buildCondition(zfAncestor); |
| | | // List<ZfAncestor> list = list(lqw); |
| | | // Long sysID = 0L; |
| | | // System.out.println("15dniwru/"+list); |
| | | // if(list.size()>0){ |
| | | // throw new RuntimeException("请勿重复添加祖先"); |
| | | // } |
| | | |
| | | // else if (list.size() == 1){ |
| | | // if (list.get(0).getSex().equals(zfAncestor.getSex())){ |
| | | // throw new RuntimeException("两位祖先不能为同性"); |
| | | // } |
| | | |
| | | |
| | | sysID = zInfoUserService.getInfoBysysId(list.get(0).getSysId()).getUserId(); |
| | | } |
| | | |
| | | // sysID = zInfoUserService.getInfoBysysId(list.get(0).getSysId()).getUserId(); |
| | | // } |
| | | // |
| | | |
| | | // if (!Long.valueOf(zfClanService.getById(zfClanManage.getClanId()).getAdminId()).equals(getUserId())) { |
| | | // throw new RuntimeException("您不是管理员,没有权力添加成员"); |
| | |
| | | // zInfoUserService.saveOrUpdate(zInfoUser); |
| | | |
| | | save(zfAncestor); |
| | | EsModel esModel = new EsModel(); |
| | | Integer inte = zfAncestor.getClanId(); |
| | | String uuid = UUID.randomUUID().toString().replace("-",""); |
| | | esModel.setId(uuid); |
| | | esModel.setCtId(Long.valueOf(inte)); |
| | | esModel.setCtTableName("家族管理"); |
| | | esModel.setBy1(zfAncestor.getName()); |
| | | |
| | | esModel.setBy5("/zfClanManage"); |
| | | // esModel.setFid(familyId); |
| | | esSer.insertTable(esModel); |
| | | // EsModel esModel = new EsModel(); |
| | | // Integer inte = zfAncestor.getClanId(); |
| | | // String uuid = UUID.randomUUID().toString().replace("-",""); |
| | | // esModel.setId(uuid); |
| | | // esModel.setCtId(Long.valueOf(inte)); |
| | | // esModel.setCtTableName("家族管理"); |
| | | // esModel.setBy1(zfAncestor.getName()); |
| | | // |
| | | // esModel.setBy5("/zfClanManage"); |
| | | //// esModel.setFid(familyId); |
| | | // esSer.insertTable(esModel); |
| | | // System.out.println(esModel); |
| | | |
| | | return sysID; |
| | | return 1L; |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @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); |
| | | if (zfAncestor.getSex() != null){ |
| | | if(updateDate.getSpouseId() != null && updateDate.getSpouseId() != 0){ |
| | | Long spouseId=updateDate.getSpouseId(); |
| | | if (zInfoUserService.getById(spouseId).getSex().equals(zfAncestor.getSex())){ |
| | | // 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); |
| | | |
| | | 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); |
| | | //操作后加入日志 |
| | | ZfLog zfLog = new ZfLog(); |
| | | zfLog.setUpdateTime(LocalDateTime.now()); |
| | | zfLog.setModule("家族修改"); |
| | | zfLog.setUpdater(zInfoUserService.getMyself().getNickName()); |
| | | zfLogService.save(zfLog); |
| | | System.out.println("===================================="+zfAncestor); |
| | | |
| | | zfAncestorService.updateById(zfAncestor1); |
| | | 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){ |
| | | newModel.setBy8(zfAncestor.getSex()); |
| | | }else { |
| | | newModel.setBy8(dataById.getSex()); |
| | | } |
| | | |
| | | return zfAncestor2; |
| | | if(zfAncestor.getName() != null){ |
| | | newModel.setBy2(zfAncestor.getName()); |
| | | }else { |
| | | newModel.setBy2(dataById.getName()); |
| | | } |
| | | |
| | | |
| | | |
| | | 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 |
| | | public ZfAncestor selectZfAncestor(ZfAncestor zfAncestor) { |
| | | LambdaQueryWrapper<ZfAncestor> queryWraper = new LambdaQueryWrapper<>(); |
| | | |
| | | queryWraper.eq(zfAncestor.getSysId() !=null , ZfAncestor::getSysId, zfAncestor.getSysId()); |
| | | List lis = this.list(queryWraper); |
| | | if(lis.size()>0) |
| | | return (ZfAncestor) lis.get(0); |
| | | else |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void deleteMember(Long ids) { |
| | | // LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>(); |
| | | // lqw.eq(ZfAncestor::getClanId,ids); |
| | | // List<ZfAncestor> zfAncestors =list(lqw) ; |
| | | //// for (ZfClanManage zfClanManage : zfClanManages) { |
| | | //// if (!zfClanManages.getAdminId().equals(getUserId())) { |
| | | //// throw new RuntimeException("您不是管理员,没有权力删除该家族"); |
| | | //// } |
| | | //// } |
| | | // |
| | | //// if (!Long.valueOf(zfClanService.getById(zfClanManages.get(0).getClanId()).getAdminId()).equals(getUserId())) { |
| | | //// throw new RuntimeException("您不是管理员,没有权力删除成员"); |
| | | //// } |
| | | // List<Integer> id = new ArrayList<>() ; |
| | | // for (ZfAncestor zfAncestor : zfAncestors) { |
| | | // ZInfoUser zInfoUser = zInfoUserService.getById(Long.valueOf(zfAncestor.getMemberId())); |
| | | // zInfoUser.setClanId(0); |
| | | // System.out.println(zInfoUser); |
| | | // zInfoUserService.saveOrUpdate(zInfoUser); |
| | | // id.add(zfAncestor.getId()); |
| | | LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZfAncestor::getClanId,ids); |
| | | List<ZfAncestor> zfAncestors =list(lqw) ; |
| | | // for (ZfClanManage zfClanManage : zfClanManages) { |
| | | // if (!zfClanManages.getAdminId().equals(getUserId())) { |
| | | // throw new RuntimeException("您不是管理员,没有权力删除该家族"); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | // if (!Long.valueOf(zfClanService.getById(zfClanManages.get(0).getClanId()).getAdminId()).equals(getUserId())) { |
| | | // throw new RuntimeException("您不是管理员,没有权力删除成员"); |
| | | // } |
| | | List<Integer> id = new ArrayList<>() ; |
| | | for (ZfAncestor zfAncestor : zfAncestors) { |
| | | ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(zfAncestor.getSysId()); |
| | | zInfoUser.setClanId(0); |
| | | zInfoUserService.saveOrUpdate(zInfoUser); |
| | | id.add(zfAncestor.getId()); |
| | | // |
| | | // } |
| | | /** |
| | | * 在用户信息表删除家族号 |
| | | */ |
| | | |
| | | |
| | | if (zfAncestorService.removeByIds(id)) { |
| | | //删除es中的数据 |
| | | zfAncestors.stream().forEach(zfAncestor1 -> { |
| | | EsModel esModel = esSer.findByCtId((zfAncestor1.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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // if (zfAncestorService.removeByIds(id)) { |
| | | // //删除es中的数据 |
| | | // zfAncestors.stream().forEach(zfAncestor -> { |
| | | // EsModel esModel = esSer.findByCtId((zfAncestor.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); |
| | | // } |
| | | // } |
| | | // }); |
| | | // |
| | | // |
| | | // }} |
| | | |
| | | }}} |
| | | } |