提交 e99ada42 编写于 作者: N nvg_haru

Auto Commit

上级 00470cde
*.js linguist-language=java
*.css linguist-language=java
*.html linguist-language=java
*.jsp linguist-language=java
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
run = "javac Main.java && java Main"
run = "java -jar server.jar"
language = "java"
[debugger]
program = "Main"
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupid</groupId>
<artifactId>myartifactid</artifactId>
<version>0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.medical</groupId>
<artifactId>smart-medicine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>smart-medicine</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<type>jar</type>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<type>jar</type>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.17</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.16.22</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency>
<!-- MyBatis Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<!-- 邮件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- 短信 -->
<dependency>
<groupId>com.github.qcloudsms</groupId>
<artifactId>qcloudsms</artifactId>
<version>1.0.2</version>
</dependency>
<!-- 人脸识别 -->
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<!-- FastJson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<!--阿里云OSS服务-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dashscope-sdk-java</artifactId>
<version>2.9.0</version>
</dependency>
<!--ok http client-->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>de.qaware.maven</groupId>
<artifactId>go-offline-maven-plugin</artifactId>
<version>1.2.5</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<dynamicDependencies>
<DynamicDependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.20.1</version>
<classifier></classifier>
<repositoryType>PLUGIN</repositoryType>
</DynamicDependency>
<DynamicDependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.2.1</version>
<classifier>jpa</classifier>
<repositoryType>MAIN</repositoryType>
</DynamicDependency>
</dynamicDependencies>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
文件已添加
package world.xuewei;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 应用启动类
*
* @author XUEW
*/
@SpringBootApplication
@MapperScan("world.xuewei.dao")
public class SmartMedicineApplication {
public static void main(String[] args) {
SpringApplication.run(SmartMedicineApplication.class, args);
}
}
package world.xuewei.component;
import cn.hutool.core.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
/**
* 邮件客户端
*
* @author XUEW
*/
@Component
public class EmailClient {
@Autowired
private JavaMailSenderImpl mailSender;
/**
* 发送方邮箱
*/
@Value("${spring.mail.username}")
private String email;
/**
* 有效时长
*/
@Value("${spring.mail.valid}")
private Integer valid;
/**
* 内容模版
*/
@Value("${spring.mail.template}")
private String template;
/**
* 标题
*/
@Value("${spring.mail.title}")
private String title;
/**
* 发送邮件验证码
*
* @param targetEmail 目标邮箱
* @return 验证码
*/
public String sendEmailCode(String targetEmail) {
// 生成随机验证码
String verifyCode = RandomUtil.randomNumbers(6);
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
try {
helper.setSubject(title);
helper.setText(String.format(template, verifyCode, valid), true);
helper.setFrom(email);
helper.setTo(targetEmail);
} catch (MessagingException e) {
e.printStackTrace();
}
mailSender.send(mimeMessage);
return verifyCode;
}
/**
* 发送邮箱
*
* @param targetEmail 目标邮箱
* @param content 发送内容
*/
public void sendEmail(String targetEmail, String title, String content) {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
try {
helper.setSubject(title);
helper.setText(content, true);
helper.setFrom(email);
helper.setTo(targetEmail);
} catch (MessagingException e) {
e.printStackTrace();
}
mailSender.send(mimeMessage);
}
}
package world.xuewei.component;
import org.springframework.web.servlet.HandlerInterceptor;
import world.xuewei.entity.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 登录拦截器
*
* @author XUEW
*/
public class LoginHandlerInterceptor implements HandlerInterceptor {
/**
* 在目标方式执行之前执行
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
User user = (User) request.getSession().getAttribute("loginUser");
if (user == null) {
//未登录,返回登录页面
response.sendRedirect("/");
return false;
} else {
//已登录,放行
return true;
}
}
}
package world.xuewei.component;
import cn.hutool.core.util.IdUtil;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* 对象存储工具
*
* @author XUEW
*/
@Component
public class OssClient {
@Value("${oss.bucket-name}")
private String bucketName;
@Value("${oss.end-point}")
private String endPoint;
@Value("${oss.access-key}")
private String accessKeyId;
@Value("${oss.access-secret}")
private String accessKeySecret;
/**
* 上传文件
*/
public String upload(MultipartFile file, String path) throws IOException {
if (file == null || path == null) {
return null;
}
OSSClient ossClient = new OSSClient(endPoint, accessKeyId, accessKeySecret);
if (!ossClient.doesBucketExist(bucketName)) {
ossClient.createBucket(bucketName);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest);
}
String extension = OssClient.getFileExtension(file);
//设置文件路径
String fileUrl = path + "/" + IdUtil.simpleUUID() + extension;
String url = "https://" + bucketName + "." + endPoint + "/" + fileUrl;
PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, fileUrl, file.getInputStream()));
//上传文件
ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
return url;
}
/**
* 获取文件的扩展名
*/
public static String getFileExtension(MultipartFile file) {
String filename = file.getOriginalFilename();
assert filename != null;
return filename.substring(filename.lastIndexOf("."));
}
}
package world.xuewei.config;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* MVC 配置
*
* @author XUEW
*/
@Configuration
public class MvcConfig implements WebMvcConfigurer, ErrorPageRegistrar {
/**
* 注册视图控制器
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// 注册错误页面
registry.addViewController("/400").setViewName("error/400");
registry.addViewController("/401").setViewName("error/401");
registry.addViewController("/404").setViewName("error/404");
registry.addViewController("/500").setViewName("error/500");
registry.addViewController("/feedback.html").setViewName("feedback");
registry.addViewController("/empty.html").setViewName("empty");
}
/**
* 配置错误页面
*/
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST, "/400");
ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401");
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500");
registry.addErrorPages(error400Page, error401Page, error404Page, error500Page);
}
/**
* 注册登录拦截器
*/
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// registry.addInterceptor(new LoginHandlerInterceptor())
// // 拦截的请求
// .addPathPatterns("/**")
// // 不拦截的请求(放行)
// .excludePathPatterns(
// "/","/index","/index.html","/join.html","/home","/material","/materials","/admin/**",
// "/login","/register",
// "/error400Page","/error401Page","/error404Page","/error500Page",
// "/**/front/**", "/asserts/**","/**/*.css", "/**/*.js", "/**/*.png ",
// "/**/*.jpg", "/**/*.jpeg","/**/*.gif", "/**/fonts/*", "/**/*.svg");
// }
}
package world.xuewei.constant;
/**
* 常量类
*
* @author XUEW
*/
public class MedicalConstants {
/**
* 用户操作类型:搜索
*/
public static final Integer TYPE_OPERATE = 1;
/**
* 用户操作类型:查看某种疾病
*/
public static final Integer TYPE_ILLNESS = 2;
/**
* 用户操作类型:查看相关的药
*/
public static final Integer TYPE_MEDICINE = 3;
}
package world.xuewei.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import world.xuewei.component.EmailClient;
import world.xuewei.dto.RespResult;
import world.xuewei.entity.IllnessKind;
import world.xuewei.entity.User;
import world.xuewei.service.*;
import world.xuewei.utils.Assert;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
* 基础控制器
* <p>
* ==========================================================================
* 郑重说明:本项目免费开源!原创作者为:薛伟同学,严禁私自出售。
* ==========================================================================
* B站账号:薛伟同学
* 微信公众号:薛伟同学
* 作者博客:http://xuewei.world
* ==========================================================================
* 陆陆续续总会收到粉丝的提醒,总会有些人为了赚取利益倒卖我的开源项目。
* 不乏有粉丝朋友出现钱付过去,那边只把代码发给他就跑路的,最后还是根据线索找到我。。
* 希望各位朋友擦亮慧眼,谨防上当受骗!
* ==========================================================================
*
* @author <a href="http://xuewei.world/about">XUEW</a>
*/
public class BaseController<T> {
@Autowired
protected ApiService apiService;
@Autowired
protected UserService userService;
@Autowired
protected IllnessKindService illnessKindService;
@Autowired
protected IllnessMedicineService illnessMedicineService;
@Autowired
protected IllnessService illnessService;
@Autowired
protected MedicalNewsService medicalNewsService;
@Autowired
protected MedicineService medicineService;
@Autowired
protected HistoryService historyService;
@Autowired
protected FeedbackService feedbackService;
@Autowired
protected BaseService<T> service;
@Autowired
protected EmailClient emailClient;
protected HttpServletRequest request;
protected HttpServletResponse response;
protected HttpSession session;
protected User loginUser;
protected List<IllnessKind> kindList;
/**
* 保存、修改
*
* @param obj 目标对象
* @return 响应结果
*/
@ResponseBody
@PostMapping("save")
public RespResult save(T obj) {
if (Assert.isEmpty(obj)) {
return RespResult.fail("保存对象不能为空");
}
obj = service.save(obj);
return RespResult.success("保存成功", obj);
}
/**
* 删除
*
* @param id 主键ID
* @return 响应结果
*/
@ResponseBody
@PostMapping("/delete")
public RespResult delete(Integer id) {
if (Assert.isEmpty(id)) {
return RespResult.fail("删除ID不能为空");
}
if (service.delete(id) == 0) {
T t = service.get(id);
if (Assert.isEmpty(t)) {
return RespResult.notFound("数据不存在");
}
return RespResult.fail("删除失败");
}
return RespResult.success("删除成功");
}
/**
* 在每个子类方法调用之前先调用
*/
@ModelAttribute
public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
this.session = request.getSession(true);
loginUser = (User) session.getAttribute("loginUser");
session.setAttribute("kindList", illnessKindService.findList());
}
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.Feedback;
/**
* 反馈控制器
*
* @author XUEW
*/
@RestController
@RequestMapping(value = "feedback")
public class FeedbackController extends BaseController<Feedback> {
}
package world.xuewei.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import world.xuewei.component.OssClient;
import world.xuewei.dto.RespResult;
import world.xuewei.entity.User;
import world.xuewei.utils.Assert;
import java.io.IOException;
/**
* 文件控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("/file")
public class FileController extends BaseController<User> {
@Autowired
private OssClient ossClient;
/**
* 上传文件
*/
@PostMapping("/upload")
public RespResult upload(@RequestParam("file") MultipartFile file) throws IOException {
String url = ossClient.upload(file, String.valueOf(loginUser.getId()));
if (Assert.isEmpty(url)) {
return RespResult.fail("上传失败", url);
}
return RespResult.success("上传成功", url);
}
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.History;
/**
* 历史控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("history")
public class HistoryController extends BaseController<History> {
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.Illness;
/**
* 疾病控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("illness")
public class IllnessController extends BaseController<Illness> {
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.IllnessKind;
/**
* 疾病分类控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("illness_kind")
public class IllnessKindController extends BaseController<IllnessKind> {
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.IllnessMedicine;
/**
* 疾病药品控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("illness_medicine")
public class IllnessMedicineController extends BaseController<IllnessMedicine> {
}
package world.xuewei.controller;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.dto.RespResult;
import world.xuewei.entity.User;
import world.xuewei.utils.Assert;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 登录控制器
* <p>
* ==========================================================================
* 郑重说明:本项目免费开源!原创作者为:薛伟同学,严禁私自出售。
* ==========================================================================
* B站账号:薛伟同学
* 微信公众号:薛伟同学
* 作者博客:http://xuewei.world
* ==========================================================================
* 陆陆续续总会收到粉丝的提醒,总会有些人为了赚取利益倒卖我的开源项目。
* 不乏有粉丝朋友出现钱付过去,那边只把代码发给他就跑路的,最后还是根据线索找到我。。
* 希望各位朋友擦亮慧眼,谨防上当受骗!
* ==========================================================================
*
* @author <a href="http://xuewei.world/about">XUEW</a>
*/
@RestController
@RequestMapping(value = "login")
public class LoginController extends BaseController<User> {
/**
* 注册
*/
@PostMapping("/register")
public RespResult register(User user, String code) {
String email = user.getUserEmail();
if (Assert.isEmpty(email)) {
return RespResult.fail("邮箱不能为空");
}
Map<String, Object> codeData = (Map<String, Object>) session.getAttribute("EMAIL_CODE" + email);
if (codeData == null) {
return RespResult.fail("尚未发送验证码");
}
String sentCode = (String) codeData.get("code");
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) codeData.get("time"));
calendar.add(Calendar.MINUTE, 5);
if (System.currentTimeMillis() > calendar.getTime().getTime()) {
session.removeAttribute("EMAIL_CODE" + email);
return RespResult.fail("验证码已经超时");
}
if (!sentCode.equals(code)) {
return RespResult.fail("验证码错误");
}
List<User> query = userService.query(User.builder().userAccount(user.getUserAccount()).build());
if (Assert.notEmpty(query)) {
return RespResult.fail("账户已被注册");
}
user.setRoleStatus(0);
user.setImgPath("https://moti-cloud-v2.oss-cn-beijing.aliyuncs.com/Snipaste_2022-05-01_15-37-01.png");
user = userService.save(user);
session.setAttribute("loginUser", user);
return RespResult.success("注册成功", user);
}
/**
* 登录
*/
@PostMapping("/login")
public RespResult login(User user) {
List<User> users = userService.query(user);
if (Assert.notEmpty(users)) {
session.setAttribute("loginUser", users.get(0));
return RespResult.success("登录成功");
}
if (Assert.isEmpty(userService.query(User.builder().userAccount(user.getUserAccount()).build()))) {
return RespResult.fail("账户尚未注册");
}
return RespResult.fail("密码错误");
}
/**
* 发送邮箱验证码
*/
@PostMapping("/sendEmailCode")
public RespResult sendEmailCode(String email, Map<String, Object> map) {
if (StrUtil.isEmpty(email)) {
return RespResult.fail("邮箱不可为空");
}
// 发送验证码
String verifyCode = emailClient.sendEmailCode(email);
map.put("email", email);
map.put("code", verifyCode);
map.put("time", new Date());
session.setAttribute("EMAIL_CODE" + email, map);
return RespResult.success("发送成功");
}
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.MedicalNews;
/**
* 咨询控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("medical_news")
public class MedicalNewsController extends BaseController<MedicalNews> {
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.entity.Medicine;
/**
* 药品控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("medicine")
public class MedicineController extends BaseController<Medicine> {
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.dto.RespResult;
import world.xuewei.entity.User;
/**
* 消息控制器
*
* @author XUEW
*/
@RestController
@RequestMapping("/message")
public class MessageController extends BaseController<User> {
/**
* 发送消息
*/
@PostMapping("/query")
public RespResult query(String content) {
String result = apiService.query(content);
return RespResult.success(result);
}
}
package world.xuewei.controller;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import world.xuewei.constant.MedicalConstants;
import world.xuewei.entity.*;
import world.xuewei.utils.Assert;
import java.util.*;
/**
* 系统跳转控制器
* <p>
* ==========================================================================
* 郑重说明:本项目免费开源!原创作者为:薛伟同学,严禁私自出售。
* ==========================================================================
* B站账号:薛伟同学
* 微信公众号:薛伟同学
* 作者博客:http://xuewei.world
* ==========================================================================
* 陆陆续续总会收到粉丝的提醒,总会有些人为了赚取利益倒卖我的开源项目。
* 不乏有粉丝朋友出现钱付过去,那边只把代码发给他就跑路的,最后还是根据线索找到我。。
* 希望各位朋友擦亮慧眼,谨防上当受骗!
* ==========================================================================
*
* @author <a href="http://xuewei.world/about">XUEW</a>
*/
@Controller
public class SystemController extends BaseController<User> {
/**
* 首页
*/
@GetMapping("/index.html")
public String index(Map<String, Object> map) {
return "index";
}
/**
* 智能医生
*/
@GetMapping("/doctor")
public String doctor(Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
return "doctor";
}
/**
* 退出登录
*/
@GetMapping("/logout")
public String logout() {
session.invalidate();
return "redirect:/index.html";
}
/**
* 所有反馈
*/
@GetMapping("/all-feedback")
public String feedback(Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
List<Feedback> feedbackList = feedbackService.all();
map.put("feedbackList", feedbackList);
return "all-feedback";
}
/**
* 我的资料
*/
@GetMapping("/profile")
public String profile(Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
return "profile";
}
/**
* 查询相关疾病
*/
@GetMapping("findIllness")
public String findIllness(Map<String, Object> map, Integer kind, String illnessName, Integer page) {
// 处理page
page = ObjectUtils.isEmpty(page) ? 1 : page;
Map<String, Object> illness = illnessService.findIllness(kind, illnessName, page);
if (Assert.notEmpty(kind)) {
map.put("title", illnessKindService.get(kind).getName() + (illnessName == null ? "" : ('"' + illnessName + '"' + "的搜索结果")));
} else {
map.put("title", illnessName == null ? "全部" : ('"' + illnessName + '"' + "的搜索结果"));
}
if (loginUser != null && kind != null) {
historyService.insetOne(loginUser.getId(), MedicalConstants.TYPE_OPERATE,
illnessKindService.get(kind).getId() + "," + (Assert.isEmpty(illnessName) ? "无" : illnessName));
}
if (loginUser != null && Assert.notEmpty(illnessName)) {
historyService.insetOne(loginUser.getId(), MedicalConstants.TYPE_ILLNESS, illnessName);
}
map.putAll(illness);
map.put("page", page);
map.put("kind", kind);
map.put("illnessName", illnessName);
map.put("kindList", illnessKindService.findList());
map.put("history", loginUser == null ? null : historyService.findList(loginUser.getId()));
return "search-illness";
}
/**
* 查询相关疾病下的药
*/
@GetMapping("findIllnessOne")
public String findIllnessOne(Map<String, Object> map, Integer id) {
Map<String, Object> illnessOne = illnessService.findIllnessOne(id);
Illness illness = illnessService.get(id);
if (loginUser != null) {
historyService.insetOne(loginUser.getId(), MedicalConstants.TYPE_ILLNESS, illness.getIllnessName());
}
map.putAll(illnessOne);
return "illness-reviews";
}
/**
* 查询相关疾病下的药
*/
@GetMapping("findMedicineOne")
public String findMedicineOne(Map<String, Object> map, Integer id) {
Medicine medicine = medicineService.get(id);
// historyService.insetOne(loginUser.getId(),MedicalConstants.TYPE_MEDICINE,medicine.getMedicineName());
map.put("medicine", medicine);
return "medicine";
}
/**
* 查询相关疾病下的药
*/
@GetMapping("findMedicines")
public String findMedicines(Map<String, Object> map, String nameValue, Integer page) {
// 处理page
page = ObjectUtils.isEmpty(page) ? 1 : page;
if (loginUser != null && Assert.notEmpty(nameValue)) {
historyService.insetOne(loginUser.getId(), MedicalConstants.TYPE_MEDICINE, nameValue);
}
map.putAll(medicineService.getMedicineList(nameValue, page));
map.put("history", loginUser == null ? null : historyService.findList(loginUser.getId()));
map.put("title", nameValue);
return "illness";
}
/**
* 查询相关疾病下的药
*/
@GetMapping("globalSelect")
public String globalSelect(Map<String, Object> map, String nameValue) {
nameValue = nameValue.replace(",", ",");
List<String> idArr = Arrays.asList(nameValue.split(","));
//首先根据关键字去查询
Set<Illness> illnessSet = new HashSet<>();
idArr.forEach(s -> {
Illness one = illnessService.getOne(new QueryWrapper<Illness>().like("illness_name", s));
if (ObjectUtil.isNotNull(one)) {
illnessSet.add(one);
}
});
idArr.forEach(s -> {
Illness one = illnessService.getOne(new QueryWrapper<Illness>().like("special_symptom", s));
if (ObjectUtil.isNotNull(one)) {
illnessSet.add(one);
}
});
idArr.forEach(s -> {
Illness one = illnessService.getOne(new QueryWrapper<Illness>().like("illness_symptom", s));
if (ObjectUtil.isNotNull(one)) {
illnessSet.add(one);
}
});
map.put("illnessSet", illnessSet);
return "index";
}
/**
* 添加疾病页面
*/
@GetMapping("add-illness")
public String addIllness(Integer id, Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
Illness illness = new Illness();
if (Assert.notEmpty(id)) {
illness = illnessService.get(id);
}
List<IllnessKind> illnessKinds = illnessKindService.all();
map.put("illness", illness);
map.put("kinds", illnessKinds);
return "add-illness";
}
/**
* 添加药品页面
*/
@GetMapping("add-medical")
public String addMedical(Integer id, Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
List<Illness> illnesses = illnessService.all();
Medicine medicine = new Medicine();
if (Assert.notEmpty(id)) {
medicine = medicineService.get(id);
for (Illness illness : illnesses) {
List<IllnessMedicine> query = illnessMedicineService.query(IllnessMedicine.builder().medicineId(id).illnessId(illness.getId()).build());
if (Assert.notEmpty(query)) {
illness.setIllnessMedicine(query.get(0));
}
}
}
map.put("illnesses", illnesses);
map.put("medicine", medicine);
return "add-medical";
}
/**
* 疾病管理页面
*/
@GetMapping("all-illness")
public String allIllness(Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
List<Illness> illnesses = illnessService.all();
for (Illness illness : illnesses) {
illness.setKind(illnessKindService.get(illness.getKindId()));
}
map.put("illnesses", illnesses);
return "all-illness";
}
/**
* 药品管理页面
*/
@GetMapping("all-medical")
public String allMedical(Map<String, Object> map) {
if (Assert.isEmpty(loginUser)) {
return "redirect:/index.html";
}
List<Medicine> medicines = medicineService.all();
map.put("medicines", medicines);
return "all-medical";
}
}
package world.xuewei.controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.xuewei.dto.RespResult;
import world.xuewei.entity.User;
import world.xuewei.utils.Assert;
/**
* 用户控制器
*
* @author XUEW
*/
@RestController
@RequestMapping(value = "user")
public class UserController extends BaseController<User> {
/**
* 修改资料
*/
@PostMapping("/saveProfile")
public RespResult saveProfile(User user) {
if (Assert.isEmpty(user)) {
return RespResult.fail("保存对象不能为空");
}
user = userService.save(user);
session.setAttribute("loginUser", user);
return RespResult.success("保存成功");
}
/**
* 修改密码
*/
@PostMapping("/savePassword")
public RespResult savePassword(String oldPass, String newPass) {
if (!loginUser.getUserPwd().equals(oldPass)) {
return RespResult.fail("旧密码错误");
}
loginUser.setUserPwd(newPass);
loginUser = userService.save(loginUser);
session.setAttribute("loginUser", loginUser);
return RespResult.success("保存成功");
}
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.Feedback;
/**
* 反馈数据库访问
*
* @author XUEW
*/
@Repository
public interface FeedbackDao extends BaseMapper<Feedback> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.History;
/**
* 历史数据库访问
*
* @author XUEW
*/
@Repository
public interface HistoryDao extends BaseMapper<History> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.Illness;
/**
* 疾病数据库访问
*
* @author XUEW
*/
@Repository
public interface IllnessDao extends BaseMapper<Illness> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.IllnessKind;
/**
* 疾病分类数据库访问
*
* @author XUEW
*/
@Repository
public interface IllnessKindDao extends BaseMapper<IllnessKind> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.IllnessMedicine;
/**
* 疾病药品数据库访问
*
* @author XUEW
*/
@Repository
public interface IllnessMedicineDao extends BaseMapper<IllnessMedicine> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.MedicalNews;
/**
* 咨询数据库访问
*
* @author XUEW
*/
@Repository
public interface MedicalNewsDao extends BaseMapper<MedicalNews> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.Medicine;
import java.util.List;
import java.util.Map;
/**
* 药品数据库访问
*
* @author XUEW
*/
@Repository
public interface MedicineDao extends BaseMapper<Medicine> {
/**
* 根据疾病查询药物
*/
List<Map<String, Object>> findMedicineList(Integer illnessId);
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.Pageview;
/**
* 分页数据库访问
*
* @author XUEW
*/
@Repository
public interface PageviewDao extends BaseMapper<Pageview> {
}
package world.xuewei.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import world.xuewei.entity.User;
/**
* 用户数据库访问
*
* @author XUEW
*/
@Repository
public interface UserDao extends BaseMapper<User> {
}
package world.xuewei.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* 响应异常
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class RespError extends RespResult {
/**
* 请求地址(发生异常时返回)
*/
private String requestUrl;
/**
* 异常类(发生异常时返回)
*/
private String exception;
}
package world.xuewei.dto;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import world.xuewei.utils.Assert;
import java.util.List;
/**
* 响应结果
*
* @author XUEW
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RespResult {
/**
* 响应编码
*/
protected String code;
/**
* 响应信息
*/
protected String message;
/**
* 响应数据
*/
protected Object data;
/**
* 请求成功
*/
public static RespResult success() {
return RespResult.builder()
.code("SUCCESS")
.message("请求成功")
.build();
}
/**
* 请求成功
*/
public static RespResult success(String message) {
return RespResult.builder()
.code("SUCCESS")
.message(message)
.build();
}
/**
* 请求成功
*/
public static RespResult success(String message, Object data) {
return RespResult.builder()
.code("SUCCESS")
.message(message)
.data(data)
.build();
}
/**
* 请求失败
*/
public static RespResult fail() {
return RespResult.builder()
.code("FAIL")
.message("请求失败")
.build();
}
/**
* 请求失败
*/
public static RespResult fail(String message) {
return RespResult.builder()
.code("FAIL")
.message(message)
.build();
}
/**
* 未查询到数据
*/
public static RespResult notFound(String message, Object data) {
return RespResult.builder()
.code("NOT_FOUND")
.message(message)
.data(data)
.build();
}
/**
* 未查询到数据
*/
public static RespResult notFound() {
return RespResult.builder()
.code("NOT_FOUND")
.message("请求失败")
.build();
}
/**
* 未查询到数据
*/
public static RespResult notFound(String message) {
return RespResult.builder()
.code("NOT_FOUND")
.message(message)
.build();
}
/**
* 请求失败
*/
public static RespResult fail(String message, Object data) {
return RespResult.builder()
.code("FAIL")
.message(message)
.data(data)
.build();
}
/**
* 请求是否成功
*/
public boolean isSuccess() {
return "SUCCESS".equals(code);
}
/**
* 请求是否成功并有数据返回
*/
public boolean isSuccessWithDateResp() {
return "SUCCESS".equals(code) && Assert.notEmpty(data);
}
/**
* 请求是否成功
*/
public boolean notSuccess() {
return !isSuccess();
}
/**
* 获取响应的数据集合
*/
public <T> List<T> getDataList(Class<T> clazz) {
String jsonString = JSONObject.toJSONString(data);
return JSONObject.parseArray(jsonString, clazz);
}
/**
* 获取响应的数据
*/
public <T> T getDataObj(Class<T> clazz) {
String jsonString = JSONObject.toJSONString(data);
return JSONObject.parseObject(jsonString, clazz);
}
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 反馈实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("feedback")
public class Feedback {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 反馈用户
*/
private String name;
/**
* 邮箱
*/
private String email;
/**
* 反馈标题
*/
private String title;
/**
* 反馈内容
*/
private String content;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 历史实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
@TableName("history")
public class History {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 浏览历史关联用户id
*/
private Integer userId;
/**
* 浏览历史类型
*/
private Integer operateType;
/**
* 浏览历史关键字
*/
private String keyword;
/**
* 浏览时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 疾病实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("illness")
public class Illness {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 疾病所属种类id
*/
private Integer kindId;
/**
* 疾病的名字
*/
private String illnessName;
/**
* 引起的原因
*/
private String includeReason;
/**
* 主要的症状
*/
private String illnessSymptom;
/**
* 特殊的症状
*/
private String specialSymptom;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
@TableField(exist = false)
private IllnessKind kind;
@TableField(exist = false)
private IllnessMedicine illnessMedicine;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 疾病分类实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("illness_kind")
public class IllnessKind {
/**
* 主键ID
*/
private int id;
/**
* 疾病种类名字
*/
private String name;
/**
* 疾病描述
*/
private String info;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 疾病药品实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("illness_medicine")
public class IllnessMedicine {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 疾病id
*/
private Integer illnessId;
/**
* 药物id
*/
private Integer medicineId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 咨询实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("medical_news")
public class MedicalNews {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 医疗咨询名字
*/
private String newsName;
/**
* 医疗咨询关键字
*/
private String newsKey;
/**
* 咨询的详细内容
*/
private String newsContent;
/**
* 包含的图片地址
*/
private String imgPath;
/**
* 关联的疾病id
*/
private Integer relationIllness;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* 药品实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("medicine")
public class Medicine {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 药物名字
*/
private String medicineName;
/**
* 关键字搜索
*/
private String keyword;
/**
* 药物的功效
*/
private String medicineEffect;
/**
* 药物的品牌
*/
private String medicineBrand;
/**
* 药物的相互作用
*/
private String interaction;
/**
* 禁忌
*/
private String taboo;
/**
* 用法用量
*/
private String usAge;
/**
* 药物的类型,0代表西药,1中药,2中成药
*/
private Integer medicineType;
/**
* 药物的图片地址
*/
private String imgPath;
/**
* 药物的价格
*/
private BigDecimal medicinePrice;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 浏览实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
@TableName("pageview")
public class Pageview implements Serializable {
/**
* 浏览量主键id
*/
private int id;
/**
* 浏览量
*/
private Integer pageviews;
/**
* 病的id
*/
private Integer illnessId;
}
package world.xuewei.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 用户实体
*
* @author XUEW
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("user")
public class User {
/**
* 主键ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 用户账号
*/
private String userAccount;
/**
* 用户真实名字
*/
private String userName;
/**
* 用户密码
*/
private String userPwd;
/**
* 用户年龄
*/
private Integer userAge;
/**
* 用户性别
*/
private String userSex;
/**
* 用户邮箱
*/
private String userEmail;
/**
* 用户电话
*/
private String userTel;
/**
* 角色状态,1代表管理员,0普通用户
*/
private Integer roleStatus;
/**
* 图片的地址
*/
private String imgPath;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
package world.xuewei.service;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationOutput;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.MessageManager;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.utils.Constants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* 智慧医生服务
* <p>
* ==========================================================================
* 郑重说明:本项目免费开源!原创作者为:薛伟同学,严禁私自出售。
* ==========================================================================
* B站账号:薛伟同学
* 微信公众号:薛伟同学
* 作者博客:http://xuewei.world
* ==========================================================================
* 陆陆续续总会收到粉丝的提醒,总会有些人为了赚取利益倒卖我的开源项目。
* 不乏有粉丝朋友出现钱付过去,那边只把代码发给他就跑路的,最后还是根据线索找到我。。
* 希望各位朋友擦亮慧眼,谨防上当受骗!
* ==========================================================================
*
* @author <a href="http://xuewei.world/about">XUEW</a>
*/
@Service
public class ApiService {
@Value("${ai-key}")
private String apiKey;
public String query(String queryMessage) {
Constants.apiKey = apiKey;
try {
Generation gen = new Generation();
MessageManager msgManager = new MessageManager(10);
Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("你是薛伟同学开发的智能医生,你只回答与医疗相关的问题,不要回答其他问题!").build();
Message userMsg = Message.builder().role(Role.USER.getValue()).content(queryMessage).build();
msgManager.add(systemMsg);
msgManager.add(userMsg);
QwenParam param = QwenParam.builder().model(Generation.Models.QWEN_TURBO).messages(msgManager.get()).resultFormat(QwenParam.ResultFormat.MESSAGE).build();
GenerationResult result = gen.call(param);
GenerationOutput output = result.getOutput();
Message message = output.getChoices().get(0).getMessage();
return message.getContent();
} catch (Exception e) {
return "智能医生现在不在线,请稍后再试~";
}
}
}
package world.xuewei.service;
import org.springframework.beans.factory.annotation.Autowired;
import world.xuewei.dao.*;
/**
* 基础服务类
*
* @author XUEW
*/
public abstract class BaseService<T> implements IService<T> {
@Autowired
protected UserDao userDao;
@Autowired
protected HistoryDao historyDao;
@Autowired
protected IllnessDao illnessDao;
@Autowired
protected IllnessKindDao illnessKindDao;
@Autowired
protected IllnessMedicineDao illnessMedicineDao;
@Autowired
protected MedicineDao medicineDao;
@Autowired
protected MedicalNewsDao medicalNewsDao;
@Autowired
protected PageviewDao pageviewDao;
}
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.FeedbackDao;
import world.xuewei.entity.Feedback;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 反馈服务类
*
* @author XUEW
*/
@Service
public class FeedbackService extends BaseService<Feedback> {
@Autowired
protected FeedbackDao userDao;
@Override
public List<Feedback> query(Feedback o) {
QueryWrapper<Feedback> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return userDao.selectList(wrapper);
}
@Override
public List<Feedback> all() {
return query(null);
}
@Override
public Feedback save(Feedback o) {
if (Assert.isEmpty(o.getId())) {
userDao.insert(o);
} else {
userDao.updateById(o);
}
return userDao.selectById(o.getId());
}
@Override
public Feedback get(Serializable id) {
return userDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return userDao.deleteById(id);
}
}
\ No newline at end of file
package world.xuewei.service;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.HistoryDao;
import world.xuewei.entity.History;
import world.xuewei.entity.IllnessKind;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
/**
* 历史服务类
*
* @author XUEW
*/
@Service
public class HistoryService extends BaseService<History> {
@Autowired
protected HistoryDao historyDao;
@Override
public List<History> query(History o) {
QueryWrapper<History> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return historyDao.selectList(wrapper);
}
@Override
public List<History> all() {
return query(null);
}
@Override
public History save(History o) {
if (Assert.isEmpty(o.getId())) {
historyDao.insert(o);
} else {
historyDao.updateById(o);
}
return historyDao.selectById(o.getId());
}
@Override
public History get(Serializable id) {
return historyDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return historyDao.deleteById(id);
}
public boolean insetOne(Integer uid, Integer type, String nameValue) {
History history = new History();
history.setUserId(uid).setKeyword(nameValue).setOperateType(type);
return historyDao.insert(history) > 0;
}
public List<Map<String, Object>> findList(Integer userId) {
List<History> list = historyDao.selectList(new QueryWrapper<History>().eq("user_id", userId)
.orderByDesc("create_time"));
List<History> histories = list.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(History::getKeyword))), LinkedList::new));
histories.sort((h1, h2) -> -h1.getCreateTime().compareTo(h2.getCreateTime()));
List<History> historyList = histories.stream().limit(10).collect(Collectors.toList());
System.out.println(histories.size());
List<Map<String, Object>> mapList = new LinkedList<>();
historyList.forEach(his -> {
Map<String, Object> map = cn.hutool.core.bean.BeanUtil.beanToMap(his);
Integer operateType = MapUtil.getInt(map, "operateType");
if (operateType == 1) {
List<String> keyword = Arrays.asList((MapUtil.getStr(map, "keyword")).split(","));
IllnessKind illnessKind = illnessKindDao.selectById(Integer.valueOf(keyword.get(0)));
map.put("kind", illnessKind.getId());
map.put("nameValue", keyword.get(1));
map.put("searchValue", illnessKind.getName() + ("无".equals(keyword.get(1)) ? "" : ("|" + keyword.get(1))));
} else if (operateType == 2) {
map.put("nameValue", MapUtil.getStr(map, "keyword"));
map.put("kind", "无");
map.put("searchValue", MapUtil.getStr(map, "keyword"));
} else if (operateType == 3) {
map.put("nameValue", MapUtil.getStr(map, "keyword"));
map.put("searchValue", MapUtil.getStr(map, "keyword"));
map.put("kind", "无");
}
mapList.add(map);
});
return mapList;
}
}
\ No newline at end of file
package world.xuewei.service;
import java.io.Serializable;
import java.util.List;
/**
* 基础服务接口
*
* @author XUEW
*/
public interface IService<T> {
/**
* 保存
*/
T save(T t);
/**
* 根据主键获取
*/
T get(Serializable id);
/**
* 根据主键删除
*/
int delete(Serializable id);
/**
* 查询
*/
List<T> query(T o);
/**
* 查询全部
*/
List<T> all();
}
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.IllnessKindDao;
import world.xuewei.entity.IllnessKind;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 疾病分类服务类
*
* @author XUEW
*/
@Service
public class IllnessKindService extends BaseService<IllnessKind> {
@Autowired
protected IllnessKindDao illnessKindDao;
@Override
public List<IllnessKind> query(IllnessKind o) {
QueryWrapper<IllnessKind> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return illnessKindDao.selectList(wrapper);
}
@Override
public List<IllnessKind> all() {
return query(null);
}
@Override
public IllnessKind save(IllnessKind o) {
if (Assert.isEmpty(o.getId())) {
illnessKindDao.insert(o);
} else {
illnessKindDao.updateById(o);
}
return illnessKindDao.selectById(o.getId());
}
@Override
public IllnessKind get(Serializable id) {
return illnessKindDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return illnessKindDao.deleteById(id);
}
public List<IllnessKind> findList() {
return illnessKindDao.selectList(new QueryWrapper<IllnessKind>());
}
}
\ No newline at end of file
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.IllnessMedicineDao;
import world.xuewei.entity.IllnessMedicine;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 疾病药品服务类
*
* @author XUEW
*/
@Service
public class IllnessMedicineService extends BaseService<IllnessMedicine> {
@Autowired
protected IllnessMedicineDao illnessMedicineDao;
@Override
public List<IllnessMedicine> query(IllnessMedicine o) {
QueryWrapper<IllnessMedicine> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return illnessMedicineDao.selectList(wrapper);
}
@Override
public List<IllnessMedicine> all() {
return query(null);
}
@Override
public IllnessMedicine save(IllnessMedicine o) {
if (Assert.isEmpty(o.getId())) {
illnessMedicineDao.insert(o);
} else {
illnessMedicineDao.updateById(o);
}
return illnessMedicineDao.selectById(o.getId());
}
@Override
public IllnessMedicine get(Serializable id) {
return illnessMedicineDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return illnessMedicineDao.deleteById(id);
}
}
\ No newline at end of file
package world.xuewei.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.IllnessDao;
import world.xuewei.entity.*;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 疾病服务类
*
* @author XUEW
*/
@Service
public class IllnessService extends BaseService<Illness> {
@Autowired
protected IllnessDao illnessDao;
@Override
public List<Illness> query(Illness o) {
QueryWrapper<Illness> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return illnessDao.selectList(wrapper);
}
@Override
public List<Illness> all() {
return query(null);
}
@Override
public Illness save(Illness o) {
if (Assert.isEmpty(o.getId())) {
illnessDao.insert(o);
} else {
illnessDao.updateById(o);
}
return illnessDao.selectById(o.getId());
}
@Override
public Illness get(Serializable id) {
return illnessDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return illnessDao.deleteById(id);
}
public Map<String, Object> findIllness(Integer kind, String illnessName, Integer page) {
Map<String, Object> map = new HashMap<>(4);
QueryWrapper<Illness> illnessQueryWrapper = new QueryWrapper<>();
if (Assert.notEmpty(illnessName)) {
illnessQueryWrapper
.like("illness_name", illnessName)
.or()
.like("include_reason", illnessName)
.or()
.like("illness_symptom", illnessName)
.or()
.like("special_symptom", illnessName);
}
if (kind != null) {
if (Assert.notEmpty(illnessName)) {
illnessQueryWrapper.last("and (kind_id = " + kind + ") ORDER BY create_time DESC limit " + (page - 1) * 9 + "," + page * 9);
} else {
illnessQueryWrapper.eq("kind_id", kind);
illnessQueryWrapper.orderByDesc("create_time");
illnessQueryWrapper.last("limit " + (page - 1) * 9 + "," + page * 9);
}
} else {
illnessQueryWrapper.orderByDesc("create_time");
illnessQueryWrapper.last("limit " + (page - 1) * 9 + "," + page * 9);
}
int size = illnessDao.selectMaps(illnessQueryWrapper).size();
List<Map<String, Object>> list = illnessDao.selectMaps(illnessQueryWrapper);
list.forEach(l -> {
Integer id = MapUtil.getInt(l, "id");
Pageview pageInfo = pageviewDao.selectOne(new QueryWrapper<Pageview>().eq("illness_id", id));
l.put("kindName", "暂无归属类");
l.put("create_time", MapUtil.getDate(l, "create_time"));
l.put("pageview", pageInfo == null ? 0 : pageInfo.getPageviews());
Integer kindId = MapUtil.getInt(l, "kind_id");
if (Assert.notEmpty(kindId)) {
IllnessKind illnessKind = illnessKindDao.selectById(kindId);
if (Assert.notEmpty(illnessKind)) {
l.put("kindName", illnessKind.getName());
}
}
});
map.put("illness", list);
map.put("size", size < 9 ? 1 : size / 9 + 1);
return map;
}
public Map<String, Object> findIllnessOne(Integer id) {
Illness illness = illnessDao.selectOne(new QueryWrapper<Illness>().eq("id", id));
List<IllnessMedicine> illnessMedicines = illnessMedicineDao.selectList(new QueryWrapper<IllnessMedicine>().eq("illness_id", id));
List<Medicine> list = new ArrayList<>(4);
Map<String, Object> map = new HashMap<>(4);
Pageview illness_id = pageviewDao.selectOne(new QueryWrapper<Pageview>().eq("illness_id", id));
if (Assert.isEmpty(illness_id)) {
illness_id = new Pageview();
illness_id.setIllnessId(id);
illness_id.setPageviews(1);
pageviewDao.insert(illness_id);
} else {
illness_id.setPageviews(illness_id.getPageviews() + 1);
pageviewDao.updateById(illness_id);
}
map.put("illness", illness);
if (CollUtil.isNotEmpty(illnessMedicines)) {
illnessMedicines.forEach(illnessMedicine -> {
Medicine medicine = medicineDao.selectOne(new QueryWrapper<Medicine>().eq("id", illnessMedicine.getMedicineId()));
if (ObjectUtil.isNotNull(medicine)) {
list.add(medicine);
}
});
map.put("medicine", list);
}
return map;
}
public Illness getOne(QueryWrapper<Illness> queryWrapper) {
return illnessDao.selectOne(queryWrapper);
}
}
\ No newline at end of file
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.MedicalNewsDao;
import world.xuewei.entity.MedicalNews;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 咨询服务类
*
* @author XUEW
*/
@Service
public class MedicalNewsService extends BaseService<MedicalNews> {
@Autowired
protected MedicalNewsDao medicalNewsDao;
@Override
public List<MedicalNews> query(MedicalNews o) {
QueryWrapper<MedicalNews> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return medicalNewsDao.selectList(wrapper);
}
@Override
public List<MedicalNews> all() {
return query(null);
}
@Override
public MedicalNews save(MedicalNews o) {
if (Assert.isEmpty(o.getId())) {
medicalNewsDao.insert(o);
} else {
medicalNewsDao.updateById(o);
}
return medicalNewsDao.selectById(o.getId());
}
@Override
public MedicalNews get(Serializable id) {
return medicalNewsDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return medicalNewsDao.deleteById(id);
}
}
\ No newline at end of file
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.MedicineDao;
import world.xuewei.entity.Medicine;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 药品服务类
*
* @author XUEW
*/
@Service
public class MedicineService extends BaseService<Medicine> {
@Autowired
protected MedicineDao medicineDao;
@Override
public List<Medicine> query(Medicine o) {
QueryWrapper<Medicine> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return medicineDao.selectList(wrapper);
}
@Override
public List<Medicine> all() {
return query(null);
}
@Override
public Medicine save(Medicine o) {
if (Assert.isEmpty(o.getId())) {
medicineDao.insert(o);
} else {
medicineDao.updateById(o);
}
return medicineDao.selectById(o.getId());
}
@Override
public Medicine get(Serializable id) {
return medicineDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return medicineDao.deleteById(id);
}
public Map<String, Object> getMedicineList(String nameValue, Integer page) {
List<Medicine> medicineList = null;
Map<String, Object> map = new HashMap<>(4);
if (Assert.notEmpty(nameValue)) {
medicineList = medicineDao.selectList(new QueryWrapper<Medicine>().
like("medicine_name", nameValue)
.or().like("keyword", nameValue)
.or().like("medicine_effect", nameValue)
.last("limit " + (page - 1) * 9 + "," + page * 9));
} else {
medicineList = medicineDao.selectList(new QueryWrapper<Medicine>()
.last("limit " + (page - 1) * 9 + "," + page * 9));
}
map.put("medicineList", medicineList);
map.put("size", medicineList.size() < 9 ? 1 : medicineList.size() / 9 + 1);
return map;
}
}
\ No newline at end of file
package world.xuewei.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.xuewei.dao.UserDao;
import world.xuewei.entity.User;
import world.xuewei.utils.Assert;
import world.xuewei.utils.BeanUtil;
import world.xuewei.utils.VariableNameUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 用户服务类
*
* @author XUEW
*/
@Service
public class UserService extends BaseService<User> {
@Autowired
protected UserDao userDao;
@Override
public List<User> query(User o) {
QueryWrapper<User> wrapper = new QueryWrapper();
if (Assert.notEmpty(o)) {
Map<String, Object> bean2Map = BeanUtil.bean2Map(o);
for (String key : bean2Map.keySet()) {
if (Assert.isEmpty(bean2Map.get(key))) {
continue;
}
wrapper.eq(VariableNameUtils.humpToLine(key), bean2Map.get(key));
}
}
return userDao.selectList(wrapper);
}
@Override
public List<User> all() {
return query(null);
}
@Override
public User save(User o) {
if (Assert.isEmpty(o.getId())) {
userDao.insert(o);
} else {
userDao.updateById(o);
}
return userDao.selectById(o.getId());
}
@Override
public User get(Serializable id) {
return userDao.selectById(id);
}
@Override
public int delete(Serializable id) {
return userDao.deleteById(id);
}
}
\ No newline at end of file
package world.xuewei.utils;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* 断言判定
*
* @author XUEW
*/
public class Assert {
public static boolean isEmpty(CharSequence s) {
if (s == null || s.length() == 0) {
return true;
}
for (int i = 0; i < s.length(); ++i) {
if (' ' != s.charAt(i)) {
return false;
}
}
return true;
}
public static boolean isEmpty(Collection<?> obj) {
return obj == null || obj.isEmpty();
}
public static boolean isEmpty(Map<?, ?> obj) {
return obj == null || obj.isEmpty();
}
public static boolean isEmpty(Object[] obj) {
return obj == null || obj.length == 0;
}
public static boolean isEmpty(Object obj) {
return obj == null;
}
public static boolean isEmpty(List<?> obj) {
return obj == null || obj.size() == 0;
}
public static boolean notEmpty(CharSequence s) {
return !isEmpty(s);
}
public static boolean notEmpty(Collection<?> obj) {
return !isEmpty(obj);
}
public static boolean notEmpty(Map<?, ?> obj) {
return !isEmpty(obj);
}
public static boolean notEmpty(Object[] obj) {
return !isEmpty(obj);
}
public static boolean notEmpty(Object obj) {
return !isEmpty(obj);
}
public static boolean notEmpty(List<?> obj) {
return !isEmpty(obj);
}
public static void assertNotEmpty(CharSequence s, String name) {
if (isEmpty(s)) {
throwException(name);
}
}
public static void assertNotEmpty(Collection<?> obj, String name) {
if (isEmpty(obj)) {
throwException(name);
}
}
public static void assertNotEmpty(Map<?, ?> obj, String name) {
if (isEmpty(obj)) {
throwException(name);
}
}
public static void assertNotEmpty(Object[] obj, String name) {
if (isEmpty(obj)) {
throwException(name);
}
}
public static void assertNotEmpty(Object obj, String name) {
if (isEmpty(obj)) {
throwException(name);
}
}
public static void assertNotEmpty(List<?> obj, String name) {
if (isEmpty(obj)) {
throwException(name);
}
}
private static String throwException(String name) {
throw new RuntimeException("REQUEST_PARAM_IS_NULL 请求参数<" + name + ">为空");
}
}
package world.xuewei.utils;
import com.alibaba.fastjson.JSON;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.beans.BeanMap;
import java.util.*;
/**
* Bean 工具
*
* @author XUEW
*/
public class BeanUtil {
private static Map<String, BeanCopier> beanCopierMap = new HashMap();
public static <T> T copy(Object src, Class<T> clazz)
throws InstantiationException, IllegalAccessException {
if ((null == src) || (null == clazz)) return null;
Object des = clazz.newInstance();
copy(src, des);
return (T) des;
}
public static void copy(Object src, Object des) {
if ((null == src) || (null == des)) return;
String key = generateKey(src.getClass(), des.getClass());
BeanCopier copier = (BeanCopier) beanCopierMap.get(key);
if (null == copier) {
copier = BeanCopier.create(src.getClass(), des.getClass(), false);
beanCopierMap.put(key, copier);
}
copier.copy(src, des, null);
}
public static <T> T map2Bean(Map<String, Object> map, Class<T> clazz)
throws InstantiationException, IllegalAccessException {
if ((null == map) || (null == clazz)) return null;
T bean = clazz.newInstance();
map2Bean(map, bean);
return bean;
}
public static <T> void map2Bean(Map<String, Object> map, T bean) {
if ((null == map) || (null == bean)) return;
BeanMap beanMap = BeanMap.create(bean);
beanMap.putAll(map);
}
public static Map<String, Object> bean2Map(Object bean) {
if (null == bean) return null;
return copy(BeanMap.create(bean));
}
public static <T> List<Map<String, Object>> mapList(List<T> beanList) {
if ((null == beanList) || (beanList.size() < 1)) return null;
List<Map<String, Object>> mapList = new ArrayList();
int i = 0;
for (int size = beanList.size(); i < size; i++) {
mapList.add(bean2Map(beanList.get(i)));
}
return mapList;
}
public static <K, V> Map<K, V> copy(Map<K, V> src) {
if (null == src) return null;
Map<K, V> des = new HashMap();
des.putAll(src);
return des;
}
public static void apply(Object des, Object... srcs) {
if ((null == des) || (null == srcs) || (srcs.length < 1)) return;
BeanMap desBeanMap = BeanMap.create(des);
Set<?> keys = desBeanMap.keySet();
BeanMap srcBeanMap = null;
for (Object src : srcs) {
if (null != src) {
srcBeanMap = BeanMap.create(src);
for (Object key : keys) {
Object value = srcBeanMap.get(key);
if ((null != value) && (null == desBeanMap.get(key))) {
desBeanMap.put(des, key, value);
}
}
}
}
}
public static void apply(Object des, List<Map<String, Object>> srcList) {
Map<String, Object> src;
if ((null == des) || (null == srcList) || (srcList.isEmpty())) return;
BeanMap desBeanMap = BeanMap.create(des);
Set<?> keys = desBeanMap.keySet();
for (Iterator localIterator1 = srcList.iterator(); localIterator1.hasNext(); ) {
src = (Map) localIterator1.next();
if ((null != src) && (!src.isEmpty())) {
for (Object key : keys) {
Object value = src.get(key);
if (null != value) {
desBeanMap.put(des, key, value);
}
}
}
}
}
private static String generateKey(Class<?> src, Class<?> des) {
return src.getName() + des.getName();
}
/**
* bean 转 String
*/
public static <T> String beanToString(T value) {
if (value == null) {
return null;
}
Class<?> clazz = value.getClass();
if (clazz == int.class || clazz == Integer.class) {
return "" + value;
} else if (clazz == String.class) {
return (String) value;
} else if (clazz == long.class || clazz == Long.class) {
return "" + value;
} else {
return JSON.toJSONString(value);
}
}
/**
* string 转 bean
*/
public static <T> T stringToBean(String str, Class<T> clazz) {
if (str == null || str.length() <= 0 || clazz == null) {
return null;
}
if (clazz == int.class || clazz == Integer.class) {
return (T) Integer.valueOf(str);
} else if (clazz == String.class) {
return (T) str;
} else if (clazz == long.class || clazz == Long.class) {
return (T) Long.valueOf(str);
} else {
return JSON.toJavaObject(JSON.parseObject(str), clazz);
}
}
}
package world.xuewei.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 变量名工具
*
* @author XUEW
*/
public class VariableNameUtils {
private static Pattern humpPattern = Pattern.compile("[A-Z]");
private static Pattern linePattern = Pattern.compile("_(\\w)");
/**
* 下划线转驼峰
*/
public static String lineToHump(String str) {
str = str.toLowerCase();
Matcher matcher = linePattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
}
matcher.appendTail(sb);
return sb.toString();
}
/**
* 驼峰转下划线
*/
public static String humpToLine(String str) {
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
}
\ No newline at end of file
spring:
# 数据源配置
datasource:
url: jdbc:mysql://mysql.sqlpub.com:3306/xin_sm_db
username: xin_root
password: 7jpx7qBdvkb6kxr7
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
# 邮件配置
mail:
username: 373675032@qq.com
password:
host: smtp.qq.com
port: 465
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
socketFactory:
port: 465
class: javax.net.ssl.SSLSocketFactory
fallback: false
valid: 5
title: "寻药就医系统 - 用户认证"
template: "您的动态验证码为:<strong style='color: red'>%s</strong>,%d分钟内有效,若非本人操作,请勿泄露。"
# 日志配置
logging:
level:
world.world.xuewei.dao.mapper: debug
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 阿里云通义千问配置
ai-key: sk-xxxxxxxxxxxxx
# 阿里云对象存储配置
oss:
bucket-name: xxxxxxxxxxx
end-point: xxxxxxxxxx
access-key: xxxxxxxxxxxxxxxx
access-secret: xxxxxxxxxxxxxxx
\ No newline at end of file
_____ __ __ ___ ___ _
/ ___/____ ___ ____ ______/ /_ / |/ /__ ____/ (_)____(_)___ ___
\__ \/ __ `__ \/ __ `/ ___/ __/_____/ /|_/ / _ \/ __ / / ___/ / __ \/ _ \
___/ / / / / / / /_/ / / / /_/_____/ / / / __/ /_/ / / /__/ / / / / __/
/____/_/ /_/ /_/\__,_/_/ \__/ /_/ /_/\___/\__,_/_/\___/_/_/ /_/\___/
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
Flaticon icon font: Flaticon
Creation date: 23/12/2019 06:12
*/
@font-face {
font-family: "Flaticon";
src: url("./Flaticon.eot");
src: url("./Flaticon.eot?#iefix") format("embedded-opentype"), url("./Flaticon.woff2") format("woff2"), url("./Flaticon.woff") format("woff"),
url("./Flaticon.ttf") format("truetype"), url("./Flaticon.svg#Flaticon") format("svg");
font-weight: normal;
font-style: normal;
}
@media screen and (-webkit-min-device-pixel-ratio: 0) {
@font-face {
font-family: "Flaticon";
src: url("./Flaticon.svg#Flaticon") format("svg");
}
}
[class^="flaticon-"]:before,
[class*=" flaticon-"]:before,
[class^="flaticon-"]:after,
[class*=" flaticon-"]:after {
font-family: Flaticon;
font-size: 16px;
font-style: normal;
}
.flaticon-airplane:before {
content: "\f100";
}
.flaticon-yatch-with-sails:before {
content: "\f101";
}
.flaticon-car:before {
content: "\f102";
}
.flaticon-building:before {
content: "\f103";
}
.flaticon-global:before {
content: "\f104";
}
.flaticon-hiker:before {
content: "\f105";
}
.flaticon-mansion:before {
content: "\f106";
}
.flaticon-like:before {
content: "\f107";
}
.flaticon-price:before {
content: "\f108";
}
.flaticon-quality:before {
content: "\f109";
}
.flaticon-call:before {
content: "\f10a";
}
.flaticon-placeholder:before {
content: "\f10b";
}
.flaticon-calendar:before {
content: "\f10c";
}
.flaticon-add-user:before {
content: "\f10d";
}
.flaticon-user:before {
content: "\f10e";
}
.flaticon-location-pin:before {
content: "\f10f";
}
.flaticon-airplane-travelling-around-earth:before {
content: "\f110";
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册