package com.peanut.modules.book.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.R; import com.peanut.modules.book.entity.*; import com.peanut.modules.book.entity.SysDictDataEntity; import com.peanut.modules.book.service.*; import com.peanut.modules.sys.service.SysDictDataService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; 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.awt.print.Book; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j @RestController @RequestMapping("book/medicaldes") public class MedicaldesController { @Autowired private MedicaldesLightService lightService; @Autowired private MedicaldesBookService medicaldesBookService; @Autowired private MedicaldesInheritService inheritService; @Autowired private MedicaldesInheritRelationService relationService; @Autowired private SysDictDataService sysDictDataService; @Autowired private BookService bookService; /** * 类型列表 */ @RequestMapping(path = "/typeList") public R typeList(String label) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); wrapper.eq(SysDictDataEntity::getDictLabel,label); return R.ok().put("result",sysDictDataService.list(wrapper)); } /** * 专著出版关系列表 */ @RequestMapping(path = "/bookRelationListByType") public R bookRelationListByType(@RequestBody Map map) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.selectAll(MedicaldesBook.class); wrapper.leftJoin(BookEntity.class,BookEntity::getId,MedicaldesBook::getBookId); if (map.containsKey("dictType")&&StringUtils.isNotEmpty(map.get("dictType").toString())){ wrapper.eq(MedicaldesBook::getTypeId,map.get("dictType")); } if (map.containsKey("bookName")&&StringUtils.isNotEmpty(map.get("bookName").toString())){ wrapper.like(BookEntity::getName,map.get("bookName")); } Page res = medicaldesBookService.page(new Page( Long.parseLong(map.get("current").toString()), Long.parseLong(map.get("limit").toString())), wrapper); List list = res.getRecords(); if (list.size() > 0) { for (MedicaldesBook b : list) { b.setBook(bookService.getById(b.getBookId())); } res.setRecords(list); } return R.ok().put("result", res); } /** * 专著出版列表 */ @RequestMapping(path = "/bookListByType") public R bookListByType(String type) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.selectAll(BookEntity.class); wrapper.leftJoin(MedicaldesBook.class,MedicaldesBook::getBookId,BookEntity::getId); wrapper.eq(MedicaldesBook::getTypeId,type); List list = bookService.list(wrapper); return R.ok().put("result", list); } @RequestMapping(path = "/saveOrUpdateBookRelation") public R saveOrUpdateBookRelation(@RequestBody MedicaldesBook medicaldesBook) { medicaldesBookService.saveOrUpdate(medicaldesBook); return R.ok(); } @RequestMapping(path = "/delBookRelation") public R delBookRelation(String id) { medicaldesBookService.removeById(id); return R.ok(); } /** * 学术传承列表分页 */ @RequestMapping(path = "/inheritListByPage") public R inheritListByPage(@RequestBody Map map) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.leftJoin(MedicaldesInheritRelation.class,MedicaldesInheritRelation::getInheritId,MedicaldesInherit::getId); wrapper.leftJoin(City.class,City::getCityId,MedicaldesInherit::getCityId); wrapper.leftJoin(Province.class,Province::getProvId,City::getProvId); wrapper.selectAll(MedicaldesInherit.class); if (map.containsKey("dictType")&&StringUtils.isNotEmpty(map.get("dictType").toString())){ wrapper.eq(MedicaldesInheritRelation::getTypeId,map.get("dictType")); } if (map.containsKey("name")&&StringUtils.isNotEmpty(map.get("name").toString())){ wrapper.like(MedicaldesInherit::getName,map.get("name")); } Page page = inheritService.page(new Page<>( Long.parseLong(map.get("current").toString()), Long.parseLong(map.get("limit").toString())),wrapper); return R.ok().put("result", page); } /** * 学术传承列表按类型、地区 */ @RequestMapping(path = "/inheritListByTypeProvId") public R inheritListByTypeProvId(String type,String provId) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.leftJoin(MedicaldesInheritRelation.class,MedicaldesInheritRelation::getInheritId,MedicaldesInherit::getId); wrapper.eq(MedicaldesInheritRelation::getTypeId,type); wrapper.leftJoin(City.class,City::getCityId,MedicaldesInherit::getCityId); wrapper.leftJoin(Province.class,Province::getProvId,City::getProvId); wrapper.selectAll(MedicaldesInherit.class); wrapper.eq(Province::getProvId,provId); List list = inheritService.list(wrapper); return R.ok().put("result", list); } @RequestMapping(path = "/getInheritById") public R getInheritById(String id) { return R.ok().put("result",inheritService.getById(id)); } @RequestMapping(path = "/saveOrUpdateInherit") public R addInherit(@RequestBody MedicaldesInherit inherit) { MedicaldesInheritRelation relation = null; if (inherit.getId()==null) { relation = new MedicaldesInheritRelation(); }else { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); wrapper.eq(MedicaldesInheritRelation::getInheritId,inherit.getId()); relation = relationService.getOne(wrapper); } inheritService.saveOrUpdate(inherit); relation.setTypeId(inherit.getType()); relation.setInheritId(inherit.getId()); relationService.saveOrUpdate(relation); return R.ok(); } @RequestMapping(path = "/delInherit") public R delInherit(String id) { inheritService.removeById(id); LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); wrapper.eq(MedicaldesInheritRelation::getInheritId,id); relationService.removeById(relationService.getOne(wrapper)); return R.ok(); } @RequestMapping(path = "/getList") public List> getList(String type) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.leftJoin(MedicaldesInheritRelation.class,MedicaldesInheritRelation::getInheritId,MedicaldesInherit::getId); wrapper.eq(MedicaldesInheritRelation::getTypeId,type); wrapper.leftJoin(City.class,City::getCityId,MedicaldesInherit::getCityId); wrapper.leftJoin(Province.class,Province::getProvId,City::getProvId); wrapper.selectAs(Province::getProvName,"provinceName"); wrapper.selectAs(Province::getProvId,"provinceId"); wrapper.select("count(*) as count"); wrapper.groupBy("provinceName"); List> list = inheritService.listMaps(wrapper); return list; } /** * 吴门之光列表 */ @RequestMapping(path = "/lightListByType") public R lightListByType(String type) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); if (StringUtils.isNotEmpty(type)){ wrapper.eq(MedicaldesLight::getType,type); } List list = lightService.list(wrapper); return R.ok().put("result", list); } /** * 吴门之光列表 */ @RequestMapping(path = "/lightListByPage") public R lightListByPage(@RequestBody Map map) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); if (map.containsKey("type")&&StringUtils.isNotEmpty(map.get("type").toString())){ wrapper.eq(MedicaldesLight::getType,map.get("type")); } if (map.containsKey("name")&&StringUtils.isNotEmpty(map.get("name").toString())){ wrapper.like(MedicaldesLight::getName,map.get("name")); } Page page = lightService.page(new Page<>( Long.parseLong(map.get("current").toString()), Long.parseLong(map.get("limit").toString())),wrapper); return R.ok().put("result", page); } @RequestMapping(path = "/getLightById") public R getLightById(String id) { return R.ok().put("result",lightService.getById(id)); } @RequestMapping(path = "/saveOrUpdateLight") public R addLight(@RequestBody MedicaldesLight light) { lightService.saveOrUpdate(light); return R.ok(); } @RequestMapping(path = "/delLight") public R delLight(String id) { lightService.removeById(id); return R.ok(); } }