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/entity/PrescriptCategoryEntity.java b/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java index 34ce5805..52d5f99f 100644 --- a/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/PrescriptCategoryEntity.java @@ -1,10 +1,10 @@ package com.peanut.modules.book.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import lombok.Data; +import java.util.List; + @Data @TableName("prescript_category") public class PrescriptCategoryEntity { @@ -18,6 +18,10 @@ public class PrescriptCategoryEntity { 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 index a3b1059b..8c1d6a08 100644 --- a/src/main/java/com/peanut/modules/book/entity/PrescriptEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/PrescriptEntity.java @@ -1,9 +1,6 @@ package com.peanut.modules.book.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableLogic; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import java.util.Date; @@ -26,7 +23,7 @@ public class PrescriptEntity { private String doseNow; - private String usage; + private String preUsage; private String preSong; diff --git a/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java b/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java index 8e69ceaa..694ebb50 100644 --- a/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java +++ b/src/main/java/com/peanut/modules/book/service/PrescriptCategoryService.java @@ -3,5 +3,11 @@ 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 index a1c286cd..621582ba 100644 --- a/src/main/java/com/peanut/modules/book/service/PrescriptService.java +++ b/src/main/java/com/peanut/modules/book/service/PrescriptService.java @@ -1,7 +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 index c80def62..a7da400c 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/PrescriptCategoryServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/PrescriptCategoryServiceImpl.java @@ -1,13 +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 index efaefd62..acc57f60 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/PrescriptServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/PrescriptServiceImpl.java @@ -1,13 +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; + }