package com.peanut.modules.book.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.sys.entity.SysDictDataEntity; import com.peanut.modules.book.service.*; import com.peanut.modules.common.entity.*; 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.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; 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; @Autowired private StringRedisTemplate redisTemplate; @Autowired private ProvinceService provinceService; @Autowired private CityService cityService; /** * 类型列表 */ @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 = "/bookList") public R bookList() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); wrapper.eq(BookEntity::getBookType,0); wrapper.orderByDesc(BookEntity::getCreateTime); return R.ok().put("result",bookService.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); wrapper.eq(BookEntity::getBookType,0); 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")); } wrapper.orderByAsc(MedicaldesBook::getSort); 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); wrapper.eq(BookEntity::getBookType,0); wrapper.orderByAsc(MedicaldesBook::getSort); List list = bookService.list(wrapper); return R.ok().put("result", list); } @RequestMapping(path = "/saveOrUpdateBookRelation") public R saveOrUpdateBookRelation(@RequestBody MedicaldesBook medicaldesBook) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.eq(MedicaldesBook::getBookId,medicaldesBook.getBookId()); wrapper.eq(MedicaldesBook::getTypeId,medicaldesBook.getTypeId()); if (medicaldesBookService.getOne(wrapper)!=null){ medicaldesBookService.remove(wrapper); } 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")); } wrapper.selectAs(MedicaldesInheritRelation::getTypeId,"type"); wrapper.selectAs(MedicaldesInheritRelation::getSort,"sort"); wrapper.orderByAsc(MedicaldesInheritRelation::getSort); 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); } //国际医师可能来自国外在省市里加入外国 public List getCounts() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); wrapper.eq(SysDictDataEntity::getDictLabel,"inheritPro"); List dataList = sysDictDataService.list(wrapper); return dataList; } public List getCityList(String cityName,int countId) { List cityList = new ArrayList<>(); City city = new City(); city.setProvId((long)countId); city.setCityName(cityName); city.setCityId((long)countId); cityList.add(city); return cityList; } /** * 学术传承列表按类型、地区 */ @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); if ("0".equals(provId)){ int[] val = new int[] {0}; //未知地址 if (getCounts()!=null&&getCounts().size() > 0){ for (int i=1;i<=getCounts().size(); i++){ val[i] = i; } } wrapper.in(MedicaldesInherit::getCityId,val); }else { wrapper.eq(Province::getProvId,provId); } wrapper.selectAs(MedicaldesInheritRelation::getSort,"sort"); wrapper.orderByAsc(MedicaldesInheritRelation::getSort); List list = inheritService.list(wrapper); return R.ok().put("result", list); } //获取地址 @RequestMapping(path = "/getMedicaldesProList") public R getMedicaldesProList() { String s = redisTemplate.opsForValue().get("Province"); List provinceList = new ArrayList<>(); if (getCounts() != null&&getCounts().size() > 0){ for (int i=0;i redisData = JSONArray.parseArray(s); for (Object object : redisData) { Province ret = JSONObject.parseObject(object.toString(), Province.class); provinceList.add(ret); } return R.ok().put("provinceEntity", provinceList); }else { provinceList.addAll(provinceService.getCity()); } return R.ok().put("provinceEntity", provinceList); } //获取市列表 @RequestMapping(path = "/getCityByPro") public R getCityByPro(@RequestParam("provId") Integer provId) { List prov = new ArrayList<>(); List list = getCounts(); boolean flag = false; if (list != null && list.size() > 0) { for (SysDictDataEntity data:list) { if (provId==Integer.parseInt(data.getDictType())){ prov.addAll(getCityList(data.getDictValue(),Integer.parseInt(data.getDictType()))); flag = true; } } } if (!flag) { prov = cityService.getBaseMapper().selectList(new QueryWrapper() .eq("prov_id", provId)); } return R.ok().put("prov", prov); } @RequestMapping(path = "/getInheritById") public R getInheritById(String id) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.eq(MedicaldesInherit::getId,id); 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.leftJoin(" (select dict_type,dict_value from sys_dict_data where dict_label = 'inheritPro') dd on dd.dict_type = t.city_id"); wrapper.select("t.*,ifnull(t2.city_name,ifnull(dd.dict_value,'其他')) as city_name,ifnull(t3.prov_name,ifnull(dd.dict_value,'其他')) as prov_name,t1.sort as sort"); Map inherit = inheritService.getMap(wrapper); return R.ok().put("result",inherit); } @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()); relation.setSort(inherit.getSort()); 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.select("count(1) count,ifnull(t3.prov_id,ifnull(dd.dict_type,'0')) AS prov_id,ifnull(t3.prov_name,ifnull(dd.dict_value,'其他')) AS prov_name "); 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.leftJoin(" (select dict_type,dict_value from sys_dict_data where dict_label = 'inheritPro') dd on dd.dict_type = t.city_id"); wrapper.groupBy("prov_name","dict_value"); wrapper.orderByAsc("t3.region_code","dict_value"); 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); } wrapper.orderByAsc(MedicaldesLight::getSort); 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")); } wrapper.orderByAsc(MedicaldesLight::getSort); 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(); } }