前言介绍
本次设计任务是要设计一个基于协同过滤算法的商品推荐系统,通过这个系统能够满足商品推荐系统的管理功能。系统的主要包括首页,个人中心,用户管理,商品类型管理,商品信息管理,系统管理,订单管理等功能。
管理员可以根据系统给定的账号进行登录,登录后可以进入商品推荐系统对个性化智能商品推荐所有模块进行管理。包括查看和修改自己的个人信息以及登录密码。
该系统为每一个用户都分配了一个用户账号,用户通过账号的登录可以在系统中查看个性化智能商品推荐信息及对个人信息进行修改等功能。
性能需求分析
对系统的性能,从(功能、运行、界面、安全)等方面进行,下面我们逐一进行分析;
1. 系统的功能是否完整进行分析:系统的功能,能对应设计出原始代码和算法,以表格同文字的形式进行详细介绍个人信息保证功能完整。
2. 系统的运行是否通畅进行分析:系统的每个功能都有编写数据的关系和应对的代码,通过需求分析和可行性分析进行分析和显示系统的物理数据,保证其进行通畅。
3. 系统的界面设计进行分析:对系统中的软件进行处理与分析的方式是由不同代码来进行的;从而使界面容易操作。
4. 系统的安全性进行分析:这样才可以每个角色的不同对应的信息也就不同,在登录系统务必使用自己的账号,密码登录,账号与密码错误自然就登录失败了。登录成功可以对自己的信息进行操作,不能对别人的账号的信息进行查看等操作,这样自然保证系统的安全性。
协同过滤算法简介
协同过滤算法是一种较为著名和常用的推荐算法,它基于对用户历史行为数据的挖掘发现用户的喜好偏向,并预测用户可能喜好的产品进行推荐。也就是常见的“猜你喜欢”,和“购买了该商品的人也喜欢”等功能。它的主要实现由:
(1)根据和你有共同喜好的人给你推荐
(2)根据你喜欢的物品给你推荐相似物品
(3)根据以上条件综合推荐
(4)因此可以得出常用的协同过滤算法分为两种,基于用户的协同过滤算法(user-based collaboratIve filtering),以及基于物品的协同过滤算法(item-based collaborative filtering)。特点可以概括为“人以类聚,物以群分”,并据此进行预测和推荐。
系统展示
前台页面
商品信息推荐
商品推荐是使用协同算法根据用户购买商品进行推荐
商品信息
商品资讯
购物车
管理员页面
用户管理
商品类型管理
商品信息管理
部分核心代码
商品类型
/*** 商品类型* 后端接口* @author * @email * @date 2022-04-17 14:24:14*/
@RestController
@RequestMapping("/shangpinleixing")
public class ShangpinleixingController {@Autowiredprivate ShangpinleixingService shangpinleixingService;/*** 后端列表*/@RequestMapping("/page")public R page(@RequestParam Map<String, Object> params,ShangpinleixingEntity shangpinleixing,HttpServletRequest request){EntityWrapper<ShangpinleixingEntity> ew = new EntityWrapper<ShangpinleixingEntity>();PageUtils page = shangpinleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinleixing), params), params));return R.ok().put("data", page);}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params,ShangpinleixingEntity shangpinleixing, HttpServletRequest request){EntityWrapper<ShangpinleixingEntity> ew = new EntityWrapper<ShangpinleixingEntity>();PageUtils page = shangpinleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinleixing), params), params));return R.ok().put("data", page);}/*** 列表*/@RequestMapping("/lists")public R list( ShangpinleixingEntity shangpinleixing){EntityWrapper<ShangpinleixingEntity> ew = new EntityWrapper<ShangpinleixingEntity>();ew.allEq(MPUtil.allEQMapPre( shangpinleixing, "shangpinleixing")); return R.ok().put("data", shangpinleixingService.selectListView(ew));}/*** 查询*/@RequestMapping("/query")public R query(ShangpinleixingEntity shangpinleixing){EntityWrapper< ShangpinleixingEntity> ew = new EntityWrapper< ShangpinleixingEntity>();ew.allEq(MPUtil.allEQMapPre( shangpinleixing, "shangpinleixing")); ShangpinleixingView shangpinleixingView = shangpinleixingService.selectView(ew);return R.ok("查询商品类型成功").put("data", shangpinleixingView);}/*** 后端详情*/@RequestMapping("/info/{id}")public R info(@PathVariable("id") Long id){ShangpinleixingEntity shangpinleixing = shangpinleixingService.selectById(id);return R.ok().put("data", shangpinleixing);}/*** 前端详情*/@IgnoreAuth@RequestMapping("/detail/{id}")public R detail(@PathVariable("id") Long id){ShangpinleixingEntity shangpinleixing = shangpinleixingService.selectById(id);return R.ok().put("data", shangpinleixing);}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody ShangpinleixingEntity shangpinleixing, HttpServletRequest request){shangpinleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());//ValidatorUtils.validateEntity(shangpinleixing);shangpinleixingService.insert(shangpinleixing);return R.ok();}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody ShangpinleixingEntity shangpinleixing, HttpServletRequest request){shangpinleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());//ValidatorUtils.validateEntity(shangpinleixing);shangpinleixingService.insert(shangpinleixing);return R.ok();}/*** 修改*/@RequestMapping("/update")public R update(@RequestBody ShangpinleixingEntity shangpinleixing, HttpServletRequest request){//ValidatorUtils.validateEntity(shangpinleixing);shangpinleixingService.updateById(shangpinleixing);//全部更新return R.ok();}/*** 删除*/@RequestMapping("/delete")public R delete(@RequestBody Long[] ids){shangpinleixingService.deleteBatchIds(Arrays.asList(ids));return R.ok();}/*** 提醒接口*/@RequestMapping("/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);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<ShangpinleixingEntity> wrapper = new EntityWrapper<ShangpinleixingEntity>();if(map.get("remindstart")!=null) {wrapper.ge(columnName, map.get("remindstart"));}if(map.get("remindend")!=null) {wrapper.le(columnName, map.get("remindend"));}int count = shangpinleixingService.selectCount(wrapper);return R.ok().put("count", count);}}
协同算法
* 协同算法(按用户购买推荐)*/@RequestMapping("/autoSort2")public R autoSort2(@RequestParam Map<String, Object> params,ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request){String userId = request.getSession().getAttribute("userId").toString();String goodtypeColumn = "shangpinleixing";List<OrdersEntity> orders = ordersService.selectList(new EntityWrapper<OrdersEntity>().eq("userid", userId).eq("tablename", "shangpinxinxi").orderBy("addtime", false));List<String> goodtypes = new ArrayList<String>();Integer limit = params.get("limit")==null?10:Integer.parseInt(params.get("limit").toString());List<ShangpinxinxiEntity> shangpinxinxiList = new ArrayList<ShangpinxinxiEntity>();//去重List<OrdersEntity> ordersDist = new ArrayList<OrdersEntity>();for(OrdersEntity o1 : orders) {boolean addFlag = true;for(OrdersEntity o2 : ordersDist) {if(o1.getGoodid()==o2.getGoodid() || o1.getGoodtype().equals(o2.getGoodtype())) {addFlag = false;break;}}if(addFlag) ordersDist.add(o1);}if(ordersDist!=null && ordersDist.size()>0) {for(OrdersEntity o : ordersDist) {shangpinxinxiList.addAll(shangpinxinxiService.selectList(new EntityWrapper<ShangpinxinxiEntity>().eq(goodtypeColumn, o.getGoodtype())));}}EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();params.put("sort", "id");params.put("order", "desc");PageUtils page = shangpinxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinxinxi), params), params));List<ShangpinxinxiEntity> pageList = (List<ShangpinxinxiEntity>)page.getList();if(shangpinxinxiList.size()<limit) {int toAddNum = (limit-shangpinxinxiList.size())<=pageList.size()?(limit-shangpinxinxiList.size()):pageList.size();for(ShangpinxinxiEntity o1 : pageList) {boolean addFlag = true;for(ShangpinxinxiEntity o2 : shangpinxinxiList) {if(o1.getId().intValue()==o2.getId().intValue()) {addFlag = false;break;}}if(addFlag) {shangpinxinxiList.add(o1);if(--toAddNum==0) break;} }} else if(shangpinxinxiList.size()>limit) {shangpinxinxiList = shangpinxinxiList.subList(0, limit);}page.setList(shangpinxinxiList);return R.ok().put("data", page);}}
登录
/*** 登录相关*/
@RequestMapping("users")
@RestController
public class UserController{@Autowiredprivate UserService userService;@Autowiredprivate TokenService tokenService;/*** 登录*/@IgnoreAuth@PostMapping(value = "/login")public R login(String username, String password, String captcha, HttpServletRequest request) {UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().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);}/*** 注册*/@IgnoreAuth@PostMapping(value = "/register")public R register(@RequestBody UserEntity user){
// ValidatorUtils.validateEntity(user);if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {return R.error("用户已存在");}userService.insert(user);return R.ok();}/*** 退出*/@GetMapping(value = "logout")public R logout(HttpServletRequest request) {request.getSession().invalidate();return R.ok("退出成功");}/*** 密码重置*/@IgnoreAuth@RequestMapping(value = "/resetPass")public R resetPass(String username, HttpServletRequest request){UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));if(user==null) {return R.error("账号不存在");}user.setPassword("123456");userService.update(user,null);return R.ok("密码已重置为:123456");}/*** 列表*/@RequestMapping("/page")public R page(@RequestParam Map<String, Object> params,UserEntity user){EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));return R.ok().put("data", page);}/*** 列表*/@RequestMapping("/list")public R list( UserEntity user){EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();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<UserEntity>().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<UserEntity>().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();}
}
上传文件
* 上传文件*/@RequestMapping("/upload")public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {if (file.isEmpty()) {throw new EIException("上传文件不能为空");}String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);File path = new File(ResourceUtils.getURL("classpath:static").getPath());if(!path.exists()) {path = new File("");}File upload = new File(path.getAbsolutePath(),"/upload/");if(!upload.exists()) {upload.mkdirs();}String fileName = new Date().getTime()+"."+fileExt;File dest = new File(upload.getAbsolutePath()+"/"+fileName);file.transferTo(dest);/*** 如果使用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<ConfigEntity>().eq("name", "faceFile"));if(configEntity==null) {configEntity = new ConfigEntity();configEntity.setName("faceFile");configEntity.setValue(fileName);} else {configEntity.setValue(fileName);}configService.insertOrUpdate(configEntity);}return R.ok().put("file", fileName);}/*** 下载文件*/@IgnoreAuth@RequestMapping("/download")public ResponseEntity<byte[]> download(@RequestParam String fileName) {try {File path = new File(ResourceUtils.getURL("classpath:static").getPath());if(!path.exists()) {path = new File("");}File upload = new File(path.getAbsolutePath(),"/upload/");if(!upload.exists()) {upload.mkdirs();}File file = new File(upload.getAbsolutePath()+"/"+fileName);if(file.exists()){/*if(!fileService.canRead(file, SessionManager.getSessionUser())){getResponse().sendError(403);}*/HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", fileName); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);}} catch (IOException e) {e.printStackTrace();}return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);}}
此源码非开源,若需要此源码可扫码添加微信或者qq:2214904953进行咨询!
2600多套项目欢迎咨询