package com.peanut.modules.book.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.peanut.common.utils.R; import com.peanut.modules.book.entity.PointCategoryEntity; import com.peanut.modules.book.entity.PointEntity; import com.peanut.modules.book.service.PointCategoryService; import com.peanut.modules.book.service.PointService; 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.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; @RestController @RequestMapping("book/point") public class PointController { @Autowired private PointService pointService; @Autowired private PointCategoryService pointCategoryService; /** * 获取脉穴分类列表-树形结构 * @return */ @RequestMapping("/getPointCategoryList") public R getPointCategoryList(){ List categoryList = pointCategoryService.getCategoryList(); return R.ok().put("categorys",categoryList); } /** * 添加脉穴分类 * @return */ @RequestMapping("/addPointCategory") public R addPointCategory(@RequestBody PointCategoryEntity p){ pointCategoryService.save(p); return R.ok(); } /** * 删除脉穴分类 * @return */ @RequestMapping("/delPointCategory") public R delPointCategory(@RequestBody Map map){ Integer id = Integer.valueOf(map.get("pointCategoryId").toString()); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(PointEntity::getPointCategoryId,id); List list = pointService.list(wrapper); if(list.size()>0){ return R.error("此分类下存在文章,请先清空文章后再尝试删除!"); } pointCategoryService.removeById(id); return R.ok(); } /** * 修改脉穴分类 * @param p * @return */ @RequestMapping("/editPointCategory") public R editPointCategory(@RequestBody PointCategoryEntity p){ pointCategoryService.updateById(p); return R.ok(); } /** * 获取脉穴文章列表 * @return */ @RequestMapping("/getPointList") public R getPointList(@RequestBody Map map){ Page pointList = pointService.getPointList(map); return R.ok().put("page",pointList); } /** * 获取脉穴文章详情 * @return */ @RequestMapping("/getPointDetail") public R getPointDetail(@RequestBody Map map){ Integer integer = Integer.valueOf(map.get("pointId").toString()); PointEntity byId = pointService.getById(integer); List strings = JSON.parseArray(byId.getImages(), String.class); byId.setImageList(strings); return R.ok().put("point",byId); } /** * 添加脉穴文章 * @return */ @RequestMapping("/addPoint") public R addPoint(@RequestBody PointEntity pointEntity){ String jsonString = JSON.toJSONString(pointEntity.getImageList()); pointEntity.setImages(jsonString); pointService.save(pointEntity); return R.ok(); } /** * 删除脉穴文章 * @param map * @return */ @RequestMapping("/delPoint") public R delPoint(@RequestBody Map map){ Integer pointId = Integer.valueOf(map.get("pointId").toString()); pointService.removeById(pointId); return R.ok(); } /** * 修改脉穴文章 * @param pointEntity * @return */ @RequestMapping("/editPoint") public R editPoint(@RequestBody PointEntity pointEntity){ String jsonString = JSON.toJSONString(pointEntity.getImageList()); pointEntity.setImages(jsonString); pointService.updateById(pointEntity); return R.ok(); } /** * 获取脉穴分类列表通过父级id * @param map * @return */ @RequestMapping("/getPointCategoryByPid") public R getPointCategoryByPid(@RequestBody Map map){ Integer pointCategoryId = Integer.valueOf(map.get("id").toString()); List categoryListByPid = pointCategoryService.getCategoryListByPid(pointCategoryId); return R.ok().put("category",categoryListByPid); } /** * 获取脉穴文章标题列表通过分类id * @param map * @return */ @RequestMapping("/getPointsByCategoryId") public R getPointsByCategoryId(@RequestBody Map map){ Integer pointCategoryId = Integer.valueOf(map.get("pointCategoryId").toString()); List points = pointService.getPoints(pointCategoryId); return R.ok().put("points",points); } /** * 搜索脉穴标题列表 * @param map * @return */ @RequestMapping("/searchPointList") public R searchPointList(@RequestBody Map map){ String keywords = map.get("keywords").toString(); List pointEntities = pointService.searchPoint(keywords); return R.ok().put("points",pointEntities); } @RequestMapping("/TGDZForYear") public R TGDZForYear(@RequestBody Map map) throws ParseException { String date = map.get("date").toString(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); simpleDateFormat.applyPattern("yyyy-MM-dd hh:mm:ss"); Date parse = simpleDateFormat.parse(date); Map stringStringMap = pointService.TGDZForDate(parse); return R.ok().put("tgdz",stringStringMap); } }