From 2039385fa4b4ac688907134ee7c7025fb2aea1fb Mon Sep 17 00:00:00 2001 From: whywhyo <1511349576@qq.com> Date: 星期日, 16 七月 2023 12:59:17 +0800 Subject: [PATCH] 666 --- zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java | 207 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 189 insertions(+), 18 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..9379889 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 @@ -7,18 +7,25 @@ import com.ruoyi.common.core.domain.AjaxResult; 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.ZAuthorityService; +import com.ruoyi.service.ZInfoUserService; +import com.ruoyi.service.ZfDoctorService; import com.ruoyi.service.ZfDoctorService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; + +import static com.ruoyi.constant.MenuAuthority.*; /** * <p> @@ -32,25 +39,82 @@ @Slf4j public class ZfDoctorServiceImpl extends ServiceImpl<ZfDoctorMapper, ZfDoctor> implements ZfDoctorService { + @Resource + ZInfoUserService zInfoUserService; + + @Resource + ZfDoctorService zfDoctorService; + + @Resource + ZAuthorityService zAuthorityService; + @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(); + 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<ZfDoctor> lqw = buildCondition(zfDoctor, idList); - Page<ZfDoctor> ZfDoctorPage = new Page<>(pageNum, pageSize); - Page<ZfDoctor> pageResult = page(ZfDoctorPage, lqw); - HashMap<String, Object> data = MapUtils.getResult(pageResult); + Page<ZfDoctor> zfDoctorPage = new Page<>(pageNum, pageSize); + Page<ZfDoctor> pageResult = page(zfDoctorPage, lqw); + + List<ZfDoctor> beanRecords = pageResult.getRecords();//寰楀埌鏌ヨ鍑烘潵鐨勬暟鎹� + + List<ZfDoctor> dtoResult = markOwnData(familyId, 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(); + //涔熻鏌ュ埆浜烘巿鏉冪殑 + 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); + + LambdaQueryWrapper<ZfDoctor> lambdaQueryWrapper = buildCondition(zfDoctor, idList); + List<ZfDoctor> beanRecords = list(lambdaQueryWrapper); + log.info("浠庢暟鎹簱涓煡鍒扮殑涓�:{}", beanRecords); + return markOwnData(familyId, beanRecords); + } + + public List<ZfDoctor> markOwnData(Long familyId,List<ZfDoctor> beanRecords){ + return beanRecords.stream().peek( + bean -> { + if (bean.getFamilyId() == familyId) { + bean.setOwnData(1); + } else { + bean.setOwnData(0); + } + } + ).collect(Collectors.toList()); } @Override @@ -64,11 +128,52 @@ } @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) { + 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); + + 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) { + + if(list.size()>0){ throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁"); } @@ -77,9 +182,72 @@ } else { return AjaxResult.error(); } - - } + + @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("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�"); + } + + if(updateById(zfDoctor)){ + 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("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�"); + } + } + + if (zfDoctorService.removeByIds(Arrays.asList(ids))) { + return AjaxResult.success(); + }else { + return AjaxResult.error(); + } + } + +// @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,12 +259,15 @@ 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()) -- Gitblit v1.9.1