diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java index a18f3bb..164a6a0 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.DigestUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; +import org.springframework.validation.ObjectError; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -917,6 +918,7 @@ public class PatientController { * @return */ @PostMapping("signInPatient") + @TokenRequired public BaseResponse signInPatient(@RequestBody LymsPatient patient) { BaseResponse baseResponse = new BaseResponse(); baseResponse.setErrorcode(1); @@ -936,59 +938,111 @@ public class PatientController { } return baseResponse; } -// /** -// * 小程序关注患者查询 -// * -// * @param patient -// * @return -// */ -// @GetMapping("getPatientAttention") -// public BaseResponse getPatientAttention(LymsPatient patient) { -// QueryWrapper queryWrapper=new QueryWrapper<>(); -// if(StringUtil.isNotEmpty(patient.getIdno())){ -// queryWrapper.lambda().eq(LymsPatient::getIdno, patient.getIdno()); -// } -// if(StringUtil.isNotEmpty(patient.getEnrolmentPhone())){ -// queryWrapper.eq("p.enrolment_phone", patient.getEnrolmentPhone()) -// .or().eq("pc.mobile", patient.getEnrolmentPhone()); -// } -// //指定返回列 -// queryWrapper.lambda().select(LymsPatient::getId, -// LymsPatient::getPname, -// LymsPatient::getSex, -// LymsPatient::getBirth, -// LymsPatient::getIdno, -// LymsPatient::getCreatedtime); -// LymsPatient resultPatient = lymsPatientService.getPatient(queryWrapper); -// -// BaseResponse baseResponse = new BaseResponse(); -// baseResponse.setErrorcode(0); -// baseResponse.setObject(resultPatient); -// baseResponse.setErrormsg("成功"); -// return baseResponse; -// } -// -// /** -// * 小程序关注的患者列表 -// * -// * @param patient -// * @return -// */ -// @GetMapping("getPatientAttentionList") -// public BaseResponse getPatientAttentionList(LymsPatientAttention patientAttention) { -// BaseResponse baseResponse = new BaseResponse(); -// if (null==patientAttention.getPid()) { -// baseResponse.setErrorcode(1); -// baseResponse.setErrormsg("参数错误"); -// return baseResponse; -// } -// QueryWrapper queryWrapper=Wrappers.query(patientAttention); -// //指定返回列 -// queryWrapper.lambda().select(LymsPatientAttention::getAttentionId); -// List ids=lymsPatientAttentionService.listObjs(queryWrapper); -// baseResponse.setErrorcode(0); -// baseResponse.setObject(ids); -// baseResponse.setErrormsg("成功"); -// return baseResponse; -// } + /** + * 小程序关注患者查询or是否关注过 + * + * @param patient + * @return + */ + @GetMapping("getPatientAttention") + @TokenRequired + public BaseResponse getPatientAttention(LymsPatient patient) { + List result=new ArrayList<>(); + if(null!=patient.getId()) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (StringUtil.isNotEmpty(patient.getIdno())) { + queryWrapper.eq("p.idno", patient.getIdno()); + } + if (StringUtil.isNotEmpty(patient.getEnrolmentPhone())) { + queryWrapper.eq("p.enrolment_phone", patient.getEnrolmentPhone()) + .or().eq("pc.mobile", patient.getEnrolmentPhone()); + } + //指定返回列 + queryWrapper.lambda().select(LymsPatient::getId, + LymsPatient::getPname, + LymsPatient::getSex, + LymsPatient::getBirth, + LymsPatient::getIdno, + LymsPatient::getCreatedtime); + result = lymsPatientService.getPatient(queryWrapper); + if (CollectionUtils.isNotEmpty(result)) { + Iterator iterator = result.iterator(); + while (iterator .hasNext()) { + Map map= iterator.next(); + if(map.get("id")==patient.getId()){ + iterator.remove(); + continue; + } + QueryWrapper queryWrapper2 = new QueryWrapper<>(); + queryWrapper2.lambda().eq(LymsPatientAttention::getPid, patient.getId()); + queryWrapper2.lambda().eq(LymsPatientAttention::getAttentionId, map.get("id")); + final int count = lymsPatientAttentionService.count(queryWrapper2); + if (count == 0) { + map.put("type", 2);//未关注 + } else { + map.put("type", 1);//已关注 + } + } + } + } + + BaseResponse baseResponse = new BaseResponse(); + baseResponse.setErrorcode(0); + baseResponse.setObject(result); + baseResponse.setErrormsg("成功"); + return baseResponse; + } + + /** + * 小程序关注的患者列表 + * + * @param patient + * @return + */ + @GetMapping("getPatientAttentionList") + @TokenRequired + public BaseResponse getPatientAttentionList(LymsPatientAttention patientAttention) { + BaseResponse baseResponse = new BaseResponse(); + if (null==patientAttention.getPid()) { + baseResponse.setErrorcode(1); + baseResponse.setErrormsg("参数错误"); + return baseResponse; + } + QueryWrapper queryWrapper=new QueryWrapper<>(); + if(null!=patientAttention.getPid()){ + queryWrapper.eq("pa.pid", patientAttention.getPid()); + } + List resultList=lymsPatientAttentionService.getPatientList(queryWrapper); + baseResponse.setErrorcode(0); + baseResponse.setObject(resultList); + baseResponse.setErrormsg("成功"); + return baseResponse; + } + /** + * 小程序关注患者 + * + * @param patient + * @return + */ + @PostMapping("addPatientAttention") + @TokenRequired + public BaseResponse addPatientAttention(@RequestBody @Validated LymsPatientAttention patientAttention,BindingResult bindingResult) { + BaseResponse baseResponse = new BaseResponse(); + //对象验证 + if(bindingResult.hasErrors()){ + baseResponse.setErrorcode(1); + for (ObjectError allError : bindingResult.getAllErrors()) { + baseResponse.setErrormsg((StringUtil.isNotEmpty(baseResponse.getErrormsg())?baseResponse.getErrormsg():"")+allError.getDefaultMessage()+";"); + } + return baseResponse; + } + final boolean result = lymsPatientAttentionService.save(patientAttention); + if(!result){ + baseResponse.setErrorcode(1); + baseResponse.setErrormsg("保存异常!"); + } + baseResponse.setErrorcode(0); + baseResponse.setErrormsg("成功"); + return baseResponse; + } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPatientAttention.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPatientAttention.java index 889e870..45580b8 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPatientAttention.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPatientAttention.java @@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import lombok.Data; +import javax.validation.constraints.NotNull; + /** * 关注的患者 * @TableName lyms_patient_attention @@ -18,12 +20,14 @@ public class LymsPatientAttention implements Serializable { * 患者id */ @TableField(value = "pid") + @NotNull(message = "pid不能为空") private Integer pid; /** * 关注的患者id */ @TableField(value = "attention_id") + @NotNull(message = "attention_id不能为空") private Integer attentionId; @TableField(exist = false) diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientAttentionMapper.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientAttentionMapper.java index 07a5763..32b4aa0 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientAttentionMapper.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientAttentionMapper.java @@ -1,13 +1,33 @@ package com.lyms.talkonlineweb.mapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.lyms.talkonlineweb.domain.LymsPatient; import com.lyms.talkonlineweb.domain.LymsPatientAttention; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; /** * @Entity com.lyms.talkonlineweb.domain.LymsPatientAttention */ +@Mapper public interface LymsPatientAttentionMapper extends BaseMapper { + @Select({ + "" + }) + List getPatientList(@Param("ew") QueryWrapper ew); } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientMapper.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientMapper.java index 9b2aacd..0f4245b 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientMapper.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientMapper.java @@ -1,5 +1,6 @@ package com.lyms.talkonlineweb.mapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.lyms.talkonlineweb.domain.LymsPatient; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @@ -29,6 +30,17 @@ public interface LymsPatientMapper extends BaseMapper { "GROUP BY pc.hid\n" + "order by pc.createdtime desc") List> getAppPatientHospital(@Param("patientId") Integer patientId); + + @Select({""}) + List getPatient(@Param("ew")QueryWrapper ew); } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientAttentionService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientAttentionService.java index ec81d5a..3132c67 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientAttentionService.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientAttentionService.java @@ -1,11 +1,17 @@ package com.lyms.talkonlineweb.service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.lyms.talkonlineweb.domain.LymsPatient; import com.lyms.talkonlineweb.domain.LymsPatientAttention; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; +import java.util.Map; + /** * */ public interface LymsPatientAttentionService extends IService { + List getPatientList(QueryWrapper queryWrapper); } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java index f637a1c..1e3da04 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java @@ -1,5 +1,6 @@ package com.lyms.talkonlineweb.service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.lyms.talkonlineweb.domain.LymsPatient; import com.baomidou.mybatisplus.extension.service.IService; @@ -12,4 +13,6 @@ import java.util.Map; public interface LymsPatientService extends IService { List> getAppPatientHospital(Integer patientId); + + List getPatient(QueryWrapper queryWrapper); } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientAttentionServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientAttentionServiceImpl.java index 17d12c6..0ec3cbf 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientAttentionServiceImpl.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientAttentionServiceImpl.java @@ -1,18 +1,29 @@ package com.lyms.talkonlineweb.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lyms.talkonlineweb.domain.LymsPatient; import com.lyms.talkonlineweb.domain.LymsPatientAttention; import com.lyms.talkonlineweb.service.LymsPatientAttentionService; import com.lyms.talkonlineweb.mapper.LymsPatientAttentionMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Map; + /** * */ @Service public class LymsPatientAttentionServiceImpl extends ServiceImpl implements LymsPatientAttentionService{ - + @Autowired + LymsPatientAttentionMapper lymsPatientAttentionMapper; + @Override + public List getPatientList(QueryWrapper queryWrapper) { + return lymsPatientAttentionMapper.getPatientList(queryWrapper); + } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java index 7cb9809..2eb3d1a 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java @@ -1,5 +1,6 @@ package com.lyms.talkonlineweb.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lyms.talkonlineweb.domain.LymsPatient; import com.lyms.talkonlineweb.service.LymsPatientService; @@ -23,6 +24,11 @@ public class LymsPatientServiceImpl extends ServiceImpl> getAppPatientHospital(Integer patientId) { return lymsPatientMapper.getAppPatientHospital(patientId); } + + @Override + public List getPatient(QueryWrapper queryWrapper) { + return lymsPatientMapper.getPatient(queryWrapper); + } }