diff --git a/springbootpt9c5/src/main/java/com/config/InterceptorConfig.java b/springbootpt9c5/src/main/java/com/config/InterceptorConfig.java index 7dc41c7e..73d476a9 100644 --- a/springbootpt9c5/src/main/java/com/config/InterceptorConfig.java +++ b/springbootpt9c5/src/main/java/com/config/InterceptorConfig.java @@ -9,27 +9,38 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp import com.interceptor.AuthorizationInterceptor; @Configuration -public class InterceptorConfig extends WebMvcConfigurationSupport{ - - @Bean +public class InterceptorConfig extends WebMvcConfigurationSupport { + + // 定义一个 Bean 方法,返回 AuthorizationInterceptor 的实例 + @Bean public AuthorizationInterceptor getAuthorizationInterceptor() { - return new AuthorizationInterceptor(); + return new AuthorizationInterceptor(); // 创建并返回一个新的 AuthorizationInterceptor 实例 } - - @Override + + // 重写 addInterceptors 方法,添加自定义拦截器 + @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/**").excludePathPatterns("/static/**"); - super.addInterceptors(registry); - } + // 将 AuthorizationInterceptor 添加到拦截器链中 + registry.addInterceptor(getAuthorizationInterceptor()) + .addPathPatterns("/**") // 匹配所有路径 + .excludePathPatterns("/static/**"); // 排除对 /static/** 路径的拦截 + super.addInterceptors(registry); // 调用父类方法继续处理其他拦截器 + } - @Override + /** + * 当使用 Spring Boot 2.0 并继承 WebMvcConfigurationSupport 时,默认的静态资源处理会被覆盖。 + * 因此需要重写 addResourceHandlers 方法来确保静态资源能够正常访问。 + */ + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/**") - .addResourceLocations("classpath:/resources/") - .addResourceLocations("classpath:/static/") - .addResourceLocations("classpath:/admin/") - .addResourceLocations("classpath:/front/") - .addResourceLocations("classpath:/public/"); - super.addResourceHandlers(registry); + // 添加资源处理器,处理所有路径的静态资源请求 + registry.addResourceHandler("/**") + .addResourceLocations("classpath:/resources/") // 从 classpath:/resources/ 目录加载资源 + .addResourceLocations("classpath:/static/") // 从 classpath:/static/ 目录加载资源 + .addResourceLocations("classpath:/admin/") // 从 classpath:/admin/ 目录加载资源 + .addResourceLocations("classpath:/front/") // 从 classpath:/front/ 目录加载资源 + .addResourceLocations("classpath:/public/"); // 从 classpath:/public/ 目录加载资源 + super.addResourceHandlers(registry); // 调用父类方法继续处理其他资源处理器 } } + diff --git a/springbootpt9c5/src/main/java/com/config/MybatisPlusConfig.java b/springbootpt9c5/src/main/java/com/config/MybatisPlusConfig.java index f1c106eb..14821ad0 100644 --- a/springbootpt9c5/src/main/java/com/config/MybatisPlusConfig.java +++ b/springbootpt9c5/src/main/java/com/config/MybatisPlusConfig.java @@ -7,12 +7,18 @@ 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(); + return new PaginationInterceptor(); // 创建并返回一个新的 PaginationInterceptor 实例 } - } + diff --git a/springbootpt9c5/src/main/java/com/controller/CommonController.java b/springbootpt9c5/src/main/java/com/controller/CommonController.java index 540abb13..4811af5d 100644 --- a/springbootpt9c5/src/main/java/com/controller/CommonController.java +++ b/springbootpt9c5/src/main/java/com/controller/CommonController.java @@ -35,208 +35,258 @@ import com.utils.BaiduUtil; import com.utils.FileUtil; import com.utils.R; +/** + * 通用接口控制器 + */ @RestController -public class CommonController{ +public class CommonController { + + @Autowired + private CommonService commonService; // 注入通用服务 + + private static AipFace client = null; // 百度人脸API客户端实例 + @Autowired - private CommonService commonService; + private ConfigService configService; // 注入配置服务 - private static AipFace client = null; - - @Autowired - private ConfigService configService; + /** + * 获取table表中的column列表(联动接口) + * @param tableName 表名 + * @param columnName 列名 + * @param level 层级(可选) + * @param parent 父节点(可选) + * @return 返回联动数据 + */ @IgnoreAuth @RequestMapping("/option/{tableName}/{columnName}") - public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("column", columnName); - if(StringUtils.isNotBlank(level)) { - params.put("level", level); + public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, + String level, String parent) { + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("column", columnName); // 添加列名 + if (StringUtils.isNotBlank(level)) { // 如果层级不为空 + params.put("level", level); // 添加层级 } - if(StringUtils.isNotBlank(parent)) { - params.put("parent", parent); + if (StringUtils.isNotBlank(parent)) { // 如果父节点不为空 + params.put("parent", parent); // 添加父节点 } - List data = commonService.getOption(params); - return R.ok().put("data", data); + List data = commonService.getOption(params); // 调用服务获取数据 + return R.ok().put("data", data); // 返回成功结果 } + /** + * 根据table中的column获取单条记录 + * @param tableName 表名 + * @param columnName 列名 + * @param columnValue 列值 + * @return 返回单条记录 + */ @IgnoreAuth @RequestMapping("/follow/{tableName}/{columnName}") - public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("column", columnName); - params.put("columnValue", columnValue); - Map result = commonService.getFollowByOption(params); - return R.ok().put("data", result); + public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, + @RequestParam String columnValue) { + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("column", columnName); // 添加列名 + params.put("columnValue", columnValue); // 添加列值 + Map result = commonService.getFollowByOption(params); // 调用服务获取结果 + return R.ok().put("data", result); // 返回成功结果 } + /** + * 修改table表的sfsh状态 + * @param tableName 表名 + * @param map 请求参数 + * @return 返回操作结果 + */ @RequestMapping("/sh/{tableName}") public R sh(@PathVariable("tableName") String tableName, @RequestBody Map map) { - map.put("table", tableName); - commonService.sh(map); - return R.ok(); + map.put("table", tableName); // 添加表名 + commonService.sh(map); // 调用服务修改状态 + return R.ok(); // 返回成功结果 } - + /** + * 获取需要提醒的记录数 + * @param tableName 表名 + * @param columnName 列名 + * @param type 提醒类型(1:数字, 2:日期) + * @param map 请求参数 + * @return 返回提醒记录数 + */ @IgnoreAuth @RequestMapping("/remind/{tableName}/{columnName}/{type}") - public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("table", tableName); - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); + public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("table", tableName); // 添加表名 + map.put("column", columnName); // 添加列名 + map.put("type", type); // 添加提醒类型 + if ("2".equals(type)) { // 如果类型为日期 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具 + Calendar c = Calendar.getInstance(); // 日历实例 + Date remindStartDate = null; // 提醒开始日期 + Date remindEndDate = null; // 提醒结束日期 + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前时间为基准 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 增加天数 + remindStartDate = c.getTime(); // 获取新的日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并更新参数 } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前时间为基准 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 增加天数 + remindEndDate = c.getTime(); // 获取新的日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并更新参数 } } - - int count = commonService.remindCount(map); - return R.ok().put("count", count); + int count = commonService.remindCount(map); // 调用服务获取提醒记录数 + return R.ok().put("count", count); // 返回成功结果 } - + /** * 单列求和 + * @param tableName 表名 + * @param columnName 列名 + * @return 返回求和结果 */ @IgnoreAuth @RequestMapping("/cal/{tableName}/{columnName}") public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("column", columnName); - Map result = commonService.selectCal(params); - return R.ok().put("data", result); + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("column", columnName); // 添加列名 + Map result = commonService.selectCal(params); // 调用服务获取求和结果 + return R.ok().put("data", result); // 返回成功结果 } - + /** * 分组统计 + * @param tableName 表名 + * @param columnName 列名 + * @return 返回分组统计结果 */ @IgnoreAuth @RequestMapping("/group/{tableName}/{columnName}") public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("column", columnName); - List> result = commonService.selectGroup(params); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("column", columnName); // 添加列名 + List> result = commonService.selectGroup(params); // 调用服务获取分组统计结果 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具 + for (Map m : result) { // 遍历结果 + for (String k : m.keySet()) { // 遍历键 + if (m.get(k) instanceof Date) { // 如果值是日期类型 + m.put(k, sdf.format((Date) m.get(k))); // 格式化日期 } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回成功结果 } - + /** * (按值统计) + * @param tableName 表名 + * @param yColumnName Y轴列名 + * @param xColumnName X轴列名 + * @return 返回按值统计结果 */ @IgnoreAuth @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}") - public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("xColumn", xColumnName); - params.put("yColumn", yColumnName); - List> result = commonService.selectValue(params); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, + @PathVariable("xColumnName") String xColumnName) { + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("xColumn", xColumnName); // 添加X轴列名 + params.put("yColumn", yColumnName); // 添加Y轴列名 + List> result = commonService.selectValue(params); // 调用服务获取按值统计结果 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具 + for (Map m : result) { // 遍历结果 + for (String k : m.keySet()) { // 遍历键 + if (m.get(k) instanceof Date) { // 如果值是日期类型 + m.put(k, sdf.format((Date) m.get(k))); // 格式化日期 } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回成功结果 } /** - * (按值统计)时间统计类型 + * (按值统计)时间统计类型 + * @param tableName 表名 + * @param xColumnName X轴列名 + * @param yColumnName Y轴列名 + * @param timeStatType 时间统计类型 + * @return 返回按值统计结果 */ @IgnoreAuth @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}/{timeStatType}") - public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) { - Map params = new HashMap(); - params.put("table", tableName); - params.put("xColumn", xColumnName); - params.put("yColumn", yColumnName); - params.put("timeStatType", timeStatType); - List> result = commonService.selectTimeStatValue(params); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, + @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) { + Map params = new HashMap(); // 参数封装 + params.put("table", tableName); // 添加表名 + params.put("xColumn", xColumnName); // 添加X轴列名 + params.put("yColumn", yColumnName); // 添加Y轴列名 + params.put("timeStatType", timeStatType); // 添加时间统计类型 + List> result = commonService.selectTimeStatValue(params); // 调用服务获取按值统计结果 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具 + for (Map m : result) { // 遍历结果 + for (String k : m.keySet()) { // 遍历键 + if (m.get(k) instanceof Date) { // 如果值是日期类型 + m.put(k, sdf.format((Date) m.get(k))); // 格式化日期 } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回成功结果 + } + + /** + * 人脸比对 + * @param face1 人脸1 + * @param face2 人脸2 + * @param request HTTP请求对象 + * @return 返回比对分数 + */ + @RequestMapping("/matchFace") + @IgnoreAuth + public R matchFace(String face1, String face2, HttpServletRequest request) { + if (client == null) { // 如果客户端未初始化 + /*String AppID = configService.selectOne(new EntityWrapper().eq("name", "AppID")).getValue();*/ + String APIKey = configService.selectOne(new EntityWrapper().eq("name", "APIKey")).getValue(); // 获取API Key + String SecretKey = configService.selectOne(new EntityWrapper().eq("name", "SecretKey")).getValue(); // 获取Secret Key + String token = BaiduUtil.getAuth(APIKey, SecretKey); // 获取访问令牌 + if (token == null) { // 如果令牌为空 + return R.error("请在配置管理中正确配置APIKey和SecretKey"); // 返回错误信息 + } + client = new AipFace(null, APIKey, SecretKey); // 初始化客户端 + client.setConnectionTimeoutInMillis(2000); // 设置连接超时时间 + client.setSocketTimeoutInMillis(60000); // 设置套接字超时时间 + } + JSONObject res = null; // 响应结果 + try { + File path = new File(ResourceUtils.getURL("classpath:static").getPath()); // 获取静态资源路径 + if (!path.exists()) { // 如果路径不存在 + path = new File(""); // 使用当前目录 + } + File upload = new File(path.getAbsolutePath(), "/upload/"); // 创建上传目录 + File file1 = new File(upload.getAbsolutePath(), face1); // 文件1 + File file2 = new File(upload.getAbsolutePath(), face2); // 文件2 + String img1 = Base64Util.encode(FileUtil.FileToByte(file1)); // 将文件1转换为Base64 + String img2 = Base64Util.encode(FileUtil.FileToByte(file2)); // 将文件2转换为Base64 + MatchRequest req1 = new MatchRequest(img1, "BASE64"); // 第一个人脸请求 + MatchRequest req2 = new MatchRequest(img2, "BASE64"); // 第二个人脸请求 + ArrayList requests = new ArrayList(); // 请求列表 + requests.add(req1); // 添加第一个请求 + requests.add(req2); // 添加第二个请求 + res = client.match(requests); // 调用人脸比对接口 + System.out.println(res.get("result")); // 打印比对结果 + } catch (FileNotFoundException e) { // 文件未找到异常 + e.printStackTrace(); // 打印堆栈信息 + return R.error("文件不存在"); // 返回错误信息 + } catch (IOException e) { // IO异常 + e.printStackTrace(); // 打印堆栈信息 + } + return R.ok().put("score", com.alibaba.fastjson.JSONObject.parse(res.getJSONObject("result").get("score").toString())); // 返回比对分数 } - - /** - * 人脸比对 - * - * @param face1 人脸1 - * @param face2 人脸2 - * @return - */ - @RequestMapping("/matchFace") - @IgnoreAuth - public R matchFace(String face1, String face2,HttpServletRequest request) { - if(client==null) { - /*String AppID = configService.selectOne(new EntityWrapper().eq("name", "AppID")).getValue();*/ - String APIKey = configService.selectOne(new EntityWrapper().eq("name", "APIKey")).getValue(); - String SecretKey = configService.selectOne(new EntityWrapper().eq("name", "SecretKey")).getValue(); - String token = BaiduUtil.getAuth(APIKey, SecretKey); - if(token==null) { - return R.error("请在配置管理中正确配置APIKey和SecretKey"); - } - client = new AipFace(null, APIKey, SecretKey); - client.setConnectionTimeoutInMillis(2000); - client.setSocketTimeoutInMillis(60000); - } - JSONObject res = null; - try { - File path = new File(ResourceUtils.getURL("classpath:static").getPath()); - if(!path.exists()) { - path = new File(""); - } - File upload = new File(path.getAbsolutePath(),"/upload/"); - File file1 = new File(upload.getAbsolutePath()+"/"+face1); - File file2 = new File(upload.getAbsolutePath()+"/"+face2); - String img1 = Base64Util.encode(FileUtil.FileToByte(file1)); - String img2 = Base64Util.encode(FileUtil.FileToByte(file2)); - MatchRequest req1 = new MatchRequest(img1, "BASE64"); - MatchRequest req2 = new MatchRequest(img2, "BASE64"); - ArrayList requests = new ArrayList(); - requests.add(req1); - requests.add(req2); - res = client.match(requests); - System.out.println(res.get("result")); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return R.error("文件不存在"); - } catch (IOException e) { - e.printStackTrace(); - } - return R.ok().put("score", com.alibaba.fastjson.JSONObject.parse(res.getJSONObject("result").get("score").toString())); - } } diff --git a/springbootpt9c5/src/main/java/com/controller/ConfigController.java b/springbootpt9c5/src/main/java/com/controller/ConfigController.java index 577a7226..46a11f00 100644 --- a/springbootpt9c5/src/main/java/com/controller/ConfigController.java +++ b/springbootpt9c5/src/main/java/com/controller/ConfigController.java @@ -1,7 +1,5 @@ - package com.controller; - import java.util.Arrays; import java.util.Map; @@ -23,64 +21,108 @@ import com.utils.R; import com.utils.ValidatorUtils; /** - * 登录相关 + * 配置管理相关接口 */ @RequestMapping("config") @RestController -public class ConfigController{ - - @Autowired - private ConfigService configService; +public class ConfigController { + @Autowired + private ConfigService configService; // 注入配置服务 + + /** + * 查询配置列表(带分页) + * @param params 查询参数 + * @param config 查询条件对象 + * @return 返回分页数据 + */ @RequestMapping("/page") - public R page(@RequestParam Map params,ConfigEntity config){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); - return R.ok().put("data", page); + public R page(@RequestParam Map params, ConfigEntity config) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回成功结果 } + + /** + * 查询配置列表(忽略认证) + * @param params 查询参数 + * @param config 查询条件对象 + * @return 返回分页数据 + */ @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,ConfigEntity config){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, ConfigEntity config) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回成功结果 } + /** + * 根据ID查询配置信息 + * @param id 配置ID + * @return 返回配置信息 + */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") String id){ - ConfigEntity config = configService.selectById(id); - return R.ok().put("data", config); + public R info(@PathVariable("id") String id) { + ConfigEntity config = configService.selectById(id); // 根据ID查询配置 + return R.ok().put("data", config); // 返回成功结果 } + /** + * 根据ID查询配置详情(忽略认证) + * @param id 配置ID + * @return 返回配置详情 + */ @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") String id){ - ConfigEntity config = configService.selectById(id); - return R.ok().put("data", config); + public R detail(@PathVariable("id") String id) { + ConfigEntity config = configService.selectById(id); // 根据ID查询配置 + return R.ok().put("data", config); // 返回成功结果 } + /** + * 根据名称查询配置信息 + * @param name 配置名称 + * @return 返回配置信息 + */ @RequestMapping("/info") - public R infoByName(@RequestParam String name){ - ConfigEntity config = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); - return R.ok().put("data", config); + public R infoByName(@RequestParam String name) { + ConfigEntity config = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); // 根据名称查询配置 + return R.ok().put("data", config); // 返回成功结果 } + + /** + * 保存配置信息 + * @param config 配置对象 + * @return 返回操作结果 + */ @PostMapping("/save") - public R save(@RequestBody ConfigEntity config){ -// ValidatorUtils.validateEntity(config); - configService.insert(config); - return R.ok(); + public R save(@RequestBody ConfigEntity config) { +// ValidatorUtils.validateEntity(config); // 验证配置对象 + configService.insert(config); // 插入配置 + return R.ok(); // 返回成功结果 } - + /** + * 更新配置信息 + * @param config 配置对象 + * @return 返回操作结果 + */ @RequestMapping("/update") - public R update(@RequestBody ConfigEntity config){ -// ValidatorUtils.validateEntity(config); - configService.updateById(config);//全部更新 - return R.ok(); + public R update(@RequestBody ConfigEntity config) { +// ValidatorUtils.validateEntity(config); // 验证配置对象 + configService.updateById(config); // 根据ID更新配置 + return R.ok(); // 返回成功结果 } + + /** + * 批量删除配置信息 + * @param ids 配置ID数组 + * @return 返回操作结果 + */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - configService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除配置 + return R.ok(); // 返回成功结果 } } diff --git a/springbootpt9c5/src/main/java/com/controller/DiscusshuodongxindeController.java b/springbootpt9c5/src/main/java/com/controller/DiscusshuodongxindeController.java index 45890cf8..60bbc34a 100644 --- a/springbootpt9c5/src/main/java/com/controller/DiscusshuodongxindeController.java +++ b/springbootpt9c5/src/main/java/com/controller/DiscusshuodongxindeController.java @@ -1,14 +1,7 @@ package com.controller; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Map; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Date; -import java.util.List; +import java.util.*; import javax.servlet.http.HttpServletRequest; import com.utils.ValidatorUtils; @@ -16,11 +9,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.format.annotation.DateTimeFormat; -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.bind.annotation.*; + import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.annotation.IgnoreAuth; @@ -38,180 +28,192 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 活动心得评论表 - * 后端接口 - * @author - * @email + * 活动心得评论表后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/discusshuodongxinde") public class DiscusshuodongxindeController { @Autowired - private DiscusshuodongxindeService discusshuodongxindeService; - - - - + private DiscusshuodongxindeService discusshuodongxindeService; // 注入服务类 /** - * 后端列表 + * 后端列表接口 + * @param params 查询参数 + * @param discusshuodongxinde 查询条件实体 + * @param request 请求对象 + * @return 返回分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,DiscusshuodongxindeEntity discusshuodongxinde, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = discusshuodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusshuodongxinde), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = discusshuodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusshuodongxinde), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回成功结果 } - + /** - * 前端列表 + * 前端列表接口(忽略认证) + * @param params 查询参数 + * @param discusshuodongxinde 查询条件实体 + * @param request 请求对象 + * @return 返回分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,DiscusshuodongxindeEntity discusshuodongxinde, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = discusshuodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusshuodongxinde), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = discusshuodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusshuodongxinde), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回成功结果 } - /** - * 列表 + /** + * 列表接口(无分页) + * @param discusshuodongxinde 查询条件实体 + * @return 返回查询结果 */ @RequestMapping("/lists") - public R list( DiscusshuodongxindeEntity discusshuodongxinde){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( discusshuodongxinde, "discusshuodongxinde")); - return R.ok().put("data", discusshuodongxindeService.selectListView(ew)); + public R list(DiscusshuodongxindeEntity discusshuodongxinde) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(discusshuodongxinde, "discusshuodongxinde")); // 设置查询条件 + return R.ok().put("data", discusshuodongxindeService.selectListView(ew)); // 返回查询结果 } - /** - * 查询 + /** + * 查询接口 + * @param discusshuodongxinde 查询条件实体 + * @return 返回查询结果 */ @RequestMapping("/query") - public R query(DiscusshuodongxindeEntity discusshuodongxinde){ - EntityWrapper< DiscusshuodongxindeEntity> ew = new EntityWrapper< DiscusshuodongxindeEntity>(); - ew.allEq(MPUtil.allEQMapPre( discusshuodongxinde, "discusshuodongxinde")); - DiscusshuodongxindeView discusshuodongxindeView = discusshuodongxindeService.selectView(ew); - return R.ok("查询活动心得评论表成功").put("data", discusshuodongxindeView); + public R query(DiscusshuodongxindeEntity discusshuodongxinde) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(discusshuodongxinde, "discusshuodongxinde")); // 设置查询条件 + DiscusshuodongxindeView discusshuodongxindeView = discusshuodongxindeService.selectView(ew); // 查询视图数据 + return R.ok("查询活动心得评论表成功").put("data", discusshuodongxindeView); // 返回查询结果 } - + /** - * 后端详情 + * 后端详情接口 + * @param id 主键ID + * @return 返回指定ID的数据 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - DiscusshuodongxindeEntity discusshuodongxinde = discusshuodongxindeService.selectById(id); - return R.ok().put("data", discusshuodongxinde); + public R info(@PathVariable("id") Long id) { + DiscusshuodongxindeEntity discusshuodongxinde = discusshuodongxindeService.selectById(id); // 根据ID查询数据 + return R.ok().put("data", discusshuodongxinde); // 返回查询结果 } /** - * 前端详情 + * 前端详情接口(忽略认证) + * @param id 主键ID + * @return 返回指定ID的数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - DiscusshuodongxindeEntity discusshuodongxinde = discusshuodongxindeService.selectById(id); - return R.ok().put("data", discusshuodongxinde); + public R detail(@PathVariable("id") Long id) { + DiscusshuodongxindeEntity discusshuodongxinde = discusshuodongxindeService.selectById(id); // 根据ID查询数据 + return R.ok().put("data", discusshuodongxinde); // 返回查询结果 } - - - /** - * 后端保存 + * 后端保存接口 + * @param discusshuodongxinde 数据实体 + * @param request 请求对象 + * @return 返回保存结果 */ @RequestMapping("/save") - public R save(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request){ - discusshuodongxinde.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(discusshuodongxinde); - discusshuodongxindeService.insert(discusshuodongxinde); - return R.ok(); + public R save(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request) { + discusshuodongxinde.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(discusshuodongxinde); // 验证数据 + discusshuodongxindeService.insert(discusshuodongxinde); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** - * 前端保存 + * 前端保存接口 + * @param discusshuodongxinde 数据实体 + * @param request 请求对象 + * @return 返回保存结果 */ @RequestMapping("/add") - public R add(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request){ - discusshuodongxinde.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(discusshuodongxinde); - discusshuodongxindeService.insert(discusshuodongxinde); - return R.ok(); + public R add(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request) { + discusshuodongxinde.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(discusshuodongxinde); // 验证数据 + discusshuodongxindeService.insert(discusshuodongxinde); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改接口 + * @param discusshuodongxinde 数据实体 + * @param request 请求对象 + * @return 返回修改结果 */ @RequestMapping("/update") - @Transactional - public R update(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request){ - //ValidatorUtils.validateEntity(discusshuodongxinde); - discusshuodongxindeService.updateById(discusshuodongxinde);//全部更新 - return R.ok(); + @Transactional // 开启事务 + public R update(@RequestBody DiscusshuodongxindeEntity discusshuodongxinde, HttpServletRequest request) { + // ValidatorUtils.validateEntity(discusshuodongxinde); // 验证数据 + discusshuodongxindeService.updateById(discusshuodongxinde); // 根据ID更新数据 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除接口 + * @param ids ID数组 + * @return 返回删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - discusshuodongxindeService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + discusshuodongxindeService.deleteBatchIds(Arrays.asList(ids)); // 批量删除数据 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param type 类型 + * @param map 查询参数 + * @return 返回提醒记录数 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = discusshuodongxindeService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加类型到参数 + + if (type.equals("2")) { // 如果类型为2 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有开始日期 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并存入参数 + } + + if (map.get("remindend") != null) { // 如果有结束日期 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并存入参数 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + int count = discusshuodongxindeService.selectCount(wrapper); // 统计符合条件的记录数 + return R.ok().put("count", count); // 返回统计结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/FileController.java b/springbootpt9c5/src/main/java/com/controller/FileController.java index 1aa99654..132e803c 100644 --- a/springbootpt9c5/src/main/java/com/controller/FileController.java +++ b/springbootpt9c5/src/main/java/com/controller/FileController.java @@ -19,11 +19,7 @@ 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.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.annotation.IgnoreAuth; @@ -34,83 +30,95 @@ import com.service.ConfigService; import com.utils.R; /** - * 上传文件映射表 + * 文件上传与下载控制器 */ @RestController @RequestMapping("file") @SuppressWarnings({"unchecked","rawtypes"}) -public class FileController{ +public class FileController { @Autowired - private ConfigService configService; + private ConfigService configService; // 注入配置服务类 + /** - * 上传文件 + * 文件上传接口 + * @param file 文件对象 + * @param type 类型标识(1表示人脸文件) + * @return 返回上传成功的文件名 + * @throws Exception 异常处理 */ @RequestMapping("/upload") - public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception { - if (file.isEmpty()) { - throw new EIException("上传文件不能为空"); + 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(""); + + 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(); + + 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); + + String fileName = new Date().getTime() + "." + fileExt; // 生成唯一的文件名 + File dest = new File(upload.getAbsolutePath() + "/" + fileName); // 定义目标文件路径 + file.transferTo(dest); // 将文件保存到目标位置 + /** - * 如果使用idea或者eclipse重启项目,发现之前上传的图片或者文件丢失,将下面一行代码注释打开 - * 请将以下的"D:\\springbootq33sd\\src\\main\\resources\\static\\upload"替换成你本地项目的upload路径, - * 并且项目路径不能存在中文、空格等特殊字符 - */ -// FileUtils.copyFile(dest, new File("D:\\springbootq33sd\\src\\main\\resources\\static\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/ - 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); + * 如果使用IDE(如IntelliJ IDEA或Eclipse)重启项目时发现上传的文件丢失: + * 1. 注释掉此段代码中的文件复制逻辑。 + * 2. 替换路径为本地项目的实际路径(例如:"D:\\\\springbootq33sd\\\\src\\\\main\\\\resources\\\\static\\\\upload")。 + * 3. 确保路径中不含中文、空格等特殊字符。 + */ +// FileUtils.copyFile(dest, new File("D:\\\\springbootq33sd\\\\src\\\\main\\\\resources\\\\static\\\\upload\\\\" + fileName)); // 复制文件到指定路径 + + if (StringUtils.isNotBlank(type) && type.equals("1")) { // 如果类型为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); + configEntity.setValue(fileName); // 更新文件名 } - configService.insertOrUpdate(configEntity); + configService.insertOrUpdate(configEntity); // 插入或更新配置项 } - return R.ok().put("file", fileName); + + return R.ok().put("file", fileName); // 返回成功结果 } - + /** - * 下载文件 + * 文件下载接口 + * @param fileName 文件名 + * @return 返回文件流 */ @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 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 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); + + File file = new File(upload.getAbsolutePath() + "/" + fileName); // 定义目标文件路径 + if (file.exists()) { // 如果文件存在 + HttpHeaders headers = new HttpHeaders(); // 设置响应头 + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // 设置内容类型 + headers.setContentDispositionFormData("attachment", fileName); // 设置附件下载 + return new ResponseEntity(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); // 返回文件流 } } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(); // 打印异常日志 } - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); // 返回错误状态码 } - } diff --git a/springbootpt9c5/src/main/java/com/controller/HuodongbaomingController.java b/springbootpt9c5/src/main/java/com/controller/HuodongbaomingController.java index c609e365..6c88ac00 100644 --- a/springbootpt9c5/src/main/java/com/controller/HuodongbaomingController.java +++ b/springbootpt9c5/src/main/java/com/controller/HuodongbaomingController.java @@ -38,188 +38,204 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 活动报名 - * 后端接口 - * @author - * @email + * 活动报名管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/huodongbaoming") public class HuodongbaomingController { @Autowired - private HuodongbaomingService huodongbaomingService; - - - - + private HuodongbaomingService huodongbaomingService; // 注入活动报名服务 /** * 后端列表 + * @param params 请求参数 + * @param huodongbaoming 活动报名实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,HuodongbaomingEntity huodongbaoming, - HttpServletRequest request){ - String tableName = request.getSession().getAttribute("tableName").toString(); - if(tableName.equals("zhiyuanzhe")) { - huodongbaoming.setXuehao((String)request.getSession().getAttribute("username")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongbaomingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongbaoming), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, HuodongbaomingEntity huodongbaoming, + HttpServletRequest request) { + String tableName = request.getSession().getAttribute("tableName").toString(); // 获取当前用户表名 + if (tableName.equals("zhiyuanzhe")) { // 如果是志愿者表 + huodongbaoming.setXuehao((String) request.getSession().getAttribute("username")); // 设置学号 + } + + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongbaomingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongbaoming), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param huodongbaoming 活动报名实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,HuodongbaomingEntity huodongbaoming, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongbaomingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongbaoming), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, HuodongbaomingEntity huodongbaoming, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongbaomingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongbaoming), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param huodongbaoming 活动报名实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( HuodongbaomingEntity huodongbaoming){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( huodongbaoming, "huodongbaoming")); - return R.ok().put("data", huodongbaomingService.selectListView(ew)); + public R list(HuodongbaomingEntity huodongbaoming) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongbaoming, "huodongbaoming")); // 设置查询条件 + return R.ok().put("data", huodongbaomingService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param huodongbaoming 活动报名实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(HuodongbaomingEntity huodongbaoming){ - EntityWrapper< HuodongbaomingEntity> ew = new EntityWrapper< HuodongbaomingEntity>(); - ew.allEq(MPUtil.allEQMapPre( huodongbaoming, "huodongbaoming")); - HuodongbaomingView huodongbaomingView = huodongbaomingService.selectView(ew); - return R.ok("查询活动报名成功").put("data", huodongbaomingView); + public R query(HuodongbaomingEntity huodongbaoming) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongbaoming, "huodongbaoming")); // 设置查询条件 + HuodongbaomingView huodongbaomingView = huodongbaomingService.selectView(ew); // 查询视图 + return R.ok("查询活动报名成功").put("data", huodongbaomingView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - HuodongbaomingEntity huodongbaoming = huodongbaomingService.selectById(id); - return R.ok().put("data", huodongbaoming); + public R info(@PathVariable("id") Long id) { + HuodongbaomingEntity huodongbaoming = huodongbaomingService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongbaoming); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - HuodongbaomingEntity huodongbaoming = huodongbaomingService.selectById(id); - return R.ok().put("data", huodongbaoming); + public R detail(@PathVariable("id") Long id) { + HuodongbaomingEntity huodongbaoming = huodongbaomingService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongbaoming); // 返回记录详情 } - - - /** * 后端保存 + * @param huodongbaoming 活动报名实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request){ - huodongbaoming.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongbaoming); - huodongbaomingService.insert(huodongbaoming); - return R.ok(); + public R save(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request) { + huodongbaoming.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongbaomingService.insert(huodongbaoming); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param huodongbaoming 活动报名实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request){ - huodongbaoming.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongbaoming); - huodongbaomingService.insert(huodongbaoming); - return R.ok(); + public R add(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request) { + huodongbaoming.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongbaomingService.insert(huodongbaoming); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param huodongbaoming 活动报名实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request){ - //ValidatorUtils.validateEntity(huodongbaoming); - huodongbaomingService.updateById(huodongbaoming);//全部更新 - return R.ok(); + public R update(@RequestBody HuodongbaomingEntity huodongbaoming, HttpServletRequest request) { + huodongbaomingService.updateById(huodongbaoming); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - huodongbaomingService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + huodongbaomingService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - String tableName = request.getSession().getAttribute("tableName").toString(); - if(tableName.equals("zhiyuanzhe")) { - wrapper.eq("xuehao", (String)request.getSession().getAttribute("username")); - } - - int count = huodongbaomingService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + String tableName = request.getSession().getAttribute("tableName").toString(); // 获取当前用户表名 + if (tableName.equals("zhiyuanzhe")) { // 如果是志愿者表 + wrapper.eq("xuehao", (String) request.getSession().getAttribute("username")); // 设置学号条件 + } + + int count = huodongbaomingService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/HuodongleixingController.java b/springbootpt9c5/src/main/java/com/controller/HuodongleixingController.java index b32eddf0..57976d1d 100644 --- a/springbootpt9c5/src/main/java/com/controller/HuodongleixingController.java +++ b/springbootpt9c5/src/main/java/com/controller/HuodongleixingController.java @@ -38,180 +38,194 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 活动类型 - * 后端接口 - * @author - * @email + * 活动类型管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/huodongleixing") public class HuodongleixingController { @Autowired - private HuodongleixingService huodongleixingService; - - - - + private HuodongleixingService huodongleixingService; // 注入活动类型服务 /** * 后端列表 + * @param params 请求参数 + * @param huodongleixing 活动类型实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,HuodongleixingEntity huodongleixing, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongleixing), params), params)); + public R page(@RequestParam Map params, HuodongleixingEntity huodongleixing, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongleixing), params), params)); - return R.ok().put("data", page); + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param huodongleixing 活动类型实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,HuodongleixingEntity huodongleixing, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongleixing), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, HuodongleixingEntity huodongleixing, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongleixing), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param huodongleixing 活动类型实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( HuodongleixingEntity huodongleixing){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( huodongleixing, "huodongleixing")); - return R.ok().put("data", huodongleixingService.selectListView(ew)); + public R list(HuodongleixingEntity huodongleixing) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongleixing, "huodongleixing")); // 设置查询条件 + return R.ok().put("data", huodongleixingService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param huodongleixing 活动类型实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(HuodongleixingEntity huodongleixing){ - EntityWrapper< HuodongleixingEntity> ew = new EntityWrapper< HuodongleixingEntity>(); - ew.allEq(MPUtil.allEQMapPre( huodongleixing, "huodongleixing")); - HuodongleixingView huodongleixingView = huodongleixingService.selectView(ew); - return R.ok("查询活动类型成功").put("data", huodongleixingView); + public R query(HuodongleixingEntity huodongleixing) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongleixing, "huodongleixing")); // 设置查询条件 + HuodongleixingView huodongleixingView = huodongleixingService.selectView(ew); // 查询视图 + return R.ok("查询活动类型成功").put("data", huodongleixingView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - HuodongleixingEntity huodongleixing = huodongleixingService.selectById(id); - return R.ok().put("data", huodongleixing); + public R info(@PathVariable("id") Long id) { + HuodongleixingEntity huodongleixing = huodongleixingService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongleixing); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - HuodongleixingEntity huodongleixing = huodongleixingService.selectById(id); - return R.ok().put("data", huodongleixing); + public R detail(@PathVariable("id") Long id) { + HuodongleixingEntity huodongleixing = huodongleixingService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongleixing); // 返回记录详情 } - - - /** * 后端保存 + * @param huodongleixing 活动类型实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request){ - huodongleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongleixing); - huodongleixingService.insert(huodongleixing); - return R.ok(); + public R save(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request) { + huodongleixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongleixingService.insert(huodongleixing); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param huodongleixing 活动类型实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request){ - huodongleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongleixing); - huodongleixingService.insert(huodongleixing); - return R.ok(); + public R add(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request) { + huodongleixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongleixingService.insert(huodongleixing); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param huodongleixing 活动类型实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request){ - //ValidatorUtils.validateEntity(huodongleixing); - huodongleixingService.updateById(huodongleixing);//全部更新 - return R.ok(); + public R update(@RequestBody HuodongleixingEntity huodongleixing, HttpServletRequest request) { + huodongleixingService.updateById(huodongleixing); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - huodongleixingService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + huodongleixingService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = huodongleixingService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + int count = huodongleixingService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/HuodongtongzhiController.java b/springbootpt9c5/src/main/java/com/controller/HuodongtongzhiController.java index 81af6134..6faaa05a 100644 --- a/springbootpt9c5/src/main/java/com/controller/HuodongtongzhiController.java +++ b/springbootpt9c5/src/main/java/com/controller/HuodongtongzhiController.java @@ -38,188 +38,204 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 活动通知 - * 后端接口 - * @author - * @email + * 活动通知管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/huodongtongzhi") public class HuodongtongzhiController { @Autowired - private HuodongtongzhiService huodongtongzhiService; - - - - + private HuodongtongzhiService huodongtongzhiService; // 注入活动通知服务 /** * 后端列表 + * @param params 请求参数 + * @param huodongtongzhi 活动通知实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,HuodongtongzhiEntity huodongtongzhi, - HttpServletRequest request){ - String tableName = request.getSession().getAttribute("tableName").toString(); - if(tableName.equals("zhiyuanzhe")) { - huodongtongzhi.setXuehao((String)request.getSession().getAttribute("username")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongtongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongtongzhi), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, HuodongtongzhiEntity huodongtongzhi, + HttpServletRequest request) { + String tableName = request.getSession().getAttribute("tableName").toString(); // 获取当前表名 + if (tableName.equals("zhiyuanzhe")) { // 如果是志愿者表 + huodongtongzhi.setXuehao((String) request.getSession().getAttribute("username")); // 设置学号 + } + + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongtongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongtongzhi), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param huodongtongzhi 活动通知实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,HuodongtongzhiEntity huodongtongzhi, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongtongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongtongzhi), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, HuodongtongzhiEntity huodongtongzhi, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongtongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongtongzhi), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param huodongtongzhi 活动通知实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( HuodongtongzhiEntity huodongtongzhi){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( huodongtongzhi, "huodongtongzhi")); - return R.ok().put("data", huodongtongzhiService.selectListView(ew)); + public R list(HuodongtongzhiEntity huodongtongzhi) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongtongzhi, "huodongtongzhi")); // 设置查询条件 + return R.ok().put("data", huodongtongzhiService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param huodongtongzhi 活动通知实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(HuodongtongzhiEntity huodongtongzhi){ - EntityWrapper< HuodongtongzhiEntity> ew = new EntityWrapper< HuodongtongzhiEntity>(); - ew.allEq(MPUtil.allEQMapPre( huodongtongzhi, "huodongtongzhi")); - HuodongtongzhiView huodongtongzhiView = huodongtongzhiService.selectView(ew); - return R.ok("查询活动通知成功").put("data", huodongtongzhiView); + public R query(HuodongtongzhiEntity huodongtongzhi) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongtongzhi, "huodongtongzhi")); // 设置查询条件 + HuodongtongzhiView huodongtongzhiView = huodongtongzhiService.selectView(ew); // 查询视图 + return R.ok("查询活动通知成功").put("data", huodongtongzhiView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - HuodongtongzhiEntity huodongtongzhi = huodongtongzhiService.selectById(id); - return R.ok().put("data", huodongtongzhi); + public R info(@PathVariable("id") Long id) { + HuodongtongzhiEntity huodongtongzhi = huodongtongzhiService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongtongzhi); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - HuodongtongzhiEntity huodongtongzhi = huodongtongzhiService.selectById(id); - return R.ok().put("data", huodongtongzhi); + public R detail(@PathVariable("id") Long id) { + HuodongtongzhiEntity huodongtongzhi = huodongtongzhiService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongtongzhi); // 返回记录详情 } - - - /** * 后端保存 + * @param huodongtongzhi 活动通知实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request){ - huodongtongzhi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongtongzhi); - huodongtongzhiService.insert(huodongtongzhi); - return R.ok(); + public R save(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request) { + huodongtongzhi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongtongzhiService.insert(huodongtongzhi); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param huodongtongzhi 活动通知实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request){ - huodongtongzhi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongtongzhi); - huodongtongzhiService.insert(huodongtongzhi); - return R.ok(); + public R add(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request) { + huodongtongzhi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + huodongtongzhiService.insert(huodongtongzhi); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param huodongtongzhi 活动通知实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request){ - //ValidatorUtils.validateEntity(huodongtongzhi); - huodongtongzhiService.updateById(huodongtongzhi);//全部更新 - return R.ok(); + public R update(@RequestBody HuodongtongzhiEntity huodongtongzhi, HttpServletRequest request) { + huodongtongzhiService.updateById(huodongtongzhi); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - huodongtongzhiService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + huodongtongzhiService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - String tableName = request.getSession().getAttribute("tableName").toString(); - if(tableName.equals("zhiyuanzhe")) { - wrapper.eq("xuehao", (String)request.getSession().getAttribute("username")); - } - - int count = huodongtongzhiService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + String tableName = request.getSession().getAttribute("tableName").toString(); // 获取当前表名 + if (tableName.equals("zhiyuanzhe")) { // 如果是志愿者表 + wrapper.eq("xuehao", (String) request.getSession().getAttribute("username")); // 设置学号过滤条件 + } + + int count = huodongtongzhiService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/HuodongxindeController.java b/springbootpt9c5/src/main/java/com/controller/HuodongxindeController.java index 1253c19f..23273f3a 100644 --- a/springbootpt9c5/src/main/java/com/controller/HuodongxindeController.java +++ b/springbootpt9c5/src/main/java/com/controller/HuodongxindeController.java @@ -40,189 +40,212 @@ import com.service.StoreupService; import com.entity.StoreupEntity; /** - * 活动心得 - * 后端接口 - * @author - * @email + * 活动心得管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/huodongxinde") public class HuodongxindeController { @Autowired - private HuodongxindeService huodongxindeService; + private HuodongxindeService huodongxindeService; // 注入活动心得服务 @Autowired - private StoreupService storeupService; - - - + private StoreupService storeupService; // 注入收藏服务 /** * 后端列表 + * @param params 请求参数 + * @param huodongxinde 活动心得实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,HuodongxindeEntity huodongxinde, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - huodongxinde.setUserid((Long)request.getSession().getAttribute("userId")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinde), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, HuodongxindeEntity huodongxinde, + HttpServletRequest request) { + // 如果不是管理员,设置用户ID + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + huodongxinde.setUserid((Long) request.getSession().getAttribute("userId")); + } + + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinde), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param huodongxinde 活动心得实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,HuodongxindeEntity huodongxinde, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinde), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, HuodongxindeEntity huodongxinde, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongxindeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinde), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param huodongxinde 活动心得实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( HuodongxindeEntity huodongxinde){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( huodongxinde, "huodongxinde")); - return R.ok().put("data", huodongxindeService.selectListView(ew)); + public R list(HuodongxindeEntity huodongxinde) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongxinde, "huodongxinde")); // 设置查询条件 + return R.ok().put("data", huodongxindeService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param huodongxinde 活动心得实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(HuodongxindeEntity huodongxinde){ - EntityWrapper< HuodongxindeEntity> ew = new EntityWrapper< HuodongxindeEntity>(); - ew.allEq(MPUtil.allEQMapPre( huodongxinde, "huodongxinde")); - HuodongxindeView huodongxindeView = huodongxindeService.selectView(ew); - return R.ok("查询活动心得成功").put("data", huodongxindeView); + public R query(HuodongxindeEntity huodongxinde) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongxinde, "huodongxinde")); // 设置查询条件 + HuodongxindeView huodongxindeView = huodongxindeService.selectView(ew); // 查询视图 + return R.ok("查询活动心得成功").put("data", huodongxindeView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - HuodongxindeEntity huodongxinde = huodongxindeService.selectById(id); - return R.ok().put("data", huodongxinde); + public R info(@PathVariable("id") Long id) { + HuodongxindeEntity huodongxinde = huodongxindeService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongxinde); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - HuodongxindeEntity huodongxinde = huodongxindeService.selectById(id); - return R.ok().put("data", huodongxinde); + public R detail(@PathVariable("id") Long id) { + HuodongxindeEntity huodongxinde = huodongxindeService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongxinde); // 返回记录详情 } - - - /** * 后端保存 + * @param huodongxinde 活动心得实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request){ - huodongxinde.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongxinde); - huodongxinde.setUserid((Long)request.getSession().getAttribute("userId")); - huodongxindeService.insert(huodongxinde); - return R.ok(); + public R save(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request) { + huodongxinde.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(huodongxinde); // 验证实体(可选) + huodongxinde.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + huodongxindeService.insert(huodongxinde); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param huodongxinde 活动心得实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request){ - huodongxinde.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongxinde); - huodongxindeService.insert(huodongxinde); - return R.ok(); + public R add(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request) { + huodongxinde.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(huodongxinde); // 验证实体(可选) + huodongxinde.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + huodongxindeService.insert(huodongxinde); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param huodongxinde 活动心得实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request){ - //ValidatorUtils.validateEntity(huodongxinde); - huodongxindeService.updateById(huodongxinde);//全部更新 - return R.ok(); + public R update(@RequestBody HuodongxindeEntity huodongxinde, HttpServletRequest request) { + // ValidatorUtils.validateEntity(huodongxinde); // 验证实体(可选) + huodongxindeService.updateById(huodongxinde); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - huodongxindeService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + huodongxindeService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - wrapper.eq("userid", (Long)request.getSession().getAttribute("userId")); - } - - - int count = huodongxindeService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + // 如果不是管理员,设置用户ID过滤条件 + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + wrapper.eq("userid", (Long) request.getSession().getAttribute("userId")); + } + + int count = huodongxindeService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/HuodongxinxiController.java b/springbootpt9c5/src/main/java/com/controller/HuodongxinxiController.java index 1bcffebc..70a9b0da 100644 --- a/springbootpt9c5/src/main/java/com/controller/HuodongxinxiController.java +++ b/springbootpt9c5/src/main/java/com/controller/HuodongxinxiController.java @@ -38,180 +38,197 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 活动信息 - * 后端接口 - * @author - * @email + * 活动信息管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/huodongxinxi") public class HuodongxinxiController { @Autowired - private HuodongxinxiService huodongxinxiService; - - - - + private HuodongxinxiService huodongxinxiService; // 注入活动信息服务 /** * 后端列表 + * @param params 请求参数 + * @param huodongxinxi 活动信息实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,HuodongxinxiEntity huodongxinxi, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinxi), params), params)); + public R page(@RequestParam Map params, HuodongxinxiEntity huodongxinxi, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinxi), params), params)); - return R.ok().put("data", page); + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param huodongxinxi 活动信息实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,HuodongxinxiEntity huodongxinxi, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = huodongxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinxi), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, HuodongxinxiEntity huodongxinxi, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = huodongxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huodongxinxi), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param huodongxinxi 活动信息实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( HuodongxinxiEntity huodongxinxi){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( huodongxinxi, "huodongxinxi")); - return R.ok().put("data", huodongxinxiService.selectListView(ew)); + public R list(HuodongxinxiEntity huodongxinxi) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongxinxi, "huodongxinxi")); // 设置查询条件 + return R.ok().put("data", huodongxinxiService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param huodongxinxi 活动信息实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(HuodongxinxiEntity huodongxinxi){ - EntityWrapper< HuodongxinxiEntity> ew = new EntityWrapper< HuodongxinxiEntity>(); - ew.allEq(MPUtil.allEQMapPre( huodongxinxi, "huodongxinxi")); - HuodongxinxiView huodongxinxiView = huodongxinxiService.selectView(ew); - return R.ok("查询活动信息成功").put("data", huodongxinxiView); + public R query(HuodongxinxiEntity huodongxinxi) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(huodongxinxi, "huodongxinxi")); // 设置查询条件 + HuodongxinxiView huodongxinxiView = huodongxinxiService.selectView(ew); // 查询视图 + return R.ok("查询活动信息成功").put("data", huodongxinxiView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - HuodongxinxiEntity huodongxinxi = huodongxinxiService.selectById(id); - return R.ok().put("data", huodongxinxi); + public R info(@PathVariable("id") Long id) { + HuodongxinxiEntity huodongxinxi = huodongxinxiService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongxinxi); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - HuodongxinxiEntity huodongxinxi = huodongxinxiService.selectById(id); - return R.ok().put("data", huodongxinxi); + public R detail(@PathVariable("id") Long id) { + HuodongxinxiEntity huodongxinxi = huodongxinxiService.selectById(id); // 查询单条记录 + return R.ok().put("data", huodongxinxi); // 返回记录详情 } - - - /** * 后端保存 + * @param huodongxinxi 活动信息实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request){ - huodongxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongxinxi); - huodongxinxiService.insert(huodongxinxi); - return R.ok(); + public R save(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request) { + huodongxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(huodongxinxi); // 验证实体(可选) + huodongxinxiService.insert(huodongxinxi); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param huodongxinxi 活动信息实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request){ - huodongxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(huodongxinxi); - huodongxinxiService.insert(huodongxinxi); - return R.ok(); + public R add(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request) { + huodongxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(huodongxinxi); // 验证实体(可选) + huodongxinxiService.insert(huodongxinxi); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param huodongxinxi 活动信息实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request){ - //ValidatorUtils.validateEntity(huodongxinxi); - huodongxinxiService.updateById(huodongxinxi);//全部更新 - return R.ok(); + public R update(@RequestBody HuodongxinxiEntity huodongxinxi, HttpServletRequest request) { + // ValidatorUtils.validateEntity(huodongxinxi); // 验证实体(可选) + huodongxinxiService.updateById(huodongxinxi); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - huodongxinxiService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + huodongxinxiService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = huodongxinxiService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + int count = huodongxinxiService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/MessagesController.java b/springbootpt9c5/src/main/java/com/controller/MessagesController.java index 54a33372..cee077a6 100644 --- a/springbootpt9c5/src/main/java/com/controller/MessagesController.java +++ b/springbootpt9c5/src/main/java/com/controller/MessagesController.java @@ -38,183 +38,200 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 交流反馈 - * 后端接口 - * @author - * @email + * 交流反馈管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/messages") public class MessagesController { @Autowired - private MessagesService messagesService; - - - - + private MessagesService messagesService; // 注入消息服务 /** * 后端列表 + * @param params 请求参数 + * @param messages 消息实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,MessagesEntity messages, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - messages.setUserid((Long)request.getSession().getAttribute("userId")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, MessagesEntity messages, + HttpServletRequest request) { + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + messages.setUserid((Long) request.getSession().getAttribute("userId")); // 设置当前用户ID + } + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param messages 消息实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,MessagesEntity messages, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, MessagesEntity messages, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param messages 消息实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( MessagesEntity messages){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( messages, "messages")); - return R.ok().put("data", messagesService.selectListView(ew)); + public R list(MessagesEntity messages) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(messages, "messages")); // 设置查询条件 + return R.ok().put("data", messagesService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param messages 消息实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(MessagesEntity messages){ - EntityWrapper< MessagesEntity> ew = new EntityWrapper< MessagesEntity>(); - ew.allEq(MPUtil.allEQMapPre( messages, "messages")); - MessagesView messagesView = messagesService.selectView(ew); - return R.ok("查询交流反馈成功").put("data", messagesView); + public R query(MessagesEntity messages) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(messages, "messages")); // 设置查询条件 + MessagesView messagesView = messagesService.selectView(ew); // 查询视图 + return R.ok("查询交流反馈成功").put("data", messagesView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - MessagesEntity messages = messagesService.selectById(id); - return R.ok().put("data", messages); + public R info(@PathVariable("id") Long id) { + MessagesEntity messages = messagesService.selectById(id); // 查询单条记录 + return R.ok().put("data", messages); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - MessagesEntity messages = messagesService.selectById(id); - return R.ok().put("data", messages); + public R detail(@PathVariable("id") Long id) { + MessagesEntity messages = messagesService.selectById(id); // 查询单条记录 + return R.ok().put("data", messages); // 返回记录详情 } - - - /** * 后端保存 + * @param messages 消息实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody MessagesEntity messages, HttpServletRequest request){ - messages.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(messages); - messagesService.insert(messages); - return R.ok(); + public R save(@RequestBody MessagesEntity messages, HttpServletRequest request) { + messages.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(messages); // 验证实体(可选) + messagesService.insert(messages); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param messages 消息实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody MessagesEntity messages, HttpServletRequest request){ - messages.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(messages); - messagesService.insert(messages); - return R.ok(); + public R add(@RequestBody MessagesEntity messages, HttpServletRequest request) { + messages.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(messages); // 验证实体(可选) + messagesService.insert(messages); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param messages 消息实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody MessagesEntity messages, HttpServletRequest request){ - //ValidatorUtils.validateEntity(messages); - messagesService.updateById(messages);//全部更新 - return R.ok(); + public R update(@RequestBody MessagesEntity messages, HttpServletRequest request) { + // ValidatorUtils.validateEntity(messages); // 验证实体(可选) + messagesService.updateById(messages); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - messagesService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + messagesService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = messagesService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + int count = messagesService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/NewsController.java b/springbootpt9c5/src/main/java/com/controller/NewsController.java index 5931505a..977c00da 100644 --- a/springbootpt9c5/src/main/java/com/controller/NewsController.java +++ b/springbootpt9c5/src/main/java/com/controller/NewsController.java @@ -38,180 +38,197 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 公告信息 - * 后端接口 - * @author - * @email + * 公告信息管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/news") public class NewsController { @Autowired - private NewsService newsService; - - - - + private NewsService newsService; // 注入新闻服务 /** * 后端列表 + * @param params 请求参数 + * @param news 新闻实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,NewsEntity news, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); + public R page(@RequestParam Map params, NewsEntity news, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); - return R.ok().put("data", page); + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param news 新闻实体 + * @param request HTTP请求对象 + * @return 分页数据 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params,NewsEntity news, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, NewsEntity news, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param news 新闻实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( NewsEntity news){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( news, "news")); - return R.ok().put("data", newsService.selectListView(ew)); + public R list(NewsEntity news) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(news, "news")); // 设置查询条件 + return R.ok().put("data", newsService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param news 新闻实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(NewsEntity news){ - EntityWrapper< NewsEntity> ew = new EntityWrapper< NewsEntity>(); - ew.allEq(MPUtil.allEQMapPre( news, "news")); - NewsView newsView = newsService.selectView(ew); - return R.ok("查询公告信息成功").put("data", newsView); + public R query(NewsEntity news) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(news, "news")); // 设置查询条件 + NewsView newsView = newsService.selectView(ew); // 查询视图 + return R.ok("查询公告信息成功").put("data", newsView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - NewsEntity news = newsService.selectById(id); - return R.ok().put("data", news); + public R info(@PathVariable("id") Long id) { + NewsEntity news = newsService.selectById(id); // 查询单条记录 + return R.ok().put("data", news); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - NewsEntity news = newsService.selectById(id); - return R.ok().put("data", news); + public R detail(@PathVariable("id") Long id) { + NewsEntity news = newsService.selectById(id); // 查询单条记录 + return R.ok().put("data", news); // 返回记录详情 } - - - /** * 后端保存 + * @param news 新闻实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody NewsEntity news, HttpServletRequest request){ - news.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(news); - newsService.insert(news); - return R.ok(); + public R save(@RequestBody NewsEntity news, HttpServletRequest request) { + news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(news); // 验证实体(可选) + newsService.insert(news); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param news 新闻实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody NewsEntity news, HttpServletRequest request){ - news.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(news); - newsService.insert(news); - return R.ok(); + public R add(@RequestBody NewsEntity news, HttpServletRequest request) { + news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(news); // 验证实体(可选) + newsService.insert(news); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param news 新闻实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody NewsEntity news, HttpServletRequest request){ - //ValidatorUtils.validateEntity(news); - newsService.updateById(news);//全部更新 - return R.ok(); + public R update(@RequestBody NewsEntity news, HttpServletRequest request) { + // ValidatorUtils.validateEntity(news); // 验证实体(可选) + newsService.updateById(news); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - newsService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + newsService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = newsService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + + int count = newsService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/StoreupController.java b/springbootpt9c5/src/main/java/com/controller/StoreupController.java index b599c6f1..05d7d366 100644 --- a/springbootpt9c5/src/main/java/com/controller/StoreupController.java +++ b/springbootpt9c5/src/main/java/com/controller/StoreupController.java @@ -38,190 +38,207 @@ import com.utils.CommonUtil; import java.io.IOException; /** - * 收藏表 - * 后端接口 - * @author - * @email + * 收藏表管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/storeup") public class StoreupController { @Autowired - private StoreupService storeupService; - - - - + private StoreupService storeupService; // 注入收藏服务 /** * 后端列表 + * @param params 请求参数 + * @param storeup 收藏实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/page") - public R page(@RequestParam Map params,StoreupEntity storeup, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - storeup.setUserid((Long)request.getSession().getAttribute("userId")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); - - return R.ok().put("data", page); + public R page(@RequestParam Map params, StoreupEntity storeup, + HttpServletRequest request) { + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + storeup.setUserid((Long) request.getSession().getAttribute("userId")); // 非管理员设置用户ID + } + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - + /** * 前端列表 + * @param params 请求参数 + * @param storeup 收藏实体 + * @param request HTTP请求对象 + * @return 分页数据 */ @RequestMapping("/list") - public R list(@RequestParam Map params,StoreupEntity storeup, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - storeup.setUserid((Long)request.getSession().getAttribute("userId")); - } - EntityWrapper ew = new EntityWrapper(); - PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, StoreupEntity storeup, + HttpServletRequest request) { + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + storeup.setUserid((Long) request.getSession().getAttribute("userId")); // 非管理员设置用户ID + } + EntityWrapper ew = new EntityWrapper<>(); // 创建查询条件 + PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); + + return R.ok().put("data", page); // 返回分页数据 } - /** - * 列表 + /** + * 列表(无分页) + * @param storeup 收藏实体 + * @return 数据列表 */ @RequestMapping("/lists") - public R list( StoreupEntity storeup){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( storeup, "storeup")); - return R.ok().put("data", storeupService.selectListView(ew)); + public R list(StoreupEntity storeup) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(storeup, "storeup")); // 设置查询条件 + return R.ok().put("data", storeupService.selectListView(ew)); // 返回数据列表 } - /** - * 查询 + /** + * 查询单条记录 + * @param storeup 收藏实体 + * @return 查询结果 */ @RequestMapping("/query") - public R query(StoreupEntity storeup){ - EntityWrapper< StoreupEntity> ew = new EntityWrapper< StoreupEntity>(); - ew.allEq(MPUtil.allEQMapPre( storeup, "storeup")); - StoreupView storeupView = storeupService.selectView(ew); - return R.ok("查询收藏表成功").put("data", storeupView); + public R query(StoreupEntity storeup) { + EntityWrapper ew = new EntityWrapper<>(); + ew.allEq(MPUtil.allEQMapPre(storeup, "storeup")); // 设置查询条件 + StoreupView storeupView = storeupService.selectView(ew); // 查询视图 + return R.ok("查询收藏表成功").put("data", storeupView); // 返回查询结果 } - + /** * 后端详情 + * @param id 记录ID + * @return 单条记录详情 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - StoreupEntity storeup = storeupService.selectById(id); - return R.ok().put("data", storeup); + public R info(@PathVariable("id") Long id) { + StoreupEntity storeup = storeupService.selectById(id); // 查询单条记录 + return R.ok().put("data", storeup); // 返回记录详情 } /** * 前端详情 + * @param id 记录ID + * @return 单条记录详情 */ - @IgnoreAuth + @IgnoreAuth @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - StoreupEntity storeup = storeupService.selectById(id); - return R.ok().put("data", storeup); + public R detail(@PathVariable("id") Long id) { + StoreupEntity storeup = storeupService.selectById(id); // 查询单条记录 + return R.ok().put("data", storeup); // 返回记录详情 } - - - /** * 后端保存 + * @param storeup 收藏实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/save") - public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request){ - storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(storeup); - storeup.setUserid((Long)request.getSession().getAttribute("userId")); - storeupService.insert(storeup); - return R.ok(); + public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request) { + storeup.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(storeup); // 验证实体(可选) + storeup.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + storeupService.insert(storeup); // 插入数据 + return R.ok(); // 返回成功结果 } - + /** * 前端保存 + * @param storeup 收藏实体 + * @param request HTTP请求对象 + * @return 保存结果 */ @RequestMapping("/add") - public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request){ - storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(storeup); - storeup.setUserid((Long)request.getSession().getAttribute("userId")); - storeupService.insert(storeup); - return R.ok(); + public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request) { + storeup.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(storeup); // 验证实体(可选) + storeup.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + storeupService.insert(storeup); // 插入数据 + return R.ok(); // 返回成功结果 } /** - * 修改 + * 修改记录 + * @param storeup 收藏实体 + * @param request HTTP请求对象 + * @return 修改结果 */ @RequestMapping("/update") @Transactional - public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request){ - //ValidatorUtils.validateEntity(storeup); - storeupService.updateById(storeup);//全部更新 - return R.ok(); + public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request) { + // ValidatorUtils.validateEntity(storeup); // 验证实体(可选) + storeupService.updateById(storeup); // 全量更新 + return R.ok(); // 返回成功结果 } - /** - * 删除 + * 删除记录 + * @param ids 记录ID数组 + * @return 删除结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - storeupService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + public R delete(@RequestBody Long[] ids) { + storeupService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 + return R.ok(); // 返回成功结果 } - + /** * 提醒接口 + * @param columnName 字段名 + * @param request HTTP请求对象 + * @param type 提醒类型 + * @param map 请求参数 + * @return 提醒结果 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - wrapper.eq("userid", (Long)request.getSession().getAttribute("userId")); - } - - - int count = storeupService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 添加字段名到参数 + map.put("type", type); // 添加提醒类型到参数 + + if (type.equals("2")) { // 如果是相对日期提醒 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + + if (map.get("remindstart") != null) { // 如果有提醒开始时间 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 计算开始日期 + remindStartDate = c.getTime(); // 获取开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 + } + + if (map.get("remindend") != null) { // 如果有提醒结束时间 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 计算结束日期 + remindEndDate = c.getTime(); // 获取结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 + } + } + + Wrapper wrapper = new EntityWrapper<>(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 + } + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 + } + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + wrapper.eq("userid", (Long) request.getSession().getAttribute("userId")); // 非管理员过滤数据 + } + + int count = storeupService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回提醒结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/UserController.java b/springbootpt9c5/src/main/java/com/controller/UserController.java index 6bce00af..b37e4677 100644 --- a/springbootpt9c5/src/main/java/com/controller/UserController.java +++ b/springbootpt9c5/src/main/java/com/controller/UserController.java @@ -1,7 +1,5 @@ - package com.controller; - import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -33,142 +31,169 @@ import com.utils.R; import com.utils.ValidatorUtils; /** - * 登录相关 + * 用户管理相关接口 */ @RequestMapping("users") @RestController -public class UserController{ - +public class UserController { + @Autowired - private UserService userService; - + private UserService userService; // 注入用户服务 + @Autowired - private TokenService tokenService; + private TokenService tokenService; // 注入令牌服务 /** - * 登录 + * 用户登录 + * @param username 用户名 + * @param password 密码 + * @param captcha 验证码(暂未使用) + * @param request HTTP请求对象 + * @return 登录结果 */ @IgnoreAuth @PostMapping(value = "/login") public R login(String username, String password, String captcha, HttpServletRequest request) { - UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username)); - if(user==null || !user.getPassword().equals(password)) { - return R.error("账号或密码不正确"); + UserEntity user = userService.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()); - return R.ok().put("token", token); + String token = tokenService.generateToken(user.getId(), username, "users", user.getRole()); // 生成令牌 + return R.ok().put("token", token); // 返回成功结果及令牌 } - + /** - * 注册 + * 用户注册 + * @param user 用户实体 + * @return 注册结果 */ @IgnoreAuth @PostMapping(value = "/register") - public R register(@RequestBody UserEntity user){ -// ValidatorUtils.validateEntity(user); - if(userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { - return R.error("用户已存在"); - } - userService.insert(user); - return R.ok(); - } + public R register(@RequestBody UserEntity user) { +// ValidatorUtils.validateEntity(user); // 验证用户实体(可选) + if (userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) != null) { // 检查用户名是否已存在 + return R.error("用户已存在"); // 返回错误信息 + } + userService.insert(user); // 插入新用户 + return R.ok(); // 返回成功结果 + } /** - * 退出 + * 用户退出 + * @param request HTTP请求对象 + * @return 退出结果 */ @GetMapping(value = "logout") public R logout(HttpServletRequest request) { - request.getSession().invalidate(); - return R.ok("退出成功"); + request.getSession().invalidate(); // 清空Session + return R.ok("退出成功"); // 返回成功信息 } - + /** - * 密码重置 - */ - @IgnoreAuth + * 密码重置 + * @param username 用户名 + * @param request HTTP请求对象 + * @return 密码重置结果 + */ + @IgnoreAuth @RequestMapping(value = "/resetPass") - public R resetPass(String username, HttpServletRequest request){ - UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username)); - if(user==null) { - return R.error("账号不存在"); - } - user.setPassword("123456"); - userService.update(user,null); - return R.ok("密码已重置为:123456"); - } - + public R resetPass(String username, HttpServletRequest request) { + UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username)); // 查询用户 + if (user == null) { // 如果用户不存在 + return R.error("账号不存在"); // 返回错误信息 + } + user.setPassword("123456"); // 设置默认密码 + userService.update(user, null); // 更新用户密码 + return R.ok("密码已重置为:123456"); // 返回成功信息 + } + + /** + * 用户列表(分页) + * @param params 请求参数 + * @param user 用户实体(用于筛选条件) + * @return 分页数据 + */ + @RequestMapping("/page") + public R page(@RequestParam Map params, UserEntity user) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回分页数据 + } + /** - * 列表 - */ - @RequestMapping("/page") - public R page(@RequestParam Map params,UserEntity user){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params)); - return R.ok().put("data", page); - } + * 用户列表(无分页) + * @param user 用户实体(用于筛选条件) + * @return 用户列表 + */ + @RequestMapping("/list") + public R list(UserEntity user) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(user, "user")); // 设置查询条件 + return R.ok().put("data", userService.selectListView(ew)); // 返回用户列表 + } /** - * 列表 - */ - @RequestMapping("/list") - public R list( UserEntity user){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( user, "user")); - return R.ok().put("data", userService.selectListView(ew)); - } - - /** - * 信息 - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") String id){ - UserEntity user = userService.selectById(id); - return R.ok().put("data", user); - } - - /** - * 获取用户的session用户信息 - */ - @RequestMapping("/session") - public R getCurrUser(HttpServletRequest request){ - Long id = (Long)request.getSession().getAttribute("userId"); - UserEntity user = userService.selectById(id); - return R.ok().put("data", user); - } - - /** - * 保存 - */ - @PostMapping("/save") - public R save(@RequestBody UserEntity user){ -// ValidatorUtils.validateEntity(user); - if(userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { - return R.error("用户已存在"); - } - userService.insert(user); - return R.ok(); - } - - /** - * 修改 - */ - @RequestMapping("/update") - public R update(@RequestBody UserEntity user){ -// ValidatorUtils.validateEntity(user); - UserEntity u = userService.selectOne(new EntityWrapper().eq("username", user.getUsername())); - if(u!=null && u.getId()!=user.getId() && u.getUsername().equals(user.getUsername())) { - return R.error("用户名已存在。"); - } - userService.updateById(user);//全部更新 - return R.ok(); - } - - /** - * 删除 - */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - userService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); - } + * 用户信息 + * @param id 用户ID + * @return 用户信息 + */ + @RequestMapping("/info/{id}") + public R info(@PathVariable("id") String id) { + UserEntity user = userService.selectById(id); // 查询用户信息 + return R.ok().put("data", user); // 返回用户信息 + } + + /** + * 获取当前用户的Session信息 + * @param request HTTP请求对象 + * @return 当前用户信息 + */ + @RequestMapping("/session") + public R getCurrUser(HttpServletRequest request) { + Long id = (Long) request.getSession().getAttribute("userId"); // 获取Session中的用户ID + UserEntity user = userService.selectById(id); // 查询用户信息 + return R.ok().put("data", user); // 返回当前用户信息 + } + + /** + * 用户保存 + * @param user 用户实体 + * @return 保存结果 + */ + @PostMapping("/save") + public R save(@RequestBody UserEntity user) { +// ValidatorUtils.validateEntity(user); // 验证用户实体(可选) + if (userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) != null) { // 检查用户名是否已存在 + return R.error("用户已存在"); // 返回错误信息 + } + userService.insert(user); // 插入新用户 + return R.ok(); // 返回成功结果 + } + + /** + * 用户修改 + * @param user 用户实体 + * @return 修改结果 + */ + @RequestMapping("/update") + public R update(@RequestBody UserEntity user) { +// ValidatorUtils.validateEntity(user); // 验证用户实体(可选) + UserEntity u = userService.selectOne(new EntityWrapper().eq("username", user.getUsername())); // 查询用户名是否存在 + if (u != null && u.getId() != user.getId() && u.getUsername().equals(user.getUsername())) { // 检查用户名是否重复 + return R.error("用户名已存在。"); // 返回错误信息 + } + userService.updateById(user); // 全量更新用户信息 + return R.ok(); // 返回成功结果 + } + + /** + * 用户删除 + * @param ids 用户ID数组 + * @return 删除结果 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Long[] ids) { + userService.deleteBatchIds(Arrays.asList(ids)); // 批量删除用户 + return R.ok(); // 返回成功结果 + } } diff --git a/springbootpt9c5/src/main/java/com/controller/ZhiyuanzheController.java b/springbootpt9c5/src/main/java/com/controller/ZhiyuanzheController.java index e9300cc0..9fb7a203 100644 --- a/springbootpt9c5/src/main/java/com/controller/ZhiyuanzheController.java +++ b/springbootpt9c5/src/main/java/com/controller/ZhiyuanzheController.java @@ -4,294 +4,314 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; -import java.util.Map; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.Date; import java.util.List; +import java.util.Map; + import javax.servlet.http.HttpServletRequest; import com.utils.ValidatorUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import org.springframework.format.annotation.DateTimeFormat; -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.bind.annotation.*; + +import com.annotation.IgnoreAuth; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; -import com.annotation.IgnoreAuth; - import com.entity.ZhiyuanzheEntity; import com.entity.view.ZhiyuanzheView; - import com.service.ZhiyuanzheService; import com.service.TokenService; -import com.utils.PageUtils; -import com.utils.R; import com.utils.MD5Util; import com.utils.MPUtil; -import com.utils.CommonUtil; -import java.io.IOException; +import com.utils.PageUtils; +import com.utils.R; /** - * 志愿者 - * 后端接口 - * @author - * @email + * 志愿者管理后端接口 + * @author [作者姓名] + * @email [作者邮箱] * @date 2022-05-06 08:33:49 */ @RestController @RequestMapping("/zhiyuanzhe") public class ZhiyuanzheController { - @Autowired - private ZhiyuanzheService zhiyuanzheService; + @Autowired + private ZhiyuanzheService zhiyuanzheService; // 注入志愿者服务 - @Autowired - private TokenService tokenService; - + private TokenService tokenService; // 注入令牌服务 + /** - * 登录 + * 用户登录 + * @param username 学号 + * @param password 密码 + * @param captcha 验证码(暂未使用) + * @param request HTTP请求对象 + * @return 登录结果 */ @IgnoreAuth @RequestMapping(value = "/login") public R login(String username, String password, String captcha, HttpServletRequest request) { - ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", username)); - if(user==null || !user.getMima().equals(password)) { - return R.error("账号或密码不正确"); + ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", username)); // 查询用户 + if (user == null || !user.getMima().equals(password)) { // 验证用户名和密码是否匹配 + return R.error("账号或密码不正确"); // 返回错误信息 + } + if ("否".equals(user.getSfsh())) { // 检查账号是否被锁定 + return R.error("账号已锁定,请联系管理员审核。"); } - - if("否".equals(user.getSfsh())) return R.error("账号已锁定,请联系管理员审核。"); - String token = tokenService.generateToken(user.getId(), username,"zhiyuanzhe", "志愿者" ); - return R.ok().put("token", token); + String token = tokenService.generateToken(user.getId(), username, "zhiyuanzhe", "志愿者"); // 生成令牌 + return R.ok().put("token", token); // 返回成功结果及令牌 } - + /** - * 注册 - */ + * 用户注册 + * @param zhiyuanzhe 志愿者实体 + * @return 注册结果 + */ @IgnoreAuth - @RequestMapping("/register") - public R register(@RequestBody ZhiyuanzheEntity zhiyuanzhe){ - //ValidatorUtils.validateEntity(zhiyuanzhe); - ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); - if(user!=null) { - return R.error("注册用户已存在"); + @RequestMapping("/register") + public R register(@RequestBody ZhiyuanzheEntity zhiyuanzhe) { + // ValidatorUtils.validateEntity(zhiyuanzhe); // 验证用户实体(可选) + ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); // 检查用户名是否已存在 + if (user != null) { + return R.error("注册用户已存在"); // 返回错误信息 } - Long uId = new Date().getTime(); - zhiyuanzhe.setId(uId); - zhiyuanzheService.insert(zhiyuanzhe); - return R.ok(); - } + Long uId = new Date().getTime(); // 生成唯一ID + zhiyuanzhe.setId(uId); // 设置用户ID + zhiyuanzheService.insert(zhiyuanzhe); // 插入新用户 + return R.ok(); // 返回成功结果 + } - /** - * 退出 + * 用户退出 + * @param request HTTP请求对象 + * @return 退出结果 */ @RequestMapping("/logout") public R logout(HttpServletRequest request) { - request.getSession().invalidate(); - return R.ok("退出成功"); + request.getSession().invalidate(); // 清空Session + return R.ok("退出成功"); // 返回成功信息 } - + /** - * 获取用户的session用户信息 - */ - @RequestMapping("/session") - public R getCurrUser(HttpServletRequest request){ - Long id = (Long)request.getSession().getAttribute("userId"); - ZhiyuanzheEntity user = zhiyuanzheService.selectById(id); - return R.ok().put("data", user); - } - - /** - * 密码重置 - */ - @IgnoreAuth - @RequestMapping(value = "/resetPass") - public R resetPass(String username, HttpServletRequest request){ - ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", username)); - if(user==null) { - return R.error("账号不存在"); - } - user.setMima("123456"); - zhiyuanzheService.updateById(user); - return R.ok("密码已重置为:123456"); - } + * 获取当前用户的Session信息 + * @param request HTTP请求对象 + * @return 当前用户信息 + */ + @RequestMapping("/session") + public R getCurrUser(HttpServletRequest request) { + Long id = (Long) request.getSession().getAttribute("userId"); // 获取Session中的用户ID + ZhiyuanzheEntity user = zhiyuanzheService.selectById(id); // 查询用户信息 + return R.ok().put("data", user); // 返回当前用户信息 + } + /** + * 密码重置 + * @param username 用户名 + * @param request HTTP请求对象 + * @return 密码重置结果 + */ + @IgnoreAuth + @RequestMapping(value = "/resetPass") + public R resetPass(String username, HttpServletRequest request) { + ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", username)); // 查询用户 + if (user == null) { // 如果用户不存在 + return R.error("账号不存在"); // 返回错误信息 + } + user.setMima("123456"); // 设置默认密码 + zhiyuanzheService.updateById(user); // 更新用户密码 + return R.ok("密码已重置为:123456"); // 返回成功信息 + } - /** - * 后端列表 - */ - @RequestMapping("/page") - public R page(@RequestParam Map params,ZhiyuanzheEntity zhiyuanzhe, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = zhiyuanzheService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhiyuanzhe), params), params)); + /** + * 后端分页查询 + * @param params 请求参数 + * @param zhiyuanzhe 志愿者实体(用于筛选条件) + * @param request HTTP请求对象 + * @return 分页数据 + */ + @RequestMapping("/page") + public R page(@RequestParam Map params, ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + PageUtils page = zhiyuanzheService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhiyuanzhe), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回分页数据 + } - return R.ok().put("data", page); - } - - /** - * 前端列表 - */ + /** + * 前端分页查询 + * @param params 请求参数 + * @param zhiyuanzhe 志愿者实体(用于筛选条件) + * @param request HTTP请求对象 + * @return 分页数据 + */ @IgnoreAuth - @RequestMapping("/list") - public R list(@RequestParam Map params,ZhiyuanzheEntity zhiyuanzhe, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = zhiyuanzheService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhiyuanzhe), params), params)); - return R.ok().put("data", page); - } + @RequestMapping("/list") + public R list(@RequestParam Map params, ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + PageUtils page = zhiyuanzheService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhiyuanzhe), params), params)); // 查询分页数据 + return R.ok().put("data", page); // 返回分页数据 + } /** - * 列表 - */ - @RequestMapping("/lists") - public R list( ZhiyuanzheEntity zhiyuanzhe){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( zhiyuanzhe, "zhiyuanzhe")); - return R.ok().put("data", zhiyuanzheService.selectListView(ew)); - } - - /** - * 查询 - */ - @RequestMapping("/query") - public R query(ZhiyuanzheEntity zhiyuanzhe){ - EntityWrapper< ZhiyuanzheEntity> ew = new EntityWrapper< ZhiyuanzheEntity>(); - ew.allEq(MPUtil.allEQMapPre( zhiyuanzhe, "zhiyuanzhe")); - ZhiyuanzheView zhiyuanzheView = zhiyuanzheService.selectView(ew); - return R.ok("查询志愿者成功").put("data", zhiyuanzheView); - } - - /** - * 后端详情 - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - ZhiyuanzheEntity zhiyuanzhe = zhiyuanzheService.selectById(id); - return R.ok().put("data", zhiyuanzhe); - } + * 后端列表查询 + * @param zhiyuanzhe 志愿者实体(用于筛选条件) + * @return 用户列表 + */ + @RequestMapping("/lists") + public R lists(ZhiyuanzheEntity zhiyuanzhe) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(zhiyuanzhe, "zhiyuanzhe")); // 设置查询条件 + return R.ok().put("data", zhiyuanzheService.selectListView(ew)); // 返回用户列表 + } - /** - * 前端详情 - */ - @IgnoreAuth - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - ZhiyuanzheEntity zhiyuanzhe = zhiyuanzheService.selectById(id); - return R.ok().put("data", zhiyuanzhe); - } - + /** + * 查询志愿者信息 + * @param zhiyuanzhe 志愿者实体(用于筛选条件) + * @return 查询结果 + */ + @RequestMapping("/query") + public R query(ZhiyuanzheEntity zhiyuanzhe) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(zhiyuanzhe, "zhiyuanzhe")); // 设置查询条件 + ZhiyuanzheView zhiyuanzheView = zhiyuanzheService.selectView(ew); // 查询视图数据 + return R.ok("查询志愿者成功").put("data", zhiyuanzheView); // 返回查询结果 + } + /** + * 后端详情查询 + * @param id 用户ID + * @return 用户详情 + */ + @RequestMapping("/info/{id}") + public R info(@PathVariable("id") Long id) { + ZhiyuanzheEntity zhiyuanzhe = zhiyuanzheService.selectById(id); // 查询用户信息 + return R.ok().put("data", zhiyuanzhe); // 返回用户详情 + } + /** + * 前端详情查询 + * @param id 用户ID + * @return 用户详情 + */ + @IgnoreAuth + @RequestMapping("/detail/{id}") + public R detail(@PathVariable("id") Long id) { + ZhiyuanzheEntity zhiyuanzhe = zhiyuanzheService.selectById(id); // 查询用户信息 + return R.ok().put("data", zhiyuanzhe); // 返回用户详情 + } - /** - * 后端保存 - */ - @RequestMapping("/save") - public R save(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request){ - zhiyuanzhe.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(zhiyuanzhe); - ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); - if(user!=null) { - return R.error("用户已存在"); + /** + * 后端保存 + * @param zhiyuanzhe 志愿者实体 + * @param request HTTP请求对象 + * @return 保存结果 + */ + @RequestMapping("/save") + public R save(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request) { + zhiyuanzhe.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(zhiyuanzhe); // 验证用户实体(可选) + ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); // 检查用户名是否已存在 + if (user != null) { + return R.error("用户已存在"); // 返回错误信息 } - zhiyuanzhe.setId(new Date().getTime()); - zhiyuanzheService.insert(zhiyuanzhe); - return R.ok(); - } - - /** - * 前端保存 - */ - @RequestMapping("/add") - public R add(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request){ - zhiyuanzhe.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(zhiyuanzhe); - ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); - if(user!=null) { - return R.error("用户已存在"); + zhiyuanzhe.setId(new Date().getTime()); // 设置用户ID + zhiyuanzheService.insert(zhiyuanzhe); // 插入新用户 + return R.ok(); // 返回成功结果 + } + + /** + * 前端保存 + * @param zhiyuanzhe 志愿者实体 + * @param request HTTP请求对象 + * @return 保存结果 + */ + @RequestMapping("/add") + public R add(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request) { + zhiyuanzhe.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(zhiyuanzhe); // 验证用户实体(可选) + ZhiyuanzheEntity user = zhiyuanzheService.selectOne(new EntityWrapper().eq("xuehao", zhiyuanzhe.getXuehao())); // 检查用户名是否已存在 + if (user != null) { + return R.error("用户已存在"); // 返回错误信息 } - zhiyuanzhe.setId(new Date().getTime()); - zhiyuanzheService.insert(zhiyuanzhe); - return R.ok(); - } + zhiyuanzhe.setId(new Date().getTime()); // 设置用户ID + zhiyuanzheService.insert(zhiyuanzhe); // 插入新用户 + return R.ok(); // 返回成功结果 + } - /** - * 修改 - */ - @RequestMapping("/update") - @Transactional - public R update(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request){ - //ValidatorUtils.validateEntity(zhiyuanzhe); - zhiyuanzheService.updateById(zhiyuanzhe);//全部更新 - return R.ok(); - } - + /** + * 修改 + * @param zhiyuanzhe 志愿者实体 + * @param request HTTP请求对象 + * @return 修改结果 + */ + @RequestMapping("/update") + @Transactional + public R update(@RequestBody ZhiyuanzheEntity zhiyuanzhe, HttpServletRequest request) { + // ValidatorUtils.validateEntity(zhiyuanzhe); // 验证用户实体(可选) + zhiyuanzheService.updateById(zhiyuanzhe); // 全量更新用户信息 + return R.ok(); // 返回成功结果 + } + + /** + * 删除 + * @param ids 用户ID数组 + * @return 删除结果 + */ + @RequestMapping("/delete") + public R delete(@RequestBody Long[] ids) { + zhiyuanzheService.deleteBatchIds(Arrays.asList(ids)); // 批量删除用户 + return R.ok(); // 返回成功结果 + } - /** - * 删除 - */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - zhiyuanzheService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); - } - - /** - * 提醒接口 - */ + /** + * 提醒接口 + * @param columnName 查询字段名 + * @param request HTTP请求对象 + * @param type 查询类型 + * @param map 请求参数 + * @return 查询结果 + */ @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 设置查询字段 + map.put("type", type); // 设置查询类型 + + if ("2".equals(type)) { // 如果类型为2 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期 + Calendar c = Calendar.getInstance(); // 获取当前日期 + Date remindStartDate = null; // 初始化开始日期 + Date remindEndDate = null; // 初始化结束日期 + if (map.get("remindstart") != null) { // 如果有开始日期 + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加天数 + remindStartDate = c.getTime(); // 获取新的日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并设置开始日期 } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); + if (map.get("remindend") != null) { // 如果有结束日期 + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数 + c.setTime(new Date()); // 设置当前日期 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 添加天数 + remindEndDate = c.getTime(); // 获取新的日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并设置结束日期 } } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); + + Wrapper wrapper = new EntityWrapper(); // 创建查询条件 + if (map.get("remindstart") != null) { // 如果有开始日期 + wrapper.ge(columnName, map.get("remindstart")); // 设置大于等于条件 } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); + if (map.get("remindend") != null) { // 如果有结束日期 + wrapper.le(columnName, map.get("remindend")); // 设置小于等于条件 } - - int count = zhiyuanzheService.selectCount(wrapper); - return R.ok().put("count", count); + int count = zhiyuanzheService.selectCount(wrapper); // 查询符合条件的记录数 + return R.ok().put("count", count); // 返回查询结果 } - - - - - - - - }