项目介绍
北部湾地区助农平台是一个旨在促进当地农业发展和农民增收的在线服务系统。该平台为农民提供市场信息、技术支持和销售渠道,帮助他们提高生产效率和产品竞争力。通过整合农业资源和优化供应链管理,不仅提升了农产品的市场响应速度,还增强了农民之间的合作与交流,对实现区域经济的均衡发展和改善农民生活水平具有积极的推动作用。本文讲述了基于java语言开发,后台数据库选择MySQL进行数据的存储。该软件的主要功能是进行北部湾地区助农的管理。主要包括农商管理、用户管理、产品分类管理、助农商品管理、助农脱贫管理、农技学堂管理、订单管理等。本文主要介绍了该应用的设计初衷、功能实现的大致过程,详细说明了北部湾地区助农平台设计思想、数据库的开发设计和功能模块的设计。整个北部湾地区助农平台的设计过程中,考虑了数据库的安全性、一致性、稳定性和可靠性的问题,并具有简洁的界面,操作也十分简单,可以投入实际应用。
开发环境
编程语言:Java
数据库 :Mysql
系统架构:B/S
前端技术:Vue
后端框架:SpringBoot
编译工具:idea或者eclipse,微信开发者工具,jdk1.8,maven
支持定做:java/php/python/android/小程序vue/爬虫/c#/asp.net
系统截图
核心代码
package com.controller;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
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 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 com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.OrdersEntity;
import com.service.OrdersService;
import com.utils.UserBasedCollaborativeFiltering;
import com.entity.ZhunongshangpinEntity;
import com.entity.view.ZhunongshangpinView;
import com.service.ZhunongshangpinService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MPUtil;
import com.utils.MapUtils;
import com.utils.CommonUtil;
import java.io.IOException;
import com.service.StoreupService;
import com.entity.StoreupEntity;
/**
* 助农商品
* 后端接口
* @author
* @email
* @date 2024-02-08 17:32:25
*/
@RestController
@RequestMapping("/zhunongshangpin")
public class ZhunongshangpinController {
@Autowired
private ZhunongshangpinService zhunongshangpinService;
@Autowired
private StoreupService storeupService;
@Autowired
private OrdersService ordersService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ZhunongshangpinEntity zhunongshangpin,
@RequestParam(required = false) Double pricestart,
@RequestParam(required = false) Double priceend,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
zhunongshangpin.setNonghuzhanghao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
if(pricestart!=null) ew.ge("price", pricestart);
if(priceend!=null) ew.le("price", priceend);
PageUtils page = zhunongshangpinService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhunongshangpin), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ZhunongshangpinEntity zhunongshangpin,
@RequestParam(required = false) Double pricestart,
@RequestParam(required = false) Double priceend,
HttpServletRequest request){
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
if(pricestart!=null) ew.ge("price", pricestart);
if(priceend!=null) ew.le("price", priceend);
PageUtils page = zhunongshangpinService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhunongshangpin), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( ZhunongshangpinEntity zhunongshangpin){
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
ew.allEq(MPUtil.allEQMapPre( zhunongshangpin, "zhunongshangpin"));
return R.ok().put("data", zhunongshangpinService.selectListView(ew));
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(ZhunongshangpinEntity zhunongshangpin){
EntityWrapper< ZhunongshangpinEntity> ew = new EntityWrapper< ZhunongshangpinEntity>();
ew.allEq(MPUtil.allEQMapPre( zhunongshangpin, "zhunongshangpin"));
ZhunongshangpinView zhunongshangpinView = zhunongshangpinService.selectView(ew);
return R.ok("查询助农商品成功").put("data", zhunongshangpinView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ZhunongshangpinEntity zhunongshangpin = zhunongshangpinService.selectById(id);
zhunongshangpin.setClicknum(zhunongshangpin.getClicknum()+1);
zhunongshangpinService.updateById(zhunongshangpin);
zhunongshangpin = zhunongshangpinService.selectView(new EntityWrapper<ZhunongshangpinEntity>().eq("id", id));
return R.ok().put("data", zhunongshangpin);
}
/**
* 前端详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ZhunongshangpinEntity zhunongshangpin = zhunongshangpinService.selectById(id);
zhunongshangpin.setClicknum(zhunongshangpin.getClicknum()+1);
zhunongshangpinService.updateById(zhunongshangpin);
zhunongshangpin = zhunongshangpinService.selectView(new EntityWrapper<ZhunongshangpinEntity>().eq("id", id));
return R.ok().put("data", zhunongshangpin);
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request){
//ValidatorUtils.validateEntity(zhunongshangpin);
zhunongshangpinService.insert(zhunongshangpin);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request){
//ValidatorUtils.validateEntity(zhunongshangpin);
zhunongshangpinService.insert(zhunongshangpin);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@Transactional
public R update(@RequestBody ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request){
//ValidatorUtils.validateEntity(zhunongshangpin);
zhunongshangpinService.updateById(zhunongshangpin);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
zhunongshangpinService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 前端智能排序
*/
@IgnoreAuth
@RequestMapping("/autoSort")
public R autoSort(@RequestParam Map<String, Object> params,ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request,String pre){
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
Map<String, Object> newMap = new HashMap<String, Object>();
Map<String, Object> param = new HashMap<String, Object>();
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
String newKey = entry.getKey();
if (pre.endsWith(".")) {
newMap.put(pre + newKey, entry.getValue());
} else if (StringUtils.isEmpty(pre)) {
newMap.put(newKey, entry.getValue());
} else {
newMap.put(pre + "." + newKey, entry.getValue());
}
}
params.put("sort", "clicknum");
params.put("order", "desc");
PageUtils page = zhunongshangpinService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhunongshangpin), params), params));
return R.ok().put("data", page);
}
/**
* 协同算法(基于用户的协同算法)
*/
@RequestMapping("/autoSort2")
public R autoSort2(@RequestParam Map<String, Object> params,ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request){
String userId = request.getSession().getAttribute("userId").toString();
Integer limit = params.get("limit")==null?10:Integer.parseInt(params.get("limit").toString());
List<OrdersEntity> orders = ordersService.selectList(new EntityWrapper<OrdersEntity>());
Map<String, Map<String, Double>> ratings = new HashMap<>();
if(orders!=null && orders.size()>0) {
for(OrdersEntity o : orders) {
Map<String, Double> userRatings = null;
if(ratings.containsKey(o.getUserid().toString())) {
userRatings = ratings.get(o.getUserid().toString());
} else {
userRatings = new HashMap<>();
ratings.put(o.getUserid().toString(), userRatings);
}
if(userRatings.containsKey(o.getGoodid().toString())) {
userRatings.put(o.getGoodid().toString(), userRatings.get(o.getGoodid().toString())+1.0);
} else {
userRatings.put(o.getGoodid().toString(), 1.0);
}
}
}
// 创建协同过滤对象
UserBasedCollaborativeFiltering filter = new UserBasedCollaborativeFiltering(ratings);
// 为指定用户推荐物品
String targetUser = userId;
int numRecommendations = limit;
List<String> recommendations = filter.recommendItems(targetUser, numRecommendations);
// 输出推荐结果
System.out.println("Recommendations for " + targetUser + ":");
for (String item : recommendations) {
System.out.println(item);
}
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
ew.in("id", recommendations);
if(recommendations!=null && recommendations.size()>0) {
ew.last("order by FIELD(id, "+String.join(",", recommendations)+")");
}
PageUtils page = zhunongshangpinService.queryPage(params, ew);
List<ZhunongshangpinEntity> pageList = (List<ZhunongshangpinEntity>)page.getList();
if(pageList.size()<limit) {
int toAddNum = limit-pageList.size();
ew = new EntityWrapper<ZhunongshangpinEntity>();
ew.notIn("id", recommendations);
ew.orderBy("id", false);
ew.last("limit "+toAddNum);
pageList.addAll(zhunongshangpinService.selectList(ew));
} else if(pageList.size()>limit) {
pageList = pageList.subList(0, limit);
}
page.setList(pageList);
return R.ok().put("data", page);
}
/**
* (按值统计)
*/
@RequestMapping("/value/{xColumnName}/{yColumnName}")
public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName);
params.put("yColumn", yColumnName);
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
ew.eq("nonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
List<Map<String, Object>> result = zhunongshangpinService.selectValue(params, ew);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for(Map<String, Object> 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);
}
/**
* (按值统计(多))
*/
@RequestMapping("/valueMul/{xColumnName}")
public R valueMul(@PathVariable("xColumnName") String xColumnName,@RequestParam String yColumnNameMul, HttpServletRequest request) {
String[] yColumnNames = yColumnNameMul.split(",");
Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName);
List<List<Map<String, Object>>> result2 = new ArrayList<List<Map<String,Object>>>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
ew.eq("nonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
for(int i=0;i<yColumnNames.length;i++) {
params.put("yColumn", yColumnNames[i]);
List<Map<String, Object>> result = zhunongshangpinService.selectValue(params, ew);
for(Map<String, Object> m : result) {
for(String k : m.keySet()) {
if(m.get(k) instanceof Date) {
m.put(k, sdf.format((Date)m.get(k)));
}
}
}
result2.add(result);
}
return R.ok().put("data", result2);
}
/**
* (按值统计)时间统计类型
*/
@RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}")
public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,HttpServletRequest request) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName);
params.put("yColumn", yColumnName);
params.put("timeStatType", timeStatType);
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
ew.eq("nonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
List<Map<String, Object>> result = zhunongshangpinService.selectTimeStatValue(params, ew);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for(Map<String, Object> 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);
}
/**
* (按值统计)时间统计类型(多)
*/
@RequestMapping("/valueMul/{xColumnName}/{timeStatType}")
public R valueMulDay(@PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,@RequestParam String yColumnNameMul,HttpServletRequest request) {
String[] yColumnNames = yColumnNameMul.split(",");
Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName);
params.put("timeStatType", timeStatType);
List<List<Map<String, Object>>> result2 = new ArrayList<List<Map<String,Object>>>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
ew.eq("nonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
for(int i=0;i<yColumnNames.length;i++) {
params.put("yColumn", yColumnNames[i]);
List<Map<String, Object>> result = zhunongshangpinService.selectTimeStatValue(params, ew);
for(Map<String, Object> m : result) {
for(String k : m.keySet()) {
if(m.get(k) instanceof Date) {
m.put(k, sdf.format((Date)m.get(k)));
}
}
}
result2.add(result);
}
return R.ok().put("data", result2);
}
/**
* 分组统计
*/
@RequestMapping("/group/{columnName}")
public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("column", columnName);
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
ew.eq("nonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
List<Map<String, Object>> result = zhunongshangpinService.selectGroup(params, ew);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for(Map<String, Object> 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);
}
/**
* 总数量
*/
@RequestMapping("/count")
public R count(@RequestParam Map<String, Object> params,ZhunongshangpinEntity zhunongshangpin, HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("nonghu")) {
zhunongshangpin.setNonghuzhanghao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<ZhunongshangpinEntity> ew = new EntityWrapper<ZhunongshangpinEntity>();
int count = zhunongshangpinService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zhunongshangpin), params), params));
return R.ok().put("data", count);
}
}
论文参考
目录
第1章 前言 - 1 -
1.1研究背景及意义 - 1 -
1.2国内外研究现状 - 1 -
1.3主要研究内容 - 2 -
第2章 相关技术介绍 - 3 -
2.1 Java语言 - 3 -
2.2 Springboot框架 - 3 -
2.3 vue技术 - 3 -
2.4 MySQL数据库 - 4 -
2.5 B/S架构 - 4 -
第3章 系统分析 - 5 -
3.1 系统可行性分析 - 5 -
3.1.1 技术可行性 - 5 -
3.1.2 操作可行性 - 5 -
3.1.3 经济可行性 - 5 -
3.2系统性能需求分析 - 5 -
3.3系统功能需求 - 6 -
3.4 系统用例分析 - 6 -
3.5 系统流程分析 - 7 -
3.5.1 登录流程 - 8 -
3.5.2 注册流程 - 8 -
3.5.3 添加流程 - 9 -
第4章 系统设计 - 10 -
4.1系统功能模块设计 - 10 -
4.2 系统数据库设计 - 10 -
4.2.1 数据库系统 - 10 -
4.2.2 数据库概念设计 - 11 -
4.2.3 E-R模型结构设计 - 11 -
4.2.4数据表设计 - 11 -
第5章 系统实现 - 23 -
5.1系统功能实现 - 23 -
5.1.1系统首页功能实现 - 23 -
5.1.2个人中心页面实现 - 25 -
5.2后台模块实现 - 25 -
5.2.1管理员模块实现 - 26 -
5.2.2农商模块实现 - 29 -
第6章 系统测试 - 30 -
6.1 系统测试概述 - 30 -
6.2 测试方法 - 30 -
6.3 测试过程和结果 - 30 -
第7章 总结和展望 - 32 -
参 考 文 献 - 33 -
致 谢 - 34 -