From b02beccf4567068cb47a3f1181a00039456c872d Mon Sep 17 00:00:00 2001 From: zqy <2522236926@qq.com> Date: 星期三, 06 八月 2025 15:37:20 +0800 Subject: [PATCH] 用户修改姓名和电话同步修改uaid --- zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 430 insertions(+), 26 deletions(-) diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java index 62f029b..1840a69 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java +++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java @@ -5,20 +5,29 @@ 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.ZfDoctor; -import com.ruoyi.domain.ZfEquipment; -import com.ruoyi.domain.ZfPet; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.domain.*; import com.ruoyi.mapper.ZfDoctorMapper; +import com.ruoyi.service.*; import com.ruoyi.service.ZfDoctorService; 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 org.springframework.web.multipart.MultipartFile; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import javax.annotation.Resource; +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +import static com.ruoyi.constant.MenuAuthority.*; /** * <p> @@ -32,25 +41,132 @@ @Slf4j public class ZfDoctorServiceImpl extends ServiceImpl<ZfDoctorMapper, ZfDoctor> implements ZfDoctorService { + @Resource + ZInfoUserService zInfoUserService; + + @Resource + ZfDoctorService zfDoctorService; + + @Resource + ZAuthorityService zAuthorityService; + + @Resource + ZfDoctorMapper zfDoctorMapper; + + @Resource + EsService esService; + + @Resource + private RestHighLevelClient restHighLevelClient; + + @Resource + ZfDoctorShareService zfDoctorShareService; + + @Resource + ZfDoctorDownloadService zfDoctorDownloadService; + + @Override public AjaxResult selectDoctorList(ZfDoctor zfDoctor, Integer pageNum, Integer pageSize) { - LambdaQueryWrapper<ZfDoctor> lqw = buildCondition(zfDoctor); - lqw.orderByDesc(ZfDoctor::getCreateTime); +// LambdaQueryWrapper<ZfDoctor> lqw = buildCondition(zfDoctor); +// lqw.orderByDesc(ZfDoctor::getCreateTime); +// +// Page<ZfDoctor> ZfDoctorPage = new Page<>(pageNum, pageSize); +// Page<ZfDoctor> pageResult = page(ZfDoctorPage, lqw); +// +// HashMap<String, Object> data = MapUtils.getResult(pageResult); +// return AjaxResult.success(data); + //瑕佹煡鑷繁瀹跺涵鐨� + ZInfoUser myself = zInfoUserService.getMyself(); + if (myself == null) { + // System.out.println("ssssss"); + return AjaxResult.success("鎮ㄦ病鍔犲叆鍒板搴旂殑瀹跺涵锛岃鑱旂郴绠$悊鍛�"); + } + Long familyId = myself.getFamilyId(); - Page<ZfDoctor> ZfDoctorPage = new Page<>(pageNum, pageSize); - Page<ZfDoctor> pageResult = page(ZfDoctorPage, lqw); + //鏌ョ湅鐖舵瘝鐨勬暟鎹細 + Long fatherFaId = 0L; + if(myself.getFatherId()!=null) + fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId(); + Long motherFaId = 0L; + if(myself.getMomId()!=null) + motherFaId = zInfoUserService.getInfoById(myself.getMomId()).getFamilyId(); - HashMap<String, Object> data = MapUtils.getResult(pageResult); + //涔熻鏌ュ埆浜烘巿鏉冪殑 + 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); + + //鍔犱笂鐖舵瘝瀹舵棌id + idList.add(fatherFaId); + idList.add(motherFaId); + List<Long> fms = zInfoUserService.findByUaidToFaid(myself.getUaid()).stream().map(ZInfoUser::getFamilyId).collect(Collectors.toList()); + if(!fms.isEmpty()) + { + idList.addAll(fms); + } +// String familyIds = listFamilyIds(); +// String secondFamilyAuthority = listSecondFamilyIds() + LambdaQueryWrapper<ZfDoctor> lqw = buildCondition(zfDoctor, idList); + + Page<ZfDoctor> zfDoctorPage = new Page<>(pageNum, pageSize); + Page<ZfDoctor> pageResult = page(zfDoctorPage, lqw); + + List<ZfDoctor> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹� + + List<ZfDoctor> dtoResult = markOwnData(familyId,fatherFaId, motherFaId, beanRecords); + HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult); return AjaxResult.success(data); } @Override public List<ZfDoctor> selectByCondition(ZfDoctor zfDoctor) { - LambdaQueryWrapper<ZfDoctor> lambdaQueryWrapper = buildCondition(zfDoctor); - lambdaQueryWrapper.orderByDesc(ZfDoctor::getCreateTime); - List<ZfDoctor> list = list(lambdaQueryWrapper); - log.info("杩斿洖鐨勬暟鎹负:{}", list); - return list; +// LambdaQueryWrapper<ZfDoctor> lambdaQueryWrapper = buildCondition(zfDoctor); +// lambdaQueryWrapper.orderByDesc(ZfDoctor::getCreateTime); +// List<ZfDoctor> list = list(lambdaQueryWrapper); +// log.info("杩斿洖鐨勬暟鎹负:{}", list); +// return list; + + //瑕佹煡鑷繁瀹跺涵鐨� + ZInfoUser myself = zInfoUserService.getMyself(); + Long familyId = myself.getFamilyId(); + + //鏌ョ湅鐖舵瘝鐨勬暟鎹細 + Long fatherFaId = 0L; + if(myself.getFatherId()!=null) + fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId(); + Long motherFaId = 0L; + if(myself.getMomId()!=null) + motherFaId = zInfoUserService.getInfoBysysId(myself.getMomId()).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); + + //鍔犱笂鐖舵瘝瀹舵棌id + idList.add(fatherFaId); + idList.add(motherFaId); + + + LambdaQueryWrapper<ZfDoctor> lambdaQueryWrapper = buildCondition(zfDoctor, idList); + List<ZfDoctor> beanRecords = list(lambdaQueryWrapper); + log.info("浠庢暟鎹簱涓煡鍒扮殑涓�:{}", beanRecords); + return markOwnData(familyId, fatherFaId, motherFaId,beanRecords); + } + + public List<ZfDoctor> markOwnData(Long familyId,Long fatherFamilyId, Long motherFamilyId, List<ZfDoctor> beanRecords) { + return beanRecords.stream().peek( + bean -> { + if (Objects.equals(bean.getFamilyId(), familyId) ||(fatherFamilyId!=0L && fatherFamilyId.equals(familyId))||(motherFamilyId!=0L && motherFamilyId.equals(familyId))) { + bean.setOwnData(1); + } else { + bean.setOwnData(0); + } + } + ).sorted((a, b) -> b.getOwnData() - a.getOwnData()).collect(Collectors.toList()); } @Override @@ -64,22 +180,264 @@ } @Override - public AjaxResult mySave(ZfDoctor zfDoctor) { + public AjaxResult importExcel(MultipartFile file) { + ExcelUtil<ZfDoctor> util = new ExcelUtil<>(ZfDoctor.class); + List<ZfDoctor> dataList = null; + try { + dataList = util.importExcel(file.getInputStream()); + } catch (Exception e) { + throw new RuntimeException(e); + } + log.info("鏁版嵁鍒楄〃涓猴細{}", dataList); + + + for (ZfDoctor zfDoctor : dataList) { +// if (zfDoctor.getSuitable().length() != 0 || zfDoctor.getType().length() != 0 || zfDoctor.getEffect().length() != 0 ) { + if(zfDoctor.getSymptom().length() == 0 || zfDoctor.getSymptom() == null){ + throw new RuntimeException("鐥囩姸涓虹┖锛屽鍏ユ暟鎹け璐�"); + } + else { + zfDoctorService.addData(zfDoctor); + } + } +// } + return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛"); + + } + + @Override + public AjaxResult addData(ZfDoctor zfDoctor) { + 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(DOCTOR_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList()); + familyIdList.add(familyId); + +// List<ZfDoctorShare> authority1 = zfDoctorShareService.getAuthority(); +// List<Long> idList1 = authority1.stream().filter(auth -> auth.getShareContent().toString().equals(DOCTOR_LIST)).map(ZfDoctorShare::getShareId).collect(Collectors.toList()); +// zfDoctorService.addData(zfDoctor); + + if (zfDoctor.getFamilyId() != null && !familyIdList.contains(zfDoctor.getFamilyId())) { + throw new RuntimeException("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�"); + } + + + if (zfDoctor.getFamilyId() == null) { + //榛樿娣诲姞鑷繁瀹跺涵鐨勬暟鎹� + zfDoctor.setFamilyId(familyId); + } + //鍒ゆ柇鏄惁鏈夐噸澶嶆暟鎹� LambdaQueryWrapper<ZfDoctor> lqw = uniqueCondition(zfDoctor); List<ZfDoctor> list = list(lqw); + if (list.size() > 0) { throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁"); } if (save(zfDoctor)) { + EsModel esModel = new EsModel(); + Integer inte = zfDoctor.getId().intValue(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + esModel.setId(uuid); + esModel.setCtId(Long.valueOf(inte)); + esModel.setCtTableName("瀹跺涵灏忓尰鐢�"); + esModel.setBy1(zfDoctor.getType()); + esModel.setBy2(zfDoctor.getSymptom()); + esModel.setBy3(zfDoctor.getEffect()); + esModel.setBy4(zfDoctor.getSuitable()); + esModel.setBy5("/family/zfDoctor"); + esModel.setBy6(zfDoctor.getCmedical()); + esModel.setBy7(zfDoctor.getWmedical()); +// esModel.setBy7(); + esModel.setRemark(zfDoctor.getRemark()); + esModel.setFid(familyId); + + + //杩欓噷瀛樺偍鏌ヨ璇︽儏鐨勮矾寰� + esService.insertTable(esModel); return AjaxResult.success(); } else { return AjaxResult.error(); } - - } + + + @Resource + ZfLogService zfLogService; + + @Override + public AjaxResult updateData(ZfDoctor zfDoctor) { + ZInfoUser myself = zInfoUserService.getMyself(); + Long familyId = myself.getFamilyId(); + + //鍏堟牴鎹甶d鏌ヨ鍑烘暟鎹殑familyId锛岀湅鐪嬫湁娌℃湁鏉冮檺鎿嶄綔 + Long dataFamilyId = getById(zfDoctor.getId()).getFamilyId(); + + List<ZAuthority> authority = zAuthorityService.getAuthority(); + List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(DOCTOR_LIST_UPDATE)).map(ZAuthority::getFid).collect(Collectors.toList()); + familyIdList.add(familyId); + + if (dataFamilyId != null && !familyIdList.contains(dataFamilyId)) { + throw new RuntimeException("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�"); + } + + //鎿嶄綔鍚庡姞鍏ユ棩蹇� + ZfLog zfLog = new ZfLog(); + zfLog.setUpdateTime(LocalDateTime.now()); + zfLog.setModule("瀹跺涵灏忓尰鐢�"); + zfLog.setUpdater(zInfoUserService.getMyself().getNickName()); + zfLogService.save(zfLog); + + if (updateById(zfDoctor)) { + //鍒版暟鎹簱涓煡璇㈠搴旂殑鏁版嵁 + ZfDoctor dataById = getById(zfDoctor.getId()); + + //鍏堝埌es涓煡璇㈠埌瀵瑰簲閭f潯鏁版嵁鍦╡s鐨刬d + EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "瀹跺涵灏忓尰鐢�"); + + if (esResult == null) { + return AjaxResult.success(); + } + + //鎿嶄綔es淇敼鏁版嵁 + EsModel newModel = new EsModel(); + if (zfDoctor.getType() != null) { + newModel.setBy1(zfDoctor.getType()); + } else { + newModel.setBy1(dataById.getType()); + } + + if (zfDoctor.getSymptom() != null) { + newModel.setBy2(zfDoctor.getSymptom()); + } else { + newModel.setBy2(dataById.getSymptom()); + } + + if (zfDoctor.getEffect() != null) { + newModel.setBy3(zfDoctor.getEffect()); + } else { + newModel.setBy3(dataById.getEffect()); + } + + if (zfDoctor.getSuitable() != null) { + newModel.setBy4(zfDoctor.getSuitable()); + } else { + newModel.setBy4(dataById.getSuitable()); + } + + if (zfDoctor.getCmedical() != null) { + newModel.setBy6(zfDoctor.getCmedical()); + } else { + newModel.setBy6(dataById.getCmedical()); + } + + if (zfDoctor.getWmedical() != null) { + newModel.setBy7(zfDoctor.getWmedical()); + } else { + newModel.setBy7(dataById.getWmedical()); + } + + if (zfDoctor.getRemark() != null) { + newModel.setRemark(zfDoctor.getRemark()); + } else { + newModel.setRemark(dataById.getRemark()); + } + + + UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId()); + updateRequest.doc( + "by1", newModel.getBy1(), + "by2", newModel.getBy2(), + "by3", newModel.getBy3(), + "by4", newModel.getBy4(), + "by6", newModel.getBy6(), + "by7", newModel.getBy7(), + "remark", newModel.getRemark() + ); + + 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<ZfDoctor> dataList = zfDoctorService.listByIds(Arrays.asList(ids)); + + ZInfoUser myself = zInfoUserService.getMyself(); + Long familyId = myself.getFamilyId(); + + List<ZAuthority> authority = zAuthorityService.getAuthority(); + List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(DOCTOR_LIST_REMOVE)).map(ZAuthority::getFid).collect(Collectors.toList()); + familyIdList.add(familyId); + + for (ZfDoctor data : dataList) { + if (!familyIdList.contains(data.getFamilyId())) { + throw new RuntimeException("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�"); + } + } + List<ZfDoctor> zfDoctors = listByIds(Arrays.asList(ids)); + if (! (zfDoctorDownloadService.deleteData(ids) && zfDoctorShareService.deleteByContentId(ids) ) ){ + return AjaxResult.error(); + } + if (zfDoctorService.removeByIds(Arrays.asList(ids))) { + + //鍒犻櫎es涓殑鏁版嵁 + zfDoctors.stream().forEach(zfDoctor -> { + EsModel esModel = esService.findByCtId(zfDoctor.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 AjaxResult listType() { + List<String> result = zfDoctorMapper.listType(); + return AjaxResult.success(result); + } + +// @Override +// public AjaxResult mySave(ZfDoctor zfDoctor) { +// //鍒ゆ柇鏄惁鏈夐噸澶嶆暟鎹� +// LambdaQueryWrapper<ZfDoctor> lqw = uniqueCondition(zfDoctor); +// List<ZfDoctor> list = list(lqw); +// if (list.size() > 0) { +// throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁"); +// } +// +// if (save(zfDoctor)) { +// return AjaxResult.success(); +// } else { +// return AjaxResult.error(); +// } +// +// +// } private LambdaQueryWrapper<ZfDoctor> uniqueCondition(ZfDoctor zfDoctor) { LambdaQueryWrapper<ZfDoctor> lqw = new LambdaQueryWrapper<>(); @@ -91,25 +449,71 @@ lqw.eq(StringUtils.isNotEmpty(zfDoctor.getEffect()), ZfDoctor::getEffect, zfDoctor.getEffect()); lqw.eq(StringUtils.isNotEmpty(zfDoctor.getSuitable()), ZfDoctor::getSuitable, zfDoctor.getSuitable()); lqw.eq(StringUtils.isNotEmpty(zfDoctor.getRemark()), ZfDoctor::getRemark, zfDoctor.getRemark()); + lqw.eq(zfDoctor.getFamilyId() != null, ZfDoctor::getFamilyId, zfDoctor.getFamilyId()); return lqw; - } - private LambdaQueryWrapper<ZfDoctor> buildCondition(ZfDoctor zfDoctor) { + private LambdaQueryWrapper<ZfDoctor> buildCondition(ZfDoctor zfDoctor, List<Long> familyIdList) { LambdaQueryWrapper<ZfDoctor> lqw = new LambdaQueryWrapper<>(); + lqw.in(ZfDoctor::getFamilyId, familyIdList); + lqw.orderByDesc(ZfDoctor::getCreateTime); lqw.like(StringUtils.isNotEmpty(zfDoctor.getType()), ZfDoctor::getType, zfDoctor.getType()) .like(StringUtils.isNotEmpty(zfDoctor.getSymptom()), ZfDoctor::getSymptom, zfDoctor.getSymptom()) .like(StringUtils.isNotEmpty(zfDoctor.getDuration()), ZfDoctor::getDuration, zfDoctor.getDuration()) .like(StringUtils.isNotEmpty(zfDoctor.getEffect()), ZfDoctor::getEffect, zfDoctor.getEffect()) .like(StringUtils.isNotEmpty(zfDoctor.getSuitable()), ZfDoctor::getSuitable, zfDoctor.getSuitable()) + .like(StringUtils.isNotEmpty(zfDoctor.getWmedical()), ZfDoctor::getWmedical, zfDoctor.getWmedical()) + .like(StringUtils.isNotEmpty(zfDoctor.getCmedical()), ZfDoctor::getCmedical, zfDoctor.getCmedical()) .like(StringUtils.isNotEmpty(zfDoctor.getRemark()), ZfDoctor::getRemark, zfDoctor.getRemark()); - if (StringUtils.isNotEmpty(zfDoctor.getPrescription())){ + if (StringUtils.isNotEmpty(zfDoctor.getPrescription())) { lqw.and(wrapper -> { - wrapper.like(StringUtils.isNotEmpty(zfDoctor.getPrescription()),ZfDoctor::getWmedical,zfDoctor.getPrescription()) + wrapper.like(StringUtils.isNotEmpty(zfDoctor.getPrescription()), ZfDoctor::getWmedical, zfDoctor.getPrescription()) .or() - .like(StringUtils.isNotEmpty(zfDoctor.getPrescription()),ZfDoctor::getCmedical,zfDoctor.getPrescription()); + .like(StringUtils.isNotEmpty(zfDoctor.getPrescription()), ZfDoctor::getCmedical, zfDoctor.getPrescription()); }); } return lqw; } -} + +// public LambdaQueryWrapper<ZfDoctor> buildCondition2(List<Long> ids) { +// LambdaQueryWrapper<ZfDoctor> lqw = new LambdaQueryWrapper<>(); +// lqw.eq(ZfDoctor::getId, ids); +// +// return lqw; +// } +// @Override +// public AjaxResult selectListById(List<Long> ids, Integer pageNum, Integer pageSize) { +// List<ZfDoctor> lqw2 = new ArrayList<>(); +// +// LambdaQueryWrapper<ZfDoctor> lqw = buildCondition2(ids); +// List<ZfDoctor> bb = list(lqw); +// System.out.println("15052222254"+bb); +// +// Page<ZfDoctor> zfDoctorPage = new Page<>(pageNum, pageSize); +// Page<ZfDoctor> pageResult = page(zfDoctorPage, lqw); +// List<ZfDoctor> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹� +// System.out.println(beanRecords); +// +// HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords); +// +// +// return AjaxResult.success(data); +//// } + +// private List<Long> buildCondition1(){ +// List<ZfDoctorShare> authority1 = zfDoctorShareService.getAuthority(); +// List<Long> idList1 = authority1.stream().filter(auth -> auth.getShareContent().toString().equals(DOCTOR_LIST)).map(ZfDoctorShare::getShareId).collect(Collectors.toList()); +// return idList1; +// } +// private LambdaQueryWrapper<ZfDoctor> buildCondition2(ZfDoctor zfDoctor, List<Long> IdList) { +// LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>(); +// lqw.in(ZfDoctorShare::getShareId, IdList); +// List<ZfDoctorShare> beanRecords = list(lqw); +// for (ZfDoctorShare shareContent : beanRecords){ +// zfDoctorService.getById(shareContent); +// } +// +// } + + +} \ No newline at end of file -- Gitblit v1.9.1