|  | @@ -0,0 +1,78 @@
 | 
	
		
			
				|  |  | +package thyyxxk.webserver.service.outpatient.comments;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.config.exception.ExceptionEnum;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.dao.his.outpatient.comments.CommentsDao;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.ResultVo;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.outpatient.comments.request.CommentInquiry;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.outpatient.comments.response.CommentsResponse;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.outpatient.comments.response.WechatPatientComment;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.service.redislike.RedisLikeService;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.utils.ResultVoUtil;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.utils.StringUtil;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.utils.TokenUtil;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class CommentsService {
 | 
	
		
			
				|  |  | +    private final CommentsDao dao;
 | 
	
		
			
				|  |  | +    private final RedisLikeService redis;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    public CommentsService(CommentsDao dao, RedisLikeService redis) {
 | 
	
		
			
				|  |  | +        this.dao = dao;
 | 
	
		
			
				|  |  | +        this.redis = redis;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ResultVo<CommentsResponse> getComments(CommentInquiry inquiry) {
 | 
	
		
			
				|  |  | +        QueryWrapper<?> wrapper = new QueryWrapper<>();
 | 
	
		
			
				|  |  | +        if (null != inquiry.getDeleted()) {
 | 
	
		
			
				|  |  | +            wrapper.eq("deleted", inquiry.getDeleted());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (null != inquiry.getCommentLevel()) {
 | 
	
		
			
				|  |  | +            wrapper.eq("comment_level", inquiry.getCommentLevel());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (StringUtil.notBlank(inquiry.getDoctorName())) {
 | 
	
		
			
				|  |  | +            wrapper.eq("doctor_name", inquiry.getDoctorName());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (StringUtil.notBlank(inquiry.getStartTime()) && StringUtil.notBlank(inquiry.getEndTime())) {
 | 
	
		
			
				|  |  | +            wrapper.ge("comment_time", inquiry.getStartTime())
 | 
	
		
			
				|  |  | +                    .le("comment_time", inquiry.getEndTime());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<WechatPatientComment> list = dao.selectComments(wrapper, inquiry.getPageNum(), inquiry.getPageSize());
 | 
	
		
			
				|  |  | +        if (list.isEmpty()) {
 | 
	
		
			
				|  |  | +            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        list.forEach(item -> item.setDepartment(redis.getDeptName(item.getDepartment())));
 | 
	
		
			
				|  |  | +        CommentsResponse response = new CommentsResponse();
 | 
	
		
			
				|  |  | +        response.setTotalSize(dao.selectValidCount(wrapper));
 | 
	
		
			
				|  |  | +        response.setList(list);
 | 
	
		
			
				|  |  | +        return ResultVoUtil.success(response);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ResultVo<String> getPatientPhoneNo(String patNo) {
 | 
	
		
			
				|  |  | +        String phone = dao.selectPatientPhoneNo(patNo);
 | 
	
		
			
				|  |  | +        if (StringUtil.isBlank(phone)) {
 | 
	
		
			
				|  |  | +            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "患者未留存联系方式。");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return ResultVoUtil.success(phone);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ResultVo<String> updateCommentStatus(int id, int deleted) {
 | 
	
		
			
				|  |  | +        String staff = null;
 | 
	
		
			
				|  |  | +        Date date = null;
 | 
	
		
			
				|  |  | +        if (deleted == 1) {
 | 
	
		
			
				|  |  | +            staff = TokenUtil.getTokenUserId();
 | 
	
		
			
				|  |  | +            date = new Date();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        int count = dao.updateCommentStatus(id, deleted, staff, date);
 | 
	
		
			
				|  |  | +        if (count == 1) {
 | 
	
		
			
				|  |  | +            return ResultVoUtil.success("操作成功。");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |