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