|
package com.ruoyi.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.mapper.ZfAncestorMapper;
|
import com.ruoyi.service.*;
|
import org.elasticsearch.client.RestHighLevelClient;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@Service
|
public class ZfAncestorServiceImpl extends ServiceImpl<ZfAncestorMapper, ZfAncestor> implements ZfAncestorService {
|
|
@Resource
|
private EsService esSer;
|
|
@Resource
|
ZInfoUserService zInfoUserService;
|
|
@Resource
|
private RestHighLevelClient restHighLevelClient;
|
|
@Resource
|
private ZfAncestorService zfAncestorService;
|
|
@Resource
|
private ZfClanService zfClanService;
|
|
|
private LambdaQueryWrapper<ZfAncestor> buildCondition(ZfAncestor zfAncestor) {
|
LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>();
|
lqw.orderByDesc(ZfAncestor::getId);
|
lqw.eq(zfAncestor.getClanId() !=null , ZfAncestor::getClanId, zfAncestor.getClanId());
|
|
return lqw;
|
}
|
|
private LambdaQueryWrapper<ZfAncestor> uniqueCondition(ZfAncestor zfAncestor){
|
LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(zfAncestor.getClanId() !=null , ZfAncestor::getClanId, zfAncestor.getClanId());
|
lqw.eq(zfAncestor.getSysId() !=null , ZfAncestor::getSysId, zfAncestor.getSysId());
|
return lqw;
|
}
|
|
/**
|
*
|
* 获取当前用户的sysUserId
|
* @return
|
*/
|
public Long getUserId(){
|
ZInfoUser myself = zInfoUserService.getMyself();
|
|
return zInfoUserService.getInfoBysysId( myself.getUserId()).getUserId();
|
|
}
|
|
@Override
|
public boolean count(Integer clanId){
|
ZfAncestor zfAncestor = new ZfAncestor();
|
zfAncestor.setClanId(clanId);
|
return list(buildCondition(zfAncestor)).size() < 2;
|
}
|
|
@Override
|
public AjaxResult selectDataList(Integer clanId, Integer pageNo, Integer pageSize) {
|
// ZfAncestor zfAncestor = new ZfAncestor();
|
// zfAncestor.setClanId(clanId);
|
// LambdaQueryWrapper<ZfAncestor> lqw = buildCondition(zfAncestor);
|
// List<ZfAncestor> beanRecords = list(lqw);
|
// List<HashMap<String, String>> zInfoUsers = new ArrayList<>();
|
//
|
// for (ZfAncestor beanRecord:beanRecords) {
|
// HashMap<String,String> idAndName = new HashMap<>();
|
// String name = zInfoUserService.getById(Long.valueOf(beanRecord.getMemberId())).getNickName();
|
// idAndName.put("名字",name);
|
// idAndName.put("角色类型",String.valueOf(beanRecord.getRoleId()));
|
// zInfoUsers.add(idAndName);
|
// }
|
//
|
// List<HashMap<String, String>> record = zInfoUsers.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
|
//
|
// int totalPage = (record.size() -1) / pageSize +1;
|
//
|
// Page<String> zInfoUserPage = new Page<>(pageNo, pageSize,totalPage);
|
// HashMap<String, Object> data = MapUtils.getShareResult(zInfoUserPage, record,zInfoUsers.size());
|
// return AjaxResult.success(data);
|
|
// List<ZfAncestor> beanRecords = list(lqw);
|
List<ZInfoUser> zInfoUsers = zInfoUserService.selectByClanId(clanId);
|
HashMap<String,Long> members = new HashMap<>();
|
for (ZInfoUser zInfoUser: zInfoUsers) {
|
members.put(zInfoUser.getNickName(),zInfoUser.getRoleId());
|
}
|
|
return AjaxResult.success(members);
|
}
|
|
|
|
|
@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("两位祖先不能为同性");
|
}
|
|
|
sysID = zInfoUserService.getInfoBysysId(list.get(0).getSysId()).getUserId();
|
}
|
|
|
// if (!Long.valueOf(zfClanService.getById(zfClanManage.getClanId()).getAdminId()).equals(getUserId())) {
|
// throw new RuntimeException("您不是管理员,没有权力添加成员");
|
//
|
// }
|
|
|
/**
|
* 在用户信息表添加家族号
|
*/
|
// ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(zfAncestor.getSysId());
|
// zInfoUser.setClanId(zfAncestor.getClanId());
|
// 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);
|
// System.out.println(esModel);
|
|
return sysID;
|
|
}
|
|
/**
|
*通过id删除
|
*/
|
@Override
|
public AjaxResult deleteData(Integer clanId,Integer id) {
|
// ZfAncestor zfAncestor1 = new ZfAncestor();
|
// zfAncestor1.setMemberId(id);
|
// zfAncestor1.setClanId(clanId);
|
// List<ZfAncestor> zfAncestors =list(buildCondition(zfAncestor1));
|
//// 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("您不是管理员,没有权力删除成员");
|
//// }
|
// /**
|
// * 在用户信息表删除家族号
|
// */
|
// ZInfoUser zInfoUser = zInfoUserService.getById(Long.valueOf(zfAncestors.get(0).getMemberId()));
|
// zInfoUser.setClanId(0);
|
// zInfoUserService.saveOrUpdate(zInfoUser);
|
//
|
// if (zfAncestorService.removeByIds(Arrays.asList(zfAncestors.get(0).getId()))) {
|
//
|
// //删除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);
|
// }
|
// }
|
// });
|
//
|
// return AjaxResult.success();
|
// } else {
|
// return AjaxResult.error();
|
// }
|
return null;
|
}
|
|
@Override
|
public void 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();
|
zfAncestor1.setId(list.get(0).getId());
|
zfAncestor1.setName(zfAncestor.getName());
|
if((updateDate.getSpouseId() != null || updateDate.getSpouseId() != 0) && zfAncestor.getSex() !=null){
|
Long spouseId=updateDate.getSpouseId();
|
if (zInfoUserService.getById(spouseId).getSex().equals(zfAncestor.getSex())){
|
throw new RuntimeException("祖先两位不能为同性");}
|
zfAncestor.setSex(zfAncestor.getSex());}
|
|
zfAncestorService.updateById(zfAncestor1);
|
|
}
|
|
/**
|
*
|
*通过家族id删除
|
*/
|
@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());
|
|
}
|
/**
|
* 在用户信息表删除家族号
|
*/
|
|
|
|
// 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);
|
// }
|
// }
|
// });
|
//
|
//
|
// }}
|
}
|