|
|
|
|
@ -0,0 +1,108 @@
|
|
|
|
|
// 定义包名,用于组织代码结构
|
|
|
|
|
package com.macro.mall.portal.controller;
|
|
|
|
|
|
|
|
|
|
// 导入通用结果类,用于统一返回操作结果
|
|
|
|
|
import com.macro.mall.common.api.CommonPage;
|
|
|
|
|
import com.macro.mall.common.api.CommonResult;
|
|
|
|
|
// 导入会员浏览历史实体类,用于封装浏览历史数据
|
|
|
|
|
import com.macro.mall.portal.domain.MemberReadHistory;
|
|
|
|
|
// 导入会员浏览历史服务接口,用于访问会员浏览历史数据
|
|
|
|
|
import com.macro.mall.portal.service.MemberReadHistoryService;
|
|
|
|
|
// 导入Swagger注解,用于生成API文档
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
// 导入Spring框架的注解,用于声明组件和自动注入
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
// 导入Java的List接口,用于操作列表数据
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 会员商品浏览记录管理Controller
|
|
|
|
|
* 该类负责处理会员商品浏览记录的增删改查操作
|
|
|
|
|
* Created by macro on 2018/8/3.
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
@Api(tags = "MemberReadHistoryController")
|
|
|
|
|
@Tag(name = "MemberReadHistoryController", description = "会员商品浏览记录管理")
|
|
|
|
|
@RequestMapping("/member/readHistory")
|
|
|
|
|
public class MemberReadHistoryController {
|
|
|
|
|
// 使用@Autowired注解自动注入MemberReadHistoryService实例
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberReadHistoryService memberReadHistoryService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建浏览记录
|
|
|
|
|
* @param memberReadHistory 会员浏览历史对象,包含会员ID和商品ID等信息
|
|
|
|
|
* @return 通用结果对象,包含操作结果和数据
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("创建浏览记录")
|
|
|
|
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public CommonResult create(@RequestBody MemberReadHistory memberReadHistory) {
|
|
|
|
|
// 调用memberReadHistoryService的create方法创建浏览记录
|
|
|
|
|
int count = memberReadHistoryService.create(memberReadHistory);
|
|
|
|
|
// 如果创建成功,返回成功的通用结果对象
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return CommonResult.success(count);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果创建失败,返回失败的通用结果对象
|
|
|
|
|
return CommonResult.failed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除浏览记录
|
|
|
|
|
* @param ids 要删除的浏览记录ID列表,以字符串列表的形式传入
|
|
|
|
|
* @return 通用结果对象,包含操作结果和数据
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("删除浏览记录")
|
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public CommonResult delete(@RequestParam("ids") List<String> ids) {
|
|
|
|
|
// 调用memberReadHistoryService的delete方法删除浏览记录
|
|
|
|
|
int count = memberReadHistoryService.delete(ids);
|
|
|
|
|
// 如果删除成功,返回成功的通用结果对象
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return CommonResult.success(count);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果删除失败,返回失败的通用结果对象
|
|
|
|
|
return CommonResult.failed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清空浏览记录
|
|
|
|
|
* @return 通用结果对象,包含操作结果和数据
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("清空浏览记录")
|
|
|
|
|
@RequestMapping(value = "/clear", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public CommonResult clear() {
|
|
|
|
|
// 调用memberReadHistoryService的clear方法清空浏览记录
|
|
|
|
|
memberReadHistoryService.clear();
|
|
|
|
|
// 返回成功的通用结果对象
|
|
|
|
|
return CommonResult.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取浏览记录
|
|
|
|
|
* @param pageNum 当前页码,用于分页显示
|
|
|
|
|
* @param pageSize 每页显示的记录数,用于分页显示
|
|
|
|
|
* @return 通用结果对象,包含分页后的浏览记录数据
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("分页获取浏览记录")
|
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public CommonResult<CommonPage<MemberReadHistory>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
|
|
|
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
|
|
|
|
|
// 调用memberReadHistoryService的list方法分页获取浏览记录
|
|
|
|
|
Page<MemberReadHistory> page = memberReadHistoryService.list(pageNum, pageSize);
|
|
|
|
|
// 将分页结果封装到CommonPage对象中,并返回成功的通用结果对象
|
|
|
|
|
return CommonResult.success(CommonPage.restPage(page));
|
|
|
|
|
}
|
|
|
|
|
}
|