diff --git a/src/main/java/com/peanut/modules/book/controller/PrescriptController.java b/src/main/java/com/peanut/modules/book/controller/PrescriptController.java new file mode 100644 index 00000000..b90f4c2d --- /dev/null +++ b/src/main/java/com/peanut/modules/book/controller/PrescriptController.java @@ -0,0 +1,74 @@ +package com.peanut.modules.book.controller; + +import com.peanut.common.utils.R; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; +import com.peanut.modules.book.service.PrescriptCategoryService; +import com.peanut.modules.book.service.PrescriptService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@Slf4j +@RestController +@RequestMapping("book/prescript") +public class PrescriptController { + @Autowired + private PrescriptService prescriptService; + @Autowired + private PrescriptCategoryService prescriptCategoryService; + + /** + * 获取方剂分类列表 + * @return + */ + @RequestMapping("/getPrescriptCategoryList") + public R getPrescriptCategoryList(){ + List prescriptCategoryList = prescriptCategoryService.getPrescriptCategoryList(); + + return R.ok().put("list",prescriptCategoryList); + } + + /** + * 添加方剂分类 + * @param p + * @return + */ + @RequestMapping("/addPrescriptCategory") + public R addPrescriptCategory(@RequestBody PrescriptCategoryEntity p){ + prescriptCategoryService.save(p); + return R.ok(); + } + + /** + * 编辑方剂分类信息 + * @param p + * @return + */ + @RequestMapping("/editPrescriptCategory") + public R editPrescriptCategory(@RequestBody PrescriptCategoryEntity p){ + prescriptCategoryService.updateById(p); + return R.ok(); + } + + /** + * 删除方剂分类 + * @param map + * @return + */ + @RequestMapping("/delPrescriptCategory") + public R delPrescriptCategory(@RequestBody Map map){ + Integer id = Integer.valueOf(map.get("prescriptCategoryId").toString()); + boolean b = prescriptCategoryService.delPrescriptCategory(id); + if(b){ + return R.ok(); + }else{ + return R.error(); + } + + } +} diff --git a/src/main/java/com/peanut/modules/book/dao/PrescriptCategoryDao.java b/src/main/java/com/peanut/modules/book/dao/PrescriptCategoryDao.java new file mode 100644 index 00000000..5c0db856 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/dao/PrescriptCategoryDao.java @@ -0,0 +1,9 @@ +package com.peanut.modules.book.dao; + +import com.github.yulichang.base.MPJBaseMapper; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PrescriptCategoryDao extends MPJBaseMapper { +} diff --git a/src/main/java/com/peanut/modules/book/dao/PrescriptDao.java b/src/main/java/com/peanut/modules/book/dao/PrescriptDao.java new file mode 100644 index 00000000..dbd729d8 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/dao/PrescriptDao.java @@ -0,0 +1,9 @@ +package com.peanut.modules.book.dao; + +import com.github.yulichang.base.MPJBaseMapper; +import com.peanut.modules.book.entity.PrescriptEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PrescriptDao extends MPJBaseMapper { +} diff --git a/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java b/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java new file mode 100644 index 00000000..52d5f99f --- /dev/null +++ b/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java @@ -0,0 +1,27 @@ +package com.peanut.modules.book.entity; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; + +import java.util.List; + +@Data +@TableName("prescript_category") +public class PrescriptCategoryEntity { + + @TableId(type = IdType.AUTO) + private Integer prescriptCategoryId; + + private String title; + + private Integer pid; + + private Integer sort; + + @TableLogic + private Integer delFlag; + + @TableField(exist = false) + private List children; + +} diff --git a/src/main/java/com/peanut/modules/book/entity/PrescriptEntity.java b/src/main/java/com/peanut/modules/book/entity/PrescriptEntity.java new file mode 100644 index 00000000..8c1d6a08 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/entity/PrescriptEntity.java @@ -0,0 +1,38 @@ +package com.peanut.modules.book.entity; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("prescript") +public class PrescriptEntity { + @TableId(type = IdType.AUTO) + private Integer prescriptId; + + private Integer prescriptCategoryId; + + private String title; + + private String images; + + private String source; + + private String doseOld; + + private String doseNow; + + private String preUsage; + + private String preSong; + + private String indications; + + private Integer sort; + + private Date createTime; + + @TableLogic + private Integer delFlag; +} diff --git a/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java b/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java new file mode 100644 index 00000000..694ebb50 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java @@ -0,0 +1,13 @@ +package com.peanut.modules.book.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; + +import java.util.List; + +public interface PrescriptCategoryService extends IService { + + List getPrescriptCategoryList(); + + boolean delPrescriptCategory(Integer prescriptCategoryId); +} diff --git a/src/main/java/com/peanut/modules/book/service/PrescriptService.java b/src/main/java/com/peanut/modules/book/service/PrescriptService.java new file mode 100644 index 00000000..621582ba --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/PrescriptService.java @@ -0,0 +1,11 @@ +package com.peanut.modules.book.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; +import com.peanut.modules.book.entity.PrescriptEntity; + +import java.util.List; + +public interface PrescriptService extends IService { + +} diff --git a/src/main/java/com/peanut/modules/book/service/impl/PrescriptCategoryServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/PrescriptCategoryServiceImpl.java new file mode 100644 index 00000000..a7da400c --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/impl/PrescriptCategoryServiceImpl.java @@ -0,0 +1,49 @@ +package com.peanut.modules.book.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.modules.book.dao.PrescriptCategoryDao; +import com.peanut.modules.book.dao.PrescriptDao; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; +import com.peanut.modules.book.entity.PrescriptEntity; +import com.peanut.modules.book.service.PrescriptCategoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@Service("prescriptCategoryService") +public class PrescriptCategoryServiceImpl extends ServiceImpl implements PrescriptCategoryService { + @Autowired + private PrescriptDao prescriptDao; + @Override + public List getPrescriptCategoryList() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PrescriptCategoryEntity::getPid,0); + List list = list(wrapper); + for (PrescriptCategoryEntity p:list){ + p.setChildren(list(new LambdaQueryWrapper().eq(PrescriptCategoryEntity::getPid,p.getPrescriptCategoryId()))); + } + return list; + } + + @Override + public boolean delPrescriptCategory(Integer prescriptCategoryId) { + PrescriptCategoryEntity byId = getById(prescriptCategoryId); + if(byId.getPid().equals(0)){ + return false; + } + List list = list(new LambdaQueryWrapper().eq(PrescriptCategoryEntity::getPid, prescriptCategoryId)); + if(list.size()>0){ + return false; + } + List prescriptEntities = prescriptDao.selectList(new LambdaQueryWrapper().eq(PrescriptEntity::getPrescriptCategoryId, prescriptCategoryId)); + if(prescriptEntities.size()>0){ + return false; + } + removeById(prescriptCategoryId); + return true; + } +} diff --git a/src/main/java/com/peanut/modules/book/service/impl/PrescriptServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/PrescriptServiceImpl.java new file mode 100644 index 00000000..acc57f60 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/impl/PrescriptServiceImpl.java @@ -0,0 +1,21 @@ +package com.peanut.modules.book.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.modules.book.dao.PrescriptCategoryDao; +import com.peanut.modules.book.dao.PrescriptDao; +import com.peanut.modules.book.entity.PrescriptCategoryEntity; +import com.peanut.modules.book.entity.PrescriptEntity; +import com.peanut.modules.book.service.PrescriptService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@Service("prescriptService") +public class PrescriptServiceImpl extends ServiceImpl implements PrescriptService { + @Autowired + private PrescriptCategoryDao prescriptCategoryDao; + +}