package com.peanut.modules.book.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.peanut.common.utils.R; import com.peanut.modules.book.entity.PrescriptCategoryEntity; import com.peanut.modules.book.entity.PrescriptEntity; 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; /** * 获取方剂文章列表 * @param map * @return */ @RequestMapping("/getPrescriptList") public R getPrescriptList(@RequestBody Map map){ Integer limit = Integer.valueOf(map.get("limit").toString()); Integer page = Integer.valueOf(map.get("page").toString()); Integer prescriptCategoryId = Integer.valueOf(map.get("prescriptCategoryId").toString()); Page prescriptList = prescriptService.getPrescriptList(prescriptCategoryId, limit, page); return R.ok().put("page",prescriptList); } /** * 获取方剂文章详情 * @param map * @return */ @RequestMapping("/getPrescriptDetail") public R getPrescriptDetail(@RequestBody Map map){ Integer integer = Integer.valueOf(map.get("prescriptId").toString()); PrescriptEntity prescript = prescriptService.getById(integer); return R.ok().put("prescript",prescript); } /** * 添加方剂文章 * @param p * @return */ @RequestMapping("/addPrescript") public R addPrescript(@RequestBody PrescriptEntity p){ if(p.getImageList()!=null&&p.getImageList().size()>0){ p.setImages(JSON.toJSONString(p.getImageList())); } prescriptService.save(p); return R.ok(); } /** * 修改方剂文章 * @param p * @return */ @RequestMapping("/editPrescript") public R editPrescript(@RequestBody PrescriptEntity p){ if(p.getImageList()!=null&&p.getImageList().size()>0){ p.setImages(JSON.toJSONString(p.getImageList())); } prescriptService.updateById(p); return R.ok(); } /** * 删除方剂文章 * @param map * @return */ @RequestMapping("/delPrescript") public R delPrescript(@RequestBody Map map){ Integer integer = Integer.valueOf(map.get("prescriptId").toString()); prescriptService.removeById(integer); return R.ok(); } /** * 获取方剂分类列表 * @param map * @return */ @RequestMapping("/prescriptCategoryList") public R prescriptCategoryList(@RequestBody Map map){ Integer id = Integer.valueOf(map.get("categoryId").toString()); List categoryByPid = prescriptCategoryService.getCategoryByPid(id); return R.ok().put("list",categoryByPid); } /** * 获取方剂分类列表 * @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.code(303,"删除失败"); } } }