357 lines
15 KiB
Java
357 lines
15 KiB
Java
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.book.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<SysDictDataEntity> wrapper = new LambdaQueryWrapper();
|
|
wrapper.eq(SysDictDataEntity::getDictLabel,label);
|
|
return R.ok().put("result",sysDictDataService.list(wrapper));
|
|
}
|
|
|
|
/**
|
|
* 书列表
|
|
*/
|
|
@RequestMapping(path = "/bookList")
|
|
public R bookList() {
|
|
LambdaQueryWrapper<BookEntity> 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<MedicaldesBook> 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<MedicaldesBook> res = medicaldesBookService.page(new Page<MedicaldesBook>(
|
|
Long.parseLong(map.get("current").toString()), Long.parseLong(map.get("limit").toString())), wrapper);
|
|
List<MedicaldesBook> 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<BookEntity> 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<BookEntity> list = bookService.list(wrapper);
|
|
return R.ok().put("result", list);
|
|
}
|
|
|
|
@RequestMapping(path = "/saveOrUpdateBookRelation")
|
|
public R saveOrUpdateBookRelation(@RequestBody MedicaldesBook medicaldesBook) {
|
|
MPJLambdaWrapper<MedicaldesBook> 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<MedicaldesInherit> 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<MedicaldesInherit> 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<SysDictDataEntity> getCounts() {
|
|
LambdaQueryWrapper<SysDictDataEntity> wrapper = new LambdaQueryWrapper();
|
|
wrapper.eq(SysDictDataEntity::getDictLabel,"inheritPro");
|
|
List<SysDictDataEntity> dataList = sysDictDataService.list(wrapper);
|
|
return dataList;
|
|
}
|
|
|
|
public List getCityList(String cityName,int countId) {
|
|
List<City> 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<MedicaldesInherit> 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<MedicaldesInherit> list = inheritService.list(wrapper);
|
|
return R.ok().put("result", list);
|
|
}
|
|
|
|
//获取地址
|
|
@RequestMapping(path = "/getMedicaldesProList")
|
|
public R getMedicaldesProList() {
|
|
String s = redisTemplate.opsForValue().get("Province");
|
|
List<Province> provinceList = new ArrayList<>();
|
|
if (getCounts() != null&&getCounts().size() > 0){
|
|
for (int i=0;i<getCounts().size();i++){
|
|
Province p = new Province();
|
|
p.setProvName(getCounts().get(i).getDictValue());
|
|
p.setProvId(Long.valueOf(getCounts().get(i).getDictType()));
|
|
p.setCityList(getCityList(getCounts().get(i).getDictValue(),Integer.parseInt(getCounts().get(i).getDictType())));
|
|
provinceList.add(p);
|
|
}
|
|
}
|
|
if (StringUtils.isNotBlank(s)) {
|
|
List<Object> 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<City> prov = new ArrayList<>();
|
|
List<SysDictDataEntity> 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<City>()
|
|
.eq("prov_id", provId));
|
|
}
|
|
return R.ok().put("prov", prov);
|
|
}
|
|
|
|
@RequestMapping(path = "/getInheritById")
|
|
public R getInheritById(String id) {
|
|
MPJLambdaWrapper<MedicaldesInherit> 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<String,Object> 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<MedicaldesInheritRelation> 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<MedicaldesInheritRelation> wrapper = new LambdaQueryWrapper();
|
|
wrapper.eq(MedicaldesInheritRelation::getInheritId,id);
|
|
relationService.removeById(relationService.getOne(wrapper));
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping(path = "/getList")
|
|
public List<Map<String,Object>> getList(String type) {
|
|
MPJLambdaWrapper<MedicaldesInherit> 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<Map<String,Object>> list = inheritService.listMaps(wrapper);
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 吴门之光列表
|
|
*/
|
|
@RequestMapping(path = "/lightListByType")
|
|
public R lightListByType(String type) {
|
|
LambdaQueryWrapper<MedicaldesLight> wrapper = new LambdaQueryWrapper();
|
|
if (StringUtils.isNotEmpty(type)){
|
|
wrapper.eq(MedicaldesLight::getType,type);
|
|
}
|
|
wrapper.orderByAsc(MedicaldesLight::getSort);
|
|
List<MedicaldesLight> list = lightService.list(wrapper);
|
|
return R.ok().put("result", list);
|
|
}
|
|
|
|
/**
|
|
* 吴门之光列表
|
|
*/
|
|
@RequestMapping(path = "/lightListByPage")
|
|
public R lightListByPage(@RequestBody Map map) {
|
|
LambdaQueryWrapper<MedicaldesLight> 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<MedicaldesLight> 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();
|
|
}
|
|
|
|
}
|