🙊作者简介:多年编程开发经验,专注java技术领域和毕业设计项目实战,系统定制、远程部署调试、代码讲解、代码修改
🍅擅长语言:springboot、ssm、vue、html、jsp、php、python、爬虫、小程序、安卓app
⬇️源码获取:文末可以获取源码+数据库+文档⚡感兴趣的可以先收藏+关注,后续会更新更多项目资料,所有项目均配有开发文档和安装配置教程
系统介绍
本果蔬作物疾病防治系统分为管理员还有用户两个权限,管理员可以管理用户的基本信息内容,可以管理公告信息以及果蔬百科信息,能够与用户进行相互交流等操作,用户可以查看果蔬百科信息,可以查看公告以及查看管理员回复信息等操作。
该果蔬作物疾病防治系统采用的是WEB应用程序开发中最受欢迎的小程序结构模式,使用占用空间小但功能齐全的MySQL数据库进行数据的存储操作,系统开发技术使用到了Java技术。该果蔬作物疾病防治系统能够解决许多传统手工操作的难题,比如数据查询耽误时间长,数据管理步骤繁琐等问题。总的来说,果蔬作物疾病防治系统性能稳定,功能较全,投入运行使用性价比很高。
系统主要技术
开发语言:Java
使用框架:SpringBoot
系统架构:B/S
前端技术:Vue、JavaScript
数据库 :Mysql 5.7/8.0
编译工具:idea或者eclipse,jdk1.8,maven
系统模块设计
果蔬作物疾病防治系统系统在进行系统中功能模块的划分时,采用层次图来进行表示。层次图具有树形结构,它能使用矩形框来描绘数据信息。顶层代表的数据结构很完整,顶层下面的矩形框表示的数据就是子集数据,当然处于最下面的矩形框就是不能再进行细分的数据元素了,使用层次方框图描述系统功能能让用户一目了然,能够明白系统的功能,以及对应功能板块下面的子功能都可以清楚领会。果蔬作物疾病防治系统分为管理员和用户两部分操作角色,下面将对他们的功能进行阐述。管理员可以管理用户的基本信息,可以管理等功能。管理员功能结构图如下:
图4.1 管理员功能结构图
系统功能实现
5.1.1 果蔬百科列表
如图5.1显示的就是果蔬百科列表页面,此页面提供给管理员的功能有:查看果蔬百科、新增果蔬百科、修改果蔬百科、删除果蔬百科等。
图5.1 果蔬百科列表页面
5.1.2 公告信息管理
管理员可以对公告信息进行管理,可以新增公告信息,修改公告信息,删除无效的公告信息。公告信息管理界面如图5.2所示。
图5.2 公告信息管理页面
5.1.3 公告类型管理
公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。下图就是公告类型管理页面。公告类型管理界面如图5.3所示。
图5.3公告类型管理界面
论文参考
![](https://i-blog.csdnimg.cn/direct/dcbe6daf03554c9d87af1c76ead4560f.png)
核心代码
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 果蔬百科
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/guoshu")
public class GuoshuController {
private static final Logger logger = LoggerFactory.getLogger(GuoshuController.class);
private static final String TABLE_NAME = "guoshu";
@Autowired
private GuoshuService guoshuService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private ForumService forumService;//论坛
@Autowired
private GonggaoService gonggaoService;//公告
@Autowired
private GuoshuCollectionService guoshuCollectionService;//果蔬百科收藏
@Autowired
private GuoshuLiuyanService guoshuLiuyanService;//果蔬百科留言
@Autowired
private YonghuService yonghuService;//用户
@Autowired
private YujingService yujingService;//预警
@Autowired
private ZhuanjiaService zhuanjiaService;//专家
@Autowired
private ZhuanjiaChatService zhuanjiaChatService;//专家咨询
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
else if("专家".equals(role))
params.put("zhuanjiaId",request.getSession().getAttribute("userId"));
params.put("guoshuDeleteStart",1);params.put("guoshuDeleteEnd",1);
CommonUtil.checkMap(params);
PageUtils page = guoshuService.queryPage(params);
//字典表数据转换
List<GuoshuView> list =(List<GuoshuView>)page.getList();
for(GuoshuView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GuoshuEntity guoshu = guoshuService.selectById(id);
if(guoshu !=null){
//entity转view
GuoshuView view = new GuoshuView();
BeanUtils.copyProperties( guoshu , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody GuoshuEntity guoshu, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,guoshu:{}",this.getClass().getName(),guoshu.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
Wrapper<GuoshuEntity> queryWrapper = new EntityWrapper<GuoshuEntity>()
.eq("guoshu_name", guoshu.getGuoshuName())
.eq("guoshu_types", guoshu.getGuoshuTypes())
.eq("guoshu_erji_types", guoshu.getGuoshuErjiTypes())
.eq("guoshu_chandi", guoshu.getGuoshuChandi())
.eq("guoshu_qihou", guoshu.getGuoshuQihou())
.eq("guoshu_jijie", guoshu.getGuoshuJijie())
.eq("shangxia_types", guoshu.getShangxiaTypes())
.eq("guoshu_delete", guoshu.getGuoshuDelete())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GuoshuEntity guoshuEntity = guoshuService.selectOne(queryWrapper);
if(guoshuEntity==null){
guoshu.setGuoshuClicknum(1);
guoshu.setShangxiaTypes(1);
guoshu.setGuoshuDelete(1);
guoshu.setInsertTime(new Date());
guoshu.setCreateTime(new Date());
guoshuService.insert(guoshu);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody GuoshuEntity guoshu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,guoshu:{}",this.getClass().getName(),guoshu.toString());
GuoshuEntity oldGuoshuEntity = guoshuService.selectById(guoshu.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
if("".equals(guoshu.getGuoshuPhoto()) || "null".equals(guoshu.getGuoshuPhoto())){
guoshu.setGuoshuPhoto(null);
}
guoshuService.updateById(guoshu);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<GuoshuEntity> oldGuoshuList =guoshuService.selectBatchIds(Arrays.asList(ids));//要删除的数据
ArrayList<GuoshuEntity> list = new ArrayList<>();
for(Integer id:ids){
GuoshuEntity guoshuEntity = new GuoshuEntity();
guoshuEntity.setId(id);
guoshuEntity.setGuoshuDelete(2);
list.add(guoshuEntity);
}
if(list != null && list.size() >0){
guoshuService.updateBatchById(list);
}
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<GuoshuEntity> guoshuList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
GuoshuEntity guoshuEntity = new GuoshuEntity();
// guoshuEntity.setGuoshuName(data.get(0)); //果蔬名称 要改的
// guoshuEntity.setGuoshuUuidNumber(data.get(0)); //果蔬编号 要改的
// guoshuEntity.setGuoshuPhoto("");//详情和图片
// guoshuEntity.setGuoshuTypes(Integer.valueOf(data.get(0))); //果蔬类型 要改的
// guoshuEntity.setGuoshuErjiTypes(Integer.valueOf(data.get(0))); //二级类型 要改的
// guoshuEntity.setGuoshuChandi(data.get(0)); //果蔬产地 要改的
// guoshuEntity.setGuoshuQihou(data.get(0)); //气候 要改的
// guoshuEntity.setGuoshuJijie(data.get(0)); //季节 要改的
// guoshuEntity.setGuoshuClicknum(Integer.valueOf(data.get(0))); //果蔬热度 要改的
// guoshuEntity.setGuoshuContent("");//详情和图片
// guoshuEntity.setGuoshuBingchonghaiContent("");//详情和图片
// guoshuEntity.setShangxiaTypes(Integer.valueOf(data.get(0))); //是否上架 要改的
// guoshuEntity.setGuoshuDelete(1);//逻辑删除字段
// guoshuEntity.setInsertTime(date);//时间
// guoshuEntity.setCreateTime(date);//时间
guoshuList.add(guoshuEntity);
//把要查询是否重复的字段放入map中
//果蔬编号
if(seachFields.containsKey("guoshuUuidNumber")){
List<String> guoshuUuidNumber = seachFields.get("guoshuUuidNumber");
guoshuUuidNumber.add(data.get(0));//要改的
}else{
List<String> guoshuUuidNumber = new ArrayList<>();
guoshuUuidNumber.add(data.get(0));//要改的
seachFields.put("guoshuUuidNumber",guoshuUuidNumber);
}
}
//查询是否重复
//果蔬编号
List<GuoshuEntity> guoshuEntities_guoshuUuidNumber = guoshuService.selectList(new EntityWrapper<GuoshuEntity>().in("guoshu_uuid_number", seachFields.get("guoshuUuidNumber")).eq("guoshu_delete", 1));
if(guoshuEntities_guoshuUuidNumber.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(GuoshuEntity s:guoshuEntities_guoshuUuidNumber){
repeatFields.add(s.getGuoshuUuidNumber());
}
return R.error(511,"数据库的该表中的 [果蔬编号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
guoshuService.insertBatch(guoshuList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 个性推荐
*/
@IgnoreAuth
@RequestMapping("/gexingtuijian")
public R gexingtuijian(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
List<GuoshuView> returnGuoshuViewList = new ArrayList<>();
//查看收藏
Map<String, Object> params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId"));
PageUtils pageUtils = guoshuCollectionService.queryPage(params1);
List<GuoshuCollectionView> collectionViewsList =(List<GuoshuCollectionView>)pageUtils.getList();
Map<Integer,Integer> typeMap=new HashMap<>();//购买的类型list
for(GuoshuCollectionView collectionView:collectionViewsList){
Integer guoshuTypes = collectionView.getGuoshuTypes();
if(typeMap.containsKey(guoshuTypes)){
typeMap.put(guoshuTypes,typeMap.get(guoshuTypes)+1);
}else{
typeMap.put(guoshuTypes,1);
}
}
List<Integer> typeList = new ArrayList<>();//排序后的有序的类型 按最多到最少
typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序
Integer limit = Integer.valueOf(String.valueOf(params.get("limit")));
for(Integer type:typeList){
Map<String, Object> params2 = new HashMap<>(params);params2.put("guoshuTypes",type);
PageUtils pageUtils1 = guoshuService.queryPage(params2);
List<GuoshuView> guoshuViewList =(List<GuoshuView>)pageUtils1.getList();
returnGuoshuViewList.addAll(guoshuViewList);
if(returnGuoshuViewList.size()>= limit) break;//返回的推荐数量大于要的数量 跳出循环
}
//正常查询出来商品,用于补全推荐缺少的数据
PageUtils page = guoshuService.queryPage(params);
if(returnGuoshuViewList.size()<limit){//返回数量还是小于要求数量
int toAddNum = limit - returnGuoshuViewList.size();//要添加的数量
List<GuoshuView> guoshuViewList =(List<GuoshuView>)page.getList();
for(GuoshuView guoshuView:guoshuViewList){
Boolean addFlag = true;
for(GuoshuView returnGuoshuView:returnGuoshuViewList){
if(returnGuoshuView.getId().intValue() ==guoshuView.getId().intValue()) addFlag=false;//返回的数据中已存在此商品
}
if(addFlag){
toAddNum=toAddNum-1;
returnGuoshuViewList.add(guoshuView);
if(toAddNum==0) break;//够数量了
}
}
}else {
returnGuoshuViewList = returnGuoshuViewList.subList(0, limit);
}
for(GuoshuView c:returnGuoshuViewList)
dictionaryService.dictionaryConvert(c, request);
page.setList(returnGuoshuViewList);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
PageUtils page = guoshuService.queryPage(params);
//字典表数据转换
List<GuoshuView> list =(List<GuoshuView>)page.getList();
for(GuoshuView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GuoshuEntity guoshu = guoshuService.selectById(id);
if(guoshu !=null){
//点击数量加1
guoshu.setGuoshuClicknum(guoshu.getGuoshuClicknum()+1);
guoshuService.updateById(guoshu);
//entity转view
GuoshuView view = new GuoshuView();
BeanUtils.copyProperties( guoshu , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody GuoshuEntity guoshu, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,guoshu:{}",this.getClass().getName(),guoshu.toString());
Wrapper<GuoshuEntity> queryWrapper = new EntityWrapper<GuoshuEntity>()
.eq("guoshu_name", guoshu.getGuoshuName())
.eq("guoshu_uuid_number", guoshu.getGuoshuUuidNumber())
.eq("guoshu_types", guoshu.getGuoshuTypes())
.eq("guoshu_erji_types", guoshu.getGuoshuErjiTypes())
.eq("guoshu_chandi", guoshu.getGuoshuChandi())
.eq("guoshu_qihou", guoshu.getGuoshuQihou())
.eq("guoshu_jijie", guoshu.getGuoshuJijie())
.eq("guoshu_clicknum", guoshu.getGuoshuClicknum())
.eq("shangxia_types", guoshu.getShangxiaTypes())
.eq("guoshu_delete", guoshu.getGuoshuDelete())
// .notIn("guoshu_types", new Integer[]{102})
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GuoshuEntity guoshuEntity = guoshuService.selectOne(queryWrapper);
if(guoshuEntity==null){
guoshu.setGuoshuClicknum(1);
guoshu.setGuoshuDelete(1);
guoshu.setInsertTime(new Date());
guoshu.setCreateTime(new Date());
guoshuService.insert(guoshu);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
}