new prescript

This commit is contained in:
wangjinlei
2023-12-14 09:59:51 +08:00
parent 75fb345328
commit 6ea7db8ebd
7 changed files with 137 additions and 8 deletions

View File

@@ -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<PrescriptCategoryEntity> 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<String,Object> map){
Integer id = Integer.valueOf(map.get("prescriptCategoryId").toString());
boolean b = prescriptCategoryService.delPrescriptCategory(id);
if(b){
return R.ok();
}else{
return R.error();
}
}
}

View File

@@ -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<PrescriptCategoryEntity> children;
}

View File

@@ -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;

View File

@@ -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<PrescriptCategoryEntity> {
List<PrescriptCategoryEntity> getPrescriptCategoryList();
boolean delPrescriptCategory(Integer prescriptCategoryId);
}

View File

@@ -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<PrescriptEntity> {
}

View File

@@ -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<PrescriptCategoryDao, PrescriptCategoryEntity> implements PrescriptCategoryService {
@Autowired
private PrescriptDao prescriptDao;
@Override
public List<PrescriptCategoryEntity> getPrescriptCategoryList() {
LambdaQueryWrapper<PrescriptCategoryEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PrescriptCategoryEntity::getPid,0);
List<PrescriptCategoryEntity> list = list(wrapper);
for (PrescriptCategoryEntity p:list){
p.setChildren(list(new LambdaQueryWrapper<PrescriptCategoryEntity>().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<PrescriptCategoryEntity> list = list(new LambdaQueryWrapper<PrescriptCategoryEntity>().eq(PrescriptCategoryEntity::getPid, prescriptCategoryId));
if(list.size()>0){
return false;
}
List<PrescriptEntity> prescriptEntities = prescriptDao.selectList(new LambdaQueryWrapper<PrescriptEntity>().eq(PrescriptEntity::getPrescriptCategoryId, prescriptCategoryId));
if(prescriptEntities.size()>0){
return false;
}
removeById(prescriptCategoryId);
return true;
}
}

View File

@@ -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<PrescriptDao, PrescriptEntity> implements PrescriptService {
@Autowired
private PrescriptCategoryDao prescriptCategoryDao;
}