pull/2/head
2593162056@qq.com 8 months ago
parent 966162e4d8
commit 6836490617

@ -1,5 +1,6 @@
package com.controller; package com.controller;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.text.ParseException; import java.text.ParseException;
@ -11,6 +12,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
@ -24,13 +26,13 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth; import com.annotation.IgnoreAuth;
import com.entity.NewsEntity; import com.entity.NewsEntity;
import com.entity.view.NewsView; import com.entity.view.NewsView;
import com.service.NewsService; import com.service.NewsService;
import com.service.TokenService; import com.service.TokenService;
import com.utils.PageUtils; import com.utils.PageUtils;
@ -50,93 +52,117 @@ import com.utils.CommonUtil;
@RequestMapping("/news") @RequestMapping("/news")
public class NewsController { public class NewsController {
@Autowired @Autowired
private NewsService newsService; private NewsService newsService;//注入新闻服务类
/** /**
* *
*/ */
@RequestMapping("/page") @RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,NewsEntity news, public R page(@RequestParam Map<String, Object> params, NewsEntity news, HttpServletRequest request) {
HttpServletRequest request){ // 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>(); EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); // 使用MPUtil工具类对查询条件进行排序和分页处理
request.setAttribute("data", page); PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 将分页结果设置到request对象中
request.setAttribute("data", page);
// 返回成功响应,包含分页结果
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@IgnoreAuth @IgnoreAuth
@RequestMapping("/list") @RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,NewsEntity news, public R list(@RequestParam Map<String, Object> params, NewsEntity news, HttpServletRequest request) {
HttpServletRequest request){ // 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>(); EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params)); // 使用MPUtil工具类对查询条件进行排序和分页处理
request.setAttribute("data", page); PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 将分页结果设置到request对象中
request.setAttribute("data", page);
// 返回成功响应,包含分页结果
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@RequestMapping("/lists") @RequestMapping("/lists")
public R list( NewsEntity news){ //一个Spring MVC的注解用于将HTTP请求映射到 list 方法。当客户端发送一个HTTP请求到 /lists 路径时Spring MVC会调用 list 方法来处理这个请求
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>(); public R list(NewsEntity news) //NewsEntity news 参数表示要查询的 NewsEntity 对象
ew.allEq(MPUtil.allEQMapPre( news, "news")); {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
// 使用MPUtil工具类对查询条件进行排序和分页处理
ew.allEq(MPUtil.allEQMapPre(news, "news"));
// 返回成功响应,包含查询结果
return R.ok().put("data", newsService.selectListView(ew)); return R.ok().put("data", newsService.selectListView(ew));
//这行代码返回一个表示请求成功的响应对象,并将 newsService.selectListView(ew) 的结果添加到响应对象中,键为 "data"。
//newsService.selectListView(ew) 方法用于查询满足 ew 对象的查询条件的记录,并返回一个包含查询结果的列表。
} }
/** /**
* *
*/ */
@RequestMapping("/query") @RequestMapping("/query")
public R query(NewsEntity news){ public R query(NewsEntity news) {
EntityWrapper< NewsEntity> ew = new EntityWrapper< NewsEntity>(); // 创建一个EntityWrapper对象用于构建查询条件
ew.allEq(MPUtil.allEQMapPre( news, "news")); EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
NewsView newsView = newsService.selectView(ew);
return R.ok("查询公告信息成功").put("data", newsView); // 使用MPUtil工具类对查询条件进行排序和分页处理
ew.allEq(MPUtil.allEQMapPre(news, "news"));
// 调用 newsService 对象的 selectView 方法,查询满足 ew 对象的查询条件的记录,并返回一个 NewsView 对象
NewsView newsView = newsService.selectView(ew);
return R.ok("查询公告信息成功").put("data", newsView);
} }
/** /**
* *
*/ */
//一个Spring MVC的注解用于将HTTP请求映射到 info 方法。
//当客户端发送一个HTTP请求到 /info/{id} 路径时Spring MVC会调用 info 方法来处理这个请求
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){ public R info(@PathVariable("id") Long id) {
// 根据ID查询并返回结果
NewsEntity news = newsService.selectById(id); NewsEntity news = newsService.selectById(id);
return R.ok().put("data", news); //调用 newsService 对象的 selectById 方法,根据 id 参数的值查询数据库中的记录,并返回一个 NewsEntity 对象。
return R.ok().put("data", news); //将 news 对象添加到响应对象中,键为 "data"
} }
/** /**
* *
*/ */
@IgnoreAuth @IgnoreAuth
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){ public R detail(@PathVariable("id") Long id) {
// 根据ID查询并返回结果
NewsEntity news = newsService.selectById(id); NewsEntity news = newsService.selectById(id);
return R.ok().put("data", news); return R.ok().put("data", news);
} }
/** /**
* *
*/ */
@RequestMapping("/save") @RequestMapping("/save")
public R save(@RequestBody NewsEntity news, HttpServletRequest request){ 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); news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体对象,如果需要验证,可以取消注释
// ValidatorUtils.validateEntity(news);
// 插入数据,将 news 对象插入到数据库中
newsService.insert(news); newsService.insert(news);
//返回一个表示请求成功的响应对象
return R.ok(); return R.ok();
} }
@ -144,87 +170,100 @@ public class NewsController {
* *
*/ */
@RequestMapping("/add") @RequestMapping("/add")
public R add(@RequestBody NewsEntity news, HttpServletRequest request){ 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); news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体对象,如果需要验证,可以取消注释
// ValidatorUtils.validateEntity(news);
// 插入数据
newsService.insert(news); newsService.insert(news);
return R.ok(); return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/update") @RequestMapping("/update")
@Transactional @Transactional
public R update(@RequestBody NewsEntity news, HttpServletRequest request){ public R update(@RequestBody NewsEntity news, HttpServletRequest request) {
//ValidatorUtils.validateEntity(news); // 验证实体对象,如果需要验证,可以取消注释
newsService.updateById(news);//全部更新 // ValidatorUtils.validateEntity(news);
// 更新数据
newsService.updateById(news);
return R.ok(); return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/delete") @RequestMapping("/delete")//这是一个Spring MVC的注解用于将HTTP请求映射到 delete方法上
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids) {
// 批量删除数据
newsService.deleteBatchIds(Arrays.asList(ids)); newsService.deleteBatchIds(Arrays.asList(ids));
return R.ok(); return R.ok();//R.ok() 方法通常表示请求成功,并返回一个默认的成功响应。
} }
/** /**
* *
*/ */
@RequestMapping("/remind/{columnName}/{type}") @RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, //这是一个Spring MVC的注解用于将HTTP请求映射到 remindCount 方法。当客户端发送一个HTTP请求到 /remind/{columnName}/{type} 路径时Spring MVC会调用 remindCount 方法来处理这个请求。
@PathVariable("type") String type,@RequestParam Map<String, Object> map) { public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
map.put("column", columnName); @PathVariable("type") String type, @RequestParam Map<String, Object> map) {
map.put("type", type); // 将列名和类型添加到map中,@PathVariable 注解表示 columnName 和 type 参数的值将从URL路径中获取
map.put("column", columnName);//将 columnName 参数的值添加到 map 中,键为 "column"。
if(type.equals("2")) { map.put("type", type);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(); if (type.equals("2")) //如果 type 参数的值为 "2"
Date remindStartDate = null; {
Date remindEndDate = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(map.get("remindstart")!=null) { //创建一个 SimpleDateFormat 对象sdf用于将日期格式化为 "yyyy-MM-dd" 格式。
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); Calendar c = Calendar.getInstance();
c.setTime(new Date()); //创建一个 Calendar 对象用于处理日期和时间。Calendar.getInstance() 方法返回一个表示当前日期和时间的 Calendar 对象。
c.add(Calendar.DAY_OF_MONTH,remindStart); Date remindStartDate = null;//声明一个变量 remindStartDate,初始化为 null,这个变量将用于存储提醒开始日期。
remindStartDate = c.getTime(); Date remindEndDate = null;
map.put("remindstart", sdf.format(remindStartDate));
} if (map.get("remindstart") != null)//如果 map 中存在键为 "remindstart" 的元素
if(map.get("remindend")!=null) { {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); //将 map 中键为 "remindstart" 的元素的值转换为 Integer 类型,并赋值给 remindStart
c.add(Calendar.DAY_OF_MONTH,remindEnd); c.setTime(new Date());//setTime(new Date()) 方法将 Calendar 对象c的时间设置为当前时间。
remindEndDate = c.getTime(); c.add(Calendar.DAY_OF_MONTH, remindStart);//将 Calendar 对象的时间增加 remindStart 天。
map.put("remindend", sdf.format(remindEndDate)); remindStartDate = c.getTime();//返回一个表示 Calendar 对象当前时间的 Date 对象,并将其赋值给 remindStartDate。
} map.put("remindstart", sdf.format(remindStartDate));//将 remindStartDate 格式化为 "yyyy-MM-dd" 格式,并将其作为 map 中键为 "remindstart" 的元素的值。
} }
Wrapper<NewsEntity> wrapper = new EntityWrapper<NewsEntity>(); if (map.get("remindend") != null)
if(map.get("remindstart")!=null) { {
wrapper.ge(columnName, map.get("remindstart")); Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
} c.setTime(new Date());//c 的时间设置为当前时间
if(map.get("remindend")!=null) { c.add(Calendar.DAY_OF_MONTH, remindEnd);//c 的时间增加 remindStart 天
wrapper.le(columnName, map.get("remindend")); remindEndDate = c.getTime();
} map.put("remindend", sdf.format(remindEndDate));
}
}
int count = newsService.selectCount(wrapper);
return R.ok().put("count", count); // 创建一个EntityWrapper对象用于构建查询条件
} Wrapper<NewsEntity> wrapper = new EntityWrapper<NewsEntity>();
//创建一个EntityWrapper对象用于构建查询条件
if (map.get("remindstart") != null)//如果map中存在键为"remindstart"的元素
{
wrapper.ge(columnName, map.get("remindstart"));
//将 wrapper 对象的查询条件设置为 columnName>=map 中键为 "remindend" 的元素的值
}
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
//将 wrapper 对象的查询条件设置为 columnName<=map 中键为 "remindend" 的元素的值
}
// 查询并返回结果
int count = newsService.selectCount(wrapper);
//查询满足wrapper对象的查询条件的记录数并赋值给 count 变量
return R.ok().put("count", count);//返回一个包含 count 变量的 R 对象(请求成功的响应对象)
}
} }

@ -52,186 +52,170 @@ public class StoreupController {
@Autowired @Autowired
private StoreupService storeupService; private StoreupService storeupService;
/** /**
* *
*/ */
@RequestMapping("/page") @RequestMapping("/page")//定义了一个处理HTTP请求的映射当请求路径为/page时会调用这个方法
public R page(@RequestParam Map<String, Object> params,StoreupEntity storeup, public R page(@RequestParam Map<String, Object> params,StoreupEntity storeup,HttpServletRequest request)
HttpServletRequest request){ {//定义了一个公共方法接收请求参数、实体对象和HTTP请求对象
if(!request.getSession().getAttribute("role").toString().equals("管理员")) { if(!request.getSession().getAttribute("role").toString().equals("管理员"))
storeup.setUserid((Long)request.getSession().getAttribute("userId")); {//检查当前用户的角色是否为管理员如果不是管理员则设置用户ID
storeup.setUserid((Long)request.getSession().getAttribute("userId"));//设置用户ID
} }
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();//创建一个实体包装器对象,用于构建查询条件
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>(); PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));//调用storeupService的queryPage方法根据查询条件和分页参数进行分页查询并返回分页结果
request.setAttribute("data", page);//将分页结果设置到HTTP请求对象中
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); return R.ok().put("data", page);//返回一个包含分页结果的响应对象
request.setAttribute("data", page);
return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@IgnoreAuth @IgnoreAuth//定义了一个注解,用于标记不需要权限认证的接口
@RequestMapping("/list") @RequestMapping("/list")//定义了一个处理HTTP请求的映射当请求路径为/list时会调用这个方法
public R list(@RequestParam Map<String, Object> params,StoreupEntity storeup, public R list(@RequestParam Map<String, Object> params,StoreupEntity storeup,HttpServletRequest request)
HttpServletRequest request){ {
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>(); EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();//创建一个实体包装器对象,用于构建查询条件
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));//调用storeupService的queryPage方法根据查询条件和分页参数进行分页查询并返回分页结果
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params)); request.setAttribute("data", page);//将分页查询结果设置到HTTP请求对象中
request.setAttribute("data", page); return R.ok().put("data", page);//返回一个包含分页查询结果的响应对象
return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@RequestMapping("/lists") @RequestMapping("/lists")
public R list( StoreupEntity storeup){ public R list( StoreupEntity storeup)//定义了一个公共方法,接收实体对象
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>(); {
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup")); EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();//创建一个实体包装器对象,用于构建查询条件
return R.ok().put("data", storeupService.selectListView(ew)); ew.allEq(MPUtil.allEQMapPre( storeup, "storeup")); //使用allEq方法设置查询条件MPUtil.allEQMapPre方法将实体对象的属性转换为Map,并添加前缀"storeup",allEq方法将Map中的键值对作为查询条件查询出符合条件的实体对象
return R.ok().put("data", storeupService.selectListView(ew));//根据查询条件查询出符合条件的实体对象列表,并返回一个包含实体对象列表的响应对象
} }
/** /**
* *
*/ */
@RequestMapping("/query") @RequestMapping("/query")//定义了一个处理HTTP请求的映射当请求路径为/query时会调用这个方法。
public R query(StoreupEntity storeup){ public R query(StoreupEntity storeup)
{
EntityWrapper< StoreupEntity> ew = new EntityWrapper< StoreupEntity>(); EntityWrapper< StoreupEntity> ew = new EntityWrapper< StoreupEntity>();
//创建一个实体包装器,用于构建查询条件
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup")); ew.allEq(MPUtil.allEQMapPre( storeup, "storeup"));
//使用allEq方法设置查询条件,MPUtil.allEQMapPre方法将实体对象的属性转换为Map,并添加前缀"storeup",allEq方法将Map中的键值对作为查询条件查询出符合条件的实体对象。
StoreupView storeupView = storeupService.selectView(ew); StoreupView storeupView = storeupService.selectView(ew);
//调用服务层的方法查询单个数据,并返回视图对象
return R.ok("查询收藏表成功").put("data", storeupView); return R.ok("查询收藏表成功").put("data", storeupView);
//返回一个包含查询结果的响应对象,并附带成功消息
} }
/** /**
* *
*/ */
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}")// 定义一个请求映射,当访问 /info/{id} 路径时,会调用这个方法
public R info(@PathVariable("id") Long id){ public R info(@PathVariable("id") Long id)// 定义一个方法,接收一个路径变量 id类型为 Long
StoreupEntity storeup = storeupService.selectById(id); {
return R.ok().put("data", storeup); StoreupEntity storeup = storeupService.selectById(id);//调用服务层的方法根据ID查询数据并返回实体对象
return R.ok().put("data", storeup);//返回一个包含查询结果的 R 对象,其中包含键 "data" 和对应的 storeup 实体对象
} }
/** /**
* *
*/ */
@IgnoreAuth @IgnoreAuth//定义了一个注解,用于标记不需要权限认证的接口
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}")//定义了一个处理HTTP请求的映射当请求路径为/detail/{id}时,会调用这个方法
public R detail(@PathVariable("id") Long id){ public R detail(@PathVariable("id") Long id)//定义了一个方法,接收一个路径变量 id类型为 Long
StoreupEntity storeup = storeupService.selectById(id); {
return R.ok().put("data", storeup); StoreupEntity storeup = storeupService.selectById(id);//调用服务层的方法根据ID查询数据并返回实体对象
return R.ok().put("data", storeup);//返回一个包含查询结果的响应对象,并附带成功消息
} }
/** /**
* *
*/ */
@RequestMapping("/save") @RequestMapping("/save")//定义了一个处理HTTP请求的映射当请求路径为/save时会调用这个方法
public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request){ public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request)//定义了一个方法接收一个JSON格式的请求体类型为 StoreupEntity并接收一个 HttpServletRequest 对象
{
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(storeup); //ValidatorUtils.validateEntity(storeup);
storeup.setUserid((Long)request.getSession().getAttribute("userId")); storeup.setUserid((Long)request.getSession().getAttribute("userId"));//从请求的 session 中获取用户ID并设置到 storeup 实体对象中
storeupService.insert(storeup);//调用服务层的方法将 storeup 实体对象插入数据库
storeupService.insert(storeup); return R.ok();//返回一个包含成功信息的 R 对象
return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/add") @RequestMapping("/add")//定义了一个处理HTTP请求的映射当请求路径为/add时会调用这个方法
public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request){ public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request) //定义一个方法,接收一个请求体中的 StoreupEntity 对象和 HttpServletRequest 对象
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); {
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());//生成一个新的唯一ID由当前时间戳加上一个随机数
//ValidatorUtils.validateEntity(storeup); //ValidatorUtils.validateEntity(storeup);
storeupService.insert(storeup);//调用服务层的方法将 storeup 实体对象插入数据库
storeupService.insert(storeup);
return R.ok(); return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/update") @RequestMapping("/update")
@Transactional @Transactional//定义了一个事务注解,表示该方法中的数据库操作应该在一个事务中执行
public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request){ public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request)//定义了一个方法,接收一个请求体中的 StoreupEntity 对象和 HttpServletRequest 对象
{
//ValidatorUtils.validateEntity(storeup); //ValidatorUtils.validateEntity(storeup);
storeupService.updateById(storeup);//全部更新 storeupService.updateById(storeup);//调用服务层的方法根据 ID 更新 storeup 实体对象的所有字段
return R.ok(); return R.ok();//返回一个包含成功信息的 R 对象
} }
/** /**
* *
*/ */
@RequestMapping("/delete") @RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids)// 定义一个方法,接收一个请求体中的 Long 数组,类型为 Long[]
storeupService.deleteBatchIds(Arrays.asList(ids)); {
return R.ok(); storeupService.deleteBatchIds(Arrays.asList(ids));//调用服务层的方法,根据传入的 ID 数组批量删除数据
return R.ok();//返回一个包含成功信息的 R 对象 R.ok()函数是R工具类中的一个静态方法用于创建一个包含成功信息的响应对象
} }
/** /**
* *
*/ */
@RequestMapping("/remind/{columnName}/{type}") @RequestMapping("/remind/{columnName}/{type}") // 定义一个请求映射,当访问 /remind/{columnName}/{type} 路径时,会调用这个方法
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) { @PathVariable("type") String type,@RequestParam Map<String, Object> map) { // 定义一个方法,接收一个路径变量 columnName 和 type类型为 String以及一个请求参数 map类型为 Map<String, Object>
map.put("column", columnName); map.put("column", columnName); // 将 columnName 添加到 map 中,键为 "column"
map.put("type", type); map.put("type", type); // 将 type 添加到 map 中,键为 "type"
if(type.equals("2")) { if(type.equals("2")) { // 如果 type 等于 "2"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 创建一个日期格式化对象,格式为 "yyyy-MM-dd"
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance(); // 创建一个日历对象,获取当前时间
Date remindStartDate = null; Date remindStartDate = null; // 创建一个日期对象,用于存储提醒开始时间
Date remindEndDate = null; Date remindEndDate = null; // 创建一个日期对象,用于存储提醒结束时间
if(map.get("remindstart")!=null) { if(map.get("remindstart")!=null) { // 如果 map 中存在 "remindstart" 键
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 将 "remindstart" 键对应的值转换为整数
c.setTime(new Date()); c.setTime(new Date()); // 设置日历对象的时间为当前时间
c.add(Calendar.DAY_OF_MONTH,remindStart); c.add(Calendar.DAY_OF_MONTH,remindStart); // 将日历对象的时间增加 remindStart 天
remindStartDate = c.getTime(); remindStartDate = c.getTime(); // 获取增加后的时间,并赋值给 remindStartDate
map.put("remindstart", sdf.format(remindStartDate)); map.put("remindstart", sdf.format(remindStartDate)); // 将 remindStartDate 格式化为 "yyyy-MM-dd" 格式,并添加到 map 中,键为 "remindstart"
} }
if(map.get("remindend")!=null) { if(map.get("remindend")!=null) { // 如果 map 中存在 "remindend" 键
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 将 "remindend" 键对应的值转换为整数
c.setTime(new Date()); c.setTime(new Date()); // 设置日历对象的时间为当前时间
c.add(Calendar.DAY_OF_MONTH,remindEnd); c.add(Calendar.DAY_OF_MONTH,remindEnd); // 将日历对象的时间增加 remindEnd 天
remindEndDate = c.getTime(); remindEndDate = c.getTime(); // 获取增加后的时间,并赋值给 remindEndDate
map.put("remindend", sdf.format(remindEndDate)); map.put("remindend", sdf.format(remindEndDate)); // 将 remindEndDate 格式化为 "yyyy-MM-dd" 格式,并添加到 map 中,键为 "remindend"
} }
} }
Wrapper<StoreupEntity> wrapper = new EntityWrapper<StoreupEntity>(); Wrapper<StoreupEntity> wrapper = new EntityWrapper<StoreupEntity>(); // 创建一个实体包装器对象,用于构建查询条件
if(map.get("remindstart")!=null) { if(map.get("remindstart")!=null) { // 如果 map 中存在 "remindstart" 键
wrapper.ge(columnName, map.get("remindstart")); wrapper.ge(columnName, map.get("remindstart")); // 设置查询条件,查询 columnName 字段大于等于 "remindstart" 键对应的值
} }
if(map.get("remindend")!=null) { if(map.get("remindend")!=null) { // 如果 map 中存在 "remindend" 键
wrapper.le(columnName, map.get("remindend")); wrapper.le(columnName, map.get("remindend")); // 设置查询条件,查询 columnName 字段小于等于 "remindend" 键对应的值
} }
if(!request.getSession().getAttribute("role").toString().equals("管理员")) { if(!request.getSession().getAttribute("role").toString().equals("管理员")) { // 如果当前用户的角色不是管理员
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId")); wrapper.eq("userid", (Long)request.getSession().getAttribute("userId")); // 设置查询条件,查询 userid 字段等于当前用户的 ID
} }
int count = storeupService.selectCount(wrapper); // 调用服务层的方法,根据查询条件查询符合条件的记录数,并赋值给 count
int count = storeupService.selectCount(wrapper); return R.ok().put("count", count); // 返回一个包含查询结果的响应对象,其中包含键 "count" 和对应的 count 值
return R.ok().put("count", count); }
}
} }

Loading…
Cancel
Save