pull/1/head
commit
f12426ca27
@ -0,0 +1,182 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.jlwl</groupId>
|
||||
<!-- 导入项目的名称 -->
|
||||
<artifactId>yiyuanguanhaojiuzhen</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>yiyuanguanhaojiuzhen</name>
|
||||
<description>医院挂号就诊系统</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<fastjson.version>1.2.8</fastjson.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--访问静态资源-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--热部署-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatisplus-spring-boot-starter</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>2.0.1.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>4.0.12</version>
|
||||
</dependency>
|
||||
|
||||
<!-- FastJson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>sqljdbc4</artifactId>
|
||||
<scope>4.0</scope>
|
||||
<version>4.0</version>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 百度人工智能 -->
|
||||
<dependency>
|
||||
<groupId>com.baidu.aip</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
<version>4.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- poi高版本额外包 -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-examples</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-excelant</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml-schemas</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-scratchpad</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,61 @@
|
||||
package com.ServletContextListener;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.entity.DictionaryEntity;
|
||||
import com.service.DictionaryService;
|
||||
import com.thread.MyThreadMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典初始化监视器 用的是服务器监听,每次项目启动,都会调用这个类
|
||||
*/
|
||||
@WebListener
|
||||
public class DictionaryServletContextListener implements ServletContextListener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DictionaryServletContextListener.class);
|
||||
private MyThreadMethod myThreadMethod;
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
logger.info("----------服务器停止----------");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
|
||||
|
||||
logger.info("----------字典表初始化开始----------");
|
||||
DictionaryService dictionaryService = (DictionaryService)appContext.getBean("dictionaryService");
|
||||
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
||||
Map<String, Map<Integer,String>> map = new HashMap<>();
|
||||
for(DictionaryEntity d :dictionaryEntities){
|
||||
Map<Integer, String> m = map.get(d.getDicCode());
|
||||
if(m ==null || m.isEmpty()){
|
||||
m = new HashMap<>();
|
||||
}
|
||||
m.put(d.getCodeIndex(),d.getIndexName());
|
||||
map.put(d.getDicCode(),m);
|
||||
}
|
||||
sce.getServletContext().setAttribute("dictionaryMap", map);
|
||||
logger.info("----------字典表初始化完成----------");
|
||||
|
||||
|
||||
|
||||
logger.info("----------线程执行开始----------");
|
||||
if (myThreadMethod == null) {
|
||||
myThreadMethod = new MyThreadMethod();
|
||||
myThreadMethod.start(); // servlet 上下文初始化时启动线程myThreadMethod
|
||||
}
|
||||
logger.info("----------线程执行结束----------");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 登录用户信息
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface APPLoginUser {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 忽略Token验证
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface IgnoreAuth {
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 登录用户信息
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface LoginUser {
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
|
||||
|
||||
/**
|
||||
* 自定义填充处理器
|
||||
*/
|
||||
public class MyMetaObjectHandler extends MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.setFieldValByName("ctime", new Date(), metaObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean openUpdateFill() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
// 关闭更新填充、这里不执行
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
|
||||
package com.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
|
||||
|
||||
/**
|
||||
* mybatis-plus配置
|
||||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,326 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 在线咨询
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/chat")
|
||||
public class ChatController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChatController.class);
|
||||
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = chatService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<ChatView> list =(List<ChatView>)page.getList();
|
||||
for(ChatView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
ChatEntity chat = chatService.selectById(id);
|
||||
if(chat !=null){
|
||||
//entity转view
|
||||
ChatView view = new ChatView();
|
||||
BeanUtils.copyProperties( chat , view );//把实体数据重构到view中
|
||||
|
||||
//级联表
|
||||
YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId());
|
||||
if(yonghu != null){
|
||||
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYonghuId(yonghu.getId());
|
||||
}
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody ChatEntity chat, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
else if("用户".equals(role))
|
||||
chat.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
|
||||
Wrapper<ChatEntity> queryWrapper = new EntityWrapper<ChatEntity>()
|
||||
.eq("yonghu_id", chat.getYonghuId())
|
||||
.eq("chat_issue", chat.getChatIssue())
|
||||
.eq("chat_reply", chat.getChatReply())
|
||||
.eq("zhuangtai_types", chat.getZhuangtaiTypes())
|
||||
.eq("chat_types", chat.getChatTypes())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
ChatEntity chatEntity = chatService.selectOne(queryWrapper);
|
||||
if(chatEntity==null){
|
||||
chat.setInsertTime(new Date());
|
||||
chatService.insert(chat);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody ChatEntity chat, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
// else if("用户".equals(role))
|
||||
// chat.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<ChatEntity> queryWrapper = new EntityWrapper<ChatEntity>()
|
||||
.notIn("id",chat.getId())
|
||||
.andNew()
|
||||
.eq("yonghu_id", chat.getYonghuId())
|
||||
.eq("chat_issue", chat.getChatIssue())
|
||||
.eq("chat_reply", chat.getChatReply())
|
||||
.eq("zhuangtai_types", chat.getZhuangtaiTypes())
|
||||
.eq("chat_types", chat.getChatTypes())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
ChatEntity chatEntity = chatService.selectOne(queryWrapper);
|
||||
if(chatEntity==null){
|
||||
chatService.updateById(chat);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
chatService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<ChatEntity> chatList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
ChatEntity chatEntity = new ChatEntity();
|
||||
// chatEntity.setYonghuId(Integer.valueOf(data.get(0))); //提问用户 要改的
|
||||
// chatEntity.setChatIssue(data.get(0)); //问题 要改的
|
||||
// chatEntity.setIssueTime(new Date(data.get(0))); //问题时间 要改的
|
||||
// chatEntity.setChatReply(data.get(0)); //回复 要改的
|
||||
// chatEntity.setReplyTime(new Date(data.get(0))); //回复时间 要改的
|
||||
// chatEntity.setZhuangtaiTypes(Integer.valueOf(data.get(0))); //状态 要改的
|
||||
// chatEntity.setChatTypes(Integer.valueOf(data.get(0))); //数据类型 要改的
|
||||
// chatEntity.setInsertTime(date);//时间
|
||||
chatList.add(chatEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
chatService.insertBatch(chatList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = chatService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<ChatView> list =(List<ChatView>)page.getList();
|
||||
for(ChatView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
ChatEntity chat = chatService.selectById(id);
|
||||
if(chat !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
ChatView view = new ChatView();
|
||||
BeanUtils.copyProperties( chat , view );//把实体数据重构到view中
|
||||
|
||||
//级联表
|
||||
YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId());
|
||||
if(yonghu != null){
|
||||
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYonghuId(yonghu.getId());
|
||||
}
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody ChatEntity chat, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString());
|
||||
Wrapper<ChatEntity> queryWrapper = new EntityWrapper<ChatEntity>()
|
||||
.eq("yonghu_id", chat.getYonghuId())
|
||||
.eq("chat_issue", chat.getChatIssue())
|
||||
.eq("chat_reply", chat.getChatReply())
|
||||
.eq("zhuangtai_types", chat.getZhuangtaiTypes())
|
||||
.eq("chat_types", chat.getChatTypes())
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
ChatEntity chatEntity = chatService.selectOne(queryWrapper);
|
||||
if(chatEntity==null){
|
||||
chat.setInsertTime(new Date());
|
||||
chatService.insert(chat);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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 com.annotation.IgnoreAuth;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.entity.ConfigEntity;
|
||||
import com.service.ConfigService;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.utils.ValidatorUtils;
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*/
|
||||
@RequestMapping("config")
|
||||
@RestController
|
||||
public class ConfigController{
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params,ConfigEntity config){
|
||||
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
|
||||
PageUtils page = configService.queryPage(params);
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params,ConfigEntity config){
|
||||
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
|
||||
PageUtils page = configService.queryPage(params);
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") String id){
|
||||
ConfigEntity config = configService.selectById(id);
|
||||
return R.ok().put("data", config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") String id){
|
||||
ConfigEntity config = configService.selectById(id);
|
||||
return R.ok().put("data", config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据name获取信息
|
||||
*/
|
||||
@RequestMapping("/info")
|
||||
public R infoByName(@RequestParam String name){
|
||||
ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
|
||||
return R.ok().put("data", config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public R save(@RequestBody ConfigEntity config){
|
||||
// ValidatorUtils.validateEntity(config);
|
||||
configService.insert(config);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody ConfigEntity config){
|
||||
// ValidatorUtils.validateEntity(config);
|
||||
configService.updateById(config);//全部更新
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
configService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class);
|
||||
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
//级联表service
|
||||
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
@IgnoreAuth
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = dictionaryService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<DictionaryView> list =(List<DictionaryView>)page.getList();
|
||||
for(DictionaryView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
DictionaryEntity dictionary = dictionaryService.selectById(id);
|
||||
if(dictionary !=null){
|
||||
//entity转view
|
||||
DictionaryView view = new DictionaryView();
|
||||
BeanUtils.copyProperties( dictionary , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
||||
.eq("dic_code", dictionary.getDicCode())
|
||||
.eq("index_name", dictionary.getIndexName())
|
||||
;
|
||||
if(dictionary.getDicCode().contains("_erji_types")){
|
||||
queryWrapper.eq("super_id",dictionary.getSuperId());
|
||||
}
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
|
||||
if(dictionaryEntity==null){
|
||||
dictionary.setCreateTime(new Date());
|
||||
dictionaryService.insert(dictionary);
|
||||
//字典表新增数据,把数据再重新查出,放入监听器中
|
||||
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
||||
ServletContext servletContext = request.getServletContext();
|
||||
Map<String, Map<Integer,String>> map = new HashMap<>();
|
||||
for(DictionaryEntity d :dictionaryEntities){
|
||||
Map<Integer, String> m = map.get(d.getDicCode());
|
||||
if(m ==null || m.isEmpty()){
|
||||
m = new HashMap<>();
|
||||
}
|
||||
m.put(d.getCodeIndex(),d.getIndexName());
|
||||
map.put(d.getDicCode(),m);
|
||||
}
|
||||
servletContext.setAttribute("dictionaryMap",map);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
||||
.notIn("id",dictionary.getId())
|
||||
.eq("dic_code", dictionary.getDicCode())
|
||||
.eq("index_name", dictionary.getIndexName())
|
||||
;
|
||||
|
||||
if(dictionary.getDicCode().contains("_erji_types")){
|
||||
queryWrapper.eq("super_id",dictionary.getSuperId());
|
||||
}
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
|
||||
if(dictionaryEntity==null){
|
||||
dictionaryService.updateById(dictionary);//根据id更新
|
||||
//如果字典表修改数据的话,把数据再重新查出,放入监听器中
|
||||
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
|
||||
ServletContext servletContext = request.getServletContext();
|
||||
Map<String, Map<Integer,String>> map = new HashMap<>();
|
||||
for(DictionaryEntity d :dictionaryEntities){
|
||||
Map<Integer, String> m = map.get(d.getDicCode());
|
||||
if(m ==null || m.isEmpty()){
|
||||
m = new HashMap<>();
|
||||
}
|
||||
m.put(d.getCodeIndex(),d.getIndexName());
|
||||
map.put(d.getDicCode(),m);
|
||||
}
|
||||
servletContext.setAttribute("dictionaryMap",map);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
dictionaryService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
*/
|
||||
@RequestMapping("/maxCodeIndex")
|
||||
public R maxCodeIndex(@RequestBody DictionaryEntity dictionary){
|
||||
logger.debug("maxCodeIndex:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
|
||||
List<String> descs = new ArrayList<>();
|
||||
descs.add("code_index");
|
||||
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
||||
.eq("dic_code", dictionary.getDicCode())
|
||||
.orderDesc(descs);
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
List<DictionaryEntity> dictionaryEntityList = dictionaryService.selectList(queryWrapper);
|
||||
if(dictionaryEntityList != null ){
|
||||
return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1);
|
||||
}else{
|
||||
return R.ok().put("maxCodeIndex",1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<DictionaryEntity> dictionaryList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
DictionaryEntity dictionaryEntity = new DictionaryEntity();
|
||||
// dictionaryEntity.setDicCode(data.get(0)); //字段 要改的
|
||||
// dictionaryEntity.setDicName(data.get(0)); //字段名 要改的
|
||||
// dictionaryEntity.setCodeIndex(Integer.valueOf(data.get(0))); //编码 要改的
|
||||
// dictionaryEntity.setIndexName(data.get(0)); //编码名字 要改的
|
||||
// dictionaryEntity.setSuperId(Integer.valueOf(data.get(0))); //父字段id 要改的
|
||||
// dictionaryEntity.setBeizhu(data.get(0)); //备注 要改的
|
||||
// dictionaryEntity.setCreateTime(date);//时间
|
||||
dictionaryList.add(dictionaryEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
dictionaryService.insertBatch(dictionaryList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.annotation.IgnoreAuth;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.entity.ConfigEntity;
|
||||
import com.entity.EIException;
|
||||
import com.service.ConfigService;
|
||||
import com.utils.R;
|
||||
|
||||
/**
|
||||
* 上传文件映射表
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("file")
|
||||
@SuppressWarnings({"unchecked","rawtypes"})
|
||||
public class FileController{
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
@RequestMapping("/upload")
|
||||
public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw new EIException("上传文件不能为空");
|
||||
}
|
||||
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
|
||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||
if(!path.exists()) {
|
||||
path = new File("");
|
||||
}
|
||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||
if(!upload.exists()) {
|
||||
upload.mkdirs();
|
||||
}
|
||||
String fileName = new Date().getTime()+"."+fileExt;
|
||||
File dest = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||
file.transferTo(dest);
|
||||
if(StringUtils.isNotBlank(type) && type.equals("1")) {
|
||||
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
|
||||
if(configEntity==null) {
|
||||
configEntity = new ConfigEntity();
|
||||
configEntity.setName("faceFile");
|
||||
configEntity.setValue(fileName);
|
||||
} else {
|
||||
configEntity.setValue(fileName);
|
||||
}
|
||||
configService.insertOrUpdate(configEntity);
|
||||
}
|
||||
return R.ok().put("file", fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/download")
|
||||
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
|
||||
try {
|
||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||
if(!path.exists()) {
|
||||
path = new File("");
|
||||
}
|
||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||
if(!upload.exists()) {
|
||||
upload.mkdirs();
|
||||
}
|
||||
File file = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||
if(file.exists()){
|
||||
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
|
||||
getResponse().sendError(403);
|
||||
}*/
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
headers.setContentDispositionFormData("attachment", fileName);
|
||||
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 挂号
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/guahao")
|
||||
public class GuahaoController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GuahaoController.class);
|
||||
|
||||
@Autowired
|
||||
private GuahaoService guahaoService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = guahaoService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<GuahaoView> list =(List<GuahaoView>)page.getList();
|
||||
for(GuahaoView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
GuahaoEntity guahao = guahaoService.selectById(id);
|
||||
if(guahao !=null){
|
||||
//entity转view
|
||||
GuahaoView view = new GuahaoView();
|
||||
BeanUtils.copyProperties( guahao , view );//把实体数据重构到view中
|
||||
|
||||
//级联表
|
||||
YishengEntity yisheng = yishengService.selectById(guahao.getYishengId());
|
||||
if(yisheng != null){
|
||||
BeanUtils.copyProperties( yisheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYishengId(yisheng.getId());
|
||||
}
|
||||
//级联表
|
||||
YonghuEntity yonghu = yonghuService.selectById(guahao.getYonghuId());
|
||||
if(yonghu != null){
|
||||
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYonghuId(yonghu.getId());
|
||||
}
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody GuahaoEntity guahao, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,guahao:{}",this.getClass().getName(),guahao.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
else if("医生".equals(role))
|
||||
guahao.setYishengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
else if("用户".equals(role))
|
||||
guahao.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
|
||||
Wrapper<GuahaoEntity> queryWrapper = new EntityWrapper<GuahaoEntity>()
|
||||
.eq("yisheng_id", guahao.getYishengId())
|
||||
.eq("yonghu_id", guahao.getYonghuId())
|
||||
.eq("guahao_uuin_number", guahao.getGuahaoUuinNumber())
|
||||
.eq("guahao_time", new SimpleDateFormat("yyyy-MM-dd").format(guahao.getGuahaoTime()))
|
||||
.eq("guahao_types", guahao.getGuahaoTypes())
|
||||
.eq("guahao_status_types", guahao.getGuahaoStatusTypes())
|
||||
.eq("guahao_yesno_types", guahao.getGuahaoYesnoTypes())
|
||||
.eq("guahao_yesno_text", guahao.getGuahaoYesnoText())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
GuahaoEntity guahaoEntity = guahaoService.selectOne(queryWrapper);
|
||||
if(guahaoEntity==null){
|
||||
guahao.setGuahaoYesnoTypes(1);
|
||||
guahao.setCreateTime(new Date());
|
||||
guahaoService.insert(guahao);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody GuahaoEntity guahao, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,guahao:{}",this.getClass().getName(),guahao.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
// else if("医生".equals(role))
|
||||
// guahao.setYishengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
// else if("用户".equals(role))
|
||||
// guahao.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<GuahaoEntity> queryWrapper = new EntityWrapper<GuahaoEntity>()
|
||||
.notIn("id",guahao.getId())
|
||||
.andNew()
|
||||
.eq("yisheng_id", guahao.getYishengId())
|
||||
.eq("yonghu_id", guahao.getYonghuId())
|
||||
.eq("guahao_uuin_number", guahao.getGuahaoUuinNumber())
|
||||
.eq("guahao_time", guahao.getGuahaoTime())
|
||||
.eq("guahao_types", guahao.getGuahaoTypes())
|
||||
.eq("guahao_status_types", guahao.getGuahaoStatusTypes())
|
||||
.eq("guahao_yesno_types", guahao.getGuahaoYesnoTypes())
|
||||
.eq("guahao_yesno_text", guahao.getGuahaoYesnoText())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
GuahaoEntity guahaoEntity = guahaoService.selectOne(queryWrapper);
|
||||
if(guahaoEntity==null){
|
||||
guahaoService.updateById(guahao);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
guahaoService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<GuahaoEntity> guahaoList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
GuahaoEntity guahaoEntity = new GuahaoEntity();
|
||||
// guahaoEntity.setYishengId(Integer.valueOf(data.get(0))); //医生 要改的
|
||||
// guahaoEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
|
||||
// guahaoEntity.setGuahaoUuinNumber(Integer.valueOf(data.get(0))); //就诊识别码 要改的
|
||||
// guahaoEntity.setGuahaoTime(new Date(data.get(0))); //挂号时间 要改的
|
||||
// guahaoEntity.setGuahaoTypes(Integer.valueOf(data.get(0))); //时间类型 要改的
|
||||
// guahaoEntity.setGuahaoStatusTypes(Integer.valueOf(data.get(0))); //挂号状态 要改的
|
||||
// guahaoEntity.setGuahaoYesnoTypes(Integer.valueOf(data.get(0))); //挂号审核 要改的
|
||||
// guahaoEntity.setGuahaoYesnoText(data.get(0)); //审核结果 要改的
|
||||
// guahaoEntity.setCreateTime(date);//时间
|
||||
guahaoList.add(guahaoEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
guahaoService.insertBatch(guahaoList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = guahaoService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<GuahaoView> list =(List<GuahaoView>)page.getList();
|
||||
for(GuahaoView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
GuahaoEntity guahao = guahaoService.selectById(id);
|
||||
if(guahao !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
GuahaoView view = new GuahaoView();
|
||||
BeanUtils.copyProperties( guahao , view );//把实体数据重构到view中
|
||||
|
||||
//级联表
|
||||
YishengEntity yisheng = yishengService.selectById(guahao.getYishengId());
|
||||
if(yisheng != null){
|
||||
BeanUtils.copyProperties( yisheng , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYishengId(yisheng.getId());
|
||||
}
|
||||
//级联表
|
||||
YonghuEntity yonghu = yonghuService.selectById(guahao.getYonghuId());
|
||||
if(yonghu != null){
|
||||
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
|
||||
view.setYonghuId(yonghu.getId());
|
||||
}
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody GuahaoEntity guahao, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,guahao:{}",this.getClass().getName(),guahao.toString());
|
||||
Wrapper<GuahaoEntity> queryWrapper = new EntityWrapper<GuahaoEntity>()
|
||||
.eq("yisheng_id", guahao.getYishengId())
|
||||
.eq("yonghu_id", guahao.getYonghuId())
|
||||
.eq("guahao_uuin_number", guahao.getGuahaoUuinNumber())
|
||||
.eq("guahao_types", guahao.getGuahaoTypes())
|
||||
.eq("guahao_status_types", guahao.getGuahaoStatusTypes())
|
||||
.eq("guahao_yesno_types", guahao.getGuahaoYesnoTypes())
|
||||
.eq("guahao_yesno_text", guahao.getGuahaoYesnoText())
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
GuahaoEntity guahaoEntity = guahaoService.selectOne(queryWrapper);
|
||||
if(guahaoEntity==null){
|
||||
guahao.setGuahaoYesnoTypes(1);
|
||||
guahao.setCreateTime(new Date());
|
||||
YonghuEntity userId = yonghuService.selectById((Integer) request.getSession().getAttribute("userId"));
|
||||
YishengEntity yishengEntity = yishengService.selectById(guahao.getYishengId());
|
||||
if(userId.getNewMoney()<yishengEntity.getYishengNewMoney()){
|
||||
return R.error("余额不足请充值");
|
||||
}
|
||||
userId.setNewMoney(userId.getNewMoney()-yishengEntity.getYishengNewMoney());
|
||||
boolean b = yonghuService.updateById(userId);
|
||||
if(!b){
|
||||
return R.error();
|
||||
}
|
||||
guahaoService.insert(guahao);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,320 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 健康教育
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/jiankangjiaoyu")
|
||||
public class JiankangjiaoyuController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JiankangjiaoyuController.class);
|
||||
|
||||
@Autowired
|
||||
private JiankangjiaoyuService jiankangjiaoyuService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
params.put("jiankangjiaoyuDeleteStart",1);params.put("jiankangjiaoyuDeleteEnd",1);
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = jiankangjiaoyuService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<JiankangjiaoyuView> list =(List<JiankangjiaoyuView>)page.getList();
|
||||
for(JiankangjiaoyuView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
JiankangjiaoyuEntity jiankangjiaoyu = jiankangjiaoyuService.selectById(id);
|
||||
if(jiankangjiaoyu !=null){
|
||||
//entity转view
|
||||
JiankangjiaoyuView view = new JiankangjiaoyuView();
|
||||
BeanUtils.copyProperties( jiankangjiaoyu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody JiankangjiaoyuEntity jiankangjiaoyu, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,jiankangjiaoyu:{}",this.getClass().getName(),jiankangjiaoyu.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
Wrapper<JiankangjiaoyuEntity> queryWrapper = new EntityWrapper<JiankangjiaoyuEntity>()
|
||||
.eq("jiankangjiaoyu_name", jiankangjiaoyu.getJiankangjiaoyuName())
|
||||
.eq("jiankangjiaoyu_types", jiankangjiaoyu.getJiankangjiaoyuTypes())
|
||||
.eq("jiankangjiaoyu_delete", jiankangjiaoyu.getJiankangjiaoyuDelete())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
JiankangjiaoyuEntity jiankangjiaoyuEntity = jiankangjiaoyuService.selectOne(queryWrapper);
|
||||
if(jiankangjiaoyuEntity==null){
|
||||
jiankangjiaoyu.setInsertTime(new Date());
|
||||
jiankangjiaoyu.setJiankangjiaoyuDelete(1);
|
||||
jiankangjiaoyu.setCreateTime(new Date());
|
||||
jiankangjiaoyuService.insert(jiankangjiaoyu);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody JiankangjiaoyuEntity jiankangjiaoyu, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,jiankangjiaoyu:{}",this.getClass().getName(),jiankangjiaoyu.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<JiankangjiaoyuEntity> queryWrapper = new EntityWrapper<JiankangjiaoyuEntity>()
|
||||
.notIn("id",jiankangjiaoyu.getId())
|
||||
.andNew()
|
||||
.eq("jiankangjiaoyu_name", jiankangjiaoyu.getJiankangjiaoyuName())
|
||||
.eq("jiankangjiaoyu_types", jiankangjiaoyu.getJiankangjiaoyuTypes())
|
||||
.eq("jiankangjiaoyu_delete", jiankangjiaoyu.getJiankangjiaoyuDelete())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
JiankangjiaoyuEntity jiankangjiaoyuEntity = jiankangjiaoyuService.selectOne(queryWrapper);
|
||||
if("".equals(jiankangjiaoyu.getJiankangjiaoyuPhoto()) || "null".equals(jiankangjiaoyu.getJiankangjiaoyuPhoto())){
|
||||
jiankangjiaoyu.setJiankangjiaoyuPhoto(null);
|
||||
}
|
||||
if(jiankangjiaoyuEntity==null){
|
||||
jiankangjiaoyuService.updateById(jiankangjiaoyu);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
ArrayList<JiankangjiaoyuEntity> list = new ArrayList<>();
|
||||
for(Integer id:ids){
|
||||
JiankangjiaoyuEntity jiankangjiaoyuEntity = new JiankangjiaoyuEntity();
|
||||
jiankangjiaoyuEntity.setId(id);
|
||||
jiankangjiaoyuEntity.setJiankangjiaoyuDelete(2);
|
||||
list.add(jiankangjiaoyuEntity);
|
||||
}
|
||||
if(list != null && list.size() >0){
|
||||
jiankangjiaoyuService.updateBatchById(list);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<JiankangjiaoyuEntity> jiankangjiaoyuList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
JiankangjiaoyuEntity jiankangjiaoyuEntity = new JiankangjiaoyuEntity();
|
||||
// jiankangjiaoyuEntity.setJiankangjiaoyuName(data.get(0)); //健康教育标题 要改的
|
||||
// jiankangjiaoyuEntity.setJiankangjiaoyuTypes(Integer.valueOf(data.get(0))); //健康教育类型 要改的
|
||||
// jiankangjiaoyuEntity.setJiankangjiaoyuPhoto("");//照片
|
||||
// jiankangjiaoyuEntity.setInsertTime(date);//时间
|
||||
// jiankangjiaoyuEntity.setJiankangjiaoyuContent("");//照片
|
||||
// jiankangjiaoyuEntity.setJiankangjiaoyuDelete(1);//逻辑删除字段
|
||||
// jiankangjiaoyuEntity.setCreateTime(date);//时间
|
||||
jiankangjiaoyuList.add(jiankangjiaoyuEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
jiankangjiaoyuService.insertBatch(jiankangjiaoyuList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = jiankangjiaoyuService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<JiankangjiaoyuView> list =(List<JiankangjiaoyuView>)page.getList();
|
||||
for(JiankangjiaoyuView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
JiankangjiaoyuEntity jiankangjiaoyu = jiankangjiaoyuService.selectById(id);
|
||||
if(jiankangjiaoyu !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
JiankangjiaoyuView view = new JiankangjiaoyuView();
|
||||
BeanUtils.copyProperties( jiankangjiaoyu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody JiankangjiaoyuEntity jiankangjiaoyu, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,jiankangjiaoyu:{}",this.getClass().getName(),jiankangjiaoyu.toString());
|
||||
Wrapper<JiankangjiaoyuEntity> queryWrapper = new EntityWrapper<JiankangjiaoyuEntity>()
|
||||
.eq("jiankangjiaoyu_name", jiankangjiaoyu.getJiankangjiaoyuName())
|
||||
.eq("jiankangjiaoyu_types", jiankangjiaoyu.getJiankangjiaoyuTypes())
|
||||
.eq("jiankangjiaoyu_delete", jiankangjiaoyu.getJiankangjiaoyuDelete())
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
JiankangjiaoyuEntity jiankangjiaoyuEntity = jiankangjiaoyuService.selectOne(queryWrapper);
|
||||
if(jiankangjiaoyuEntity==null){
|
||||
jiankangjiaoyu.setInsertTime(new Date());
|
||||
jiankangjiaoyu.setJiankangjiaoyuDelete(1);
|
||||
jiankangjiaoyu.setCreateTime(new Date());
|
||||
jiankangjiaoyuService.insert(jiankangjiaoyu);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,304 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 公告信息
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/news")
|
||||
public class NewsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NewsController.class);
|
||||
|
||||
@Autowired
|
||||
private NewsService newsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = newsService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<NewsView> list =(List<NewsView>)page.getList();
|
||||
for(NewsView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
NewsEntity news = newsService.selectById(id);
|
||||
if(news !=null){
|
||||
//entity转view
|
||||
NewsView view = new NewsView();
|
||||
BeanUtils.copyProperties( news , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody NewsEntity news, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
|
||||
.eq("news_name", news.getNewsName())
|
||||
.eq("news_types", news.getNewsTypes())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
|
||||
if(newsEntity==null){
|
||||
news.setInsertTime(new Date());
|
||||
news.setCreateTime(new Date());
|
||||
newsService.insert(news);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody NewsEntity news, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
|
||||
.notIn("id",news.getId())
|
||||
.andNew()
|
||||
.eq("news_name", news.getNewsName())
|
||||
.eq("news_types", news.getNewsTypes())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
|
||||
if("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())){
|
||||
news.setNewsPhoto(null);
|
||||
}
|
||||
if(newsEntity==null){
|
||||
newsService.updateById(news);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
newsService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<NewsEntity> newsList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
NewsEntity newsEntity = new NewsEntity();
|
||||
// newsEntity.setNewsName(data.get(0)); //公告名称 要改的
|
||||
// newsEntity.setNewsPhoto("");//照片
|
||||
// newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); //公告类型 要改的
|
||||
// newsEntity.setInsertTime(date);//时间
|
||||
// newsEntity.setNewsContent("");//照片
|
||||
// newsEntity.setCreateTime(date);//时间
|
||||
newsList.add(newsEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
newsService.insertBatch(newsList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = newsService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<NewsView> list =(List<NewsView>)page.getList();
|
||||
for(NewsView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
NewsEntity news = newsService.selectById(id);
|
||||
if(news !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
NewsView view = new NewsView();
|
||||
BeanUtils.copyProperties( news , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody NewsEntity news, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
|
||||
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
|
||||
.eq("news_name", news.getNewsName())
|
||||
.eq("news_types", news.getNewsTypes())
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
|
||||
if(newsEntity==null){
|
||||
news.setInsertTime(new Date());
|
||||
news.setCreateTime(new Date());
|
||||
newsService.insert(news);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"表中有相同数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,475 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 医生
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/yisheng")
|
||||
public class YishengController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YishengController.class);
|
||||
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = yishengService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<YishengView> list =(List<YishengView>)page.getList();
|
||||
for(YishengView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YishengEntity yisheng = yishengService.selectById(id);
|
||||
if(yisheng !=null){
|
||||
//entity转view
|
||||
YishengView view = new YishengView();
|
||||
BeanUtils.copyProperties( yisheng , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody YishengEntity yisheng, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,yisheng:{}",this.getClass().getName(),yisheng.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
Wrapper<YishengEntity> queryWrapper = new EntityWrapper<YishengEntity>()
|
||||
.eq("username", yisheng.getUsername())
|
||||
.or()
|
||||
.eq("yisheng_phone", yisheng.getYishengPhone())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YishengEntity yishengEntity = yishengService.selectOne(queryWrapper);
|
||||
if(yishengEntity==null){
|
||||
yisheng.setCreateTime(new Date());
|
||||
yisheng.setPassword("123456");
|
||||
yishengService.insert(yisheng);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者联系方式已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody YishengEntity yisheng, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,yisheng:{}",this.getClass().getName(),yisheng.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<YishengEntity> queryWrapper = new EntityWrapper<YishengEntity>()
|
||||
.notIn("id",yisheng.getId())
|
||||
.andNew()
|
||||
.eq("username", yisheng.getUsername())
|
||||
.or()
|
||||
.eq("yisheng_phone", yisheng.getYishengPhone())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YishengEntity yishengEntity = yishengService.selectOne(queryWrapper);
|
||||
if("".equals(yisheng.getYishengPhoto()) || "null".equals(yisheng.getYishengPhoto())){
|
||||
yisheng.setYishengPhoto(null);
|
||||
}
|
||||
if(yishengEntity==null){
|
||||
yishengService.updateById(yisheng);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者联系方式已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
yishengService.deleteBatchIds(Arrays.asList(ids));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<YishengEntity> yishengList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
YishengEntity yishengEntity = new YishengEntity();
|
||||
// yishengEntity.setYishengUuidNumber(data.get(0)); //医生工号 要改的
|
||||
// yishengEntity.setUsername(data.get(0)); //账户 要改的
|
||||
// //yishengEntity.setPassword("123456");//密码
|
||||
// yishengEntity.setYishengName(data.get(0)); //医生名称 要改的
|
||||
// yishengEntity.setYishengTypes(Integer.valueOf(data.get(0))); //科室 要改的
|
||||
// yishengEntity.setZhiweiTypes(Integer.valueOf(data.get(0))); //职位 要改的
|
||||
// yishengEntity.setYishengZhichneg(data.get(0)); //职称 要改的
|
||||
// yishengEntity.setYishengPhoto("");//照片
|
||||
// yishengEntity.setYishengPhone(data.get(0)); //联系方式 要改的
|
||||
// yishengEntity.setYishengGuahao(data.get(0)); //挂号须知 要改的
|
||||
// yishengEntity.setYishengEmail(data.get(0)); //邮箱 要改的
|
||||
// yishengEntity.setYishengNewMoney(data.get(0)); //挂号价格 要改的
|
||||
// yishengEntity.setYishengContent("");//照片
|
||||
// yishengEntity.setCreateTime(date);//时间
|
||||
yishengList.add(yishengEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
//医生工号
|
||||
if(seachFields.containsKey("yishengUuidNumber")){
|
||||
List<String> yishengUuidNumber = seachFields.get("yishengUuidNumber");
|
||||
yishengUuidNumber.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yishengUuidNumber = new ArrayList<>();
|
||||
yishengUuidNumber.add(data.get(0));//要改的
|
||||
seachFields.put("yishengUuidNumber",yishengUuidNumber);
|
||||
}
|
||||
//账户
|
||||
if(seachFields.containsKey("username")){
|
||||
List<String> username = seachFields.get("username");
|
||||
username.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> username = new ArrayList<>();
|
||||
username.add(data.get(0));//要改的
|
||||
seachFields.put("username",username);
|
||||
}
|
||||
//联系方式
|
||||
if(seachFields.containsKey("yishengPhone")){
|
||||
List<String> yishengPhone = seachFields.get("yishengPhone");
|
||||
yishengPhone.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yishengPhone = new ArrayList<>();
|
||||
yishengPhone.add(data.get(0));//要改的
|
||||
seachFields.put("yishengPhone",yishengPhone);
|
||||
}
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
//医生工号
|
||||
List<YishengEntity> yishengEntities_yishengUuidNumber = yishengService.selectList(new EntityWrapper<YishengEntity>().in("yisheng_uuid_number", seachFields.get("yishengUuidNumber")));
|
||||
if(yishengEntities_yishengUuidNumber.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YishengEntity s:yishengEntities_yishengUuidNumber){
|
||||
repeatFields.add(s.getYishengUuidNumber());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [医生工号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
//账户
|
||||
List<YishengEntity> yishengEntities_username = yishengService.selectList(new EntityWrapper<YishengEntity>().in("username", seachFields.get("username")));
|
||||
if(yishengEntities_username.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YishengEntity s:yishengEntities_username){
|
||||
repeatFields.add(s.getUsername());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
//联系方式
|
||||
List<YishengEntity> yishengEntities_yishengPhone = yishengService.selectList(new EntityWrapper<YishengEntity>().in("yisheng_phone", seachFields.get("yishengPhone")));
|
||||
if(yishengEntities_yishengPhone.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YishengEntity s:yishengEntities_yishengPhone){
|
||||
repeatFields.add(s.getYishengPhone());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [联系方式] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
yishengService.insertBatch(yishengList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping(value = "/login")
|
||||
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
||||
YishengEntity yisheng = yishengService.selectOne(new EntityWrapper<YishengEntity>().eq("username", username));
|
||||
if(yisheng==null || !yisheng.getPassword().equals(password))
|
||||
return R.error("账号或密码不正确");
|
||||
// // 获取监听器中的字典表
|
||||
// ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
|
||||
// Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
|
||||
// Map<Integer, String> role_types = dictionaryMap.get("role_types");
|
||||
// role_types.get(.getRoleTypes());
|
||||
String token = tokenService.generateToken(yisheng.getId(),username, "yisheng", "医生");
|
||||
R r = R.ok();
|
||||
r.put("token", token);
|
||||
r.put("role","医生");
|
||||
r.put("username",yisheng.getYishengName());
|
||||
r.put("tableName","yisheng");
|
||||
r.put("userId",yisheng.getId());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@PostMapping(value = "/register")
|
||||
public R register(@RequestBody YishengEntity yisheng){
|
||||
// ValidatorUtils.validateEntity(user);
|
||||
Wrapper<YishengEntity> queryWrapper = new EntityWrapper<YishengEntity>()
|
||||
.eq("username", yisheng.getUsername())
|
||||
.or()
|
||||
.eq("yisheng_phone", yisheng.getYishengPhone())
|
||||
;
|
||||
YishengEntity yishengEntity = yishengService.selectOne(queryWrapper);
|
||||
if(yishengEntity != null)
|
||||
return R.error("账户或者联系方式已经被使用");
|
||||
yisheng.setYishengNewMoney(0.0);
|
||||
yisheng.setCreateTime(new Date());
|
||||
yishengService.insert(yisheng);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
@GetMapping(value = "/resetPassword")
|
||||
public R resetPassword(Integer id){
|
||||
YishengEntity yisheng = new YishengEntity();
|
||||
yisheng.setPassword("123456");
|
||||
yisheng.setId(id);
|
||||
yishengService.updateById(yisheng);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping(value = "/resetPass")
|
||||
public R resetPass(String username, HttpServletRequest request) {
|
||||
YishengEntity yisheng = yishengService.selectOne(new EntityWrapper<YishengEntity>().eq("username", username));
|
||||
if(yisheng!=null){
|
||||
yisheng.setPassword("123456");
|
||||
boolean b = yishengService.updateById(yisheng);
|
||||
if(!b){
|
||||
return R.error();
|
||||
}
|
||||
}else{
|
||||
return R.error("账号不存在");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的session用户信息
|
||||
*/
|
||||
@RequestMapping("/session")
|
||||
public R getCurrYisheng(HttpServletRequest request){
|
||||
Integer id = (Integer)request.getSession().getAttribute("userId");
|
||||
YishengEntity yisheng = yishengService.selectById(id);
|
||||
if(yisheng !=null){
|
||||
//entity转view
|
||||
YishengView view = new YishengView();
|
||||
BeanUtils.copyProperties( yisheng , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
@GetMapping(value = "logout")
|
||||
public R logout(HttpServletRequest request) {
|
||||
request.getSession().invalidate();
|
||||
return R.ok("退出成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = yishengService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<YishengView> list =(List<YishengView>)page.getList();
|
||||
for(YishengView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YishengEntity yisheng = yishengService.selectById(id);
|
||||
if(yisheng !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
YishengView view = new YishengView();
|
||||
BeanUtils.copyProperties( yisheng , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody YishengEntity yisheng, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,yisheng:{}",this.getClass().getName(),yisheng.toString());
|
||||
Wrapper<YishengEntity> queryWrapper = new EntityWrapper<YishengEntity>()
|
||||
.eq("username", yisheng.getUsername())
|
||||
.or()
|
||||
.eq("yisheng_phone", yisheng.getYishengPhone())
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YishengEntity yishengEntity = yishengService.selectOne(queryWrapper);
|
||||
if(yishengEntity==null){
|
||||
yisheng.setCreateTime(new Date());
|
||||
yisheng.setPassword("123456");
|
||||
yishengService.insert(yisheng);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者联系方式已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,503 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.entity.*;
|
||||
import com.entity.view.*;
|
||||
import com.service.*;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.R;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/yonghu")
|
||||
public class YonghuController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YonghuController.class);
|
||||
|
||||
@Autowired
|
||||
private YonghuService yonghuService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
//级联表service
|
||||
|
||||
@Autowired
|
||||
private YishengService yishengService;
|
||||
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("医生".equals(role))
|
||||
params.put("yishengId",request.getSession().getAttribute("userId"));
|
||||
params.put("yonghuDeleteStart",1);params.put("yonghuDeleteEnd",1);
|
||||
if(params.get("orderBy")==null || params.get("orderBy")==""){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = yonghuService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||
for(YonghuView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
}
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端详情
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("yonghu_delete", 1)
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity==null){
|
||||
yonghu.setYonghuDelete(1);
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.insert(yonghu);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||
logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
//根据字段查询是否有相同数据
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.notIn("id",yonghu.getId())
|
||||
.andNew()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("yonghu_delete", 1)
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){
|
||||
yonghu.setYonghuPhoto(null);
|
||||
}
|
||||
if(yonghuEntity==null){
|
||||
yonghuService.updateById(yonghu);//根据id更新
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
ArrayList<YonghuEntity> list = new ArrayList<>();
|
||||
for(Integer id:ids){
|
||||
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||
yonghuEntity.setId(id);
|
||||
yonghuEntity.setYonghuDelete(2);
|
||||
list.add(yonghuEntity);
|
||||
}
|
||||
if(list != null && list.size() >0){
|
||||
yonghuService.updateBatchById(list);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
try {
|
||||
List<YonghuEntity> yonghuList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||
// yonghuEntity.setUsername(data.get(0)); //账户 要改的
|
||||
// //yonghuEntity.setPassword("123456");//密码
|
||||
// yonghuEntity.setYonghuName(data.get(0)); //用户姓名 要改的
|
||||
// yonghuEntity.setYonghuPhoto("");//照片
|
||||
// yonghuEntity.setYonghuPhone(data.get(0)); //用户手机号 要改的
|
||||
// yonghuEntity.setYonghuIdNumber(data.get(0)); //用户身份证号 要改的
|
||||
// yonghuEntity.setYonghuEmail(data.get(0)); //邮箱 要改的
|
||||
// yonghuEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的
|
||||
// yonghuEntity.setNewMoney(data.get(0)); //余额 要改的
|
||||
// yonghuEntity.setYonghuDelete(1);//逻辑删除字段
|
||||
// yonghuEntity.setCreateTime(date);//时间
|
||||
yonghuList.add(yonghuEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
//账户
|
||||
if(seachFields.containsKey("username")){
|
||||
List<String> username = seachFields.get("username");
|
||||
username.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> username = new ArrayList<>();
|
||||
username.add(data.get(0));//要改的
|
||||
seachFields.put("username",username);
|
||||
}
|
||||
//用户手机号
|
||||
if(seachFields.containsKey("yonghuPhone")){
|
||||
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
||||
yonghuPhone.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yonghuPhone = new ArrayList<>();
|
||||
yonghuPhone.add(data.get(0));//要改的
|
||||
seachFields.put("yonghuPhone",yonghuPhone);
|
||||
}
|
||||
//用户身份证号
|
||||
if(seachFields.containsKey("yonghuIdNumber")){
|
||||
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
||||
yonghuIdNumber.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yonghuIdNumber = new ArrayList<>();
|
||||
yonghuIdNumber.add(data.get(0));//要改的
|
||||
seachFields.put("yonghuIdNumber",yonghuIdNumber);
|
||||
}
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
//账户
|
||||
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("yonghu_delete", 1));
|
||||
if(yonghuEntities_username.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_username){
|
||||
repeatFields.add(s.getUsername());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
//用户手机号
|
||||
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("yonghu_delete", 1));
|
||||
if(yonghuEntities_yonghuPhone.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_yonghuPhone){
|
||||
repeatFields.add(s.getYonghuPhone());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
//用户身份证号
|
||||
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("yonghu_delete", 1));
|
||||
if(yonghuEntities_yonghuIdNumber.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){
|
||||
repeatFields.add(s.getYonghuIdNumber());
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
}
|
||||
yonghuService.insertBatch(yonghuList);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping(value = "/login")
|
||||
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||
if(yonghu==null || !yonghu.getPassword().equals(password))
|
||||
return R.error("账号或密码不正确");
|
||||
else if(yonghu.getYonghuDelete() != 1)
|
||||
return R.error("账户已被删除");
|
||||
// // 获取监听器中的字典表
|
||||
// ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
|
||||
// Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
|
||||
// Map<Integer, String> role_types = dictionaryMap.get("role_types");
|
||||
// role_types.get(.getRoleTypes());
|
||||
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户");
|
||||
R r = R.ok();
|
||||
r.put("token", token);
|
||||
r.put("role","用户");
|
||||
r.put("username",yonghu.getYonghuName());
|
||||
r.put("tableName","yonghu");
|
||||
r.put("userId",yonghu.getId());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@PostMapping(value = "/register")
|
||||
public R register(@RequestBody YonghuEntity yonghu){
|
||||
// ValidatorUtils.validateEntity(user);
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("yonghu_delete", 1)
|
||||
;
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity != null)
|
||||
return R.error("账户或者用户手机号或者用户身份证号已经被使用");
|
||||
yonghu.setNewMoney(0.0);
|
||||
yonghu.setYonghuDelete(1);
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghuService.insert(yonghu);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
@GetMapping(value = "/resetPassword")
|
||||
public R resetPassword(Integer id){
|
||||
YonghuEntity yonghu = new YonghuEntity();
|
||||
yonghu.setPassword("123456");
|
||||
yonghu.setId(id);
|
||||
yonghuService.updateById(yonghu);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping(value = "/resetPass")
|
||||
public R resetPass(String username, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||
if(yonghu!=null){
|
||||
yonghu.setPassword("123456");
|
||||
boolean b = yonghuService.updateById(yonghu);
|
||||
if(!b){
|
||||
return R.error();
|
||||
}
|
||||
}else{
|
||||
return R.error("账号不存在");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的session用户信息
|
||||
*/
|
||||
@RequestMapping("/session")
|
||||
public R getCurrYonghu(HttpServletRequest request){
|
||||
Integer id = (Integer)request.getSession().getAttribute("userId");
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
@GetMapping(value = "logout")
|
||||
public R logout(HttpServletRequest request) {
|
||||
request.getSession().invalidate();
|
||||
return R.ok("退出成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
// 没有指定排序字段就默认id倒序
|
||||
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
|
||||
params.put("orderBy","id");
|
||||
}
|
||||
PageUtils page = yonghuService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||
for(YonghuView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
return R.ok().put("data", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("yonghu_delete", 1)
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity==null){
|
||||
yonghu.setYonghuDelete(1);
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.insert(yonghu);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.ChatEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.ChatView;
|
||||
|
||||
/**
|
||||
* 在线咨询 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface ChatDao extends BaseMapper<ChatEntity> {
|
||||
|
||||
List<ChatView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
|
||||
package com.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.entity.ConfigEntity;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
public interface ConfigDao extends BaseMapper<ConfigEntity> {
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.DictionaryEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.DictionaryView;
|
||||
|
||||
/**
|
||||
* 字典表 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface DictionaryDao extends BaseMapper<DictionaryEntity> {
|
||||
|
||||
List<DictionaryView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.GuahaoEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.GuahaoView;
|
||||
|
||||
/**
|
||||
* 挂号 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface GuahaoDao extends BaseMapper<GuahaoEntity> {
|
||||
|
||||
List<GuahaoView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.JiankangjiaoyuEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.JiankangjiaoyuView;
|
||||
|
||||
/**
|
||||
* 健康教育 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface JiankangjiaoyuDao extends BaseMapper<JiankangjiaoyuEntity> {
|
||||
|
||||
List<JiankangjiaoyuView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.NewsEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.NewsView;
|
||||
|
||||
/**
|
||||
* 公告信息 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface NewsDao extends BaseMapper<NewsEntity> {
|
||||
|
||||
List<NewsView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package com.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
import com.entity.TokenEntity;
|
||||
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
public interface TokenDao extends BaseMapper<TokenEntity> {
|
||||
|
||||
List<TokenEntity> selectListView(@Param("ew") Wrapper<TokenEntity> wrapper);
|
||||
|
||||
List<TokenEntity> selectListView(Pagination page,@Param("ew") Wrapper<TokenEntity> wrapper);
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package com.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
import com.entity.UsersEntity;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
public interface UsersDao extends BaseMapper<UsersEntity> {
|
||||
|
||||
List<UsersEntity> selectListView(@Param("ew") Wrapper<UsersEntity> wrapper);
|
||||
|
||||
List<UsersEntity> selectListView(Pagination page, @Param("ew") Wrapper<UsersEntity> wrapper);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.YishengEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.YishengView;
|
||||
|
||||
/**
|
||||
* 医生 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface YishengDao extends BaseMapper<YishengEntity> {
|
||||
|
||||
List<YishengView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.dao;
|
||||
|
||||
import com.entity.YonghuEntity;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.entity.view.YonghuView;
|
||||
|
||||
/**
|
||||
* 用户 Dao 接口
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public interface YonghuDao extends BaseMapper<YonghuEntity> {
|
||||
|
||||
List<YonghuView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
|
||||
package com.entity;
|
||||
|
||||
/**
|
||||
* 自定义异常
|
||||
*/
|
||||
public class EIException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String msg;
|
||||
private int code = 500;
|
||||
|
||||
public EIException(String msg) {
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public EIException(String msg, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public EIException(String msg, int code) {
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public EIException(String msg, int code, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
|
||||
/**
|
||||
* token表
|
||||
*/
|
||||
@TableName("token")
|
||||
public class TokenEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userid;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tablename;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Date expiratedtime;
|
||||
|
||||
/**
|
||||
* 新增时间
|
||||
*/
|
||||
private Date addtime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(Integer userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public String getTablename() {
|
||||
return tablename;
|
||||
}
|
||||
|
||||
public void setTablename(String tablename) {
|
||||
this.tablename = tablename;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public Date getExpiratedtime() {
|
||||
return expiratedtime;
|
||||
}
|
||||
|
||||
public void setExpiratedtime(Date expiratedtime) {
|
||||
this.expiratedtime = expiratedtime;
|
||||
}
|
||||
|
||||
public Date getAddtime() {
|
||||
return addtime;
|
||||
}
|
||||
|
||||
public void setAddtime(Date addtime) {
|
||||
this.addtime = addtime;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public TokenEntity(Integer userid, String username, String tablename,String role, String token, Date expiratedtime) {
|
||||
super();
|
||||
this.userid = userid;
|
||||
this.username = username;
|
||||
this.tablename = tablename;
|
||||
this.role = role;
|
||||
this.token = token;
|
||||
this.expiratedtime = expiratedtime;
|
||||
}
|
||||
|
||||
public TokenEntity() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableName("users")
|
||||
public class UsersEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private String role;
|
||||
|
||||
private Date addtime;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Date getAddtime() {
|
||||
return addtime;
|
||||
}
|
||||
|
||||
public void setAddtime(Date addtime) {
|
||||
this.addtime = addtime;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.interceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import com.annotation.IgnoreAuth;
|
||||
import com.entity.EIException;
|
||||
import com.entity.TokenEntity;
|
||||
import com.service.TokenService;
|
||||
import com.utils.R;
|
||||
|
||||
/**
|
||||
* 权限(Token)验证
|
||||
*/
|
||||
@Component
|
||||
public class AuthorizationInterceptor implements HandlerInterceptor {
|
||||
|
||||
public static final String LOGIN_TOKEN_KEY = "Token";
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Override
|
||||
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
|
||||
String servletPath = request.getServletPath();
|
||||
if("/dictionary/page".equals(request.getServletPath()) || "/file/upload".equals(request.getServletPath()) || "/yonghu/register".equals(request.getServletPath()) ){//请求路径是字典表或者文件上传 直接放行
|
||||
return true;
|
||||
}
|
||||
//支持跨域请求
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,request-source,Token, Origin,imgType, Content-Type, cache-control,postman-token,Cookie, Accept,authorization");
|
||||
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
||||
|
||||
IgnoreAuth annotation;
|
||||
if (handler instanceof HandlerMethod) {
|
||||
annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
//从header中获取token
|
||||
String token = request.getHeader(LOGIN_TOKEN_KEY);
|
||||
|
||||
/**
|
||||
* 不需要验证权限的方法直接放过
|
||||
*/
|
||||
if(annotation!=null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TokenEntity tokenEntity = null;
|
||||
if(StringUtils.isNotBlank(token)) {
|
||||
tokenEntity = tokenService.getTokenEntity(token);
|
||||
}
|
||||
|
||||
if(tokenEntity != null) {
|
||||
request.getSession().setAttribute("userId", tokenEntity.getUserid());
|
||||
request.getSession().setAttribute("role", tokenEntity.getRole());
|
||||
request.getSession().setAttribute("tableName", tokenEntity.getTablename());
|
||||
request.getSession().setAttribute("username", tokenEntity.getUsername());
|
||||
return true;
|
||||
}
|
||||
|
||||
PrintWriter writer = null;
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
try {
|
||||
writer = response.getWriter();
|
||||
writer.print(JSONObject.toJSONString(R.error(401, "请先登录")));
|
||||
} finally {
|
||||
if(writer != null){
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
// throw new EIException("请先登录", 401);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.ChatEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 在线咨询 服务类
|
||||
*/
|
||||
public interface ChatService extends IService<ChatEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
|
||||
package com.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.entity.ConfigEntity;
|
||||
import com.utils.PageUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author yangliyuan
|
||||
* @date 2019年10月10日 上午9:18:20
|
||||
*/
|
||||
public interface ConfigService extends IService<ConfigEntity> {
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.DictionaryEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 字典表 服务类
|
||||
*/
|
||||
public interface DictionaryService extends IService<DictionaryEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
/**
|
||||
* 字典表转换
|
||||
* @param obj
|
||||
*/
|
||||
void dictionaryConvert(Object obj, HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.GuahaoEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 挂号 服务类
|
||||
*/
|
||||
public interface GuahaoService extends IService<GuahaoEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.JiankangjiaoyuEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 健康教育 服务类
|
||||
*/
|
||||
public interface JiankangjiaoyuService extends IService<JiankangjiaoyuEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.NewsEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 公告信息 服务类
|
||||
*/
|
||||
public interface NewsService extends IService<NewsEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
|
||||
package com.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.entity.TokenEntity;
|
||||
import com.utils.PageUtils;
|
||||
|
||||
|
||||
/**
|
||||
* token
|
||||
* @author yangliyuan
|
||||
* @date 2019年10月10日 上午9:18:20
|
||||
*/
|
||||
public interface TokenService extends IService<TokenEntity> {
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper);
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params,Wrapper<TokenEntity> wrapper);
|
||||
|
||||
String generateToken(Integer userid,String username,String tableName, String role);
|
||||
|
||||
TokenEntity getTokenEntity(String token);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
|
||||
package com.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.entity.UsersEntity;
|
||||
import com.utils.PageUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author yangliyuan
|
||||
* @date 2019年10月10日 上午9:18:20
|
||||
*/
|
||||
public interface UsersService extends IService<UsersEntity> {
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
List<UsersEntity> selectListView(Wrapper<UsersEntity> wrapper);
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params, Wrapper<UsersEntity> wrapper);
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.YishengEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 医生 服务类
|
||||
*/
|
||||
public interface YishengService extends IService<YishengEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.utils.PageUtils;
|
||||
import com.entity.YonghuEntity;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 用户 服务类
|
||||
*/
|
||||
public interface YonghuService extends IService<YonghuEntity> {
|
||||
|
||||
/**
|
||||
* @param params 查询参数
|
||||
* @return 带分页的查询出来的数据
|
||||
*/
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.ChatDao;
|
||||
import com.entity.ChatEntity;
|
||||
import com.service.ChatService;
|
||||
import com.entity.view.ChatView;
|
||||
|
||||
/**
|
||||
* 在线咨询 服务实现类
|
||||
*/
|
||||
@Service("chatService")
|
||||
@Transactional
|
||||
public class ChatServiceImpl extends ServiceImpl<ChatDao, ChatEntity> implements ChatService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<ChatView> page =new Query<ChatView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
|
||||
package com.service.impl;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.dao.ConfigDao;
|
||||
import com.entity.ConfigEntity;
|
||||
import com.service.ConfigService;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author yangliyuan
|
||||
* @date 2019年10月10日 上午9:17:59
|
||||
*/
|
||||
@Service("configService")
|
||||
public class ConfigServiceImpl extends ServiceImpl<ConfigDao, ConfigEntity> implements ConfigService {
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
Page<ConfigEntity> page = this.selectPage(
|
||||
new Query<ConfigEntity>(params).getPage(),
|
||||
new EntityWrapper<ConfigEntity>()
|
||||
);
|
||||
return new PageUtils(page);
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.DictionaryDao;
|
||||
import com.entity.DictionaryEntity;
|
||||
import com.service.DictionaryService;
|
||||
import com.entity.view.DictionaryView;
|
||||
|
||||
/**
|
||||
* 字典表 服务实现类
|
||||
*/
|
||||
@Service("dictionaryService")
|
||||
@Transactional
|
||||
public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, DictionaryEntity> implements DictionaryService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<DictionaryView> page =new Query<DictionaryView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 赋值给字典表
|
||||
* @param obj view对象
|
||||
*/
|
||||
public void dictionaryConvert(Object obj, HttpServletRequest request) {
|
||||
try {
|
||||
if (obj == null) return;
|
||||
//当前view和entity中的所有types的字段
|
||||
List<String> fieldNameList = new ArrayList<>();
|
||||
Class tempClass = obj.getClass();
|
||||
while (tempClass !=null) {
|
||||
Field[] declaredFields = tempClass.getDeclaredFields();
|
||||
for (Field f : declaredFields) {
|
||||
f.setAccessible(true);
|
||||
if (f.getType().getName().equals("java.lang.Integer") && f.getName().contains("Types")) {
|
||||
fieldNameList.add(f.getName());
|
||||
}
|
||||
}
|
||||
tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己
|
||||
}
|
||||
|
||||
// 获取监听器中的字典表
|
||||
// ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
|
||||
ServletContext servletContext = request.getServletContext();
|
||||
Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
|
||||
|
||||
//通过Types的值给Value字段赋值
|
||||
for (String s : fieldNameList) {
|
||||
Field types = null;
|
||||
if(hasField(obj.getClass(),s)){
|
||||
//判断view中有没有这个字段,有就通过反射取出字段
|
||||
types= obj.getClass().getDeclaredField(s);//获取Types私有字段
|
||||
}else{
|
||||
//本表中没有这个字段,说明它是父表中的字段,也就是entity中的字段,从entity中取值
|
||||
types=obj.getClass().getSuperclass().getDeclaredField(s);
|
||||
}
|
||||
Field value = obj.getClass().getDeclaredField(s.replace("Types", "Value"));//获取value私有字段
|
||||
//设置权限
|
||||
types.setAccessible(true);
|
||||
value.setAccessible(true);
|
||||
|
||||
//赋值
|
||||
if (StringUtil.isNotEmpty(String.valueOf(types.get(obj)))) { //types的值不为空
|
||||
int i = Integer.parseInt(String.valueOf(types.get(obj)));//type
|
||||
//把s1字符中的所有大写转小写,并在前面加 _
|
||||
char[] chars = s.toCharArray();
|
||||
StringBuffer sbf = new StringBuffer();
|
||||
for(int b=0; b< chars.length; b++){
|
||||
char ch = chars[b];
|
||||
if(ch <= 90 && ch >= 65){
|
||||
sbf.append("_");
|
||||
ch += 32;
|
||||
}
|
||||
sbf.append(ch);
|
||||
}
|
||||
String s2 = dictionaryMap.get(sbf.toString()).get(i);
|
||||
value.set(obj, s2);
|
||||
} else {
|
||||
new Exception("字典表赋值出现问题::::"+value.getName());
|
||||
value.set(obj, "");
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断本实体有没有这个字段
|
||||
* @param c
|
||||
* @param fieldName
|
||||
* @return
|
||||
*/
|
||||
public boolean hasField(Class c, String fieldName){
|
||||
Field[] fields = c.getDeclaredFields();
|
||||
|
||||
for (Field f : fields) {
|
||||
if (fieldName.equals(f.getName())) {
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.GuahaoDao;
|
||||
import com.entity.GuahaoEntity;
|
||||
import com.service.GuahaoService;
|
||||
import com.entity.view.GuahaoView;
|
||||
|
||||
/**
|
||||
* 挂号 服务实现类
|
||||
*/
|
||||
@Service("guahaoService")
|
||||
@Transactional
|
||||
public class GuahaoServiceImpl extends ServiceImpl<GuahaoDao, GuahaoEntity> implements GuahaoService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<GuahaoView> page =new Query<GuahaoView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.JiankangjiaoyuDao;
|
||||
import com.entity.JiankangjiaoyuEntity;
|
||||
import com.service.JiankangjiaoyuService;
|
||||
import com.entity.view.JiankangjiaoyuView;
|
||||
|
||||
/**
|
||||
* 健康教育 服务实现类
|
||||
*/
|
||||
@Service("jiankangjiaoyuService")
|
||||
@Transactional
|
||||
public class JiankangjiaoyuServiceImpl extends ServiceImpl<JiankangjiaoyuDao, JiankangjiaoyuEntity> implements JiankangjiaoyuService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<JiankangjiaoyuView> page =new Query<JiankangjiaoyuView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.NewsDao;
|
||||
import com.entity.NewsEntity;
|
||||
import com.service.NewsService;
|
||||
import com.entity.view.NewsView;
|
||||
|
||||
/**
|
||||
* 公告信息 服务实现类
|
||||
*/
|
||||
@Service("newsService")
|
||||
@Transactional
|
||||
public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<NewsView> page =new Query<NewsView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
|
||||
package com.service.impl;
|
||||
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.dao.TokenDao;
|
||||
import com.entity.TokenEntity;
|
||||
import com.entity.TokenEntity;
|
||||
import com.service.TokenService;
|
||||
import com.utils.CommonUtil;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
|
||||
|
||||
/**
|
||||
* token
|
||||
* @author
|
||||
*/
|
||||
@Service("tokenService")
|
||||
public class TokenServiceImpl extends ServiceImpl<TokenDao, TokenEntity> implements TokenService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
Page<TokenEntity> page = this.selectPage(
|
||||
new Query<TokenEntity>(params).getPage(),
|
||||
new EntityWrapper<TokenEntity>()
|
||||
);
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper) {
|
||||
return baseMapper.selectListView(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params,
|
||||
Wrapper<TokenEntity> wrapper) {
|
||||
Page<TokenEntity> page =new Query<TokenEntity>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,wrapper));
|
||||
PageUtils pageUtil = new PageUtils(page);
|
||||
return pageUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateToken(Integer userid,String username, String tableName, String role) {
|
||||
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("userid", userid).eq("role", role));
|
||||
String token = CommonUtil.getRandomString(32);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(Calendar.HOUR_OF_DAY, 1);
|
||||
if(tokenEntity!=null) {
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setExpiratedtime(cal.getTime());
|
||||
this.updateById(tokenEntity);
|
||||
} else {
|
||||
this.insert(new TokenEntity(userid,username, tableName, role, token, cal.getTime()));
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenEntity getTokenEntity(String token) {
|
||||
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("token", token));
|
||||
if(tokenEntity == null || tokenEntity.getExpiratedtime().getTime()<new Date().getTime()) {
|
||||
return null;
|
||||
}
|
||||
return tokenEntity;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
|
||||
package com.service.impl;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.service.UsersService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.dao.UsersDao;
|
||||
import com.entity.UsersEntity;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author
|
||||
*/
|
||||
@Service("userService")
|
||||
public class UsersServiceImpl extends ServiceImpl<UsersDao, UsersEntity> implements UsersService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
Page<UsersEntity> page = this.selectPage(
|
||||
new Query<UsersEntity>(params).getPage(),
|
||||
new EntityWrapper<UsersEntity>()
|
||||
);
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsersEntity> selectListView(Wrapper<UsersEntity> wrapper) {
|
||||
return baseMapper.selectListView(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params,
|
||||
Wrapper<UsersEntity> wrapper) {
|
||||
Page<UsersEntity> page =new Query<UsersEntity>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,wrapper));
|
||||
PageUtils pageUtil = new PageUtils(page);
|
||||
return pageUtil;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.YishengDao;
|
||||
import com.entity.YishengEntity;
|
||||
import com.service.YishengService;
|
||||
import com.entity.view.YishengView;
|
||||
|
||||
/**
|
||||
* 医生 服务实现类
|
||||
*/
|
||||
@Service("yishengService")
|
||||
@Transactional
|
||||
public class YishengServiceImpl extends ServiceImpl<YishengDao, YishengEntity> implements YishengService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<YishengView> page =new Query<YishengView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.service.impl;
|
||||
|
||||
import com.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.utils.PageUtils;
|
||||
import com.utils.Query;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.dao.YonghuDao;
|
||||
import com.entity.YonghuEntity;
|
||||
import com.service.YonghuService;
|
||||
import com.entity.view.YonghuView;
|
||||
|
||||
/**
|
||||
* 用户 服务实现类
|
||||
*/
|
||||
@Service("yonghuService")
|
||||
@Transactional
|
||||
public class YonghuServiceImpl extends ServiceImpl<YonghuDao, YonghuEntity> implements YonghuService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String,Object> params) {
|
||||
if(params != null && (params.get("limit") == null || params.get("page") == null)){
|
||||
params.put("page","1");
|
||||
params.put("limit","10");
|
||||
}
|
||||
Page<YonghuView> page =new Query<YonghuView>(params).getPage();
|
||||
page.setRecords(baseMapper.selectListView(page,params));
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CommonUtil {
|
||||
/**
|
||||
* 获取随机字符串
|
||||
*
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static String getRandomString(Integer num) {
|
||||
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random = new Random();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < num; i++) {
|
||||
int number = random.nextInt(base.length());
|
||||
sb.append(base.charAt(number));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
/**
|
||||
* HttpClient工具类
|
||||
*/
|
||||
public class HttpClientUtils {
|
||||
|
||||
/**
|
||||
* @param uri
|
||||
* @return String
|
||||
* @description get请求方式
|
||||
* @author: long.he01
|
||||
*/
|
||||
public static String doGet(String uri) {
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
try {
|
||||
String res = "";
|
||||
URL url = new URL(uri);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
res += line+"\n";
|
||||
}
|
||||
in.close();
|
||||
return res;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.utils;
|
||||
|
||||
public class JQPageInfo{
|
||||
private Integer page;
|
||||
|
||||
private Integer limit;
|
||||
|
||||
private String sidx;
|
||||
|
||||
private String order;
|
||||
|
||||
private Integer offset;
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(Integer limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public String getSidx() {
|
||||
return sidx;
|
||||
}
|
||||
|
||||
public void setSidx(String sidx) {
|
||||
this.sidx = sidx;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Integer getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(Integer offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package com.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||
|
||||
/**
|
||||
* Mybatis-Plus工具类
|
||||
*/
|
||||
public class MPUtil {
|
||||
public static final char UNDERLINE = '_';
|
||||
|
||||
|
||||
//mybatis plus allEQ 表达式转换
|
||||
public static Map allEQMapPre(Object bean,String pre) {
|
||||
Map<String, Object> map =BeanUtil.beanToMap(bean);
|
||||
return camelToUnderlineMap(map,pre);
|
||||
}
|
||||
|
||||
//mybatis plus allEQ 表达式转换
|
||||
public static Map allEQMap(Object bean) {
|
||||
Map<String, Object> map =BeanUtil.beanToMap(bean);
|
||||
return camelToUnderlineMap(map,"");
|
||||
}
|
||||
|
||||
public static Wrapper allLikePre(Wrapper wrapper,Object bean,String pre) {
|
||||
Map<String, Object> map =BeanUtil.beanToMap(bean);
|
||||
Map result = camelToUnderlineMap(map,pre);
|
||||
|
||||
return genLike(wrapper,result);
|
||||
}
|
||||
|
||||
public static Wrapper allLike(Wrapper wrapper,Object bean) {
|
||||
Map result = BeanUtil.beanToMap(bean, true, true);
|
||||
return genLike(wrapper,result);
|
||||
}
|
||||
|
||||
|
||||
public static Wrapper genLike( Wrapper wrapper,Map param) {
|
||||
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
|
||||
int i=0;
|
||||
while (it.hasNext()) {
|
||||
if(i>0) wrapper.and();
|
||||
Map.Entry<String, Object> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
String value = (String) entry.getValue();
|
||||
wrapper.like(key, value);
|
||||
i++;
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static Wrapper likeOrEq(Wrapper wrapper,Object bean) {
|
||||
Map result = BeanUtil.beanToMap(bean, true, true);
|
||||
return genLikeOrEq(wrapper,result);
|
||||
}
|
||||
|
||||
public static Wrapper genLikeOrEq( Wrapper wrapper,Map param) {
|
||||
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
|
||||
int i=0;
|
||||
while (it.hasNext()) {
|
||||
if(i>0) wrapper.and();
|
||||
Map.Entry<String, Object> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
if(entry.getValue().toString().contains("%")) {
|
||||
wrapper.like(key, entry.getValue().toString().replace("%", ""));
|
||||
} else {
|
||||
wrapper.eq(key, entry.getValue());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static Wrapper allEq(Wrapper wrapper,Object bean) {
|
||||
Map result = BeanUtil.beanToMap(bean, true, true);
|
||||
return genEq(wrapper,result);
|
||||
}
|
||||
|
||||
|
||||
public static Wrapper genEq( Wrapper wrapper,Map param) {
|
||||
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
|
||||
int i=0;
|
||||
while (it.hasNext()) {
|
||||
if(i>0) wrapper.and();
|
||||
Map.Entry<String, Object> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
wrapper.eq(key, entry.getValue());
|
||||
i++;
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
public static Wrapper between(Wrapper wrapper,Map<String, Object> params) {
|
||||
for(String key : params.keySet()) {
|
||||
String columnName = "";
|
||||
if(key.endsWith("_start")) {
|
||||
columnName = key.substring(0, key.indexOf("_start"));
|
||||
if(StringUtils.isNotBlank(params.get(key).toString())) {
|
||||
wrapper.ge(columnName, params.get(key));
|
||||
}
|
||||
}
|
||||
if(key.endsWith("_end")) {
|
||||
columnName = key.substring(0, key.indexOf("_end"));
|
||||
if(StringUtils.isNotBlank(params.get(key).toString())) {
|
||||
wrapper.le(columnName, params.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static Wrapper sort(Wrapper wrapper,Map<String, Object> params) {
|
||||
String order = "";
|
||||
if(params.get("order") != null && StringUtils.isNotBlank(params.get("order").toString())) {
|
||||
order = params.get("order").toString();
|
||||
}
|
||||
if(params.get("sort") != null && StringUtils.isNotBlank(params.get("sort").toString())) {
|
||||
if(order.equalsIgnoreCase("desc")) {
|
||||
wrapper.orderDesc(Arrays.asList(params.get("sort")));
|
||||
} else {
|
||||
wrapper.orderAsc(Arrays.asList(params.get("sort")));
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 驼峰格式字符串转换为下划线格式字符串
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public static String camelToUnderline(String param) {
|
||||
if (param == null || "".equals(param.trim())) {
|
||||
return "";
|
||||
}
|
||||
int len = param.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = param.charAt(i);
|
||||
if (Character.isUpperCase(c)) {
|
||||
sb.append(UNDERLINE);
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] ages) {
|
||||
System.out.println(camelToUnderline("ABCddfANM"));
|
||||
}
|
||||
|
||||
public static Map camelToUnderlineMap(Map param, String pre) {
|
||||
|
||||
Map<String, Object> newMap = new HashMap<String, Object>();
|
||||
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, Object> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
String newKey = camelToUnderline(key);
|
||||
if (pre.endsWith(".")) {
|
||||
newMap.put(pre + newKey, entry.getValue());
|
||||
} else if (StringUtils.isEmpty(pre)) {
|
||||
newMap.put(newKey, entry.getValue());
|
||||
} else {
|
||||
|
||||
newMap.put(pre + "." + newKey, entry.getValue());
|
||||
}
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
|
||||
package com.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
|
||||
/**
|
||||
* 分页工具类
|
||||
*/
|
||||
public class PageUtils implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
//总记录数
|
||||
private long total;
|
||||
//每页记录数
|
||||
private int pageSize;
|
||||
//总页数
|
||||
private long totalPage;
|
||||
//当前页数
|
||||
private int currPage;
|
||||
//列表数据
|
||||
private List<?> list;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
* @param list 列表数据
|
||||
* @param totalCount 总记录数
|
||||
* @param pageSize 每页记录数
|
||||
* @param currPage 当前页数
|
||||
*/
|
||||
public PageUtils(List<?> list, int totalCount, int pageSize, int currPage) {
|
||||
this.list = list;
|
||||
this.total = totalCount;
|
||||
this.pageSize = pageSize;
|
||||
this.currPage = currPage;
|
||||
this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public PageUtils(Page<?> page) {
|
||||
this.list = page.getRecords();
|
||||
this.total = page.getTotal();
|
||||
this.pageSize = page.getSize();
|
||||
this.currPage = page.getCurrent();
|
||||
this.totalPage = page.getPages();
|
||||
}
|
||||
|
||||
/*
|
||||
* 空数据的分页
|
||||
*/
|
||||
public PageUtils(Map<String, Object> params) {
|
||||
Page page =new Query(params).getPage();
|
||||
new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getCurrPage() {
|
||||
return currPage;
|
||||
}
|
||||
|
||||
public void setCurrPage(int currPage) {
|
||||
this.currPage = currPage;
|
||||
}
|
||||
|
||||
public List<?> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<?> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public long getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(long totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package com.utils;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件导入到处
|
||||
*/
|
||||
public class PoiUtil {
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<List<String>> poiImport(String url) throws Exception {
|
||||
List<List<String>> list = new ArrayList<>();
|
||||
// 创建Excel 读取文件内容
|
||||
HSSFWorkbook workbook = new HSSFWorkbook(FileUtils.openInputStream(new File(url)));
|
||||
/**
|
||||
* 第一种方式读取Sheet页
|
||||
*/
|
||||
// HSSFSheet sheet = workbook.getSheet("Sheet0");
|
||||
/**
|
||||
* 第二种方式读取Sheet页
|
||||
*/
|
||||
HSSFSheet sheet = workbook.getSheetAt(0);//获取工作表
|
||||
for (int i = 0; i < sheet.getLastRowNum()+1; i++) {
|
||||
HSSFRow row = sheet.getRow(i);//获取行
|
||||
List<String> rowlist = new ArrayList<>();//行数据
|
||||
for (int j = 0; j < row.getLastCellNum(); j++) {
|
||||
HSSFCell cell = row.getCell(j);
|
||||
cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String value = cell.getStringCellValue();
|
||||
rowlist.add(value);//行中数据添加到行中
|
||||
}
|
||||
list.add(rowlist);//将行数据添加到list中
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 导出
|
||||
public static void poiExport(List<List<String>> list, String url) throws Exception {
|
||||
//创建Excel工作薄
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
//创建一个工作表shheet
|
||||
HSSFSheet sheet = workbook.createSheet();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
HSSFRow row = sheet.createRow(i);
|
||||
List<String> dataList = list.get(i);
|
||||
for (int j = 0; j < dataList.size(); j++) {
|
||||
HSSFCell cell = row.createCell(j);
|
||||
cell.setCellValue(dataList.get(j));
|
||||
}
|
||||
|
||||
}
|
||||
FileOutputStream stream = FileUtils.openOutputStream(new File(url));
|
||||
workbook.write(stream);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//导入
|
||||
List<List<String>> lists = PoiUtil.poiImport("C:/Users/Administrator/Desktop/工作1.xls");
|
||||
System.out.println();
|
||||
|
||||
|
||||
//导出
|
||||
|
||||
PoiUtil.poiExport(lists, "C:/Users/Administrator/Desktop/工作1.xls");
|
||||
|
||||
//
|
||||
// List<List<String>> list = new ArrayList<>();
|
||||
// ArrayList<String> dataList = new ArrayList<>();
|
||||
// dataList.add("标题1");
|
||||
// dataList.add("标题2");
|
||||
// dataList.add("标题3");
|
||||
// list.add(dataList);
|
||||
// // 追加数据
|
||||
// for (int i = 1; i < 10; i++) {// 这里的int 起始是1 也就是第二行开始
|
||||
// ArrayList<String> dataList111 = new ArrayList<>();
|
||||
// dataList111.add("内容" + i);
|
||||
// dataList111.add("内容1111111121222222222333333333377777777411111111477777777" + i);
|
||||
// dataList111.add("内容" + i);
|
||||
// list.add(dataList111);
|
||||
// }
|
||||
// PoiUtil.poiExport(list, "C:/Users/Administrator/Desktop/工作1.xls");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 返回数据
|
||||
*/
|
||||
public class R extends HashMap<String, Object> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public R() {
|
||||
put("code", 0);
|
||||
}
|
||||
|
||||
public static R error() {
|
||||
return error(500, "未知异常,请联系管理员");
|
||||
}
|
||||
|
||||
public static R error(String msg) {
|
||||
return error(500, msg);
|
||||
}
|
||||
|
||||
public static R error(int code, String msg) {
|
||||
R r = new R();
|
||||
r.put("code", code);
|
||||
r.put("msg", msg);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok(String msg) {
|
||||
R r = new R();
|
||||
r.put("msg", msg);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok(Map<String, Object> map) {
|
||||
R r = new R();
|
||||
r.putAll(map);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok() {
|
||||
return new R();
|
||||
}
|
||||
|
||||
public R put(String key, Object value) {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
|
||||
package com.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.entity.EIException;
|
||||
|
||||
/**
|
||||
* SQL过滤
|
||||
*/
|
||||
public class SQLFilter {
|
||||
|
||||
/**
|
||||
* SQL注入过滤
|
||||
* @param str 待验证的字符串
|
||||
*/
|
||||
public static String sqlInject(String str){
|
||||
if(StringUtils.isBlank(str)){
|
||||
return null;
|
||||
}
|
||||
//去掉'|"|;|\字符
|
||||
str = StringUtils.replace(str, "'", "");
|
||||
str = StringUtils.replace(str, "\"", "");
|
||||
str = StringUtils.replace(str, ";", "");
|
||||
str = StringUtils.replace(str, "\\", "");
|
||||
|
||||
//转换成小写
|
||||
str = str.toLowerCase();
|
||||
|
||||
//非法字符
|
||||
String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"};
|
||||
|
||||
//判断是否包含非法字符
|
||||
for(String keyword : keywords){
|
||||
if(str.indexOf(keyword) != -1){
|
||||
throw new EIException("包含非法字符");
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
|
||||
package com.utils;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* Spring Context 工具类
|
||||
*/
|
||||
@Component
|
||||
public class SpringContextUtils implements ApplicationContextAware {
|
||||
public static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
SpringContextUtils.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public static Object getBean(String name) {
|
||||
return applicationContext.getBean(name);
|
||||
}
|
||||
|
||||
public static <T> T getBean(String name, Class<T> requiredType) {
|
||||
return applicationContext.getBean(name, requiredType);
|
||||
}
|
||||
|
||||
public static boolean containsBean(String name) {
|
||||
return applicationContext.containsBean(name);
|
||||
}
|
||||
|
||||
public static boolean isSingleton(String name) {
|
||||
return applicationContext.isSingleton(name);
|
||||
}
|
||||
|
||||
public static Class<? extends Object> getType(String name) {
|
||||
return applicationContext.getType(name);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue