├── src └── main │ ├── resources │ ├── db.config.yml │ ├── log4j2.xml │ ├── mybatis.config.xml │ └── net │ │ └── penyo │ │ └── herbms │ │ └── mapper │ │ ├── ExperienceMapper.xml │ │ ├── PrescriptionMapper.xml │ │ ├── ItemDifferentiationMapper.xml │ │ ├── PrescriptionInfoMapper.xml │ │ ├── HerbMapper.xml │ │ └── ItemDifferentiationInfoMapper.xml │ ├── java │ └── net │ │ └── penyo │ │ └── herbms │ │ ├── util │ │ ├── AppConfig.java │ │ ├── Pool.java │ │ ├── WebConfig.java │ │ └── Logger.java │ │ ├── dao │ │ ├── ItemDifferentiationDAO.java │ │ ├── AbstractDAO.java │ │ ├── PrescriptionDAO.java │ │ ├── ExperienceDAO.java │ │ ├── ItemDifferentiationInfoDAO.java │ │ ├── HerbDAO.java │ │ ├── PrescriptionInfoDAO.java │ │ └── GenericDAO.java │ │ ├── service │ │ ├── AbstractService.java │ │ ├── GenericService.java │ │ ├── ItemDifferentiationService.java │ │ ├── PrescriptionService.java │ │ ├── ExperienceService.java │ │ ├── PrescriptionInfoService.java │ │ ├── HerbService.java │ │ └── ItemDifferentiationInfoService.java │ │ ├── pojo │ │ ├── ReturnDataPack.java │ │ ├── GenericBean.java │ │ ├── Experience.java │ │ ├── ItemDifferentiationInfo.java │ │ ├── PrescriptionInfo.java │ │ ├── AbstractBean.java │ │ ├── Prescription.java │ │ ├── ItemDifferentiation.java │ │ └── Herb.java │ │ └── controller │ │ ├── AbstractController.java │ │ ├── ItemDifferentiationController.java │ │ ├── ExperienceController.java │ │ ├── GenericController.java │ │ ├── HerbController.java │ │ ├── PrescriptionInfoController.java │ │ ├── ItemDifferentiationInfoController.java │ │ └── PrescriptionController.java │ └── sql │ └── herbms.sql ├── .gitignore ├── LICENSE ├── README.md ├── .run └── Run Application.run.xml └── pom.xml /src/main/resources/db.config.yml: -------------------------------------------------------------------------------- 1 | driver: com.mysql.cj.jdbc.Driver 2 | url: jdbc:mysql:///herbms?serverTimezone=UTC 3 | username: root 4 | password: 1234 -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | 26 | # Dev Env Cache 27 | .vscode 28 | .idea 29 | .svn 30 | target 31 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/util/AppConfig.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.util; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | /** 8 | * 应用配置 9 | * 10 | * @author Penyo 11 | */ 12 | @Configuration 13 | @ComponentScan("net.penyo.herbms") 14 | @EnableAspectJAutoProxy(proxyTargetClass = true) 15 | public class AppConfig { 16 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) Penyo 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/ItemDifferentiationDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.ItemDifferentiation; 4 | import org.springframework.stereotype.Repository; 5 | 6 | /** 7 | * 条辨的数据访问代理 8 | * 9 | * @author Penyo 10 | * @see ItemDifferentiation 11 | * @see GenericDAO 12 | */ 13 | @Repository 14 | public class ItemDifferentiationDAO extends GenericDAO { 15 | public ItemDifferentiationDAO() { 16 | super("ItemDifferentiationMapper"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/AbstractService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.dao.AbstractDAO; 4 | import net.penyo.herbms.pojo.GenericBean; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 抽象业务代理 10 | * 11 | * @author Penyo 12 | * @see GenericBean 13 | * @see AbstractDAO 14 | */ 15 | public interface AbstractService extends AbstractDAO { 16 | @Override 17 | default List selectAll() { 18 | throw new UnsupportedOperationException(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/util/Pool.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.util; 2 | 3 | import org.apache.ibatis.session.SqlSession; 4 | import org.apache.ibatis.session.SqlSessionFactory; 5 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 6 | 7 | /** 8 | * SQL 会话池 9 | * 10 | * @author Penyo 11 | */ 12 | public class Pool { 13 | /** 14 | * 公共连接池 15 | */ 16 | private static final SqlSessionFactory POOL = new SqlSessionFactoryBuilder().build(Pool.class.getClassLoader().getResourceAsStream("mybatis.config.xml")); 17 | 18 | /** 19 | * 获取 SQL 会话。 20 | */ 21 | public static SqlSession getSession() { 22 | return POOL.openSession(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/ReturnDataPack.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 返回数据包 7 | * 8 | * @author Penyo 9 | * @see GenericBean 10 | */ 11 | public class ReturnDataPack extends GenericBean { 12 | /** 13 | * 影响行数 14 | */ 15 | private final int affectedRows; 16 | /** 17 | * 结果 18 | */ 19 | private final List objs; 20 | 21 | public ReturnDataPack(List objs) { 22 | this.affectedRows = -114514; 23 | this.objs = objs; 24 | } 25 | 26 | public ReturnDataPack(int affectedRows, List objs) { 27 | this.affectedRows = affectedRows; 28 | this.objs = objs; 29 | } 30 | 31 | public int getAffectedRows() { 32 | return affectedRows; 33 | } 34 | 35 | public List getObjs() { 36 | return objs; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/AbstractDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.GenericBean; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 抽象数据访问代理 9 | * 10 | * @author Penyo 11 | * @see GenericBean 12 | */ 13 | public interface AbstractDAO { 14 | /** 15 | * 添加单个元素。 16 | */ 17 | int add(UnknownBean o); 18 | 19 | /** 20 | * 删除单个元素。 21 | */ 22 | int delete(int id); 23 | 24 | /** 25 | * 修改单个元素。 26 | */ 27 | int update(UnknownBean o); 28 | 29 | /** 30 | * 根据 ID 查找单个元素。 31 | */ 32 | UnknownBean selectById(int id); 33 | 34 | /** 35 | * 根据关键字集合模糊查找多个元素。 36 | */ 37 | List selectByFields(List fields); 38 | 39 | /** 40 | * 查找全部元素。 41 | */ 42 | List selectAll(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/PrescriptionDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.Prescription; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | /** 9 | * 处方的数据访问代理 10 | * 11 | * @author Penyo 12 | * @see Prescription 13 | * @see GenericDAO 14 | */ 15 | @Repository 16 | public class PrescriptionDAO extends GenericDAO { 17 | public PrescriptionDAO() { 18 | super("PrescriptionMapper"); 19 | } 20 | 21 | /** 22 | * 根据处方 ID 查询单个元素。 23 | */ 24 | public Prescription selectByPrescriptionId(int id) { 25 | Prescription o = null; 26 | 27 | try (SqlSession s = Pool.getSession()) { 28 | o = s.selectOne(fullMapperName + ".selectByPrescriptionId", id); 29 | } 30 | return o; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/GenericService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.dao.*; 4 | import net.penyo.herbms.pojo.GenericBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | /** 8 | * 通用业务代理 9 | * 10 | * @author Penyo 11 | * @see GenericBean 12 | * @see AbstractService 13 | */ 14 | public abstract class GenericService implements AbstractService { 15 | @Autowired 16 | protected HerbDAO herbDAO; 17 | @Autowired 18 | protected ExperienceDAO experienceDAO; 19 | @Autowired 20 | protected PrescriptionInfoDAO prescriptionInfoDAO; 21 | @Autowired 22 | protected PrescriptionDAO prescriptionDAO; 23 | @Autowired 24 | protected ItemDifferentiationInfoDAO itemDifferentiationInfoDAO; 25 | @Autowired 26 | protected ItemDifferentiationDAO itemDifferentiationDAO; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/util/WebConfig.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.util; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 6 | 7 | /** 8 | * 网络配置 9 | * 10 | * @author Penyo 11 | */ 12 | @Configuration 13 | @ComponentScan("net.penyo.herbms.controller") 14 | public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer { 15 | @Override 16 | protected Class[] getRootConfigClasses() { 17 | return new Class[]{AppConfig.class}; 18 | } 19 | 20 | @Override 21 | protected Class[] getServletConfigClasses() { 22 | return new Class[]{WebConfig.class}; 23 | } 24 | 25 | @Override 26 | protected String[] getServletMappings() { 27 | return new String[]{"/"}; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/ExperienceDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.Experience; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * 中草药使用心得的数据访问代理 13 | * 14 | * @author Penyo 15 | * @see Experience 16 | * @see GenericDAO 17 | */ 18 | @Repository 19 | public class ExperienceDAO extends GenericDAO { 20 | public ExperienceDAO() { 21 | super("ExperienceMapper"); 22 | } 23 | 24 | /** 25 | * 根据中草药使用心得 ID 查找多个元素。 26 | */ 27 | public List selectByHerbId(int id) { 28 | List os = new ArrayList<>(); 29 | 30 | try (SqlSession s = Pool.getSession()) { 31 | os.addAll(s.selectList(fullMapperName + ".selectByHerbId", id)); 32 | } 33 | return os; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/GenericBean.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | 6 | import java.util.Objects; 7 | 8 | /** 9 | * 通用数据容器 10 | * 11 | * @author Penyo 12 | * @see AbstractBean 13 | */ 14 | public abstract class GenericBean implements AbstractBean { 15 | @Override 16 | public String toString() { 17 | try { 18 | return new ObjectMapper().writeValueAsString(this); 19 | } catch (JsonProcessingException e) { 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(getId()); 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | if (obj == this) return true; 32 | if (!(obj instanceof GenericBean safeObj)) return false; 33 | return safeObj.getId() == this.getId(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/ItemDifferentiationInfoDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.ItemDifferentiationInfo; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * 条辨概要的数据访问代理 13 | * 14 | * @author Penyo 15 | * @see ItemDifferentiationInfo 16 | * @see GenericDAO 17 | */ 18 | @Repository 19 | public class ItemDifferentiationInfoDAO extends GenericDAO { 20 | public ItemDifferentiationInfoDAO() { 21 | super("ItemDifferentiationInfoMapper"); 22 | } 23 | 24 | /** 25 | * 根据处方 ID 查询元素。 26 | */ 27 | public List selectByPrescriptionId(int id) { 28 | List is = new ArrayList<>(); 29 | 30 | try (SqlSession s = Pool.getSession()) { 31 | is.addAll(s.selectList(fullMapperName + ".selectByPrescriptionId", id)); 32 | } 33 | return is; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/ItemDifferentiationService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.ItemDifferentiation; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 条辩的业务代理 10 | * 11 | * @author Penyo 12 | * @see ItemDifferentiation 13 | * @see GenericService 14 | */ 15 | @Service 16 | public class ItemDifferentiationService extends GenericService { 17 | @Override 18 | public int add(ItemDifferentiation o) { 19 | return itemDifferentiationDAO.add(o); 20 | } 21 | 22 | @Override 23 | public int delete(int id) { 24 | return itemDifferentiationDAO.delete(id); 25 | } 26 | 27 | @Override 28 | public int update(ItemDifferentiation o) { 29 | return itemDifferentiationDAO.update(o); 30 | } 31 | 32 | @Override 33 | public ItemDifferentiation selectById(int id) { 34 | return itemDifferentiationDAO.selectById(id); 35 | } 36 | 37 | @Override 38 | public List selectByFields(List fields) { 39 | return itemDifferentiationDAO.selectByFields(fields); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/HerbDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.Herb; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * 中草药的数据访问代理 13 | * 14 | * @author Penyo 15 | * @see Herb 16 | * @see GenericDAO 17 | */ 18 | @Repository 19 | public class HerbDAO extends GenericDAO { 20 | public HerbDAO() { 21 | super("HerbMapper"); 22 | } 23 | 24 | /** 25 | * 根据中草药使用心得 ID 查找单个元素。 26 | */ 27 | public Herb selectByExperienceId(int id) { 28 | Herb o = null; 29 | 30 | try (SqlSession s = Pool.getSession()) { 31 | o = s.selectOne(fullMapperName + ".selectByExperienceId", id); 32 | } 33 | return o; 34 | } 35 | 36 | /** 37 | * 根据处方 ID 查找多个元素。 38 | */ 39 | public List selectByPrescriptionId(int id) { 40 | List os = new ArrayList<>(); 41 | 42 | try (SqlSession s = Pool.getSession()) { 43 | os.addAll(s.selectList(fullMapperName + ".selectByPrescriptionId", id)); 44 | } 45 | return os; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/PrescriptionService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.Prescription; 4 | import net.penyo.herbms.pojo.PrescriptionInfo; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 处方的业务代理 11 | * 12 | * @author Penyo 13 | * @see Prescription 14 | * @see GenericService 15 | */ 16 | @Service 17 | public class PrescriptionService extends GenericService { 18 | @Override 19 | public int add(Prescription o) { 20 | return prescriptionDAO.add(o); 21 | } 22 | 23 | @Override 24 | public int delete(int id) { 25 | return prescriptionDAO.delete(id); 26 | } 27 | 28 | @Override 29 | public int update(Prescription o) { 30 | return prescriptionDAO.update(o); 31 | } 32 | 33 | @Override 34 | public Prescription selectById(int id) { 35 | return prescriptionDAO.selectById(id); 36 | } 37 | 38 | @Override 39 | public List selectByFields(List fields) { 40 | return prescriptionDAO.selectByFields(fields); 41 | } 42 | 43 | /** 44 | * 根据处方 ID 查找处方概要。 45 | */ 46 | public PrescriptionInfo selectPrescriptionInfoByPrescriptionId(int id) { 47 | return prescriptionInfoDAO.selectByPrescriptionId(id); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/PrescriptionInfoDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.PrescriptionInfo; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * 处方概要的数据访问代理 13 | * 14 | * @author Penyo 15 | * @see PrescriptionInfo 16 | * @see GenericDAO 17 | */ 18 | @Repository 19 | public class PrescriptionInfoDAO extends GenericDAO { 20 | public PrescriptionInfoDAO() { 21 | super("PrescriptionInfoMapper"); 22 | } 23 | 24 | /** 25 | * 根据处方 ID 查询单个元素。 26 | */ 27 | public PrescriptionInfo selectByPrescriptionId(int id) { 28 | PrescriptionInfo o = null; 29 | 30 | try (SqlSession s = Pool.getSession()) { 31 | o = s.selectOne(fullMapperName + ".selectByPrescriptionId", id); 32 | } 33 | return o; 34 | } 35 | 36 | /** 37 | * 根据条辩 ID 查询多个元素。 38 | */ 39 | public List selectByIDTIId(int id) { 40 | List os = new ArrayList<>(); 41 | 42 | try (SqlSession s = Pool.getSession()) { 43 | os.addAll(s.selectList(fullMapperName + ".selectByIDTIId", id)); 44 | } 45 | return os; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/ExperienceService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.Experience; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 中草药使用心得的业务代理 11 | * 12 | * @author Penyo 13 | * @see Experience 14 | * @see GenericService 15 | */ 16 | @Service 17 | public class ExperienceService extends GenericService { 18 | @Override 19 | public int add(Experience o) { 20 | return experienceDAO.add(o); 21 | } 22 | 23 | @Override 24 | public int delete(int id) { 25 | return experienceDAO.delete(id); 26 | } 27 | 28 | @Override 29 | public int update(Experience o) { 30 | return experienceDAO.update(o); 31 | } 32 | 33 | @Override 34 | public Experience selectById(int id) { 35 | return experienceDAO.selectById(id); 36 | } 37 | 38 | @Override 39 | public List selectByFields(List fields) { 40 | return experienceDAO.selectByFields(fields); 41 | } 42 | 43 | /** 44 | * 根据中草药 ID 查找多个中草药使用心得内容。 45 | */ 46 | public List selectContentsByHerbId(int id) { 47 | List contents = new ArrayList<>(); 48 | 49 | for (Experience h : experienceDAO.selectByHerbId(id)) 50 | contents.add(h.getContent()); 51 | return contents; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/Experience.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | /** 4 | * 中草药使用心得的数据容器 5 | * 6 | * @author Penyo 7 | * @see GenericBean 8 | */ 9 | public class Experience extends GenericBean { 10 | /** 11 | * 唯一识别码 12 | */ 13 | private int id; 14 | /** 15 | * 中草药 ID(外键) 16 | */ 17 | private int herbId; 18 | /** 19 | * 出处 20 | */ 21 | private String derivation; 22 | /** 23 | * 内容 24 | */ 25 | private String content; 26 | 27 | public Experience() { 28 | } 29 | 30 | public Experience(int id, int herbId, String derivation, String content) { 31 | this.id = id; 32 | this.herbId = herbId; 33 | this.derivation = derivation; 34 | this.content = content; 35 | } 36 | 37 | @Override 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public void setId(int id) { 43 | this.id = id; 44 | } 45 | 46 | public int getHerbId() { 47 | return herbId; 48 | } 49 | 50 | public void setHerbId(int herbId) { 51 | this.herbId = herbId; 52 | } 53 | 54 | public String getDerivation() { 55 | return derivation; 56 | } 57 | 58 | public void setDerivation(String derivation) { 59 | this.derivation = derivation; 60 | } 61 | 62 | public String getContent() { 63 | return content; 64 | } 65 | 66 | public void setContent(String content) { 67 | this.content = content; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/ItemDifferentiationInfo.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | /** 4 | * 条辨概要的数据容器 5 | * 6 | * @author Penyo 7 | * @see GenericBean 8 | */ 9 | public class ItemDifferentiationInfo extends GenericBean { 10 | /** 11 | * 唯一识别码 12 | */ 13 | private int id; 14 | /** 15 | * 编号 16 | */ 17 | private int code; 18 | /** 19 | * 内容 20 | */ 21 | private String content; 22 | /** 23 | * 注释 24 | */ 25 | private String annotation; 26 | 27 | public ItemDifferentiationInfo() { 28 | } 29 | 30 | public ItemDifferentiationInfo(int id, int code, String content, String annotation) { 31 | this.id = id; 32 | this.code = code; 33 | this.content = content; 34 | this.annotation = annotation; 35 | } 36 | 37 | @Override 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public void setId(int id) { 43 | this.id = id; 44 | } 45 | 46 | public int getCode() { 47 | return code; 48 | } 49 | 50 | public void setCode(int code) { 51 | this.code = code; 52 | } 53 | 54 | public String getContent() { 55 | return content; 56 | } 57 | 58 | public void setContent(String content) { 59 | this.content = content; 60 | } 61 | 62 | public String getAnnotation() { 63 | return annotation; 64 | } 65 | 66 | public void setAnnotation(String annotation) { 67 | this.annotation = annotation; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/PrescriptionInfo.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | /** 4 | * 处方概要的数据容器 5 | * 6 | * @author Penyo 7 | * @see GenericBean 8 | */ 9 | public class PrescriptionInfo extends GenericBean { 10 | /** 11 | * 唯一识别码 12 | */ 13 | private int id; 14 | /** 15 | * 名称 16 | */ 17 | private String name; 18 | /** 19 | * 别名 20 | */ 21 | private String nickname; 22 | /** 23 | * 解释 24 | */ 25 | private String description; 26 | 27 | public PrescriptionInfo() { 28 | } 29 | 30 | public PrescriptionInfo(int id, String name, String nickname, String description) { 31 | this.id = id; 32 | this.name = name; 33 | this.nickname = nickname; 34 | this.description = description; 35 | } 36 | 37 | @Override 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public void setId(int id) { 43 | this.id = id; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getNickname() { 55 | return nickname; 56 | } 57 | 58 | public void setNickname(String nickname) { 59 | this.nickname = nickname; 60 | } 61 | 62 | public String getDescription() { 63 | return description; 64 | } 65 | 66 | public void setDescription(String description) { 67 | this.description = description; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/PrescriptionInfoService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.PrescriptionInfo; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 处方概要的业务代理 11 | * 12 | * @author Penyo 13 | * @see PrescriptionInfo 14 | * @see GenericService 15 | */ 16 | @Service 17 | public class PrescriptionInfoService extends GenericService { 18 | @Override 19 | public int add(PrescriptionInfo o) { 20 | return prescriptionInfoDAO.add(o); 21 | } 22 | 23 | @Override 24 | public int delete(int id) { 25 | return prescriptionInfoDAO.delete(id); 26 | } 27 | 28 | @Override 29 | public int update(PrescriptionInfo o) { 30 | return prescriptionInfoDAO.update(o); 31 | } 32 | 33 | @Override 34 | public PrescriptionInfo selectById(int id) { 35 | return prescriptionInfoDAO.selectById(id); 36 | } 37 | 38 | @Override 39 | public List selectByFields(List fields) { 40 | return prescriptionInfoDAO.selectByFields(fields); 41 | } 42 | 43 | /** 44 | * 根据条辨 ID 查找多个经方名称。 45 | */ 46 | public List selectNamesByIDTIId(int id) { 47 | List names = new ArrayList<>(); 48 | 49 | for (PrescriptionInfo o : prescriptionInfoDAO.selectByIDTIId(id)) 50 | names.add(o.getName()); 51 | return names; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/AbstractBean.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | import java.beans.JavaBean; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * 抽象数据容器 8 | * 9 | * @author Penyo 10 | */ 11 | @JavaBean 12 | public interface AbstractBean extends Serializable { 13 | /** 14 | * “禅” 15 | */ 16 | String ZEN = """ 17 | Beautiful is better than ugly. 18 | Explicit is better than implicit. 19 | Simple is better than complex. 20 | Complex is better than complicated. 21 | Flat is better than nested. 22 | Sparse is better than dense. 23 | Readability counts. 24 | Special cases aren't special enough to break the rules. 25 | Although practicality beats purity. 26 | Errors should never pass silently. 27 | Unless explicitly silenced. 28 | In the face of ambiguity, refuse the temptation to guess. 29 | There should be one-- and preferably only one --obvious way to do it. 30 | Although that way may not be obvious at first unless you're Penyo. 31 | Now is better than never. 32 | Although never is often better than *right* now. 33 | If the implementation is hard to explain, it's a bad idea. 34 | If the implementation is easy to explain, it may be a good idea. 35 | Namespaces are one honking great idea -- let's do more of those!"""; 36 | 37 | /** 38 | * 获取唯一识别码。 39 | */ 40 | default int getId() { 41 | return -114514; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/HerbService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.Herb; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 中草药的业务代理 11 | * 12 | * @author Penyo 13 | * @see Herb 14 | * @see GenericService 15 | */ 16 | @Service 17 | public class HerbService extends GenericService { 18 | @Override 19 | public int add(Herb o) { 20 | return herbDAO.add(o); 21 | } 22 | 23 | @Override 24 | public int delete(int id) { 25 | return herbDAO.delete(id); 26 | } 27 | 28 | @Override 29 | public int update(Herb o) { 30 | return herbDAO.update(o); 31 | } 32 | 33 | @Override 34 | public Herb selectById(int id) { 35 | return herbDAO.selectById(id); 36 | } 37 | 38 | @Override 39 | public List selectByFields(List fields) { 40 | return herbDAO.selectByFields(fields); 41 | } 42 | 43 | /** 44 | * 根据中草药使用心得 ID 查询单个中草药名称。 45 | */ 46 | public String selectNameByExperienceId(int id) { 47 | return herbDAO.selectByExperienceId(id).getName(); 48 | } 49 | 50 | /** 51 | * 根据处方 ID 查找多个中草药名称和解释。 52 | */ 53 | public List selectNamesAndDescriptionsByPrescriptionId(int id) { 54 | List names = new ArrayList<>(); 55 | 56 | for (Herb o : herbDAO.selectByPrescriptionId(id)) 57 | names.add(o.getName() + "/" + o.getDescription()); 58 | return names; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/AbstractController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.GenericBean; 5 | import net.penyo.herbms.util.AppConfig; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | 8 | import java.util.Enumeration; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * 抽象控制器代理 14 | * 15 | * @author Penyo 16 | * @see GenericBean 17 | */ 18 | public interface AbstractController { 19 | /** 20 | * 将请求参数转化为图。 21 | */ 22 | default Map toMap(HttpServletRequest request) { 23 | Map params = new HashMap<>(); 24 | 25 | Enumeration paramNames = request.getParameterNames(); 26 | while (paramNames.hasMoreElements()) { 27 | String key = paramNames.nextElement(); 28 | params.put(key, request.getParameter(key)); 29 | } 30 | 31 | return params; 32 | } 33 | 34 | /** 35 | * 获取已被增强的业务对象。 36 | */ 37 | default UnknownService getService(Class def) { 38 | return new AnnotationConfigApplicationContext(AppConfig.class).getBean(def); 39 | } 40 | 41 | /** 42 | * 处理主要请求。 43 | */ 44 | String requestMain(HttpServletRequest request); 45 | 46 | /** 47 | * 处理次要请求。 48 | */ 49 | String requestSub(HttpServletRequest request); 50 | 51 | /** 52 | * 从参数图中获取值并构造数据容器。 53 | */ 54 | UnknownBean getInstance(Map params); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/service/ItemDifferentiationInfoService.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.service; 2 | 3 | import net.penyo.herbms.pojo.ItemDifferentiationInfo; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 条辩概要的业务代理 11 | * 12 | * @author Penyo 13 | * @see ItemDifferentiationInfo 14 | * @see GenericService 15 | */ 16 | @Service 17 | public class ItemDifferentiationInfoService extends GenericService { 18 | @Override 19 | public int add(ItemDifferentiationInfo o) { 20 | return itemDifferentiationInfoDAO.add(o); 21 | } 22 | 23 | @Override 24 | public int delete(int id) { 25 | return itemDifferentiationInfoDAO.delete(id); 26 | } 27 | 28 | @Override 29 | public int update(ItemDifferentiationInfo o) { 30 | return itemDifferentiationInfoDAO.update(o); 31 | } 32 | 33 | @Override 34 | public ItemDifferentiationInfo selectById(int id) { 35 | return itemDifferentiationInfoDAO.selectById(id); 36 | } 37 | 38 | @Override 39 | public List selectByFields(List fields) { 40 | return itemDifferentiationInfoDAO.selectByFields(fields); 41 | } 42 | 43 | /** 44 | * 根据处方 ID 查询多个条辨内容。 45 | */ 46 | public List selectContentsByPrescriptionId(int id) { 47 | List contents = new ArrayList<>(); 48 | 49 | for (ItemDifferentiationInfo oo : itemDifferentiationInfoDAO.selectByPrescriptionId(id)) 50 | contents.add(oo.getContent()); 51 | return contents; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/ItemDifferentiationController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.ItemDifferentiation; 5 | import net.penyo.herbms.pojo.ReturnDataPack; 6 | import net.penyo.herbms.service.ItemDifferentiationService; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Map; 13 | 14 | /** 15 | * 条辩的控制器代理 16 | * 17 | * @author Penyo 18 | * @see ItemDifferentiation 19 | * @see GenericController 20 | */ 21 | @Controller 22 | public class ItemDifferentiationController extends GenericController { 23 | @Override 24 | @RequestMapping("/use-item_differentiations") 25 | @ResponseBody 26 | public String requestMain(HttpServletRequest request) { 27 | return requestMain(toMap(request), getService(ItemDifferentiationService.class)).toString(); 28 | } 29 | 30 | @Override 31 | @RequestMapping("/use-item_differentiations-specific") 32 | @ResponseBody 33 | public String requestSub(HttpServletRequest request) { 34 | return new ReturnDataPack<>(new ArrayList<>()).toString(); 35 | } 36 | 37 | @Override 38 | public ItemDifferentiation getInstance(Map params) { 39 | return new ItemDifferentiation(Integer.parseInt(params.get("id")), Integer.parseInt(params.get("itemDifferentiationId")), Integer.parseInt(params.get("prescriptionId")), params.get("type")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/mybatis.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/Prescription.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | /** 4 | * 处方的数据容器 5 | * 6 | * @author Penyo 7 | * @see GenericBean 8 | */ 9 | public class Prescription extends GenericBean { 10 | /** 11 | * 唯一识别码 12 | */ 13 | private int id; 14 | /** 15 | * 中草药处方 ID(外键) 16 | */ 17 | private int prescriptionId; 18 | /** 19 | * 中草药 ID(外键) 20 | */ 21 | private int herbId; 22 | /** 23 | * 用量 24 | */ 25 | private String dosage; 26 | /** 27 | * 用法 28 | */ 29 | private String usage; 30 | 31 | public Prescription() { 32 | } 33 | 34 | public Prescription(int id, int prescriptionId, int herbId, String dosage, String usage) { 35 | this.id = id; 36 | this.prescriptionId = prescriptionId; 37 | this.herbId = herbId; 38 | this.dosage = dosage; 39 | this.usage = usage; 40 | } 41 | 42 | @Override 43 | public int getId() { 44 | return id; 45 | } 46 | 47 | public void setId(int id) { 48 | this.id = id; 49 | } 50 | 51 | public int getPrescriptionId() { 52 | return prescriptionId; 53 | } 54 | 55 | public void setPrescriptionID(int prescriptionId) { 56 | this.prescriptionId = prescriptionId; 57 | } 58 | 59 | public int getHerbId() { 60 | return herbId; 61 | } 62 | 63 | public void setHerbId(int herbId) { 64 | this.herbId = herbId; 65 | } 66 | 67 | public String getDosage() { 68 | return dosage; 69 | } 70 | 71 | public void setDosage(String dosage) { 72 | this.dosage = dosage; 73 | } 74 | 75 | public String getUsage() { 76 | return usage; 77 | } 78 | 79 | public void setUsage(String usage) { 80 | this.usage = usage; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/ExperienceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | INSERT experiences (herb_id, derivation, content) 12 | VALUES (#{herbId}, #{derivation}, #{content}) 13 | 14 | 15 | 16 | DELETE 17 | FROM experiences 18 | WHERE id = #{id} 19 | 20 | 21 | 22 | UPDATE experiences 23 | SET herb_id = #{herbId}, 24 | derivation = #{derivation}, 25 | content = #{content} 26 | WHERE id = #{id} 27 | 28 | 29 | 34 | 35 | 43 | 44 | 48 | 49 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/PrescriptionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | INSERT prescriptions (prescription_id, herb_id, dosage, `usage`) 13 | VALUES (#{prescriptionId}, #{herbId}, #{dosage}, #{usage}) 14 | 15 | 16 | 17 | DELETE 18 | FROM prescriptions 19 | WHERE id = #{id} 20 | 21 | 22 | 23 | UPDATE prescriptions 24 | SET prescription_id = #{prescriptionId}, 25 | herb_id = #{herbId}, 26 | dosage = #{dosage}, 27 | `usage` = #{usage} 28 | WHERE id = #{id} 29 | 30 | 31 | 36 | 37 | 45 | 46 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/ItemDifferentiationMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | INSERT 13 | item_differentiations (item_differentiation_id, prescription_id, type) 14 | VALUES ( 15 | #{itemDifferentiationId}, 16 | #{prescriptionId}, 17 | #{type} 18 | ) 19 | 20 | 21 | 22 | DELETE 23 | FROM item_differentiations 24 | WHERE id = #{id} 25 | 26 | 27 | 28 | UPDATE item_differentiations 29 | SET itemDifferentiation_id = #{itemDifferentiationId}, 30 | prescription_id = #{prescriptionId}, 31 | type = #{type} 32 | WHERE id = #{id} 33 | 34 | 35 | 40 | 41 | 49 | 50 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/ExperienceController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.Experience; 5 | import net.penyo.herbms.pojo.ReturnDataPack; 6 | import net.penyo.herbms.service.ExperienceService; 7 | import net.penyo.herbms.service.HerbService; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * 中草药使用心得的控制器代理 18 | * 19 | * @author Penyo 20 | * @see Experience 21 | * @see GenericController 22 | */ 23 | @Controller 24 | public class ExperienceController extends GenericController { 25 | @Override 26 | @RequestMapping("/use-experiences") 27 | @ResponseBody 28 | public String requestMain(HttpServletRequest request) { 29 | return requestMain(toMap(request), getService(ExperienceService.class)).toString(); 30 | } 31 | 32 | @Override 33 | @RequestMapping("/use-experiences-specific") 34 | @ResponseBody 35 | public String requestSub(HttpServletRequest request) { 36 | List hs = new ArrayList<>(); 37 | 38 | ReturnDataPack exps = requestMain(toMap(request), getService(ExperienceService.class)); 39 | for (Experience o : exps.getObjs()) { 40 | StringBuilder hTemp = new StringBuilder("\""); 41 | hTemp.append(getService(HerbService.class).selectNameByExperienceId(o.getId())); 42 | hs.add(hTemp.append("\"").toString()); 43 | } 44 | return new ReturnDataPack<>(hs).toString(); 45 | } 46 | 47 | @Override 48 | public Experience getInstance(Map params) { 49 | return new Experience(Integer.parseInt(params.get("id")), Integer.parseInt(params.get("herbId")), params.get("derivation"), params.get("content")); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/GenericController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import net.penyo.herbms.pojo.GenericBean; 4 | import net.penyo.herbms.pojo.ReturnDataPack; 5 | import net.penyo.herbms.service.GenericService; 6 | import org.springframework.web.bind.annotation.CrossOrigin; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * 通用控制器代理 15 | * 16 | * @author Penyo 17 | * @see GenericBean 18 | * @see AbstractController 19 | */ 20 | @CrossOrigin("*") 21 | public abstract class GenericController implements AbstractController { 22 | /** 23 | * 通用处理主要请求。 24 | */ 25 | public ReturnDataPack requestMain(Map params, GenericService serv) { 26 | String keyword = ""; 27 | String keywordOri = params.get("keyword"); 28 | if (keywordOri != null) keyword = keywordOri; 29 | 30 | boolean isId = false; 31 | String isIdOri = params.get("isId"); 32 | if (isIdOri != null) isId = isIdOri.equals("on"); 33 | 34 | List objs = new ArrayList<>(); 35 | 36 | int affectedRows = -1; 37 | 38 | String oId = params.get("id"); 39 | if (oId != null) { 40 | String opType = params.get("opType"); 41 | try { 42 | int id = Integer.parseInt(oId); 43 | if (opType.equals("delete")) { 44 | affectedRows = serv.delete(id); 45 | } else { 46 | UnknownBean obj = getInstance(params); 47 | if (opType.equals("add")) affectedRows = serv.add(obj); 48 | else affectedRows = serv.update(obj); 49 | } 50 | } catch (NumberFormatException e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | 55 | if (isId) objs.add(serv.selectById(Integer.parseInt(keyword))); 56 | else objs = serv.selectByFields(Arrays.asList(keyword.split(","))); 57 | 58 | return new ReturnDataPack<>(affectedRows, objs); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/ItemDifferentiation.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * 条辨的数据容器 7 | * 8 | * @author Penyo 9 | * @see GenericBean 10 | */ 11 | public class ItemDifferentiation extends GenericBean { 12 | /** 13 | * 唯一识别码 14 | */ 15 | private int id; 16 | /** 17 | * 条辨 ID(外键) 18 | */ 19 | private int itemDifferentiationId; 20 | /** 21 | * 处方 ID(外键) 22 | */ 23 | private int prescriptionId; 24 | /** 25 | * 类型 26 | */ 27 | private String type; 28 | 29 | public ItemDifferentiation() { 30 | } 31 | 32 | public ItemDifferentiation(int id, int itemDifferentiationId, int prescriptionId, String type) { 33 | this.id = id; 34 | this.itemDifferentiationId = itemDifferentiationId; 35 | this.prescriptionId = prescriptionId; 36 | setType(type); 37 | } 38 | 39 | @Override 40 | public int getId() { 41 | return id; 42 | } 43 | 44 | public void setId(int id) { 45 | this.id = id; 46 | } 47 | 48 | public int getItemDifferentiationId() { 49 | return itemDifferentiationId; 50 | } 51 | 52 | public void setItemDifferentiationId(int itemDifferentiationId) { 53 | this.itemDifferentiationId = itemDifferentiationId; 54 | } 55 | 56 | public int getPrescriptionId() { 57 | return prescriptionId; 58 | } 59 | 60 | public void setPrescriptionId(int prescriptionId) { 61 | this.prescriptionId = prescriptionId; 62 | } 63 | 64 | public static boolean isTypeValid(String type) { 65 | final Map TYPES = Map.of("对症", true, "不适用", true, "其他", true); 66 | 67 | return TYPES.get(type) != null; 68 | } 69 | 70 | public String getType() { 71 | return type; 72 | } 73 | 74 | public void setType(String type) { 75 | try { 76 | if (!ItemDifferentiation.isTypeValid(type)) throw new TypeNotPresentException(type, null); 77 | this.type = type; 78 | } catch (TypeNotPresentException e) { 79 | this.type = "对症"; 80 | e.printStackTrace(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/HerbController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.Herb; 5 | import net.penyo.herbms.pojo.ReturnDataPack; 6 | import net.penyo.herbms.service.ExperienceService; 7 | import net.penyo.herbms.service.HerbService; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * 中草药的控制器代理 18 | * 19 | * @author Penyo 20 | * @see Herb 21 | * @see GenericController 22 | */ 23 | @Controller 24 | public class HerbController extends GenericController { 25 | @Override 26 | @RequestMapping("/use-herbs") 27 | @ResponseBody 28 | public String requestMain(HttpServletRequest request) { 29 | return requestMain(toMap(request), getService(HerbService.class)).toString(); 30 | } 31 | 32 | @Override 33 | @RequestMapping("/use-herbs-specific") 34 | @ResponseBody 35 | public String requestSub(HttpServletRequest request) { 36 | List exps = new ArrayList<>(); 37 | 38 | ReturnDataPack hs = requestMain(toMap(request), getService(HerbService.class)); 39 | for (Herb o : hs.getObjs()) { 40 | StringBuilder expTemp = new StringBuilder("\""); 41 | for (String oo : getService(ExperienceService.class).selectContentsByHerbId(o.getId())) 42 | expTemp.append(oo); 43 | if (expTemp.length() > 1) exps.add(expTemp.append("\"").toString()); 44 | } 45 | return new ReturnDataPack<>(exps).toString(); 46 | } 47 | 48 | @Override 49 | public Herb getInstance(Map params) { 50 | return new Herb(Integer.parseInt(params.get("id")), Integer.parseInt(params.get("code")), params.get("name"), params.get("nickname"), params.get("type"), params.get("description"), params.get("efficacy"), params.get("taste"), params.get("origin"), params.get("dosage"), params.get("taboo"), params.get("processing")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/PrescriptionInfoController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.PrescriptionInfo; 5 | import net.penyo.herbms.pojo.ReturnDataPack; 6 | import net.penyo.herbms.service.ItemDifferentiationInfoService; 7 | import net.penyo.herbms.service.PrescriptionInfoService; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * 处方概要的控制器代理 18 | * 19 | * @author Penyo 20 | * @see PrescriptionInfo 21 | * @see GenericController 22 | */ 23 | @Controller 24 | public class PrescriptionInfoController extends GenericController { 25 | @Override 26 | @RequestMapping("/use-prescription_infos") 27 | @ResponseBody 28 | public String requestMain(HttpServletRequest request) { 29 | return requestMain(toMap(request), getService(PrescriptionInfoService.class)).toString(); 30 | } 31 | 32 | @Override 33 | @RequestMapping("/use-prescription_infos-specific") 34 | @ResponseBody 35 | public String requestSub(HttpServletRequest request) { 36 | List idtis = new ArrayList<>(); 37 | 38 | ReturnDataPack pis = requestMain(toMap(request), getService(PrescriptionInfoService.class)); 39 | for (PrescriptionInfo o : pis.getObjs()) { 40 | StringBuilder idtiTemp = new StringBuilder("\""); 41 | for (String content : getService(ItemDifferentiationInfoService.class).selectContentsByPrescriptionId(o.getId())) 42 | idtiTemp.append(content).append("/"); 43 | if (idtiTemp.length() > 1) 44 | idtis.add(idtiTemp.delete(idtiTemp.length() - 1, idtiTemp.length()).append("\"").toString()); 45 | } 46 | return new ReturnDataPack<>(idtis).toString(); 47 | } 48 | 49 | @Override 50 | public PrescriptionInfo getInstance(Map params) { 51 | return new PrescriptionInfo(Integer.parseInt(params.get("id")), params.get("name"), params.get("nickname"), params.get("description")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 欢迎使用 HerbMS 2 | 3 | Herb Management System:中药处方管理系统,基于 SSM 框架构建的 Jakarta EE 应用程序。 4 | 5 | ## 快速开始 6 | 7 | 本项目所需依赖如下: 8 | 9 | | 名称 | 类型 | 最低版本 | 10 | |----------------------------------------------------------------|------------|-------| 11 | | [VS Code](https://code.visualstudio.com/#alt-downloads) | IDE | N/A | 12 | | [IntelliJ IDEA](https://www.jetbrains.com/zh-cn/idea/download) | IDE | N/A | 13 | | [JDK](https://www.oracle.com/cn/java/technologies/downloads/) | 基本环境 | 17 | 14 | | [Maven](https://maven.apache.org/download.cgi) | 依赖管理器 | 3.9.0 | 15 | | [Tomcat](https://tomcat.apache.org/download-10.cgi) | Servlet 容器 | 10 | 16 | | [MySQL](https://dev.mysql.com/downloads/mysql/) | 数据库 | 8.0.0 | 17 | | [Git](https://git-scm.com/download/) | 版本控制器 | N/A | 18 | | [HerbMS-Vue](https://github.com/pen-yo/HerbMS-Vue) | 前端 | 1.0.0 | 19 | 20 | 下图较好地概述了流程核心: 21 | 22 | ```mermaid 23 | flowchart 24 | s1["安装全部基础设施"] 25 | s2["git clone 项目"] 26 | subgraph s3["在 VS Code 中(前端)"] 27 | s3.1["安装插件 Volar"] 28 | s3.2["运行 NPM 脚本 dev"] 29 | end 30 | subgraph s4["配置数据库"] 31 | s4.1["修改 src/main/resources/db.config.yml"] 32 | s4.2["执行 src/main/sql/herbms.sql"] 33 | end 34 | subgraph s5["在 IntelliJ IDEA 中(后端)"] 35 | s5.1["运行配置 Run Application"] 36 | end 37 | s1 --> s2 --> s3 --> s4 --> s5 38 | ``` 39 | 40 | ## 模块设计 41 | 42 | HerbMS(后端)主要由四部分构成:数据容器(Bean)、数据访问代理(DAO)、业务代理(Service)和控制器代理(Controller),下图展示了各模块间的基本关系: 43 | 44 | ```mermaid 45 | classDiagram 46 | class AbstractController~UnknownBean~ { 47 | <> 48 | +UnknownSerivice getService() 49 | +UnknownBean getInstance() 50 | } 51 | class AbstractService~UnknownBean~ { 52 | <> 53 | +UnknownBean select*() 54 | } 55 | class AbstractDAO~UnknownBean~ { 56 | <> 57 | +UnknownBean select*() 58 | } 59 | class AbstractBean { 60 | <> 61 | } 62 | AbstractController --> AbstractService 63 | AbstractDAO <|-- AbstractService 64 | AbstractDAO --> AbstractBean 65 | ``` 66 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/ItemDifferentiationInfoController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.ItemDifferentiationInfo; 5 | import net.penyo.herbms.pojo.ReturnDataPack; 6 | import net.penyo.herbms.service.ItemDifferentiationInfoService; 7 | import net.penyo.herbms.service.PrescriptionInfoService; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * 条辩概要的控制器代理 18 | * 19 | * @author Penyo 20 | * @see ItemDifferentiationInfo 21 | * @see GenericController 22 | */ 23 | @Controller 24 | public class ItemDifferentiationInfoController extends GenericController { 25 | @Override 26 | @RequestMapping("/use-item_differentiation_infos") 27 | @ResponseBody 28 | public String requestMain(HttpServletRequest request) { 29 | return requestMain(toMap(request), getService(ItemDifferentiationInfoService.class)).toString(); 30 | } 31 | 32 | @Override 33 | @RequestMapping("/use-item_differentiation_infos-specific") 34 | @ResponseBody 35 | public String requestSub(HttpServletRequest request) { 36 | List ps = new ArrayList<>(); 37 | 38 | ReturnDataPack idtis = requestMain(toMap(request), getService(ItemDifferentiationInfoService.class)); 39 | for (ItemDifferentiationInfo idti : idtis.getObjs()) { 40 | StringBuilder idtiTemp = new StringBuilder("\""); 41 | for (String name : getService(PrescriptionInfoService.class).selectNamesByIDTIId(idti.getId())) 42 | idtiTemp.append(name).append("/"); 43 | if (idtiTemp.length() > 1) 44 | ps.add(idtiTemp.delete(idtiTemp.length() - 1, idtiTemp.length()).append("\"").toString()); 45 | } 46 | return new ReturnDataPack<>(ps).toString(); 47 | } 48 | 49 | @Override 50 | public ItemDifferentiationInfo getInstance(Map params) { 51 | return new ItemDifferentiationInfo(Integer.parseInt(params.get("id")), Integer.parseInt(params.get("code")), params.get("content"), params.get("annotation")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/PrescriptionInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | INSERT prescription_infos (name, nickname, description) 8 | VALUES (#{name}, #{nickname}, #{description}) 9 | 10 | 11 | 12 | DELETE 13 | FROM prescription_infos 14 | WHERE id = #{id} 15 | 16 | 17 | 18 | UPDATE prescription_infos 19 | SET name = #{name}, 20 | nickname = #{nickname}, 21 | description = #{description} 22 | WHERE id = #{id} 23 | 24 | 25 | 30 | 31 | 39 | 40 | 44 | 45 | 52 | 53 | 60 | 61 | 68 | 69 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/HerbMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | INSERT herbs (code, name, nickname, type, description, efficacy, taste, origin, dosage, taboo, processing) 8 | VALUES (#{code}, #{name}, #{nickname}, #{type}, #{description}, #{efficacy}, #{taste}, #{origin}, #{dosage}, 9 | #{taboo}, #{processing}) 10 | 11 | 12 | 13 | DELETE 14 | FROM herbs 15 | WHERE id = #{id} 16 | 17 | 18 | 19 | UPDATE herbs 20 | SET code = #{code}, 21 | name = #{name}, 22 | nickname = #{nickname}, 23 | type = #{type}, 24 | description = #{description}, 25 | efficacy = #{efficacy}, 26 | taste = #{taste}, 27 | origin = #{origin}, 28 | dosage = #{dosage}, 29 | taboo = #{taboo}, 30 | processing = #{processing} 31 | WHERE id = #{id} 32 | 33 | 34 | 39 | 40 | 48 | 49 | 53 | 54 | 61 | 62 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/resources/net/penyo/herbms/mapper/ItemDifferentiationInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | INSERT item_differentiation_infos (code, content, annotation) 8 | VALUES (#{code}, #{content}, #{annotation}) 9 | 10 | 11 | 12 | DELETE 13 | FROM item_differentiation_infos 14 | WHERE id = #{id} 15 | 16 | 17 | 18 | UPDATE item_differentiation_infos 19 | SET code = #{code}, 20 | content = #{content}, 21 | annotation = #{annotation} 22 | WHERE id = #{id} 23 | 24 | 25 | 30 | 31 | 39 | 40 | 44 | 45 | 52 | 53 | 67 | 68 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/controller/PrescriptionController.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.controller; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import net.penyo.herbms.pojo.Prescription; 5 | import net.penyo.herbms.pojo.PrescriptionInfo; 6 | import net.penyo.herbms.pojo.ReturnDataPack; 7 | import net.penyo.herbms.service.HerbService; 8 | import net.penyo.herbms.service.PrescriptionService; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * 处方的控制器代理 19 | * 20 | * @author Penyo 21 | * @see Prescription 22 | * @see GenericController 23 | */ 24 | @Controller 25 | public class PrescriptionController extends GenericController { 26 | @Override 27 | @RequestMapping("/use-prescriptions") 28 | @ResponseBody 29 | public String requestMain(HttpServletRequest request) { 30 | return requestMain(toMap(request), getService(PrescriptionService.class)).toString(); 31 | } 32 | 33 | @Override 34 | @RequestMapping("/use-prescriptions-specific") 35 | @ResponseBody 36 | public String requestSub(HttpServletRequest request) { 37 | List annotations = new ArrayList<>(); 38 | 39 | ReturnDataPack ps = requestMain(toMap(request), getService(PrescriptionService.class)); 40 | for (Prescription o : ps.getObjs()) { 41 | StringBuilder annoTemp = new StringBuilder("\""); 42 | annoTemp.append(getService(HerbService.class).selectNamesAndDescriptionsByPrescriptionId(o.getId())).append("/"); 43 | if (annoTemp.length() > 1) annoTemp.delete(annoTemp.length() - 1, annoTemp.length()).append(":"); 44 | PrescriptionInfo oo = getService(PrescriptionService.class).selectPrescriptionInfoByPrescriptionId(o.getId()); 45 | annoTemp.append(oo.getName()); 46 | if (!oo.getNickname().equals("无")) annoTemp.append("(").append(oo.getNickname()).append(")"); 47 | annoTemp.append(":").append(oo.getDescription()); 48 | annotations.add((annoTemp.append("\"").toString())); 49 | } 50 | return new ReturnDataPack<>(annotations).toString(); 51 | } 52 | 53 | @Override 54 | public Prescription getInstance(Map params) { 55 | return new Prescription(Integer.parseInt(params.get("id")), Integer.parseInt(params.get("prescriptionId")), Integer.parseInt("herbId"), params.get("dosage"), params.get("usage")); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/dao/GenericDAO.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.dao; 2 | 3 | import net.penyo.herbms.pojo.GenericBean; 4 | import net.penyo.herbms.util.Pool; 5 | import org.apache.ibatis.session.SqlSession; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * 通用数据访问代理 12 | * 13 | * @author Penyo 14 | * @see GenericBean 15 | * @see AbstractDAO 16 | */ 17 | public abstract class GenericDAO implements AbstractDAO { 18 | /** 19 | * 映射器全名 20 | */ 21 | protected final String fullMapperName; 22 | 23 | protected GenericDAO(String mapperName) { 24 | fullMapperName = "net.penyo.herbms.mapper." + mapperName; 25 | } 26 | 27 | @Override 28 | public final synchronized int add(UnknownBean o) { 29 | if (selectById(o.getId()) != null) return 0; 30 | 31 | int affectedRows = 0; 32 | try (SqlSession s = Pool.getSession()) { 33 | affectedRows = s.insert(fullMapperName + ".add", o); 34 | s.commit(); 35 | } 36 | return affectedRows; 37 | } 38 | 39 | @Override 40 | public final synchronized int delete(int id) { 41 | int affectedRows = 0; 42 | try (SqlSession s = Pool.getSession()) { 43 | affectedRows = s.delete(fullMapperName + ".delete", id); 44 | s.commit(); 45 | } 46 | return affectedRows; 47 | } 48 | 49 | @Override 50 | public final synchronized int update(UnknownBean o) { 51 | if (selectById(o.getId()) == null) return 0; 52 | 53 | int affectedRows = 0; 54 | try (SqlSession s = Pool.getSession()) { 55 | affectedRows = s.update(fullMapperName + ".update", o); 56 | s.commit(); 57 | } 58 | return affectedRows; 59 | } 60 | 61 | @Override 62 | public final UnknownBean selectById(int id) { 63 | UnknownBean o = null; 64 | 65 | try (SqlSession s = Pool.getSession()) { 66 | o = s.selectOne(fullMapperName + ".selectById", id); 67 | } 68 | return o; 69 | } 70 | 71 | @Override 72 | public final List selectByFields(List fields) { 73 | if (fields.size() <= 1 && fields.get(0).isEmpty()) return selectAll(); 74 | 75 | List os = new ArrayList<>(); 76 | 77 | try (SqlSession s = Pool.getSession()) { 78 | os.addAll(s.selectList(fullMapperName + ".selectByFields", fields)); 79 | } 80 | return os; 81 | } 82 | 83 | @Override 84 | public final List selectAll() { 85 | List os = new ArrayList<>(); 86 | 87 | try (SqlSession s = Pool.getSession()) { 88 | os.addAll(s.selectList(fullMapperName + ".selectAll")); 89 | } 90 | return os; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/util/Logger.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.util; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.*; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Arrays; 10 | 11 | /** 12 | * 全局日志发生器 13 | * 14 | * @author Penyo 15 | */ 16 | @Component 17 | @Aspect 18 | public class Logger { 19 | /** 20 | * 公共日志发生器 21 | */ 22 | private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(Logger.class); 23 | 24 | /** 25 | * 监听业务层全部查询的返回值并输出。 26 | */ 27 | @AfterReturning(value = "execution(* net.penyo.herbms.service.*.select*(..))", returning = "result") 28 | public void listenQueryResult(JoinPoint joinPoint, Object result) { 29 | LOGGER.info("\n\t- 来自 " + joinPoint.getSignature().toLongString() + "\n\t- 捕获 " + result.toString()); 30 | } 31 | 32 | /** 33 | * 监听业务层全部查询的异常并输出。 34 | */ 35 | @AfterThrowing(value = "execution(* net.penyo.herbms.service.*.*(..))", throwing = "exception") 36 | public void listenQueryException(JoinPoint joinPoint, Throwable exception) { 37 | LOGGER.info("\n\t- 来自 " + joinPoint.getSignature().toLongString() + "\n\t- 捕获 " + exception.toString()); 38 | } 39 | 40 | /** 41 | * 监听业务层全部查询的必要信息并输出。 42 | */ 43 | @Around(value = "execution(* net.penyo.herbms.service.*.*(..))") 44 | public Object listenQueryAlways(ProceedingJoinPoint joinPoint) { 45 | Object result = null; 46 | try { 47 | result = joinPoint.proceed(); 48 | } catch (Throwable throwable) { 49 | LOGGER.info("\n\t- 捕获 " + throwable); 50 | } finally { 51 | LOGGER.info("\n\t- 来自 " + joinPoint.getSignature().toLongString() + "\n\t- 参数 " + Arrays.toString(joinPoint.getArgs())); 52 | } 53 | return result; 54 | } 55 | 56 | /** 57 | * 监听业务层全部查询的参数并输出。 58 | */ 59 | @Before(value = "execution(* net.penyo.herbms.service.*.*(..))") 60 | public void listenQuery(JoinPoint joinPoint) { 61 | LOGGER.info("\n\t- 来自 " + joinPoint.getSignature().toLongString() + "\n\t- 参数 " + Arrays.toString(joinPoint.getArgs())); 62 | } 63 | 64 | /** 65 | * 监听业务层全部查询的耗时并输出。 66 | */ 67 | @Around(value = "execution(* net.penyo.herbms.service.*.select*(..))") 68 | public Object listenQueryExecutionTime(ProceedingJoinPoint joinPoint) { 69 | long start = System.currentTimeMillis(); 70 | LOGGER.info("\n\t- 来自 " + joinPoint.getTarget().getClass().getName() + joinPoint.getSignature()); 71 | LOGGER.info("\n\t- 方法开始时间 " + start); 72 | Object result = null; 73 | try { 74 | result = joinPoint.proceed(); 75 | } catch (Throwable throwable) { 76 | LOGGER.info("\n\t- 捕获 " + throwable); 77 | } finally { 78 | long end = System.currentTimeMillis(); 79 | LOGGER.info("\n\t- 方法结束时间 " + end + "\n\t- 总耗时 " + (end - start) + "ms"); 80 | } 81 | return result; 82 | } 83 | } -------------------------------------------------------------------------------- /src/main/java/net/penyo/herbms/pojo/Herb.java: -------------------------------------------------------------------------------- 1 | package net.penyo.herbms.pojo; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * 中草药的数据容器 7 | * 8 | * @author Penyo 9 | * @see GenericBean 10 | */ 11 | public class Herb extends GenericBean { 12 | /** 13 | * 唯一识别码 14 | */ 15 | private int id; 16 | /** 17 | * 编号 18 | */ 19 | private int code; 20 | /** 21 | * 学名 22 | */ 23 | private String name; 24 | /** 25 | * 别名 26 | */ 27 | private String nickname; 28 | /** 29 | * 归属类别 30 | */ 31 | private String type; 32 | /** 33 | * 本经原文 34 | */ 35 | private String description; 36 | /** 37 | * 主治 38 | */ 39 | private String efficacy; 40 | /** 41 | * 性味 42 | */ 43 | private String taste; 44 | /** 45 | * 产地 46 | */ 47 | private String origin; 48 | /** 49 | * 用量 50 | */ 51 | private String dosage; 52 | /** 53 | * 禁忌 54 | */ 55 | private String taboo; 56 | /** 57 | * 炮制方法 58 | */ 59 | private String processing; 60 | 61 | public Herb() { 62 | } 63 | 64 | public Herb(int id, int code, String name, String nickname, String type, String description, String efficacy, String taste, String origin, String dosage, String taboo, String processing) { 65 | this.id = id; 66 | this.code = code; 67 | this.name = name; 68 | this.nickname = nickname; 69 | setType(type); 70 | this.description = description; 71 | this.efficacy = efficacy; 72 | this.taste = taste; 73 | this.origin = origin; 74 | this.dosage = dosage; 75 | this.taboo = taboo; 76 | this.processing = processing; 77 | } 78 | 79 | @Override 80 | public int getId() { 81 | return id; 82 | } 83 | 84 | public void setId(int id) { 85 | this.id = id; 86 | } 87 | 88 | public int getCode() { 89 | return code; 90 | } 91 | 92 | public void setCode(int code) { 93 | this.code = code; 94 | } 95 | 96 | public String getName() { 97 | return name; 98 | } 99 | 100 | public void setName(String name) { 101 | this.name = name; 102 | } 103 | 104 | public String getNickname() { 105 | return nickname; 106 | } 107 | 108 | public void setNickname(String nickname) { 109 | this.nickname = nickname; 110 | } 111 | 112 | public static boolean isTypeValid(String type) { 113 | final Map TYPES = Map.of("上经", true, "中经", true, "下经", true, "增补", true); 114 | 115 | return TYPES.get(type) != null; 116 | } 117 | 118 | public String getType() { 119 | return type; 120 | } 121 | 122 | public void setType(String type) { 123 | try { 124 | if (!Herb.isTypeValid(type)) throw new TypeNotPresentException(type, null); 125 | this.type = type; 126 | } catch (TypeNotPresentException e) { 127 | this.type = "上经"; 128 | e.printStackTrace(); 129 | } 130 | } 131 | 132 | public String getDescription() { 133 | return description; 134 | } 135 | 136 | public void setDescription(String description) { 137 | this.description = description; 138 | } 139 | 140 | public String getEfficacy() { 141 | return efficacy; 142 | } 143 | 144 | public void setEfficacy(String efficacy) { 145 | this.efficacy = efficacy; 146 | } 147 | 148 | public String getTaste() { 149 | return taste; 150 | } 151 | 152 | public void setTaste(String taste) { 153 | this.taste = taste; 154 | } 155 | 156 | public String getOrigin() { 157 | return origin; 158 | } 159 | 160 | public void setOrigin(String origin) { 161 | this.origin = origin; 162 | } 163 | 164 | public String getDosage() { 165 | return dosage; 166 | } 167 | 168 | public void setDosage(String dosage) { 169 | this.dosage = dosage; 170 | } 171 | 172 | public String getTaboo() { 173 | return taboo; 174 | } 175 | 176 | public void setTaboo(String taboo) { 177 | this.taboo = taboo; 178 | } 179 | 180 | public String getProcessing() { 181 | return processing; 182 | } 183 | 184 | public void setProcessing(String processing) { 185 | this.processing = processing; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /.run/Run Application.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 92 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | net.penyo 9 | herbms 10 | 1.0.0 11 | war 12 | 13 | Herb Management System 14 | https://github.com/pen-yo/HerbMS 15 | 16 | 17 | UTF-8 18 | 17 19 | 17 20 | 21 | 22 | 23 | 24 | org.springframework 25 | spring-core 26 | 6.1.2 27 | 28 | 29 | org.springframework 30 | spring-beans 31 | 6.1.2 32 | 33 | 34 | org.springframework 35 | spring-context 36 | 6.1.2 37 | 38 | 39 | org.springframework 40 | spring-webmvc 41 | 6.1.2 42 | 43 | 44 | org.springframework 45 | spring-expression 46 | 6.1.2 47 | 48 | 49 | org.springframework 50 | spring-aop 51 | 6.1.2 52 | 53 | 54 | org.springframework 55 | spring-aspects 56 | 6.1.2 57 | 58 | 59 | org.aspectj 60 | aspectjweaver 61 | 1.9.21 62 | 63 | 64 | 65 | org.yaml 66 | snakeyaml 67 | 2.0 68 | 69 | 70 | com.fasterxml.jackson.core 71 | jackson-databind 72 | 2.16.0 73 | 74 | 75 | 76 | org.apache.logging.log4j 77 | log4j-core 78 | 2.22.0 79 | 80 | 81 | org.apache.logging.log4j 82 | log4j-api 83 | 2.22.0 84 | 85 | 86 | 87 | org.mybatis 88 | mybatis 89 | 3.5.14 90 | 91 | 92 | jakarta.servlet 93 | jakarta.servlet-api 94 | 6.0.0 95 | provided 96 | 97 | 98 | mysql 99 | mysql-connector-java 100 | 8.0.33 101 | 102 | 103 | org.junit.jupiter 104 | junit-jupiter-api 105 | 5.10.1 106 | test 107 | 108 | 109 | 110 | 111 | herbms 112 | 113 | 114 | 115 | maven-clean-plugin 116 | 3.1.0 117 | 118 | 119 | maven-resources-plugin 120 | 3.0.2 121 | 122 | 123 | maven-compiler-plugin 124 | 3.8.0 125 | 126 | 127 | maven-surefire-plugin 128 | 2.22.1 129 | 130 | 131 | maven-war-plugin 132 | 3.2.2 133 | 134 | 135 | maven-install-plugin 136 | 2.5.2 137 | 138 | 139 | maven-deploy-plugin 140 | 2.8.2 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /src/main/sql/herbms.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat Premium Data Transfer 3 | 4 | Source Server : Local MySQL 5 | Source Server Type : MySQL 6 | Source Server Version : 80018 (8.0.18) 7 | Source Host : localhost:3306 8 | Source Schema : herbms 9 | 10 | Target Server Type : MySQL 11 | Target Server Version : 80018 (8.0.18) 12 | File Encoding : 65001 13 | 14 | Date: 25/11/2023 22:36:13 15 | */ 16 | 17 | SET NAMES utf8mb4; 18 | SET FOREIGN_KEY_CHECKS = 0; 19 | 20 | -- ---------------------------- 21 | -- Table structure for experiences 22 | -- ---------------------------- 23 | DROP TABLE IF EXISTS `experiences`; 24 | CREATE TABLE `experiences` ( 25 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 26 | `herb_id` int(11) NOT NULL COMMENT '中草药 ID', 27 | `derivation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '出处', 28 | `content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '心得内容', 29 | PRIMARY KEY (`id`) USING BTREE, 30 | INDEX `experiences::herb_id`(`herb_id` ASC) USING BTREE, 31 | CONSTRAINT `experiences::herb_id` FOREIGN KEY (`herb_id`) REFERENCES `herbs` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT 32 | ) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '中草药使用心得' ROW_FORMAT = DYNAMIC; 33 | 34 | -- ---------------------------- 35 | -- Records of experiences 36 | -- ---------------------------- 37 | INSERT INTO `experiences` VALUES (1, 1, '《本草纲目》', '人参是一种具有补气养血、益精填髓的药材,对于气虚血弱、四肢乏力、心悸失眠等症状有很好的效果。'); 38 | INSERT INTO `experiences` VALUES (2, 1, '《神农本草经》', '人参可用于治疗气虚乏力、脾胃虚弱等症状,具有补中益气、健脾开胃的功效。'); 39 | INSERT INTO `experiences` VALUES (3, 1, '《本经逢原》', '人参具有补气固表、益肺生津的作用,适用于气虚血弱、自汗、久咳等症状的调理。'); 40 | INSERT INTO `experiences` VALUES (4, 2, '《本草纲目》', '黄芪是一种常用的中药材,具有益气固表、健脾生津的功效,适用于气虚乏力、食欲不振、久泻久痢等症状的调理。'); 41 | INSERT INTO `experiences` VALUES (5, 2, '《本经逢原》', '黄芪可用于治疗气虚乏力、脾胃虚弱等症状,具有补中益气、健脾开胃的功效。'); 42 | INSERT INTO `experiences` VALUES (6, 2, '《本草纲目》', '黄芪具有益气固表、托毒剂的作用,适用于气虚乏力、久泻久痢等症状的调理。'); 43 | INSERT INTO `experiences` VALUES (7, 3, '《本草纲目》', '白术是一种常用的中药材,具有健脾益胃、止泻固肠的作用,适用于脾胃虚弱、食欲不振、泄泻等症状的治疗。'); 44 | INSERT INTO `experiences` VALUES (8, 3, '《神农本草经》', '白术可用于治疗脾胃虚弱、食欲不振等症状,具有健脾开胃的功效。'); 45 | INSERT INTO `experiences` VALUES (9, 3, '《本经逢原》', '白术具有健脾固肾、和胃止泻的作用,适用于脾胃虚弱、泄泻等症状的调理。'); 46 | 47 | -- ---------------------------- 48 | -- Table structure for herbs 49 | -- ---------------------------- 50 | DROP TABLE IF EXISTS `herbs`; 51 | CREATE TABLE `herbs` ( 52 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 53 | `code` int(11) NOT NULL COMMENT '编号', 54 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '学名', 55 | `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '别名', 56 | `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '归属类别', 57 | `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '本经原文', 58 | `efficacy` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '主治', 59 | `taste` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '性味', 60 | `origin` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '产地', 61 | `dosage` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用量', 62 | `taboo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '禁忌', 63 | `processing` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '炮制方法', 64 | PRIMARY KEY (`id`) USING BTREE 65 | ) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '中草药' ROW_FORMAT = DYNAMIC; 66 | 67 | -- ---------------------------- 68 | -- Records of herbs 69 | -- ---------------------------- 70 | INSERT INTO `herbs` VALUES (1, 100, '人参', '参、芝', '增补', '本品为五加科植物人参的干燥根茎。', '补气健脾,生津止渴。', '甘甜微苦,平。', '主产于东北、华北等地。', '煎服,3~9g;或入丸、散、膏剂。', '大热亢阳、阴虚火旺者忌服。', '鲜品捣烂,晒干;或鲜品晒干.'); 71 | INSERT INTO `herbs` VALUES (2, 101, '黄芪', '黄芪、黄精', '增补', '本品为豆科植物黄芪的根及根茎。', '益气固表,利水除湿。', '甘平。', '主产于陕西、甘肃、河北等地。', '煎服,6~12g;或入丸、散、膏剂。', '表证发热者忌服。', '去须、泥、杂质,洗净,晒干.'); 72 | INSERT INTO `herbs` VALUES (3, 102, '白术', '半夏、半叶', '中经', '本品为菊科植物白术的块茎。', '健脾胃,燥湿化痰。', '甘苦,温。', '主产于长江流域一带。', '煎服,3~10g;或入丸、散、膏剂。', '脾胃虚寒、腹胀便溏者忌服。', '鲜品除去泥土,洗净,切片,晒干.'); 73 | INSERT INTO `herbs` VALUES (4, 103, '甘草', '甘草、甘遂', '增补', '本品为豆科植物甘草的根及根茎。', '和中止痛,解毒润肺。', '甘平。', '主产于甘肃、内蒙古等地。', '煎服,1~5g;或入丸、散、膏剂。', '阳明热盛、阴虚发热者忌服。', '除去须根泥土,洗净,晒干.'); 74 | INSERT INTO `herbs` VALUES (5, 104, '当归', '当归、唐柏', '上经', '本品为伞形科植物当归的根。', '养血活血,调经止痛。', '辛、甘、温。', '主产于四川、陕西、甘肃等地。', '煎服,3~10g;或入丸、散、膏剂。', '孕妇慎用。', '除去泥土,洗净,切段,晒干.'); 75 | INSERT INTO `herbs` VALUES (6, 105, '枸杞', '枸杞、地骨皮', '增补', '本品为茄科植物枸杞的果实。', '滋阴补肾,明目益精。', '甘平。', '主产于宁夏、甘肃等地。', '煎服,6~12g;或入丸、散、膏剂。', '脾胃虚寒、腹胀便溏者慎用.', '除去杂质、泥土,洗净,晒干.'); 76 | INSERT INTO `herbs` VALUES (7, 106, '川芎', '川芎、茶花', '上经', '本品为伞形科植物川芎的根茎。', '活血止痛,祛风通络。', '辛、温。', '主产于四川、陕西等地。', '煎服,3~10g;或入丸、散、膏剂。', '孕妇慎用。', '去泥土、杂质,洗净,晒干.'); 77 | INSERT INTO `herbs` VALUES (8, 107, '桂枝', '桂枝、桂皮', '上经', '本品为樟科植物桂枝的干燥枝、枝皮。', '解表散寒,和胃止呕。', '辛、甘、温。', '主产于湖北、湖南等地。', '煎服,3~10g;或入丸、散、膏剂。', '外感发热者慎用.', '除去粗壳、泥土,洗净,切段,晒干.'); 78 | INSERT INTO `herbs` VALUES (9, 108, '茯苓', '茯苓、茯神', '中经', '本品为多孔菌科真菌茯苓子实体。', '利水渗湿,健脾安神。', '甘淡、平。', '主产于湖北、湖南、四川等地。', '煎服,6~15g;或入丸、散、膏剂。', '脾胃虚寒、食滞不化者慎用.', '除去外皮及泥土,洗净,晒至半干,切片,再晒干.'); 79 | INSERT INTO `herbs` VALUES (10, 109, '黄连', '黄连、龙胆', '下经', '本品为马兜铃科植物黄连的根茎。', '清热燥湿,泻火解毒。', '苦寒。', '主产于四川、广西等地。', '煎服,1~3g;或入丸、散、膏剂。', '脾胃虚寒、腹胀便溏者慎用.', '除去泥土,洗净,切片,晒干.'); 80 | 81 | -- ---------------------------- 82 | -- Table structure for item_differentiation_infos 83 | -- ---------------------------- 84 | DROP TABLE IF EXISTS `item_differentiation_infos`; 85 | CREATE TABLE `item_differentiation_infos` ( 86 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 87 | `code` int(11) NOT NULL COMMENT '编号', 88 | `content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '内容', 89 | `annotation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '注释', 90 | PRIMARY KEY (`id`) USING BTREE 91 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '条辨概要' ROW_FORMAT = DYNAMIC; 92 | 93 | -- ---------------------------- 94 | -- Records of item_differentiation_infos 95 | -- ---------------------------- 96 | INSERT INTO `item_differentiation_infos` VALUES (1, 100, '补气健脾,生津止渴', '无'); 97 | INSERT INTO `item_differentiation_infos` VALUES (2, 101, '益气固表,利水除湿', '无'); 98 | INSERT INTO `item_differentiation_infos` VALUES (3, 102, '健脾胃,燥湿化痰', '无'); 99 | 100 | -- ---------------------------- 101 | -- Table structure for item_differentiations 102 | -- ---------------------------- 103 | DROP TABLE IF EXISTS `item_differentiations`; 104 | CREATE TABLE `item_differentiations` ( 105 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 106 | `item_differentiation_id` int(11) NOT NULL COMMENT '条辨 ID', 107 | `prescription_id` int(11) NOT NULL COMMENT '处方 ID', 108 | `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '类型', 109 | PRIMARY KEY (`id`) USING BTREE, 110 | INDEX `item_differentiations::item_differentiation_id`(`item_differentiation_id` ASC) USING BTREE, 111 | INDEX `item_differentiations::prescription_id`(`prescription_id` ASC) USING BTREE, 112 | CONSTRAINT `item_differentiations::item_differentiation_id` FOREIGN KEY (`item_differentiation_id`) REFERENCES `item_differentiation_infos` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, 113 | CONSTRAINT `item_differentiations::prescription_id` FOREIGN KEY (`prescription_id`) REFERENCES `prescription_infos` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT 114 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '条辨' ROW_FORMAT = DYNAMIC; 115 | 116 | -- ---------------------------- 117 | -- Records of item_differentiations 118 | -- ---------------------------- 119 | INSERT INTO `item_differentiations` VALUES (1, 1, 1, '对症'); 120 | INSERT INTO `item_differentiations` VALUES (2, 2, 2, '对症'); 121 | INSERT INTO `item_differentiations` VALUES (3, 3, 3, '对症'); 122 | 123 | -- ---------------------------- 124 | -- Table structure for prescription_infos 125 | -- ---------------------------- 126 | DROP TABLE IF EXISTS `prescription_infos`; 127 | CREATE TABLE `prescription_infos` ( 128 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 129 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称', 130 | `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '别名', 131 | `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '解释', 132 | PRIMARY KEY (`id`) USING BTREE, 133 | INDEX `name`(`name` ASC) USING BTREE 134 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '处方概要' ROW_FORMAT = DYNAMIC; 135 | 136 | -- ---------------------------- 137 | -- Records of prescription_infos 138 | -- ---------------------------- 139 | INSERT INTO `prescription_infos` VALUES (1, '补气生津方', '无', '养阴润燥,益气生津'); 140 | INSERT INTO `prescription_infos` VALUES (2, '祛湿利水方', '无', '祛湿利水,健脾利湿'); 141 | INSERT INTO `prescription_infos` VALUES (3, '调经止痛方', '无', '活血调经,舒筋止痛'); 142 | 143 | -- ---------------------------- 144 | -- Table structure for prescriptions 145 | -- ---------------------------- 146 | DROP TABLE IF EXISTS `prescriptions`; 147 | CREATE TABLE `prescriptions` ( 148 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一识别码', 149 | `prescription_id` int(11) NOT NULL COMMENT '中草药处方 ID', 150 | `herb_id` int(11) NOT NULL COMMENT '中草药 ID', 151 | `dosage` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用量', 152 | `usage` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用法', 153 | PRIMARY KEY (`id`) USING BTREE, 154 | INDEX `prescriptions::prescription_id`(`prescription_id` ASC) USING BTREE, 155 | INDEX `prescriptions::herb_id`(`herb_id` ASC) USING BTREE, 156 | CONSTRAINT `prescriptions::herb_id` FOREIGN KEY (`herb_id`) REFERENCES `herbs` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, 157 | CONSTRAINT `prescriptions::prescription_id` FOREIGN KEY (`prescription_id`) REFERENCES `prescription_infos` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT 158 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '处方' ROW_FORMAT = DYNAMIC; 159 | 160 | -- ---------------------------- 161 | -- Records of prescriptions 162 | -- ---------------------------- 163 | INSERT INTO `prescriptions` VALUES (1, 1, 1, '3~9g', '煎服'); 164 | INSERT INTO `prescriptions` VALUES (2, 2, 2, '6~12g', '煎服'); 165 | INSERT INTO `prescriptions` VALUES (3, 3, 3, '3~10g', '煎服'); 166 | 167 | SET FOREIGN_KEY_CHECKS = 1; 168 | --------------------------------------------------------------------------------