diff --git a/.idea/.gitignore b/.idea/.gitignore index 89be8cf..bc93133 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -2,7 +2,11 @@ /shelf/ /workspace.xml # 数据源本地存储已忽略文件 +<<<<<<< HEAD +/../../../../../../:\Users\33424\Desktop\jianshenfanggl没有注释\.idea/dataSources/ +======= /../../../../../../../:\Users\33424\Desktop\gym\jianshenfanggl\.idea/dataSources/ +>>>>>>> develop /dataSources.local.xml # 基于编辑器的 HTTP 客户端请求 /httpRequests/ diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..656cf71 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +jianshenfanggl \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..54f6a93 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b784bbc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 51e0d1c..f5aa6c4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,11 @@ +<<<<<<< HEAD + +======= +>>>>>>> develop \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..113f660 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,9 @@ +<<<<<<< HEAD + +======= +>>>>>>> develop \ No newline at end of file diff --git a/gym b/gym new file mode 160000 index 0000000..efe5258 --- /dev/null +++ b/gym @@ -0,0 +1 @@ +Subproject commit efe5258eda99ba1aac5fb7fffdc2414d5412705d diff --git a/jianshenfanggl.iml b/jianshenfanggl.iml new file mode 100644 index 0000000..1daccae --- /dev/null +++ b/jianshenfanggl.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/annotation/APPLoginUser.java b/src/main/java/com/annotation/APPLoginUser.java index 8b5936c..51329cd 100644 --- a/src/main/java/com/annotation/APPLoginUser.java +++ b/src/main/java/com/annotation/APPLoginUser.java @@ -1,3 +1,20 @@ +<<<<<<< HEAD +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 { + +} +======= // 声明该代码文件所在的包名为 com.annotation package com.annotation; @@ -26,4 +43,5 @@ import java.lang.annotation.Target; public @interface APPLoginUser { // 定义一个空注解,作为标记使用 // 实际使用时可以配合拦截器或参数解析器,自动注入当前登录用户对象 -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/annotation/ColumnInfo.java b/src/main/java/com/annotation/ColumnInfo.java index 21ae1ec..d2d79bf 100644 --- a/src/main/java/com/annotation/ColumnInfo.java +++ b/src/main/java/com/annotation/ColumnInfo.java @@ -1,3 +1,18 @@ +<<<<<<< HEAD +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.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ColumnInfo { + String comment(); + String type(); +} +======= // 定义该文件所在的包路径,将该 Java 类组织到 com.annotation 这个包空间下,方便项目的模块化管理和避免类名冲突 package com.annotation; @@ -24,4 +39,5 @@ public @interface ColumnInfo { // 定义type属性,表示字段的类型 String type(); -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/annotation/IgnoreAuth.java b/src/main/java/com/annotation/IgnoreAuth.java index d620996..bd48726 100644 --- a/src/main/java/com/annotation/IgnoreAuth.java +++ b/src/main/java/com/annotation/IgnoreAuth.java @@ -1,3 +1,18 @@ +<<<<<<< HEAD +package com.annotation; + +import java.lang.annotation.*; + +/** + * 忽略Token验证 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface IgnoreAuth { + +} +======= // 定义该文件所在的包路径 package com.annotation; @@ -15,4 +30,5 @@ import java.lang.annotation.*; public @interface IgnoreAuth { // 这是一个标记注解,不包含任何属性 // 仅用于标识需要跳过Token验证的方法 -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/annotation/LoginUser.java b/src/main/java/com/annotation/LoginUser.java index 12f266d..8badabf 100644 --- a/src/main/java/com/annotation/LoginUser.java +++ b/src/main/java/com/annotation/LoginUser.java @@ -1,3 +1,20 @@ +<<<<<<< HEAD +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 { + +} +======= // 定义该文件所在的包路径,在 Java 里,包是组织类和接口的一种方式,此包路径为 com.annotation,能防止命名冲突,也便于代码的管理与维护 package com.annotation; @@ -22,4 +39,5 @@ import java.lang.annotation.Target; public @interface LoginUser { // 这是一个标记注解,不包含任何属性 // 用于标识需要自动注入当前登录用户信息的参数 -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/config/InterceptorConfig.java b/src/main/java/com/config/InterceptorConfig.java index 5867530..767380d 100644 --- a/src/main/java/com/config/InterceptorConfig.java +++ b/src/main/java/com/config/InterceptorConfig.java @@ -1,3 +1,44 @@ +<<<<<<< HEAD +package com.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import com.interceptor.AuthorizationInterceptor; + +@Configuration +public class InterceptorConfig extends WebMvcConfigurationSupport{ + + @Bean + public AuthorizationInterceptor getAuthorizationInterceptor() { + return new AuthorizationInterceptor(); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/**").excludePathPatterns("/static/**"); + super.addInterceptors(registry); + } + + /** + * springboot 2.0配置WebMvcConfigurationSupport之后,会导致默认配置被覆盖,要访问静态资源需要重写addResourceHandlers方法 + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/**") + .addResourceLocations("classpath:/resources/") + .addResourceLocations("classpath:/static/") + .addResourceLocations("classpath:/admin/") + .addResourceLocations("classpath:/img/") + .addResourceLocations("classpath:/front/") + .addResourceLocations("classpath:/public/"); + super.addResourceHandlers(registry); + } +} +======= // 声明当前文件所在的包路径,在 Java 项目中,包用于组织代码结构,这里表示该文件属于 com.config 包,有助于模块化管理和避免命名冲突 package com.config; @@ -63,4 +104,5 @@ public class InterceptorConfig extends WebMvcConfigurationSupport { registry.addResourceLocations("classpath:/public/"); super.addResourceHandlers(registry); } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/config/MyMetaObjectHandler.java b/src/main/java/com/config/MyMetaObjectHandler.java index c017e16..ddff0c4 100644 --- a/src/main/java/com/config/MyMetaObjectHandler.java +++ b/src/main/java/com/config/MyMetaObjectHandler.java @@ -1,3 +1,33 @@ +<<<<<<< HEAD +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) { + // 关闭更新填充、这里不执行 + } +} +======= // 声明当前文件所在的包路径 package com.config; @@ -41,4 +71,5 @@ public class MyMetaObjectHandler extends MetaObjectHandler { // 如需启用更新填充,可在此添加类似: // this.setFieldValByName("utime", new Date(), metaObject); } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/config/MybatisPlusConfig.java b/src/main/java/com/config/MybatisPlusConfig.java index a87c3c6..b7c58bb 100644 --- a/src/main/java/com/config/MybatisPlusConfig.java +++ b/src/main/java/com/config/MybatisPlusConfig.java @@ -1,3 +1,29 @@ +<<<<<<< HEAD + +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(); + } + +} +======= // 声明当前文件所在的包路径,在 Java 项目里,包用于组织和管理代码,此包路径为 com.config,有助于将相关的配置类集中管理,避免命名冲突 package com.config; @@ -29,4 +55,5 @@ public class MybatisPlusConfig { // - 性能分析插件 // - 乐观锁插件 // - SQL注入器等 -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/CommonController.java b/src/main/java/com/controller/CommonController.java index 0ab38b3..7008b5e 100644 --- a/src/main/java/com/controller/CommonController.java +++ b/src/main/java/com/controller/CommonController.java @@ -1,3 +1,25 @@ +<<<<<<< HEAD +package com.controller; + +import java.io.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.*; + +import javax.servlet.http.HttpServletRequest; + +import com.alibaba.fastjson.JSON; +import com.utils.StringUtil; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.util.ResourceUtils; +======= // 声明当前文件所在的包路径 package com.controller; @@ -31,12 +53,24 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.ResourceUtils; // 导入Spring MVC注解 +>>>>>>> develop 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; +<<<<<<< HEAD +import com.annotation.IgnoreAuth; +import com.baidu.aip.face.AipFace; +import com.baidu.aip.face.MatchRequest; +import com.baidu.aip.util.Base64Util; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.mapper.Wrapper; +import com.entity.ConfigEntity; +import com.service.CommonService; +import com.service.ConfigService; +======= // 导入自定义注解 import com.annotation.IgnoreAuth; // 导入百度AI相关类 @@ -52,10 +86,19 @@ import com.entity.ConfigEntity; import com.service.CommonService; import com.service.ConfigService; // 导入工具类 +>>>>>>> develop import com.utils.BaiduUtil; import com.utils.FileUtil; import com.utils.R; +<<<<<<< HEAD +/** + * 通用接口 + */ +@RestController +public class CommonController { + private static final Logger logger = LoggerFactory.getLogger(CommonController.class); +======= //通用接口控制器 //提供系统通用的各种功能接口 @@ -65,10 +108,55 @@ public class CommonController { private static final Logger logger = LoggerFactory.getLogger(CommonController.class); // 自动注入通用服务 +>>>>>>> develop @Autowired private CommonService commonService; +<<<<<<< HEAD + /** + * Java代码实现MySQL数据库导出 + * + * @param mysqlUrl MySQL安装路径 + * @param hostIP MySQL数据库所在服务器地址IP + * @param userName 进入数据库所需要的用户名 + * @param hostPort 数据库端口 + * @param password 进入数据库所需要的密码 + * @param savePath 数据库文件保存路径 + * @param fileName 数据库导出文件文件名 + * @param databaseName 要导出的数据库名 + * @return 返回true表示导出成功,否则返回false。 + */ + @IgnoreAuth + @RequestMapping("/beifen") + public R beifen(String mysqlUrl, String hostIP, String userName, String hostPort, String password, String savePath, String fileName, String databaseName) { + File saveFile = new File(savePath); + if (!saveFile.exists()) {// 如果目录不存在  + saveFile.mkdirs();// 创建文件夹  + } + if (!savePath.endsWith(File.separator)) { + savePath = savePath + File.separator; + } + PrintWriter printWriter = null; + BufferedReader bufferedReader = null; + try { + Runtime runtime = Runtime.getRuntime(); + String cmd = mysqlUrl + "mysqldump -h" + hostIP + " -u" + userName + " -P" + hostPort + " -p" + password + " " + databaseName; + runtime.exec(cmd); + Process process = runtime.exec(cmd); + InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), "utf8"); + bufferedReader = new BufferedReader(inputStreamReader); + printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(savePath + fileName), "utf8")); + String line; + while ((line = bufferedReader.readLine()) != null) { + printWriter.println(line); + } + printWriter.flush(); + } catch (Exception e) { + e.printStackTrace(); + return R.error("备份数据出错"); + } finally { +======= // * MySQL数据库备份接口 // * @param mysqlUrl MySQL安装路径 // * @param hostIP 数据库服务器IP @@ -131,6 +219,7 @@ public class CommonController { return R.error("备份数据出错"); } finally { // 在finally块中确保资源关闭 +>>>>>>> develop try { if (bufferedReader != null) { bufferedReader.close(); @@ -142,6 +231,42 @@ public class CommonController { e.printStackTrace(); } } +<<<<<<< HEAD + return R.ok(); + } + + /** + * Java实现MySQL数据库导入 + * + * @param mysqlUrl MySQL安装路径 + * @param hostIP MySQL数据库所在服务器地址IP + * @param userName 进入数据库所需要的用户名 + * @param hostPort 数据库端口 + * @param password 进入数据库所需要的密码 + * @param savePath 数据库文件保存路径 + * @param fileName 数据库导出文件文件名 + * @param databaseName 要导出的数据库名 + */ + @IgnoreAuth + @RequestMapping("/huanyuan") + public R huanyuan(String mysqlUrl, String hostIP, String userName, String hostPort, String password, String savePath, String fileName, String databaseName) { + try { + Runtime rt = Runtime.getRuntime(); + Process child1 = rt.exec(mysqlUrl+"mysql.exe -h" + hostIP + " -u" + userName + " -P" + hostPort + " -p" + password + " " + databaseName); + OutputStream out = child1.getOutputStream();//控制台的输入信息作为输出流 + String inStr; + StringBuffer sb = new StringBuffer(""); + String outStr; + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(savePath+"/"+fileName), "utf-8")); + while ((inStr = br.readLine()) != null) { + sb.append(inStr + "\r\n"); + } + outStr = sb.toString(); + OutputStreamWriter writer = new OutputStreamWriter(out, "utf8"); + writer.write(outStr); +// 注:这里如果用缓冲方式写入文件的话,会导致中文乱码,用flush()方法则可以避免 + writer.flush(); +======= // 返回成功结果 return R.ok(); } @@ -191,20 +316,100 @@ public class CommonController { writer.flush(); // 关闭资源 +>>>>>>> develop out.close(); br.close(); writer.close(); } catch (Exception e) { +<<<<<<< HEAD + e.printStackTrace(); + return R.error("数据导入出错"); + } +======= // 打印异常堆栈 e.printStackTrace(); // 返回错误信息 return R.error("数据导入出错"); } // 返回成功结果 +>>>>>>> develop return R.ok(); } +<<<<<<< HEAD + /** + * 饼状图求和 + * @return + */ + @RequestMapping("/pieSum") + public R pieSum(@RequestParam Map params) { + logger.debug("饼状图求和:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.pieSum(params); + return R.ok().put("data", result); + } + + /** + * 饼状图统计 + * @return + */ + @RequestMapping("/pieCount") + public R pieCount(@RequestParam Map params) { + logger.debug("饼状图统计:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.pieCount(params); + return R.ok().put("data", result); + } + + /** + * 柱状图求和单列 + * @return + */ + @RequestMapping("/barSumOne") + public R barSumOne(@RequestParam Map params) { + logger.debug("柱状图求和单列:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.barSumOne(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add(""); + for(Map map :result){ + String oneValue = String.valueOf(map.get("name")); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } + Map resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } + /** + * 柱状图统计单列 + * @return + */ + @RequestMapping("/barCountOne") + public R barCountOne(@RequestParam Map params) { + logger.debug("柱状图统计单列:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.barCountOne(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add(""); + for(Map map :result){ + String oneValue = String.valueOf(map.get("name")); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } +======= // * 饼状图求和接口 //* @param params 请求参数Map // * @return 包含求和结果的响应 @@ -264,10 +469,476 @@ public class CommonController { } // 构建结果Map +>>>>>>> develop + Map resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); +<<<<<<< HEAD + return R.ok().put("data", resultMap); + } + + /** + * 柱状图统计双列 + * @return + */ + @RequestMapping("/barSumTwo") + public R barSumTwo(@RequestParam Map params) { + logger.debug("柱状图统计双列:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.barSumTwo(params); + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + Map> dataMap = new LinkedHashMap<>(); + for(Map map :result){ + String name1Value = String.valueOf(map.get("name1")); + String name2Value = String.valueOf(map.get("name2")); + String value = String.valueOf(map.get("value")); + if(!legend.contains(name2Value)){ + legend.add(name2Value);//添加完成后 就是最全的第二列的类型 + } + if(dataMap.containsKey(name1Value)){ + dataMap.get(name1Value).put(name2Value,value); + }else{ + HashMap name1Data = new HashMap<>(); + name1Data.put(name2Value,value); + dataMap.put(name1Value,name1Data); + } + + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i data = yAxis.get(i); + if(StringUtil.isNotEmpty(map.get(legend.get(i)))){ + data.add(map.get(legend.get(i))); + }else{ + data.add("0"); + } + } + } + System.out.println(); + + Map resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } + /** + * 柱状图统计双列 + * @return + */ + @RequestMapping("/barCountTwo") + public R barCountTwo(@RequestParam Map params) { + logger.debug("柱状图统计双列:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.barCountTwo(params); + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + Map> dataMap = new LinkedHashMap<>(); + for(Map map :result){ + String name1Value = String.valueOf(map.get("name1")); + String name2Value = String.valueOf(map.get("name2")); + String value = String.valueOf(map.get("value")); + if(!legend.contains(name2Value)){ + legend.add(name2Value);//添加完成后 就是最全的第二列的类型 + } + if(dataMap.containsKey(name1Value)){ + dataMap.get(name1Value).put(name2Value,value); + }else{ + HashMap name1Data = new HashMap<>(); + name1Data.put(name2Value,value); + dataMap.put(name1Value,name1Data); + } + + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i data = yAxis.get(i); + if(StringUtil.isNotEmpty(map.get(legend.get(i)))){ + data.add(map.get(legend.get(i))); + }else{ + data.add("0"); + } + } + } + System.out.println(); + + Map resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } + + /** + tableName 查询表 + condition1 条件1 + condition1Value 条件1值 + average 计算平均评分 + + 取值 + 有值 Number(res.data.value.toFixed(1)) + 无值 if(res.data){} + * */ + @IgnoreAuth + @RequestMapping("/queryScore") + public R queryScore(@RequestParam Map params) { + logger.debug("queryScore:,,Controller:{},,params:{}",this.getClass().getName(),params); + Map queryScore = commonService.queryScore(params); + return R.ok().put("data", queryScore); + } + + /** + * 查询字典表的分组统计总条数 + * tableName 表名 + * groupColumn 分组字段 + * @return + */ + @RequestMapping("/newSelectGroupCount") + public R newSelectGroupCount(@RequestParam Map params) { + logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.newSelectGroupCount(params); + return R.ok().put("data", result); + } + + /** + * 查询字典表的分组求和 + * tableName 表名 + * groupColumn 分组字段 + * sumCloum 统计字段 + * @return + */ + @RequestMapping("/newSelectGroupSum") + public R newSelectGroupSum(@RequestParam Map params) { + logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> result = commonService.newSelectGroupSum(params); + return R.ok().put("data", result); + } + + /** + * 柱状图求和 老的 + */ + @RequestMapping("/barSum") + public R barSum(@RequestParam Map params) { + logger.debug("barSum方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params)); + Boolean isJoinTableFlag = false;//是否有级联表相关 + String one = "";//第一优先 + String two = "";//第二优先 + + //处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组 + //当前表 + Map thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class); + params.put("thisTable",thisTable); + + //级联表 + String joinTableString = String.valueOf(params.get("joinTable")); + if(StringUtil.isNotEmpty(joinTableString)) { + Map joinTable = JSON.parseObject(joinTableString, Map.class); + params.put("joinTable", joinTable); + isJoinTableFlag = true; + } + + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期 + thisTable.put("date",String.valueOf(thisTable.get("date")).split(",")); + one = "thisDate0"; + } + if(isJoinTableFlag){//级联表日期 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){ + joinTable.put("date",String.valueOf(joinTable.get("date")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinDate0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinDate0"; + } + } + } + } + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串 + thisTable.put("string",String.valueOf(thisTable.get("string")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="thisString0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="thisString0"; + } + } + } + if(isJoinTableFlag){//级联表字符串 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){ + joinTable.put("string",String.valueOf(joinTable.get("string")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinString0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinString0"; + } + } + } + } + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型 + thisTable.put("types",String.valueOf(thisTable.get("types")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="thisTypes0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="thisTypes0"; + } + } + } + if(isJoinTableFlag){//级联表类型 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){ + joinTable.put("types",String.valueOf(joinTable.get("types")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinTypes0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinTypes0"; + } + } + + } + } + + List> result = commonService.barSum(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + if(StringUtil.isEmpty(two)){//不包含第二列 + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add(""); + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } + }else{//包含第二列 + Map> dataMap = new LinkedHashMap<>(); + if(StringUtil.isNotEmpty(two)){ + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String twoValue = String.valueOf(map.get(two)); + String value = String.valueOf(map.get("value")); + if(!legend.contains(twoValue)){ + legend.add(twoValue);//添加完成后 就是最全的第二列的类型 + } + if(dataMap.containsKey(oneValue)){ + dataMap.get(oneValue).put(twoValue,value); + }else{ + HashMap oneData = new HashMap<>(); + oneData.put(twoValue,value); + dataMap.put(oneValue,oneData); + } + + } + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i data = yAxis.get(i); + if(StringUtil.isNotEmpty(map.get(legend.get(i)))){ + data.add(map.get(legend.get(i))); + }else{ + data.add("0"); + } + } + } + System.out.println(); + } + + Map resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } + + /** + * 柱状图统计 老的 + */ + @RequestMapping("/barCount") + public R barCount(@RequestParam Map params) { + logger.debug("barCount方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params)); + Boolean isJoinTableFlag = false;//是否有级联表相关 + String one = "";//第一优先 + String two = "";//第二优先 + + //处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组 + //当前表 + Map thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class); + params.put("thisTable",thisTable); + + //级联表 + String joinTableString = String.valueOf(params.get("joinTable")); + if(StringUtil.isNotEmpty(joinTableString)) { + Map joinTable = JSON.parseObject(joinTableString, Map.class); + params.put("joinTable", joinTable); + isJoinTableFlag = true; + } + + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期 + thisTable.put("date",String.valueOf(thisTable.get("date")).split(",")); + one = "thisDate0"; + } + if(isJoinTableFlag){//级联表日期 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){ + joinTable.put("date",String.valueOf(joinTable.get("date")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinDate0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinDate0"; + } + } + } + } + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串 + thisTable.put("string",String.valueOf(thisTable.get("string")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="thisString0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="thisString0"; + } + } + } + if(isJoinTableFlag){//级联表字符串 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){ + joinTable.put("string",String.valueOf(joinTable.get("string")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinString0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinString0"; + } + } + } + } + if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型 + thisTable.put("types",String.valueOf(thisTable.get("types")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="thisTypes0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="thisTypes0"; + } + } + } + if(isJoinTableFlag){//级联表类型 + Map joinTable = (Map) params.get("joinTable"); + if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){ + joinTable.put("types",String.valueOf(joinTable.get("types")).split(",")); + if(StringUtil.isEmpty(one)){ + one ="joinTypes0"; + }else{ + if(StringUtil.isEmpty(two)){ + two ="joinTypes0"; + } + } + + } + } + + List> result = commonService.barCount(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + if(StringUtil.isEmpty(two)){//不包含第二列 + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add(""); + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } + }else{//包含第二列 + Map> dataMap = new LinkedHashMap<>(); + if(StringUtil.isNotEmpty(two)){ + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String twoValue = String.valueOf(map.get(two)); + String value = String.valueOf(map.get("value")); + if(!legend.contains(twoValue)){ + legend.add(twoValue);//添加完成后 就是最全的第二列的类型 + } + if(dataMap.containsKey(oneValue)){ + dataMap.get(oneValue).put(twoValue,value); + }else{ + HashMap oneData = new HashMap<>(); + oneData.put(twoValue,value); + dataMap.put(oneValue,oneData); + } + + } + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i data = yAxis.get(i); + if(StringUtil.isNotEmpty(map.get(legend.get(i)))){ + data.add(map.get(legend.get(i))); + }else{ + data.add("0"); + } + } + } + System.out.println(); + } + Map resultMap = new HashMap<>(); resultMap.put("xAxis",xAxis); resultMap.put("yAxis",yAxis); resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } +} +======= // 返回成功结果和数据 return R.ok().put("data", resultMap); } @@ -288,4 +959,5 @@ public class CommonController { // - 返回值说明 // - 关键处理逻辑说明 // - 异常处理说明 -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/ConfigController.java b/src/main/java/com/controller/ConfigController.java index 86604be..97a65cd 100644 --- a/src/main/java/com/controller/ConfigController.java +++ b/src/main/java/com/controller/ConfigController.java @@ -1,3 +1,116 @@ +<<<<<<< HEAD + +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 params,ConfigEntity config){ + EntityWrapper ew = new EntityWrapper(); + PageUtils page = configService.queryPage(params); + return R.ok().put("data", page); + } + + /** + * 列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params,ConfigEntity config){ + EntityWrapper ew = new EntityWrapper(); + 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().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(); + } +} +======= package com.controller; import java.util.Arrays; // 导入Java的Arrays类,用于操作数组 @@ -97,3 +210,4 @@ public class ConfigController { } } +>>>>>>> develop diff --git a/src/main/java/com/controller/DictionaryController.java b/src/main/java/com/controller/DictionaryController.java index 3cabcbc..5b97e81 100644 --- a/src/main/java/com/controller/DictionaryController.java +++ b/src/main/java/com/controller/DictionaryController.java @@ -1,3 +1,274 @@ +<<<<<<< HEAD + +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); + + private static final String TABLE_NAME = "dictionary"; + + @Autowired + private DictionaryService dictionaryService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + @IgnoreAuth + public R page(@RequestParam Map params, HttpServletRequest request){ + logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + CommonUtil.checkMap(params); + PageUtils page = dictionaryService.queryPage(params); + + //字典表数据转换 + List list =(List)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 queryWrapper = new EntityWrapper() + .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 dictionaryEntities = dictionaryService.selectList(new EntityWrapper()); + ServletContext servletContext = request.getServletContext(); + Map> map = new HashMap<>(); + for(DictionaryEntity d :dictionaryEntities){ + Map 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) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); + DictionaryEntity oldDictionaryEntity = dictionaryService.selectById(dictionary.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); + + dictionaryService.updateById(dictionary);//根据id更新 + //如果字典表修改数据的话,把数据再重新查出,放入监听器中 + List dictionaryEntities = dictionaryService.selectList(new EntityWrapper()); + ServletContext servletContext = request.getServletContext(); + Map> map = new HashMap<>(); + for(DictionaryEntity d :dictionaryEntities){ + Map 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(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldDictionaryList =dictionaryService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + 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 descs = new ArrayList<>(); + descs.add("code_index"); + Wrapper queryWrapper = new EntityWrapper() + .eq("dic_code", dictionary.getDicCode()) + .orderDesc(descs); + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + List dictionaryEntityList = dictionaryService.selectList(queryWrapper); + if(dictionaryEntityList.size()>0 ){ + return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1); + }else{ + return R.ok().put("maxCodeIndex",1); + } + } + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List dictionaryList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List 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(); +======= package com.controller; // 文件操作相关类 import java.io.File; @@ -274,12 +545,26 @@ public class DictionaryController { } dictionaryService.insertBatch(dictionaryList); // 批量插入数据 return R.ok(); // 返回成功响应 +>>>>>>> develop } } } }catch (Exception e){ +<<<<<<< HEAD + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); + } + } + + + + +} + +======= e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误响应 } } } +>>>>>>> develop diff --git a/src/main/java/com/controller/FileController.java b/src/main/java/com/controller/FileController.java index b588286..70c3d57 100644 --- a/src/main/java/com/controller/FileController.java +++ b/src/main/java/com/controller/FileController.java @@ -1,3 +1,114 @@ +<<<<<<< HEAD +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().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 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(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED); + } + } catch (IOException e) { + e.printStackTrace(); + } + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + +======= package com.controller; // 定义包路径 // 文件操作相关类 @@ -156,4 +267,5 @@ public class FileController{ // 返回服务器错误响应 return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } +>>>>>>> develop } diff --git a/src/main/java/com/controller/ForumController.java b/src/main/java/com/controller/ForumController.java index 878fced..a795ef1 100644 --- a/src/main/java/com/controller/ForumController.java +++ b/src/main/java/com/controller/ForumController.java @@ -1,3 +1,45 @@ +<<<<<<< HEAD + +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 +*/ +======= package com.controller;// 定义包路径,表示该文件位于com.controller包下 import java.io.File; // 导入文件操作类 @@ -37,12 +79,115 @@ import com.alibaba.fastjson.*; // 导入FastJSON相关类 //@author //@email +>>>>>>> develop @RestController @Controller @RequestMapping("/forum") public class ForumController { private static final Logger logger = LoggerFactory.getLogger(ForumController.class); +<<<<<<< HEAD + private static final String TABLE_NAME = "forum"; + + @Autowired + private ForumService forumService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map params, HttpServletRequest request){ + logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + CommonUtil.checkMap(params); + PageUtils page = forumService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(ForumView 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); + ForumEntity forum = forumService.selectById(id); + if(forum !=null){ + //entity转view + ForumView view = new ForumView(); + BeanUtils.copyProperties( forum , view );//把实体数据重构到view中 + //级联表 用户 + //级联表 + YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" +, "jiaolianId" +, "usersId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表 + view.setYonghuId(yonghu.getId()); + } + //级联表 教练 + //级联表 + JiaolianEntity jiaolian = jiaolianService.selectById(forum.getJiaolianId()); + if(jiaolian != null){ + BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" +, "jiaolianId" +, "usersId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表 + view.setJiaolianId(jiaolian.getId()); + } + //级联表 管理员 + //管理员表做额外的处理 + UsersEntity users = usersService.selectById(forum.getUsersId()); + if(users != null){ + view.setUsersId(users.getId()); + view.setUusername(users.getUsername()); + view.setUpassword(users.getPassword()); + view.setUrole(users.getRole()); + view.setUaddtime(users.getAddtime()); + } + //修改对应字典表字段 + dictionaryService.dictionaryConvert(view, request); + return R.ok().put("data", view); + }else { + return R.error(511,"查不到数据"); + } + + } + + /** + * 后端保存 + */ +======= private static final String TABLE_NAME = "forum"; // 数据库表名 @Autowired @@ -134,10 +279,80 @@ public class ForumController { //后端保存 +>>>>>>> develop @RequestMapping("/save") public R save(@RequestBody ForumEntity forum, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); +<<<<<<< HEAD + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + else if("用户".equals(role)) + forum.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + else if("教练".equals(role)) + forum.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + else if("管理员".equals(role)) + forum.setUsersId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + Wrapper queryWrapper = new EntityWrapper() + .eq("forum_name", forum.getForumName()) + .eq("yonghu_id", forum.getYonghuId()) + .eq("jiaolian_id", forum.getJiaolianId()) + .eq("users_id", forum.getUsersId()) + .eq("super_ids", forum.getSuperIds()) + .eq("forum_state_types", forum.getForumStateTypes()) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + ForumEntity forumEntity = forumService.selectOne(queryWrapper); + if(forumEntity==null){ + forum.setInsertTime(new Date()); + forum.setCreateTime(new Date()); + forumService.insert(forum); + return R.ok(); + }else { + return R.error(511,"表中有相同数据"); + } + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody ForumEntity forum, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); + ForumEntity oldForumEntity = forumService.selectById(forum.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); +// else if("用户".equals(role)) +// forum.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); +// else if("教练".equals(role)) +// forum.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); +// else if("管理员".equals(role)) +// forum.setUsersId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + if("".equals(forum.getForumContent()) || "null".equals(forum.getForumContent())){ + forum.setForumContent(null); + } + forum.setUpdateTime(new Date()); + + forumService.updateById(forum);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldForumList =forumService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + forumService.deleteBatchIds(Arrays.asList(ids)); +======= String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 if(false) return R.error(511,"永远不会进入"); @@ -193,11 +408,62 @@ public class ForumController { logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); List oldForumList =forumService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 forumService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 +>>>>>>> develop return R.ok(); } +<<<<<<< HEAD + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List forumList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + ForumEntity forumEntity = new ForumEntity(); +// forumEntity.setForumName(data.get(0)); //帖子标题 要改的 +// forumEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的 +// forumEntity.setJiaolianId(Integer.valueOf(data.get(0))); //教练 要改的 +// forumEntity.setUsersId(Integer.valueOf(data.get(0))); //管理员 要改的 +// forumEntity.setForumContent("");//详情和图片 +// forumEntity.setSuperIds(Integer.valueOf(data.get(0))); //父id 要改的 +// forumEntity.setForumStateTypes(Integer.valueOf(data.get(0))); //帖子状态 要改的 +// forumEntity.setInsertTime(date);//时间 +// forumEntity.setUpdateTime(sdf.parse(data.get(0))); //修改时间 要改的 +// forumEntity.setCreateTime(date);//时间 + forumList.add(forumEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 +======= //批量上传 @RequestMapping("/batchInsert") public R save( String fileName, HttpServletRequest request){ @@ -229,6 +495,7 @@ public class ForumController { forumList.add(forumEntity); // 添加到列表 } // 批量插入数据 +>>>>>>> develop forumService.insertBatch(forumList); return R.ok(); } @@ -236,6 +503,19 @@ public class ForumController { } }catch (Exception e){ e.printStackTrace(); +<<<<<<< HEAD + return R.error(511,"批量插入数据异常,请联系管理员"); + } + } + + + + + /** + * 前端列表 + */ + @IgnoreAuth +======= return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 } } @@ -243,10 +523,74 @@ public class ForumController { // 前端列表 @IgnoreAuth // 忽略认证 +>>>>>>> develop @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); +<<<<<<< HEAD + CommonUtil.checkMap(params); + PageUtils page = forumService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(ForumView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + ForumEntity forum = forumService.selectById(id); + if(forum !=null){ + + + //entity转view + ForumView view = new ForumView(); + BeanUtils.copyProperties( forum , view );//把实体数据重构到view中 + + //级联表 + YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" +, "jiaolianId" +, "usersId"});//把级联的数据添加到view中,并排除id和创建时间字段 + view.setYonghuId(yonghu.getId()); + } + //级联表 + JiaolianEntity jiaolian = jiaolianService.selectById(forum.getJiaolianId()); + if(jiaolian != null){ + BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" +, "jiaolianId" +, "usersId"});//把级联的数据添加到view中,并排除id和创建时间字段 + view.setJiaolianId(jiaolian.getId()); + } + UsersEntity users = usersService.selectById(forum.getUsersId()); + if(users != null){ + view.setUsersId(users.getId()); + view.setUusername(users.getUsername()); + view.setUpassword(users.getPassword()); + view.setUrole(users.getRole()); + view.setUaddtime(users.getAddtime()); + } + //修改对应字典表字段 + dictionaryService.dictionaryConvert(view, request); + return R.ok().put("data", view); + }else { + return R.error(511,"查不到数据"); + } + } + + + /** + * 前端保存 + */ +======= CommonUtil.checkMap(params); // 检查参数 PageUtils page = forumService.queryPage(params); // 查询分页数据 @@ -304,10 +648,36 @@ public class ForumController { //前端保存 +>>>>>>> develop @RequestMapping("/add") public R add(@RequestBody ForumEntity forum, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); Wrapper queryWrapper = new EntityWrapper() +<<<<<<< HEAD + .eq("forum_name", forum.getForumName()) + .eq("yonghu_id", forum.getYonghuId()) + .eq("jiaolian_id", forum.getJiaolianId()) + .eq("users_id", forum.getUsersId()) + .eq("super_ids", forum.getSuperIds()) + .eq("forum_state_types", forum.getForumStateTypes()) +// .notIn("forum_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + ForumEntity forumEntity = forumService.selectOne(queryWrapper); + if(forumEntity==null){ + forum.setInsertTime(new Date()); + forum.setCreateTime(new Date()); + forumService.insert(forum); + + return R.ok(); + }else { + return R.error(511,"表中有相同数据"); + } + } + +} + +======= .eq("forum_name", forum.getForumName()) // 帖子标题 .eq("yonghu_id", forum.getYonghuId()) // 用户ID .eq("jiaolian_id", forum.getJiaolianId()) // 教练ID @@ -327,4 +697,5 @@ public class ForumController { return R.error(511,"表中有相同数据"); // 数据已存在返回错误 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengCollectionController.java b/src/main/java/com/controller/JianshenkechengCollectionController.java index ee017fe..0a39ed0 100644 --- a/src/main/java/com/controller/JianshenkechengCollectionController.java +++ b/src/main/java/com/controller/JianshenkechengCollectionController.java @@ -1,3 +1,250 @@ +<<<<<<< HEAD + +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("/jianshenkechengCollection") +public class JianshenkechengCollectionController { + private static final Logger logger = LoggerFactory.getLogger(JianshenkechengCollectionController.class); + + private static final String TABLE_NAME = "jianshenkechengCollection"; + + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengCollectionService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengCollectionView 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); + JianshenkechengCollectionEntity jianshenkechengCollection = jianshenkechengCollectionService.selectById(id); + if(jianshenkechengCollection !=null){ + //entity转view + JianshenkechengCollectionView view = new JianshenkechengCollectionView(); + BeanUtils.copyProperties( jianshenkechengCollection , view );//把实体数据重构到view中 + //级联表 健身课程 + //级联表 + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengCollection.getJianshenkechengId()); + if(jianshenkecheng != null){ + BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表 + view.setJianshenkechengId(jianshenkecheng.getId()); + } + //级联表 用户 + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jianshenkechengCollection.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request){ + logger.debug("save方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); + + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + else if("用户".equals(role)) + jianshenkechengCollection.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + Wrapper queryWrapper = new EntityWrapper() + .eq("jianshenkecheng_id", jianshenkechengCollection.getJianshenkechengId()) + .eq("yonghu_id", jianshenkechengCollection.getYonghuId()) + .eq("jianshenkecheng_collection_types", jianshenkechengCollection.getJianshenkechengCollectionTypes()) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JianshenkechengCollectionEntity jianshenkechengCollectionEntity = jianshenkechengCollectionService.selectOne(queryWrapper); + if(jianshenkechengCollectionEntity==null){ + jianshenkechengCollection.setInsertTime(new Date()); + jianshenkechengCollection.setCreateTime(new Date()); + jianshenkechengCollectionService.insert(jianshenkechengCollection); + return R.ok(); + }else { + return R.error(511,"表中有相同数据"); + } + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); + JianshenkechengCollectionEntity oldJianshenkechengCollectionEntity = jianshenkechengCollectionService.selectById(jianshenkechengCollection.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); +// else if("用户".equals(role)) +// jianshenkechengCollection.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + jianshenkechengCollectionService.updateById(jianshenkechengCollection);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldJianshenkechengCollectionList =jianshenkechengCollectionService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + jianshenkechengCollectionService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List jianshenkechengCollectionList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + JianshenkechengCollectionEntity jianshenkechengCollectionEntity = new JianshenkechengCollectionEntity(); +// jianshenkechengCollectionEntity.setJianshenkechengId(Integer.valueOf(data.get(0))); //健身课程 要改的 +// jianshenkechengCollectionEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的 +// jianshenkechengCollectionEntity.setJianshenkechengCollectionTypes(Integer.valueOf(data.get(0))); //类型 要改的 +// jianshenkechengCollectionEntity.setInsertTime(date);//时间 +// jianshenkechengCollectionEntity.setCreateTime(date);//时间 + jianshenkechengCollectionList.add(jianshenkechengCollectionEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 + jianshenkechengCollectionService.insertBatch(jianshenkechengCollectionList); + return R.ok(); +======= package com.controller; // 定义包路径,表示该文件位于com.controller包下 import java.io.File; // 导入文件操作类 @@ -212,16 +459,107 @@ public class JianshenkechengCollectionController { // 批量插入数据 jianshenkechengCollectionService.insertBatch(jianshenkechengCollectionList); return R.ok(); // 返回成功 +>>>>>>> develop } } } }catch (Exception e){ +<<<<<<< HEAD + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); +======= e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 +>>>>>>> develop + } + } + + +<<<<<<< HEAD + + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengCollectionService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengCollectionView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + JianshenkechengCollectionEntity jianshenkechengCollection = jianshenkechengCollectionService.selectById(id); + if(jianshenkechengCollection !=null){ + + + //entity转view + JianshenkechengCollectionView view = new JianshenkechengCollectionView(); + BeanUtils.copyProperties( jianshenkechengCollection , view );//把实体数据重构到view中 + + //级联表 + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengCollection.getJianshenkechengId()); + if(jianshenkecheng != null){ + BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段 + view.setJianshenkechengId(jianshenkecheng.getId()); + } + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jianshenkechengCollection.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request){ + logger.debug("add方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); + Wrapper queryWrapper = new EntityWrapper() + .eq("jianshenkecheng_id", jianshenkechengCollection.getJianshenkechengId()) + .eq("yonghu_id", jianshenkechengCollection.getYonghuId()) + .eq("jianshenkecheng_collection_types", jianshenkechengCollection.getJianshenkechengCollectionTypes()) +// .notIn("jianshenkecheng_collection_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JianshenkechengCollectionEntity jianshenkechengCollectionEntity = jianshenkechengCollectionService.selectOne(queryWrapper); + if(jianshenkechengCollectionEntity==null){ + jianshenkechengCollection.setInsertTime(new Date()); + jianshenkechengCollection.setCreateTime(new Date()); + jianshenkechengCollectionService.insert(jianshenkechengCollection); + + return R.ok(); + }else { + return R.error(511,"您已经收藏过了"); } } +} +======= //前端列表 @IgnoreAuth // 忽略认证 @RequestMapping("/list") // 处理列表请求 @@ -292,4 +630,5 @@ public class JianshenkechengCollectionController { return R.error(511,"您已经收藏过了"); // 已经收藏过返回错误 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengController.java b/src/main/java/com/controller/JianshenkechengController.java index 299fba0..d17b73c 100644 --- a/src/main/java/com/controller/JianshenkechengController.java +++ b/src/main/java/com/controller/JianshenkechengController.java @@ -1,3 +1,277 @@ +<<<<<<< HEAD + +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("/jianshenkecheng") +public class JianshenkechengController { + private static final Logger logger = LoggerFactory.getLogger(JianshenkechengController.class); + + private static final String TABLE_NAME = "jianshenkecheng"; + + @Autowired + private JianshenkechengService jianshenkechengService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengView 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); + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(id); + if(jianshenkecheng !=null){ + //entity转view + JianshenkechengView view = new JianshenkechengView(); + BeanUtils.copyProperties( jianshenkecheng , view );//把实体数据重构到view中 + //级联表 教练 + //级联表 + JiaolianEntity jiaolian = jiaolianService.selectById(jianshenkecheng.getJiaolianId()); + if(jiaolian != null){ + BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "jiaolianId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表 + view.setJiaolianId(jiaolian.getId()); + } + //修改对应字典表字段 + dictionaryService.dictionaryConvert(view, request); + return R.ok().put("data", view); + }else { + return R.error(511,"查不到数据"); + } + + } + + /** + * 后端保存 + */ + @RequestMapping("/save") + public R save(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request){ + logger.debug("save方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); + + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + else if("教练".equals(role)) + jianshenkecheng.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + Wrapper queryWrapper = new EntityWrapper() + .eq("jiaolian_id", jianshenkecheng.getJiaolianId()) + .eq("jianshenkecheng_name", jianshenkecheng.getJianshenkechengName()) + .eq("jianshenkecheng_video", jianshenkecheng.getJianshenkechengVideo()) + .eq("zan_number", jianshenkecheng.getZanNumber()) + .eq("cai_number", jianshenkecheng.getCaiNumber()) + .eq("jianshenkecheng_types", jianshenkecheng.getJianshenkechengTypes()) + .eq("data_delete", 1) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JianshenkechengEntity jianshenkechengEntity = jianshenkechengService.selectOne(queryWrapper); + if(jianshenkechengEntity==null){ + jianshenkecheng.setZanNumber(1); + jianshenkecheng.setCaiNumber(1); + jianshenkecheng.setJianshenkechengClicknum(1); + jianshenkecheng.setDataDelete(1); + jianshenkecheng.setInsertTime(new Date()); + jianshenkecheng.setCreateTime(new Date()); + jianshenkechengService.insert(jianshenkecheng); + return R.ok(); + }else { + return R.error(511,"表中有相同数据"); + } + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); + JianshenkechengEntity oldJianshenkechengEntity = jianshenkechengService.selectById(jianshenkecheng.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); +// else if("教练".equals(role)) +// jianshenkecheng.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + if("".equals(jianshenkecheng.getJianshenkechengPhoto()) || "null".equals(jianshenkecheng.getJianshenkechengPhoto())){ + jianshenkecheng.setJianshenkechengPhoto(null); + } + if("".equals(jianshenkecheng.getJianshenkechengVideo()) || "null".equals(jianshenkecheng.getJianshenkechengVideo())){ + jianshenkecheng.setJianshenkechengVideo(null); + } + if("".equals(jianshenkecheng.getJianshenkechengContent()) || "null".equals(jianshenkecheng.getJianshenkechengContent())){ + jianshenkecheng.setJianshenkechengContent(null); + } + + jianshenkechengService.updateById(jianshenkecheng);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldJianshenkechengList =jianshenkechengService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + ArrayList list = new ArrayList<>(); + for(Integer id:ids){ + JianshenkechengEntity jianshenkechengEntity = new JianshenkechengEntity(); + jianshenkechengEntity.setId(id); + jianshenkechengEntity.setDataDelete(2); + list.add(jianshenkechengEntity); + } + if(list != null && list.size() >0){ + jianshenkechengService.updateBatchById(list); + } + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List jianshenkechengList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + JianshenkechengEntity jianshenkechengEntity = new JianshenkechengEntity(); +// jianshenkechengEntity.setJiaolianId(Integer.valueOf(data.get(0))); //教练 要改的 +// jianshenkechengEntity.setJianshenkechengName(data.get(0)); //健身课程名称 要改的 +// jianshenkechengEntity.setJianshenkechengPhoto("");//详情和图片 +// jianshenkechengEntity.setJianshenkechengVideo(data.get(0)); //课程视频 要改的 +// jianshenkechengEntity.setZanNumber(Integer.valueOf(data.get(0))); //赞 要改的 +// jianshenkechengEntity.setCaiNumber(Integer.valueOf(data.get(0))); //踩 要改的 +// jianshenkechengEntity.setJianshenkechengTypes(Integer.valueOf(data.get(0))); //健身课程类型 要改的 +// jianshenkechengEntity.setJianshenkechengClicknum(Integer.valueOf(data.get(0))); //健身课程热度 要改的 +// jianshenkechengEntity.setJianshenkechengContent("");//详情和图片 +// jianshenkechengEntity.setDataDelete(1);//逻辑删除字段 +// jianshenkechengEntity.setInsertTime(date);//时间 +// jianshenkechengEntity.setCreateTime(date);//时间 + jianshenkechengList.add(jianshenkechengEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 + jianshenkechengService.insertBatch(jianshenkechengList); + return R.ok(); +======= package com.controller; // 声明包路径,表示该文件位于com.controller包下 import java.io.File; // 导入文件操作类 @@ -234,16 +508,177 @@ public class JianshenkechengController { // 批量插入数据 jianshenkechengService.insertBatch(jianshenkechengList); return R.ok(); // 返回成功 +>>>>>>> develop } } } }catch (Exception e){ +<<<<<<< HEAD + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); +======= e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 +>>>>>>> develop + } + } + + +<<<<<<< HEAD + + /** + * 个性推荐 + */ + @IgnoreAuth + @RequestMapping("/gexingtuijian") + public R gexingtuijian(@RequestParam Map params, HttpServletRequest request){ + logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + CommonUtil.checkMap(params); + List returnJianshenkechengViewList = new ArrayList<>(); + + //查看收藏 + Map params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId")); + params1.put("shangxiaTypes",1); + params1.put("jianshenkechengYesnoTypes",2); + PageUtils pageUtils = jianshenkechengCollectionService.queryPage(params1); + List collectionViewsList =(List)pageUtils.getList(); + Map typeMap=new HashMap<>();//购买的类型list + for(JianshenkechengCollectionView collectionView:collectionViewsList){ + Integer jianshenkechengTypes = collectionView.getJianshenkechengTypes(); + if(typeMap.containsKey(jianshenkechengTypes)){ + typeMap.put(jianshenkechengTypes,typeMap.get(jianshenkechengTypes)+1); + }else{ + typeMap.put(jianshenkechengTypes,1); + } + } + List typeList = new ArrayList<>();//排序后的有序的类型 按最多到最少 + typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序 + Integer limit = Integer.valueOf(String.valueOf(params.get("limit"))); + for(Integer type:typeList){ + Map params2 = new HashMap<>(params);params2.put("jianshenkechengTypes",type); + params2.put("shangxiaTypes",1); + params2.put("jianshenkechengYesnoTypes",2); + PageUtils pageUtils1 = jianshenkechengService.queryPage(params2); + List jianshenkechengViewList =(List)pageUtils1.getList(); + returnJianshenkechengViewList.addAll(jianshenkechengViewList); + if(returnJianshenkechengViewList.size()>= limit) break;//返回的推荐数量大于要的数量 跳出循环 + } + params.put("shangxiaTypes",1); + params.put("jianshenkechengYesnoTypes",2); + //正常查询出来商品,用于补全推荐缺少的数据 + PageUtils page = jianshenkechengService.queryPage(params); + if(returnJianshenkechengViewList.size() jianshenkechengViewList =(List)page.getList(); + for(JianshenkechengView jianshenkechengView:jianshenkechengViewList){ + Boolean addFlag = true; + for(JianshenkechengView returnJianshenkechengView:returnJianshenkechengViewList){ + if(returnJianshenkechengView.getId().intValue() ==jianshenkechengView.getId().intValue()) addFlag=false;//返回的数据中已存在此商品 + } + if(addFlag){ + toAddNum=toAddNum-1; + returnJianshenkechengViewList.add(jianshenkechengView); + if(toAddNum==0) break;//够数量了 + } + } + }else { + returnJianshenkechengViewList = returnJianshenkechengViewList.subList(0, limit); + } + + for(JianshenkechengView c:returnJianshenkechengViewList) + dictionaryService.dictionaryConvert(c, request); + page.setList(returnJianshenkechengViewList); + return R.ok().put("data", page); + } + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(id); + if(jianshenkecheng !=null){ + + //点击数量加1 + jianshenkecheng.setJianshenkechengClicknum(jianshenkecheng.getJianshenkechengClicknum()+1); + jianshenkechengService.updateById(jianshenkecheng); + + //entity转view + JianshenkechengView view = new JianshenkechengView(); + BeanUtils.copyProperties( jianshenkecheng , view );//把实体数据重构到view中 + + //级联表 + JiaolianEntity jiaolian = jiaolianService.selectById(jianshenkecheng.getJiaolianId()); + if(jiaolian != null){ + BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "jiaolianId"});//把级联的数据添加到view中,并排除id和创建时间字段 + view.setJiaolianId(jiaolian.getId()); + } + //修改对应字典表字段 + dictionaryService.dictionaryConvert(view, request); + return R.ok().put("data", view); + }else { + return R.error(511,"查不到数据"); + } + } + + + /** + * 前端保存 + */ + @RequestMapping("/add") + public R add(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request){ + logger.debug("add方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); + Wrapper queryWrapper = new EntityWrapper() + .eq("jiaolian_id", jianshenkecheng.getJiaolianId()) + .eq("jianshenkecheng_name", jianshenkecheng.getJianshenkechengName()) + .eq("jianshenkecheng_video", jianshenkecheng.getJianshenkechengVideo()) + .eq("zan_number", jianshenkecheng.getZanNumber()) + .eq("cai_number", jianshenkecheng.getCaiNumber()) + .eq("jianshenkecheng_types", jianshenkecheng.getJianshenkechengTypes()) + .eq("jianshenkecheng_clicknum", jianshenkecheng.getJianshenkechengClicknum()) + .eq("data_delete", jianshenkecheng.getDataDelete()) +// .notIn("jianshenkecheng_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JianshenkechengEntity jianshenkechengEntity = jianshenkechengService.selectOne(queryWrapper); + if(jianshenkechengEntity==null){ + jianshenkecheng.setZanNumber(1); + jianshenkecheng.setCaiNumber(1); + jianshenkecheng.setJianshenkechengClicknum(1); + jianshenkecheng.setDataDelete(1); + jianshenkecheng.setInsertTime(new Date()); + jianshenkecheng.setCreateTime(new Date()); + jianshenkechengService.insert(jianshenkecheng); + + return R.ok(); + }else { + return R.error(511,"表中有相同数据"); } } +} +======= //个性推荐 @IgnoreAuth // 忽略认证 @RequestMapping("/gexingtuijian") // 处理个性推荐请求 @@ -386,4 +821,5 @@ public class JianshenkechengController { return R.error(511,"表中有相同数据"); // 数据已存在返回错误 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengLiuyanController.java b/src/main/java/com/controller/JianshenkechengLiuyanController.java index 5d8488a..7ce51c2 100644 --- a/src/main/java/com/controller/JianshenkechengLiuyanController.java +++ b/src/main/java/com/controller/JianshenkechengLiuyanController.java @@ -1,3 +1,248 @@ +<<<<<<< HEAD + +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("/jianshenkechengLiuyan") +public class JianshenkechengLiuyanController { + private static final Logger logger = LoggerFactory.getLogger(JianshenkechengLiuyanController.class); + + private static final String TABLE_NAME = "jianshenkechengLiuyan"; + + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengLiuyanService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengLiuyanView 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); + JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); + if(jianshenkechengLiuyan !=null){ + //entity转view + JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); + BeanUtils.copyProperties( jianshenkechengLiuyan , view );//把实体数据重构到view中 + //级联表 健身课程 + //级联表 + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId()); + if(jianshenkecheng != null){ + BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表 + view.setJianshenkechengId(jianshenkecheng.getId()); + } + //级联表 用户 + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){ + logger.debug("save方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); + + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + else if("用户".equals(role)) + jianshenkechengLiuyan.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + jianshenkechengLiuyan.setCreateTime(new Date()); + jianshenkechengLiuyan.setInsertTime(new Date()); + jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); + + return R.ok(); + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); + JianshenkechengLiuyanEntity oldJianshenkechengLiuyanEntity = jianshenkechengLiuyanService.selectById(jianshenkechengLiuyan.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); +// else if("用户".equals(role)) +// jianshenkechengLiuyan.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + if("".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText()) || "null".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText())){ + jianshenkechengLiuyan.setJianshenkechengLiuyanText(null); + } + if("".equals(jianshenkechengLiuyan.getReplyText()) || "null".equals(jianshenkechengLiuyan.getReplyText())){ + jianshenkechengLiuyan.setReplyText(null); + } + jianshenkechengLiuyan.setUpdateTime(new Date()); + + jianshenkechengLiuyanService.updateById(jianshenkechengLiuyan);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldJianshenkechengLiuyanList =jianshenkechengLiuyanService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + jianshenkechengLiuyanService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List jianshenkechengLiuyanList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + JianshenkechengLiuyanEntity jianshenkechengLiuyanEntity = new JianshenkechengLiuyanEntity(); +// jianshenkechengLiuyanEntity.setJianshenkechengId(Integer.valueOf(data.get(0))); //健身课程 要改的 +// jianshenkechengLiuyanEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的 +// jianshenkechengLiuyanEntity.setJianshenkechengLiuyanText(data.get(0)); //留言内容 要改的 +// jianshenkechengLiuyanEntity.setInsertTime(date);//时间 +// jianshenkechengLiuyanEntity.setReplyText(data.get(0)); //回复内容 要改的 +// jianshenkechengLiuyanEntity.setUpdateTime(sdf.parse(data.get(0))); //回复时间 要改的 +// jianshenkechengLiuyanEntity.setCreateTime(date);//时间 + jianshenkechengLiuyanList.add(jianshenkechengLiuyanEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 + jianshenkechengLiuyanService.insertBatch(jianshenkechengLiuyanList); + return R.ok(); +======= package com.controller; // 声明包路径,表示该文件位于com.controller包下 import java.io.File; // 导入文件操作类,用于处理文件上传 @@ -212,16 +457,95 @@ public class JianshenkechengLiuyanController { } jianshenkechengLiuyanService.insertBatch(jianshenkechengLiuyanList); // 批量插入数据 return R.ok(); // 返回成功信息 +>>>>>>> develop } } } }catch (Exception e){ +<<<<<<< HEAD + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); +======= e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 +>>>>>>> develop } } +<<<<<<< HEAD + + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = jianshenkechengLiuyanService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JianshenkechengLiuyanView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); + if(jianshenkechengLiuyan !=null){ + + + //entity转view + JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); + BeanUtils.copyProperties( jianshenkechengLiuyan , view );//把实体数据重构到view中 + + //级联表 + JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId()); + if(jianshenkecheng != null){ + BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段 + view.setJianshenkechengId(jianshenkecheng.getId()); + } + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){ + logger.debug("add方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); + jianshenkechengLiuyan.setCreateTime(new Date()); + jianshenkechengLiuyan.setInsertTime(new Date()); + jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); + + return R.ok(); + } + +} + +======= //前端列表 //处理前端分页查询请求 @IgnoreAuth // 忽略认证 @@ -282,4 +606,5 @@ public class JianshenkechengLiuyanController { jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); // 调用服务层保存数据 return R.ok(); // 返回成功信息 } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/JiaolianController.java b/src/main/java/com/controller/JiaolianController.java index 3993bfd..08f271b 100644 --- a/src/main/java/com/controller/JiaolianController.java +++ b/src/main/java/com/controller/JiaolianController.java @@ -1,3 +1,45 @@ +<<<<<<< HEAD + +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 +*/ +======= // 声明当前 Java 文件所属的包,此包一般用于存放控制器相关的类,负责处理 HTTP 请求和响应 package com.controller; @@ -66,6 +108,7 @@ import com.alibaba.fastjson.*; //后端接口 //@author //@email +>>>>>>> develop @RestController @Controller @RequestMapping("/jiaolian") @@ -103,7 +146,13 @@ public class JiaolianController { private UsersService usersService;//管理员 +<<<<<<< HEAD + /** + * 后端列表 + */ +======= //后端列表 +>>>>>>> develop @RequestMapping("/page") public R page(@RequestParam Map params, HttpServletRequest request){ logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); @@ -127,8 +176,14 @@ public class JiaolianController { return R.ok().put("data", page); } +<<<<<<< HEAD + /** + * 后端详情 + */ +======= //后端详情 +>>>>>>> develop @RequestMapping("/info/{id}") public R info(@PathVariable("id") Long id, HttpServletRequest request){ logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); @@ -146,7 +201,13 @@ public class JiaolianController { } +<<<<<<< HEAD + /** + * 后端保存 + */ +======= //后端保存 +>>>>>>> develop @RequestMapping("/save") public R save(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); @@ -176,8 +237,14 @@ public class JiaolianController { } } +<<<<<<< HEAD + /** + * 后端修改 + */ +======= //后端修改 +>>>>>>> develop @RequestMapping("/update") public R update(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { logger.debug("update方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); @@ -199,8 +266,14 @@ public class JiaolianController { +<<<<<<< HEAD + /** + * 删除 + */ +======= //删除 +>>>>>>> develop @RequestMapping("/delete") public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); @@ -220,8 +293,14 @@ public class JiaolianController { } +<<<<<<< HEAD + /** + * 批量上传 + */ +======= //批量上传 +>>>>>>> develop @RequestMapping("/batchInsert") public R save( String fileName, HttpServletRequest request){ logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); @@ -315,8 +394,14 @@ public class JiaolianController { } } +<<<<<<< HEAD + /** + * 登录 + */ +======= //登录 +>>>>>>> develop @IgnoreAuth @RequestMapping(value = "/login") public R login(String username, String password, String captcha, HttpServletRequest request) { @@ -335,7 +420,13 @@ public class JiaolianController { return r; } +<<<<<<< HEAD + /** + * 注册 + */ +======= //注册 +>>>>>>> develop @IgnoreAuth @PostMapping(value = "/register") public R register(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) { @@ -358,8 +449,14 @@ public class JiaolianController { return R.ok(); } +<<<<<<< HEAD + /** + * 重置密码 + */ +======= //重置密码 +>>>>>>> develop @GetMapping(value = "/resetPassword") public R resetPassword(Integer id, HttpServletRequest request) { JiaolianEntity jiaolian = jiaolianService.selectById(id); @@ -368,8 +465,14 @@ public class JiaolianController { return R.ok(); } +<<<<<<< HEAD + /** + * 修改密码 + */ +======= //修改密码 +>>>>>>> develop @GetMapping(value = "/updatePassword") public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { JiaolianEntity jiaolian = jiaolianService.selectById((Integer)request.getSession().getAttribute("userId")); @@ -389,8 +492,14 @@ public class JiaolianController { +<<<<<<< HEAD + /** + * 忘记密码 + */ +======= //忘记密码 +>>>>>>> develop @IgnoreAuth @RequestMapping(value = "/resetPass") public R resetPass(String username, HttpServletRequest request) { @@ -405,7 +514,13 @@ public class JiaolianController { } +<<<<<<< HEAD + /** + * 获取用户的session用户信息 + */ +======= //获取用户的session用户信息 +>>>>>>> develop @RequestMapping("/session") public R getCurrJiaolian(HttpServletRequest request){ Integer id = (Integer)request.getSession().getAttribute("userId"); @@ -424,8 +539,14 @@ public class JiaolianController { } +<<<<<<< HEAD + /** + * 退出 + */ +======= //退出 +>>>>>>> develop @GetMapping(value = "logout") public R logout(HttpServletRequest request) { request.getSession().invalidate(); @@ -434,8 +555,14 @@ public class JiaolianController { +<<<<<<< HEAD + /** + * 前端列表 + */ +======= //前端列表 +>>>>>>> develop @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ @@ -452,8 +579,14 @@ public class JiaolianController { return R.ok().put("data", page); } +<<<<<<< HEAD + /** + * 前端详情 + */ +======= //前端详情 +>>>>>>> develop @RequestMapping("/detail/{id}") public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); @@ -474,8 +607,14 @@ public class JiaolianController { } +<<<<<<< HEAD + /** + * 前端保存 + */ +======= //前端保存 +>>>>>>> develop @RequestMapping("/add") public R add(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); diff --git a/src/main/java/com/controller/JiaolianYuyueController.java b/src/main/java/com/controller/JiaolianYuyueController.java index 16d4242..8bd2c05 100644 --- a/src/main/java/com/controller/JiaolianYuyueController.java +++ b/src/main/java/com/controller/JiaolianYuyueController.java @@ -1,3 +1,283 @@ +<<<<<<< HEAD + +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("/jiaolianYuyue") +public class JiaolianYuyueController { + private static final Logger logger = LoggerFactory.getLogger(JiaolianYuyueController.class); + + private static final String TABLE_NAME = "jiaolianYuyue"; + + @Autowired + private JiaolianYuyueService jiaolianYuyueService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + CommonUtil.checkMap(params); + PageUtils page = jiaolianYuyueService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JiaolianYuyueView 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); + JiaolianYuyueEntity jiaolianYuyue = jiaolianYuyueService.selectById(id); + if(jiaolianYuyue !=null){ + //entity转view + JiaolianYuyueView view = new JiaolianYuyueView(); + BeanUtils.copyProperties( jiaolianYuyue , view );//把实体数据重构到view中 + //级联表 用户 + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jiaolianYuyue.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request){ + logger.debug("save方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); + + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + else if("用户".equals(role)) + jiaolianYuyue.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + + Wrapper queryWrapper = new EntityWrapper() + .eq("yonghu_id", jiaolianYuyue.getYonghuId()) + .in("jiaolian_yuyue_yesno_types", new Integer[]{1,2}) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JiaolianYuyueEntity jiaolianYuyueEntity = jiaolianYuyueService.selectOne(queryWrapper); + if(jiaolianYuyueEntity==null){ + jiaolianYuyue.setJiaolianYuyueYesnoTypes(1); + jiaolianYuyue.setInsertTime(new Date()); + jiaolianYuyue.setCreateTime(new Date()); + jiaolianYuyueService.insert(jiaolianYuyue); + return R.ok(); + }else { + if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==1) + return R.error(511,"有相同的待审核的数据"); + else if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==2) + return R.error(511,"有相同的审核通过的数据"); + else + return R.error(511,"表中有相同数据"); + } + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); + JiaolianYuyueEntity oldJiaolianYuyueEntity = jiaolianYuyueService.selectById(jiaolianYuyue.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); +// else if("用户".equals(role)) +// jiaolianYuyue.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); + if("".equals(jiaolianYuyue.getJiaolianYuyueText()) || "null".equals(jiaolianYuyue.getJiaolianYuyueText())){ + jiaolianYuyue.setJiaolianYuyueText(null); + } + if("".equals(jiaolianYuyue.getJiaolianYuyueYesnoText()) || "null".equals(jiaolianYuyue.getJiaolianYuyueYesnoText())){ + jiaolianYuyue.setJiaolianYuyueYesnoText(null); + } + + jiaolianYuyueService.updateById(jiaolianYuyue);//根据id更新 + return R.ok(); + } + + + /** + * 审核 + */ + @RequestMapping("/shenhe") + public R shenhe(@RequestBody JiaolianYuyueEntity jiaolianYuyueEntity, HttpServletRequest request){ + logger.debug("shenhe方法:,,Controller:{},,jiaolianYuyueEntity:{}",this.getClass().getName(),jiaolianYuyueEntity.toString()); + + JiaolianYuyueEntity oldJiaolianYuyue = jiaolianYuyueService.selectById(jiaolianYuyueEntity.getId());//查询原先数据 + +// if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes() == 2){//通过 +// jiaolianYuyueEntity.setJiaolianYuyueTypes(); +// }else if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes() == 3){//拒绝 +// jiaolianYuyueEntity.setJiaolianYuyueTypes(); +// } + jiaolianYuyueService.updateById(jiaolianYuyueEntity);//审核 + + return R.ok(); + } + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldJiaolianYuyueList =jiaolianYuyueService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + jiaolianYuyueService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List jiaolianYuyueList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + JiaolianYuyueEntity jiaolianYuyueEntity = new JiaolianYuyueEntity(); +// jiaolianYuyueEntity.setJiaolianYuyueUuidNumber(data.get(0)); //预约编号 要改的 +// jiaolianYuyueEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的 +// jiaolianYuyueEntity.setJiaolianYuyueText(data.get(0)); //预约备注 要改的 +// jiaolianYuyueEntity.setJiaolianYuyueTime(sdf.parse(data.get(0))); //预约时间 要改的 +// jiaolianYuyueEntity.setJiaolianYuyueYesnoTypes(Integer.valueOf(data.get(0))); //预约状态 要改的 +// jiaolianYuyueEntity.setJiaolianYuyueYesnoText(data.get(0)); //审核回复 要改的 +// jiaolianYuyueEntity.setInsertTime(date);//时间 +// jiaolianYuyueEntity.setCreateTime(date);//时间 + jiaolianYuyueList.add(jiaolianYuyueEntity); + + + //把要查询是否重复的字段放入map中 + //预约编号 + if(seachFields.containsKey("jiaolianYuyueUuidNumber")){ + List jiaolianYuyueUuidNumber = seachFields.get("jiaolianYuyueUuidNumber"); + jiaolianYuyueUuidNumber.add(data.get(0));//要改的 + }else{ + List jiaolianYuyueUuidNumber = new ArrayList<>(); + jiaolianYuyueUuidNumber.add(data.get(0));//要改的 + seachFields.put("jiaolianYuyueUuidNumber",jiaolianYuyueUuidNumber); + } + } + + //查询是否重复 + //预约编号 +======= package com.controller; // 声明包路径,表示该文件位于com.controller包下 import java.io.File; // 导入文件操作类,用于处理文件上传 @@ -244,6 +524,7 @@ public class JiaolianYuyueController { } // 检查预约编号是否已存在 +>>>>>>> develop List jiaolianYuyueEntities_jiaolianYuyueUuidNumber = jiaolianYuyueService.selectList(new EntityWrapper().in("jiaolian_yuyue_uuid_number", seachFields.get("jiaolianYuyueUuidNumber"))); if(jiaolianYuyueEntities_jiaolianYuyueUuidNumber.size() >0 ){ ArrayList repeatFields = new ArrayList<>(); @@ -252,18 +533,115 @@ public class JiaolianYuyueController { } return R.error(511,"数据库的该表中的 [预约编号] 字段已经存在 存在数据为:"+repeatFields.toString()); } +<<<<<<< HEAD + jiaolianYuyueService.insertBatch(jiaolianYuyueList); + return R.ok(); +======= jiaolianYuyueService.insertBatch(jiaolianYuyueList); // 批量插入数据 return R.ok(); // 返回成功信息 +>>>>>>> develop } } } }catch (Exception e){ +<<<<<<< HEAD + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); +======= e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 +>>>>>>> develop + } + } + + +<<<<<<< HEAD + + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = jiaolianYuyueService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(JiaolianYuyueView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + JiaolianYuyueEntity jiaolianYuyue = jiaolianYuyueService.selectById(id); + if(jiaolianYuyue !=null){ + + + //entity转view + JiaolianYuyueView view = new JiaolianYuyueView(); + BeanUtils.copyProperties( jiaolianYuyue , view );//把实体数据重构到view中 + + //级联表 + YonghuEntity yonghu = yonghuService.selectById(jiaolianYuyue.getYonghuId()); + if(yonghu != null){ + BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});//把级联的数据添加到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 JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request){ + logger.debug("add方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); + Wrapper queryWrapper = new EntityWrapper() + .eq("jiaolian_yuyue_uuid_number", jiaolianYuyue.getJiaolianYuyueUuidNumber()) + .eq("yonghu_id", jiaolianYuyue.getYonghuId()) + .eq("jiaolian_yuyue_text", jiaolianYuyue.getJiaolianYuyueText()) + .in("jiaolian_yuyue_yesno_types", new Integer[]{1,2}) + .eq("jiaolian_yuyue_yesno_text", jiaolianYuyue.getJiaolianYuyueYesnoText()) +// .notIn("jiaolian_yuyue_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + JiaolianYuyueEntity jiaolianYuyueEntity = jiaolianYuyueService.selectOne(queryWrapper); + if(jiaolianYuyueEntity==null){ + jiaolianYuyue.setJiaolianYuyueYesnoTypes(1); + jiaolianYuyue.setInsertTime(new Date()); + jiaolianYuyue.setCreateTime(new Date()); + jiaolianYuyueService.insert(jiaolianYuyue); + + return R.ok(); + }else { + if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==1) + return R.error(511,"有相同的待审核的数据"); + else if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==2) + return R.error(511,"有相同的审核通过的数据"); + else + return R.error(511,"表中有相同数据"); } } +} +======= //前端列表 //处理前端分页查询请求 @IgnoreAuth // 忽略认证 @@ -337,4 +715,5 @@ public class JiaolianYuyueController { return R.error(511,"表中有相同数据"); // 返回错误信息 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/NewsController.java b/src/main/java/com/controller/NewsController.java index 8c486a8..b7c4373 100644 --- a/src/main/java/com/controller/NewsController.java +++ b/src/main/java/com/controller/NewsController.java @@ -1,3 +1,45 @@ +<<<<<<< HEAD + +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 +*/ +======= package com.controller; // 定义包名为com.controller import java.io.File; // 文件操作类 @@ -38,12 +80,94 @@ import com.alibaba.fastjson.*; // 阿里巴巴FastJSON库 //@author // @email +>>>>>>> develop @RestController @Controller @RequestMapping("/news") public class NewsController { private static final Logger logger = LoggerFactory.getLogger(NewsController.class); +<<<<<<< HEAD + private static final String TABLE_NAME = "news"; + + @Autowired + private NewsService newsService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + CommonUtil.checkMap(params); + PageUtils page = newsService.queryPage(params); + + //字典表数据转换 + List list =(List)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,"查不到数据"); + } + + } + + /** + * 后端保存 + */ +======= private static final String TABLE_NAME = "news"; // 数据库表名 @Autowired @@ -129,10 +253,104 @@ public class NewsController { //@param news 资讯实体 //@param request HTTP请求对象 //@return 返回操作结果状态 +>>>>>>> develop @RequestMapping("/save") public R save(@RequestBody NewsEntity news, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); +<<<<<<< HEAD + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + + Wrapper queryWrapper = new EntityWrapper() + .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) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); + NewsEntity oldNewsEntity = newsService.selectById(news.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); + if("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())){ + news.setNewsPhoto(null); + } + if("".equals(news.getNewsContent()) || "null".equals(news.getNewsContent())){ + news.setNewsContent(null); + } + + newsService.updateById(news);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldNewsList =newsService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + newsService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List newsList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + NewsEntity newsEntity = new NewsEntity(); +// newsEntity.setNewsName(data.get(0)); //资讯标题 要改的 +// newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); //资讯类型 要改的 +======= String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 if(false) return R.error(511,"永远不会进入"); @@ -229,10 +447,22 @@ public class NewsController { NewsEntity newsEntity = new NewsEntity(); // newsEntity.setNewsName(data.get(0)); // 资讯标题 要改的 // newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); // 资讯类型 要改的 +>>>>>>> develop // newsEntity.setNewsPhoto("");//详情和图片 // newsEntity.setInsertTime(date);//时间 // newsEntity.setNewsContent("");//详情和图片 // newsEntity.setCreateTime(date);//时间 +<<<<<<< HEAD + newsList.add(newsEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 + newsService.insertBatch(newsList); + return R.ok(); +======= newsList.add(newsEntity); // 添加到列表 // 把要查询是否重复的字段放入map中 @@ -241,26 +471,78 @@ public class NewsController { // 查询是否重复 newsService.insertBatch(newsList); // 批量插入 return R.ok(); // 返回成功 +>>>>>>> develop } } } }catch (Exception e){ e.printStackTrace(); +<<<<<<< HEAD + return R.error(511,"批量插入数据异常,请联系管理员"); +======= return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 +>>>>>>> develop } } +<<<<<<< HEAD + + + /** + * 前端列表 + */ +======= //前端列表 //分页查询健身资讯数据(无需认证) //@param params 请求参数,包含分页和查询条件 //@param request HTTP请求对象 //@return 返回分页数据和状态信息 +>>>>>>> develop @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); +<<<<<<< HEAD + CommonUtil.checkMap(params); + PageUtils page = newsService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(NewsView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer 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,"查不到数据"); + } + } + + + /** + * 前端保存 + */ +======= CommonUtil.checkMap(params); // 检查参数 PageUtils page = newsService.queryPage(params); // 分页查询 @@ -301,10 +583,32 @@ public class NewsController { //@param news 资讯实体 //@param request HTTP请求对象 //@return 返回操作结果状态 +>>>>>>> develop @RequestMapping("/add") public R add(@RequestBody NewsEntity news, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); Wrapper queryWrapper = new EntityWrapper() +<<<<<<< HEAD + .eq("news_name", news.getNewsName()) + .eq("news_types", news.getNewsTypes()) +// .notIn("news_types", new Integer[]{102}) + ; + 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,"表中有相同数据"); + } + } + +} + +======= .eq("news_name", news.getNewsName()) // 资讯标题相等 .eq("news_types", news.getNewsTypes()) // 资讯类型相等 // .notIn("news_types", new Integer[]{102}) @@ -321,4 +625,5 @@ public class NewsController { return R.error(511,"表中有相同数据"); // 返回错误信息 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/SingleSeachController.java b/src/main/java/com/controller/SingleSeachController.java index c15f76a..1584c4a 100644 --- a/src/main/java/com/controller/SingleSeachController.java +++ b/src/main/java/com/controller/SingleSeachController.java @@ -1,3 +1,241 @@ +<<<<<<< HEAD + +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("/singleSeach") +public class SingleSeachController { + private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class); + + private static final String TABLE_NAME = "singleSeach"; + + @Autowired + private SingleSeachService singleSeachService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private YonghuService yonghuService;//用户 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + CommonUtil.checkMap(params); + PageUtils page = singleSeachService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(SingleSeachView 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); + SingleSeachEntity singleSeach = singleSeachService.selectById(id); + if(singleSeach !=null){ + //entity转view + SingleSeachView view = new SingleSeachView(); + BeanUtils.copyProperties( singleSeach , view );//把实体数据重构到view中 + //修改对应字典表字段 + dictionaryService.dictionaryConvert(view, request); + return R.ok().put("data", view); + }else { + return R.error(511,"查不到数据"); + } + + } + + /** + * 后端保存 + */ + @RequestMapping("/save") + public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){ + logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); + + String role = String.valueOf(request.getSession().getAttribute("role")); + if(false) + return R.error(511,"永远不会进入"); + + Wrapper queryWrapper = new EntityWrapper() + .eq("single_seach_types",singleSeach.getSingleSeachTypes()) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); + if(singleSeachEntity==null){ + singleSeach.setCreateTime(new Date()); + singleSeachService.insert(singleSeach); + return R.ok(); + }else { + return R.error(511,"该类型已经有存在的,请删除后重新新增"); + } + } + + /** + * 后端修改 + */ + @RequestMapping("/update") + public R update(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); + SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); + if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){ + singleSeach.setSingleSeachPhoto(null); + } + if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){ + singleSeach.setSingleSeachContent(null); + } + + singleSeachService.updateById(singleSeach);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldSingleSeachList =singleSeachService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + singleSeachService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List singleSeachList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + SingleSeachEntity singleSeachEntity = new SingleSeachEntity(); +// singleSeachEntity.setSingleSeachName(data.get(0)); //名字 要改的 +// singleSeachEntity.setSingleSeachTypes(Integer.valueOf(data.get(0))); //数据类型 要改的 +// singleSeachEntity.setSingleSeachPhoto("");//详情和图片 +// singleSeachEntity.setSingleSeachContent("");//详情和图片 +// singleSeachEntity.setCreateTime(date);//时间 + singleSeachList.add(singleSeachEntity); + + + //把要查询是否重复的字段放入map中 + } + + //查询是否重复 + singleSeachService.insertBatch(singleSeachList); + return R.ok(); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + return R.error(511,"批量插入数据异常,请联系管理员"); +======= // 声明当前文件所在的包路径 package com.controller; @@ -231,10 +469,73 @@ public class SingleSeachController { }catch (Exception e){ // 捕获异常 e.printStackTrace(); // 打印异常堆栈 return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 +>>>>>>> develop + } + } + + +<<<<<<< HEAD + + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = singleSeachService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(SingleSeachView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ + logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + SingleSeachEntity singleSeach = singleSeachService.selectOne(new EntityWrapper().eq("single_seach_types", id)); + if(singleSeach != null) + return R.ok().put("data", singleSeach); + else + return R.error(511,"查不到数据"); + + } + + + /** + * 前端保存 + */ + @RequestMapping("/add") + public R add(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){ + logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); + Wrapper queryWrapper = new EntityWrapper() + .eq("single_seach_types",singleSeach.getSingleSeachTypes()) +// .notIn("single_seach_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); + if(singleSeachEntity==null){ + singleSeach.setCreateTime(new Date()); + singleSeachService.insert(singleSeach); + + return R.ok(); + }else { + return R.error(511,"该类型已经有存在的,请删除后重新新增"); } } +} +======= //前端列表 //无需认证的分页查询 //@param params 请求参数Map @@ -294,4 +595,5 @@ public class SingleSeachController { return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/UsersController.java b/src/main/java/com/controller/UsersController.java index 5f38676..81b8f20 100644 --- a/src/main/java/com/controller/UsersController.java +++ b/src/main/java/com/controller/UsersController.java @@ -1,3 +1,197 @@ +<<<<<<< HEAD + +package com.controller; + +import java.util.List; +import java.util.Arrays; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import com.service.UsersService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +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.UsersEntity; +import com.service.TokenService; +import com.utils.MPUtil; +import com.utils.PageUtils; +import com.utils.R; + +/** + * 登录相关 + */ +@RequestMapping("users") +@RestController +public class UsersController { + + @Autowired + private UsersService usersService; + + @Autowired + private TokenService tokenService; + + /** + * 登录 + */ + @IgnoreAuth + @PostMapping(value = "/login") + public R login(String username, String password, String captcha, HttpServletRequest request) { + UsersEntity user = usersService.selectOne(new EntityWrapper().eq("username", username)); + if(user==null || !user.getPassword().equals(password)) { + return R.error("账号或密码不正确"); + } + String token = tokenService.generateToken(user.getId(),username, "users", user.getRole()); + R r = R.ok(); + r.put("token", token); + r.put("role",user.getRole()); + r.put("userId",user.getId()); + return r; + } + + /** + * 注册 + */ + @IgnoreAuth + @PostMapping(value = "/register") + public R register(@RequestBody UsersEntity user){ +// ValidatorUtils.validateEntity(user); + if(usersService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { + return R.error("用户已存在"); + } + usersService.insert(user); + return R.ok(); + } + + /** + * 退出 + */ + @GetMapping(value = "logout") + public R logout(HttpServletRequest request) { + request.getSession().invalidate(); + return R.ok("退出成功"); + } + + /** + * 修改密码 + */ + @GetMapping(value = "/updatePassword") + public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { + UsersEntity users = usersService.selectById((Integer)request.getSession().getAttribute("userId")); + if(newPassword == null){ + return R.error("新密码不能为空") ; + } + if(!oldPassword.equals(users.getPassword())){ + return R.error("原密码输入错误"); + } + if(newPassword.equals(users.getPassword())){ + return R.error("新密码不能和原密码一致") ; + } + users.setPassword(newPassword); + usersService.updateById(users); + return R.ok(); + } + + /** + * 密码重置 + */ + @IgnoreAuth + @RequestMapping(value = "/resetPass") + public R resetPass(String username, HttpServletRequest request){ + UsersEntity user = usersService.selectOne(new EntityWrapper().eq("username", username)); + if(user==null) { + return R.error("账号不存在"); + } + user.setPassword("123456"); + usersService.update(user,null); + return R.ok("密码已重置为:123456"); + } + + /** + * 列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map params,UsersEntity user){ + EntityWrapper ew = new EntityWrapper(); + PageUtils page = usersService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params)); + return R.ok().put("data", page); + } + + /** + * 列表 + */ + @RequestMapping("/list") + public R list( UsersEntity user){ + EntityWrapper ew = new EntityWrapper(); + ew.allEq(MPUtil.allEQMapPre( user, "user")); + return R.ok().put("data", usersService.selectListView(ew)); + } + + /** + * 信息 + */ + @RequestMapping("/info/{id}") + public R info(@PathVariable("id") String id){ + UsersEntity user = usersService.selectById(id); + return R.ok().put("data", user); + } + + /** + * 获取用户的session用户信息 + */ + @RequestMapping("/session") + public R getCurrUser(HttpServletRequest request){ + Integer id = (Integer)request.getSession().getAttribute("userId"); + UsersEntity user = usersService.selectById(id); + return R.ok().put("data", user); + } + + /** + * 保存 + */ + @PostMapping("/save") + public R save(@RequestBody UsersEntity user){ +// ValidatorUtils.validateEntity(user); + if(usersService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { + return R.error("用户已存在"); + } + usersService.insert(user); + return R.ok(); + } + + /** + * 修改 + */ + @RequestMapping("/update") + public R update(@RequestBody UsersEntity user){ +// ValidatorUtils.validateEntity(user); + usersService.updateById(user);//全部更新 + return R.ok(); + } + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Long[] ids){ + List user = usersService.selectList(null); + if(user.size() > 1){ + usersService.deleteBatchIds(Arrays.asList(ids)); + }else{ + return R.error("管理员最少保留一个"); + } + return R.ok(); + } +} +======= package com.controller; // 声明当前类所在的包路径 // 导入Java集合类 @@ -233,4 +427,5 @@ public class UsersController { } return R.ok(); // 返回成功结果 } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/controller/YonghuController.java b/src/main/java/com/controller/YonghuController.java index 92b67df..2b33dbf 100644 --- a/src/main/java/com/controller/YonghuController.java +++ b/src/main/java/com/controller/YonghuController.java @@ -1,3 +1,415 @@ +<<<<<<< HEAD + +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); + + private static final String TABLE_NAME = "yonghu"; + + @Autowired + private YonghuService yonghuService; + + + @Autowired + private TokenService tokenService; + + @Autowired + private DictionaryService dictionaryService;//字典 + @Autowired + private ForumService forumService;//健身论坛 + @Autowired + private JianshenkechengService jianshenkechengService;//健身课程 + @Autowired + private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏 + @Autowired + private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言 + @Autowired + private JiaolianService jiaolianService;//教练 + @Autowired + private JiaolianYuyueService jiaolianYuyueService;//教练预约申请 + @Autowired + private NewsService newsService;//健身资讯 + @Autowired + private SingleSeachService singleSeachService;//单页数据 + @Autowired + private UsersService usersService;//管理员 + + + /** + * 后端列表 + */ + @RequestMapping("/page") + public R page(@RequestParam Map 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("jiaolianId",request.getSession().getAttribute("userId")); + params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); + CommonUtil.checkMap(params); + PageUtils page = yonghuService.queryPage(params); + + //字典表数据转换 + List list =(List)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 queryWrapper = new EntityWrapper() + .eq("username", yonghu.getUsername()) + .or() + .eq("yonghu_phone", yonghu.getYonghuPhone()) + .or() + .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) + .eq("data_delete", 1) + ; + + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); + if(yonghuEntity==null){ + yonghu.setDataDelete(1); + yonghu.setInsertTime(new Date()); + 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) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { + logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString()); + YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId());//查询原先数据 + + String role = String.valueOf(request.getSession().getAttribute("role")); +// if(false) +// return R.error(511,"永远不会进入"); + if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){ + yonghu.setYonghuPhoto(null); + } + + yonghuService.updateById(yonghu);//根据id更新 + return R.ok(); + } + + + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ + logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + List oldYonghuList =yonghuService.selectBatchIds(Arrays.asList(ids));//要删除的数据 + ArrayList list = new ArrayList<>(); + for(Integer id:ids){ + YonghuEntity yonghuEntity = new YonghuEntity(); + yonghuEntity.setId(id); + yonghuEntity.setDataDelete(2); + list.add(yonghuEntity); + } + if(list != null && list.size() >0){ + yonghuService.updateBatchById(list); + } + + return R.ok(); + } + + + /** + * 批量上传 + */ + @RequestMapping("/batchInsert") + public R save( String fileName, HttpServletRequest request){ + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date())) + try { + List yonghuList = new ArrayList<>();//上传的东西 + Map> 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> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件 + dataList.remove(0);//删除第一行,因为第一行是提示 + for(List data:dataList){ + //循环 + YonghuEntity yonghuEntity = new YonghuEntity(); +// yonghuEntity.setUsername(data.get(0)); //账户 要改的 +// yonghuEntity.setPassword("123456");//密码 +// yonghuEntity.setYonghuName(data.get(0)); //用户名称 要改的 +// yonghuEntity.setYonghuPhone(data.get(0)); //用户手机号 要改的 +// yonghuEntity.setYonghuIdNumber(data.get(0)); //用户身份证号 要改的 +// yonghuEntity.setYonghuPhoto("");//详情和图片 +// yonghuEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的 +// yonghuEntity.setYonghuEmail(data.get(0)); //用户邮箱 要改的 +// yonghuEntity.setNewMoney(data.get(0)); //现有余额 要改的 +// yonghuEntity.setDataDelete(1);//逻辑删除字段 +// yonghuEntity.setInsertTime(date);//时间 +// yonghuEntity.setCreateTime(date);//时间 + yonghuList.add(yonghuEntity); + + + //把要查询是否重复的字段放入map中 + //账户 + if(seachFields.containsKey("username")){ + List username = seachFields.get("username"); + username.add(data.get(0));//要改的 + }else{ + List username = new ArrayList<>(); + username.add(data.get(0));//要改的 + seachFields.put("username",username); + } + //用户手机号 + if(seachFields.containsKey("yonghuPhone")){ + List yonghuPhone = seachFields.get("yonghuPhone"); + yonghuPhone.add(data.get(0));//要改的 + }else{ + List yonghuPhone = new ArrayList<>(); + yonghuPhone.add(data.get(0));//要改的 + seachFields.put("yonghuPhone",yonghuPhone); + } + //用户身份证号 + if(seachFields.containsKey("yonghuIdNumber")){ + List yonghuIdNumber = seachFields.get("yonghuIdNumber"); + yonghuIdNumber.add(data.get(0));//要改的 + }else{ + List yonghuIdNumber = new ArrayList<>(); + yonghuIdNumber.add(data.get(0));//要改的 + seachFields.put("yonghuIdNumber",yonghuIdNumber); + } + } + + //查询是否重复 + //账户 + List yonghuEntities_username = yonghuService.selectList(new EntityWrapper().in("username", seachFields.get("username")).eq("data_delete", 1)); + if(yonghuEntities_username.size() >0 ){ + ArrayList repeatFields = new ArrayList<>(); + for(YonghuEntity s:yonghuEntities_username){ + repeatFields.add(s.getUsername()); + } + return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString()); + } + //用户手机号 + List yonghuEntities_yonghuPhone = yonghuService.selectList(new EntityWrapper().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1)); + if(yonghuEntities_yonghuPhone.size() >0 ){ + ArrayList repeatFields = new ArrayList<>(); + for(YonghuEntity s:yonghuEntities_yonghuPhone){ + repeatFields.add(s.getYonghuPhone()); + } + return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString()); + } + //用户身份证号 + List yonghuEntities_yonghuIdNumber = yonghuService.selectList(new EntityWrapper().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1)); + if(yonghuEntities_yonghuIdNumber.size() >0 ){ + ArrayList 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){ + e.printStackTrace(); + 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().eq("username", username)); + if(yonghu==null || !yonghu.getPassword().equals(password)) + return R.error("账号或密码不正确"); + else if(yonghu.getDataDelete() != 1) + return R.error("账户已被删除"); + 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, HttpServletRequest request) { +// ValidatorUtils.validateEntity(user); + Wrapper queryWrapper = new EntityWrapper() + .eq("username", yonghu.getUsername()) + .or() + .eq("yonghu_phone", yonghu.getYonghuPhone()) + .or() + .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) + .andNew() + .eq("data_delete", 1) + ; + YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); + if(yonghuEntity != null) + return R.error("账户或者用户手机号或者用户身份证号已经被使用"); + yonghu.setNewMoney(0.0); + yonghu.setDataDelete(1); + yonghu.setInsertTime(new Date()); + yonghu.setCreateTime(new Date()); + yonghuService.insert(yonghu); + + return R.ok(); + } + + /** + * 重置密码 + */ + @GetMapping(value = "/resetPassword") + public R resetPassword(Integer id, HttpServletRequest request) { + YonghuEntity yonghu = yonghuService.selectById(id); + yonghu.setPassword("123456"); + yonghuService.updateById(yonghu); + return R.ok(); + } + + /** + * 修改密码 + */ + @GetMapping(value = "/updatePassword") + public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { + YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId")); + if(newPassword == null){ + return R.error("新密码不能为空") ; + } + if(!oldPassword.equals(yonghu.getPassword())){ + return R.error("原密码输入错误"); + } + if(newPassword.equals(yonghu.getPassword())){ + return R.error("新密码不能和原密码一致") ; + } + yonghu.setPassword(newPassword); + yonghuService.updateById(yonghu); + return R.ok(); + } + + + + /** + * 忘记密码 + */ + @IgnoreAuth + @RequestMapping(value = "/resetPass") + public R resetPass(String username, HttpServletRequest request) { + YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper().eq("username", username)); + if(yonghu!=null){ + yonghu.setPassword("123456"); + yonghuService.updateById(yonghu); + return R.ok(); + }else{ + return R.error("账号不存在"); +======= package com.controller; // 声明当前类所在的包路径 // 导入Java IO类 @@ -428,10 +840,30 @@ public class YonghuController { return R.ok(); // 返回成功结果 }else{ // 如果用户不存在 return R.error("账号不存在"); // 返回错误信息 +>>>>>>> develop } } +<<<<<<< HEAD + /** + * 获取用户的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,"查不到数据"); +======= //获取当前会话用户信息 //@param request HTTP请求对象 //@return 用户信息 @@ -446,10 +878,99 @@ public class YonghuController { return R.ok().put("data", view); // 返回用户信息 }else { return R.error(511,"查不到数据"); // 返回错误信息 +>>>>>>> develop + } + } + + +<<<<<<< HEAD + /** + * 退出 + */ + @GetMapping(value = "logout") + public R logout(HttpServletRequest request) { + request.getSession().invalidate(); + return R.ok("退出成功"); + } + + + + /** + * 前端列表 + */ + @IgnoreAuth + @RequestMapping("/list") + public R list(@RequestParam Map params, HttpServletRequest request){ + logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + + CommonUtil.checkMap(params); + PageUtils page = yonghuService.queryPage(params); + + //字典表数据转换 + List list =(List)page.getList(); + for(YonghuView c:list) + dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段 + + return R.ok().put("data", page); + } + + /** + * 前端详情 + */ + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Integer 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 queryWrapper = new EntityWrapper() + .eq("username", yonghu.getUsername()) + .or() + .eq("yonghu_phone", yonghu.getYonghuPhone()) + .or() + .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) + .andNew() + .eq("data_delete", 1) +// .notIn("yonghu_types", new Integer[]{102}) + ; + logger.info("sql语句:"+queryWrapper.getSqlSegment()); + YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); + if(yonghuEntity==null){ + yonghu.setDataDelete(1); + yonghu.setInsertTime(new Date()); + yonghu.setCreateTime(new Date()); + yonghu.setPassword("123456"); + yonghuService.insert(yonghu); + + return R.ok(); + }else { + return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); } } +} +======= //用户退出 //@param request HTTP请求对象 //@return 操作结果 @@ -529,4 +1050,5 @@ public class YonghuController { return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息 } } -} \ No newline at end of file +} +>>>>>>> develop diff --git a/src/main/java/com/jianshenfangglApplication.java b/src/main/java/com/jianshenfangglApplication.java index 4871ada..2edb84c 100644 --- a/src/main/java/com/jianshenfangglApplication.java +++ b/src/main/java/com/jianshenfangglApplication.java @@ -1,4 +1,7 @@ -package com; + +package com; // 定义包名为com,表示该文件位于com包下 + +// 导入Spring Boot和MyBatis相关的注解和类 import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -7,17 +10,21 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -@SpringBootApplication -@ServletComponentScan(value = "com.ServletContextListener") -@MapperScan(basePackages = {"com.dao"}) -public class jianshenfangglApplication extends SpringBootServletInitializer{ +@SpringBootApplication // 标识这是一个Spring Boot应用程序的主类,包含自动配置、组件扫描等功能 +@ServletComponentScan(value = "com.ServletContextListener") // 指定扫描Servlet组件的包路径,用于注册Servlet、Filter等 +@MapperScan(basePackages = {"com.dao"}) // 指定MyBatis的Mapper接口所在的包路径,Spring会自动扫描并注册这些接口 +public class jianshenfangglApplication extends SpringBootServletInitializer { // 主类继承SpringBootServletInitializer,支持以WAR包形式部署 public static void main(String[] args) { + // 主方法,启动Spring Boot应用程序 SpringApplication.run(jianshenfangglApplication.class, args); } - + @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) { - return applicationBuilder.sources(jianshenfangglApplication.class); - } + protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) { + // 重写configure方法,用于配置Spring Boot应用程序的启动源,支持外部容器(如Tomcat)部署 + return applicationBuilder.sources(jianshenfangglApplication.class); + } } + + diff --git a/src/main/java/com/utils/R.java b/src/main/java/com/utils/R.java index 680b3f8..80fac85 100644 --- a/src/main/java/com/utils/R.java +++ b/src/main/java/com/utils/R.java @@ -1,3 +1,97 @@ +<<<<<<< HEAD +package com.utils; // 定义包名为com.utils,表示该类位于com.utils包下 + +import java.util.HashMap; // 导入HashMap类,用于实现键值对存储 +import java.util.Map; // 导入Map接口,用于处理键值对集合 + + +// 返回数据工具类 +//继承HashMap,提供统一的API响应格式封装 + +public class R extends HashMap { + private static final long serialVersionUID = 1L; // 序列化版本ID,保证序列化兼容性 + + + // 默认构造函数 + //初始化时默认设置code为0(表示成功) + + public R() { + put("code", 0); // 默认成功状态码 + } + + + // 创建错误响应(使用默认错误码和消息) + //@return 包含默认错误信息的R对象 + + public static R error() { + return error(500, "未知异常,请联系管理员"); // 默认服务器错误 + } + + + // 创建带自定义消息的错误响应(使用默认错误码500) + //@param msg 错误消息 + //@return 包含自定义错误消息的R对象 + + public static R error(String msg) { + return error(500, msg); // 使用默认错误码500 + } + + + // 创建带自定义错误码和消息的错误响应 + //@param code 错误码 + //@param msg 错误消息 + //@return 包含自定义错误信息的R对象 + + public static R error(int code, String msg) { + R r = new R(); + r.put("code", code); // 设置错误码 + r.put("msg", msg); // 设置错误消息 + return r; + } + + + // 创建成功响应(带自定义消息) + //@param msg 成功消息 + //@return 包含成功消息的R对象 + + public static R ok(String msg) { + R r = new R(); + r.put("msg", msg); // 设置成功消息 + return r; + } + + + // 创建成功响应(带多个数据) + //@param map 包含多个键值对的数据集合 + //@return 包含所有数据的R对象 + + public static R ok(Map map) { + R r = new R(); + r.putAll(map); // 添加所有数据到响应中 + return r; + } + + + // 创建默认成功响应 + //@return 只包含默认成功码的R对象 + + public static R ok() { + return new R(); // 使用默认构造函数 + } + + + // 添加键值对到响应中(链式调用支持) + //@param key 键名 + //@param value 键值 + //@return 当前R对象(支持链式调用) + + @Override + public R put(String key, Object value) { + super.put(key, value); // 调用父类HashMap的put方法 + return this; // 返回当前对象以实现链式调用 + } +} +======= package com.utils; import java.util.HashMap; @@ -49,3 +143,4 @@ public class R extends HashMap { return this; } } +>>>>>>> develop