作者主页:源码空间站2022

简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目分为前后台,分为普通用户、管理员、企业用户三种角色;
普通用户无需登录,可在前台直接进行溯源查询,管理员、企业用户可登录后台进行管理;

超级管理员角色包含以下功能:

登录,管理企业,设置管理员,增加管理员,删除管理员等功能。

用户角色包含以下功能:
用户首页,用户进行溯源查询,溯源结果等功能。

企业角色包含以下功能:

注册,登录,企业登录后主页,增删改查农产品列表,新增农产品,二维码列表查看,溯源列表,查看近期溯源人数,修改企业信息,查看溯源二维码等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

5.数据库:MySql 5.7版本;

6.是否Maven项目:是;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:JSP+CSS+JavaScript+LayUI+jQuery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中database.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ncpsy 登录 
注:Tomcat中配置路径必须为/ncpsy 否则会有异常
管理员账号/密码:admin/admin

企业账号/密码:user/123456

运行截图

普通用户界面

管理员用户界面

企业用户界面

代码相关

农产品管理控制器

@Controller
@RequestMapping("/handle")
public class NcpController {protected Logger logger = LoggerFactory.getLogger(this.getClass());@Autowiredprivate INcpService ncpService;@Autowiredprivate IEwmService ewmService;/*** 新增农产品(生成二维码数据,插入二维码表)* @param ncp* @return*/@RequestMapping("/product/add")@ResponseBodypublic boolean productAdd(@RequestBody Ncp ncp, HttpServletRequest request) {logger.info("/handle/product/add===> ncp={}", ncp);QueryWrapper<Ncp> queryWrapper = new QueryWrapper<>();//设置农产品idqueryWrapper.eq("qyid", ncp.getQyid());int num = ncpService.count(queryWrapper) + 1;String ncpid = "ncp";while(ncp.getNcpid() == null) {if(num /10 == 0) {ncpid = ncpid.concat("00" + num);} else if(num / 10 >= 1 && num / 10 < 10) {ncpid = ncpid.concat("0" + num);} else {ncpid = ncpid.concat("" + num);}ncpid = ncpid.concat("-" + ncp.getQyid());//查询数据库是否存在相同的ncpid,存在则num+1,继续循环QueryWrapper<Ncp> ncpidQueryWrapper = new QueryWrapper<>();ncpidQueryWrapper.eq("ncpid", ncpid);int isExist = ncpService.count(ncpidQueryWrapper);if(isExist > 0) {num += 1;ncpid = "ncp";continue;} else {break;}}ncp.setNcpid(ncpid);//生成二维码idQueryWrapper<Ewm> ewmQueryWrapper = new QueryWrapper<>();ewmQueryWrapper.likeLeft("ewmid", ncp.getQyid());//int num2 = ewmService.count(ewmQueryWrapper) + 1;int num2 = num;String ewmid = "ewm";while(ncp.getEwmid() == null) {if(num2 /10 == 0) {ewmid = ewmid.concat("00" + num2);} else if(num2 / 10 >= 1 && num2 / 10 < 10) {ewmid = ewmid.concat("0" + num2);} else {ewmid = ewmid.concat("" + num2);}ewmid = ewmid.concat("-" + ncpid);//查询数据库是否存在相同的ewmid,存在则num+1,继续循环QueryWrapper<Ewm> ewmidQueryWrapper = new QueryWrapper<>();ewmidQueryWrapper.eq("ewmid", ewmid);int isExist = ewmService.count(ewmidQueryWrapper);if(isExist > 0) {num2 += 1;ewmid = "ewm";continue;} else {break;}}//获取服务器地址、端口、项目名HttpServletRequest httpRequest=(HttpServletRequest)request;String baseUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + httpRequest.getContextPath();//插入二维码表String ewmsj = baseUrl + "/info/product-info?ncpid=" + ncpid;Ewm ewm = new Ewm();ewm.setEwmid(ewmid);ewm.setEwmsj(ewmsj);boolean flag = ewmService.save(ewm);//如果二维码表插入成功,则插入ncp表//在插入农产品表的时候可能会出错导致插入失败,这样上面插入的二维码表字段就作废了,所以在这里catch紅酒表的错误,并把上面二维码表字段删除try {if(flag) {ncp.setEwmid(ewmid);boolean flag2 = ncpService.save(ncp);return flag2;} else {return flag;}} catch (Exception e) {ewmQueryWrapper.eq("ewmid", ewm.getEwmid());ewmService.remove(ewmQueryWrapper);e.printStackTrace();return false;}}/*** 农产品列表* @param ncp* @param page* @param limit* @return* @throws Exception*/@RequestMapping("/product/list")@ResponseBodypublic Map productList(Ncp ncp, @RequestParam int page, @RequestParam int limit) throws Exception {logger.info("/handle/product/list===> ncp={}", ncp);logger.info("page = {}", page);logger.info("limit = {}", limit);QueryWrapper<Ncp> ncpQueryWrapper = new QueryWrapper<>();//遍历ncp对象的属性Field field[] = ncp.getClass().getDeclaredFields();for(int i = 0; i < field.length; i++) {//获取属性名String name = field[i].getName();//将属性的首字符大写,方便构造get,set方法String getterName = name.substring(0,1).toUpperCase()+name.substring(1);//获取属性的类型String type = field[i].getGenericType().toString();//根据类型做操作if (type.equals("class java.lang.String")) {//获得getter方法Method m = ncp.getClass().getMethod("get" + getterName);//调用getter方法String value = (String) m.invoke(ncp);//如果非空,则加入查询条件if (value != null) {ncpQueryWrapper.eq(name, value);}}}List<Ncp> ncpList = ncpService.list(ncpQueryWrapper);logger.info("=========={}", ncpList);//查询到的总量,返回数据要用int count = ncpList.size();//list截取分页的索引int fromIndex = (page-1)*limit;int toIndex = page * limit;//截取分页数据if(page*limit > count) {toIndex = count;}ncpList = ncpList.subList(fromIndex, toIndex);Map response = new HashMap();response.put("code", 0);response.put("msg", "");response.put("count", count);response.put("data", ncpList);return response;}/*** 获取农产品表一个数据* @param ncp* @return*/@RequestMapping("/product/getone")@ResponseBodypublic Ncp productGetone(@RequestBody Ncp ncp) {logger.info("/handle/product/getone===> ncp={}", ncp);QueryWrapper<Ncp> ncpQueryWrapper = new QueryWrapper<>();ncpQueryWrapper.eq("ncpid", ncp.getNcpid());ncp = ncpService.getOne(ncpQueryWrapper);return ncp;}@RequestMapping("/product/modify")@ResponseBodypublic boolean productModify(@RequestBody Ncp ncp) {logger.info("/handle/product/modify===> ncp={}", ncp);QueryWrapper<Ncp> ncpQueryWrapper = new QueryWrapper<>();ncpQueryWrapper.eq("ncpid", ncp.getNcpid());Ncp ncpEntity = ncpService.getOne(ncpQueryWrapper);ncp.setQyid(ncpEntity.getQyid());ncp.setEwmid(ncpEntity.getEwmid());UpdateWrapper<Ncp> ncpUpdateWrapper = new UpdateWrapper<>();ncpUpdateWrapper.eq("ncpid", ncp.getNcpid());boolean flag = ncpService.update(ncp, ncpUpdateWrapper);return flag;}/*** 删除农产品* @param ncp* @return*/@RequestMapping("/product/delete")@ResponseBodypublic boolean productDelete(@RequestBody Ncp ncp) {logger.info("/handle/product/list===> ncp={}", ncp);QueryWrapper<Ncp> queryWrapper = new QueryWrapper<>();queryWrapper.eq("ncpid", ncp.getNcpid());ncp = ncpService.getOne(queryWrapper);boolean flag = ncpService.remove(queryWrapper);if(flag) {QueryWrapper<Ewm> ewmQueryWrapper = new QueryWrapper<>();ewmQueryWrapper.eq("ewmid", ncp.getEwmid());boolean flag2 = ewmService.remove(ewmQueryWrapper);return flag2;} else {return flag;}}
}

溯源管理控制器

@Controller
@RequestMapping("/handle")
public class SylyController {protected Logger logger = LoggerFactory.getLogger(this.getClass());@Autowiredprivate ISylyService sylyService;@Autowiredprivate SylyMapper sylyMapper;private static Tool tool = new Tool();/*** 溯源来源计数* @param syly* @param request* @return*/@RequestMapping("/source/count")@ResponseBodypublic boolean sourceCount(@RequestBody Syly syly, HttpServletRequest request) {logger.info("/handle/source/count===> syly={}", syly);//查询syly总数,即溯源总数QueryWrapper<Syly> countQueryWrapper = new QueryWrapper<>();countQueryWrapper.eq("syqyid", syly.getSyqyid());int count = sylyService.count(countQueryWrapper) + 1;//获取当前日期,设置溯源时间Date now = new Date();syly.setSysj(now);//设置溯源idSimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");String newNo = df.format(now);String syid = "syly-" + newNo + "-" + count;syly.setSyid(syid);//设置溯源ipString syip = request.getRemoteAddr();syly.setSyip(syip);boolean flag = sylyService.save(syly);return flag;}/*** 溯源列表* @param syly* @param page* @param limit* @return* @throws Exception*/@RequestMapping("/source/list")@ResponseBodypublic Map sourceList(Syly syly, @RequestParam int page, @RequestParam int limit) throws Exception {logger.info("/handle/source/list===> syly={}", syly);logger.info("page = {}", page);logger.info("limit = {}", limit);QueryWrapper<Syly> sylyQueryWrapper = new QueryWrapper<>();//遍历syly对象的属性Field field[] = syly.getClass().getDeclaredFields();for(int i = 0; i < field.length; i++) {//获取属性名String name = field[i].getName();//将属性的首字符大写,方便构造get,set方法String getterName = name.substring(0,1).toUpperCase()+name.substring(1);//获取属性的类型String type = field[i].getGenericType().toString();//根据类型做操作if (type.equals("class java.lang.String")) {//获得getter方法Method m = syly.getClass().getMethod("get" + getterName);//调用getter方法String value = (String) m.invoke(syly);//如果非空,则加入查询条件if (value != null) {sylyQueryWrapper.eq(name, value);}}}List<Syly> sylyList = sylyService.list(sylyQueryWrapper);logger.info("=========={}", sylyList);//查询到的总量,返回数据要用int count = sylyList.size();//list截取分页的索引int fromIndex = (page-1)*limit;int toIndex = page * limit;//截取分页数据if(page*limit > count) {toIndex = count;}sylyList = sylyList.subList(fromIndex, toIndex);Map response = new HashMap();response.put("code", 0);response.put("msg", "");response.put("count", count);response.put("data", sylyList);return response;}/*** 获取7天溯源数据* @param syly* @return*/@RequestMapping("/source/line")@ResponseBodypublic Map sourceChart(@RequestBody Syly syly) {logger.info("/handle/source/line===> syly={}", syly);//groud by 溯源时间查询listQueryWrapper<Syly> sylyQueryWrapper = new QueryWrapper<>();//map对象用来储存返回数据Map map = new HashMap();//新建sysjList和counts,用于保存时间和访问数List<String> sysjList = new ArrayList<>();List<Integer> countList = new ArrayList<>();for(int i = 6; i >= 0; i--) {//获取i天前日期对象Date date = tool.getDateBefore(new Date(), i);//溯源时间转字符串SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");String sysjString = df.format(date);//查询i天前溯源数量QueryWrapper<Syly> countQueryWrapper = new QueryWrapper<>();countQueryWrapper.eq("sysj", sysjString).eq("syqyid", syly.getSyqyid());int count = sylyService.count(countQueryWrapper);//将结果插入listcountList.add(count);sysjList.add(sysjString);}map.put("sysjList", sysjList);map.put("counts",countList);return map;}/*** 获取溯源农产品分布数据* @param syly* @return*/@RequestMapping("/source/pie")@ResponseBodypublic Map sourcePie(@RequestBody Syly syly) {logger.info("/handle/source/pie===> syly={}", syly);//获取溯源总数QueryWrapper<Syly> sylyQueryWrapper = new QueryWrapper<>();sylyQueryWrapper.eq("syqyid", syly.getSyqyid());int count = sylyService.count(sylyQueryWrapper);int alreadyGet = 0;//获取最大溯源量的4个ncpList<SylyCountNcpGroupByNcpid> dataList = sylyMapper.selectSylyCountNcpGroupByNcpid(syly.getSyqyid());//新建两个列表对象储存返回数据List<String> ncpmcList = new ArrayList<>();List<Integer> countList = new ArrayList<>();//插入查询到的数据到listfor(SylyCountNcpGroupByNcpid item : dataList) {ncpmcList.add(item.getNcpmc());countList.add(item.getCount());alreadyGet += item.getCount();}ncpmcList.add("其他");countList.add(count-alreadyGet);Map map = new HashMap();map.put("ncpmcList", ncpmcList);map.put("countList", countList);return map;}/*** 获取总溯源数* @param syly* @return*/@RequestMapping("/source/total")@ResponseBodypublic List<String> sourceTotal(@RequestBody Syly syly) {logger.info("/handle/source/total===> syly={}", syly);//获取溯源总数QueryWrapper<Syly> sylyQueryWrapper = new QueryWrapper<>();sylyQueryWrapper.eq("syqyid", syly.getSyqyid());int count = sylyService.count(sylyQueryWrapper);List<String> list = new ArrayList<>();list.add(count+"");return list;}/*** 获取当日溯源数和同比增长比例* @param syly* @return*/@RequestMapping("/source/today")@ResponseBodypublic List<String> sourceToday(@RequestBody Syly syly) {logger.info("/handle/source/today===> syly={}", syly);//获取今天日期SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");String todayString = df.format(new Date());//获取昨天日期SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");String yesterdayString = df.format(new Date(new Date().getTime()-86400000L));//查询今天总数QueryWrapper<Syly> todayQueryWrapper = new QueryWrapper<>();todayQueryWrapper.eq("syqyid", syly.getSyqyid()).eq("sysj", todayString);int todayCount = sylyService.count(todayQueryWrapper);//查询昨天总数QueryWrapper<Syly> yesterdayQueryWrapper = new QueryWrapper<>();yesterdayQueryWrapper.eq("syqyid", syly.getSyqyid()).eq("sysj", yesterdayString);int yesterdayCount = sylyService.count(yesterdayQueryWrapper);//算出同比增长比例float rise = ((float)todayCount - (float)yesterdayCount) / (float)yesterdayCount * 100;List<String> list = new ArrayList<>();list.add(todayCount+"");list.add(rise+"%");return list;}/*** 获取7天溯源人数和同比增长比例* @param syly* @return*/@RequestMapping("/source/week")@ResponseBodypublic List<String> sourceWeek(@RequestBody Syly syly) {logger.info("/handle/source/week===> syly={}", syly);//获取今天和七天前的日期SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");String dateString = df.format(new Date());String weekBeforeString = df.format(tool.getDateBefore(new Date(), 6));//查询介于两个日期之间的总数QueryWrapper<Syly> countQueryWrapper = new QueryWrapper<>();countQueryWrapper.between("sysj", weekBeforeString, dateString).eq("syqyid", syly.getSyqyid());int count = sylyService.count(countQueryWrapper);//获取上一期的两个日期String lastDateString = df.format(tool.getDateBefore(new Date(), 7));String lastWeekBeforeString = df.format(tool.getDateBefore(new Date(), 13));//同样查询两个日期之间的总数QueryWrapper<Syly> lastCountQueryWrapper = new QueryWrapper<>();lastCountQueryWrapper.between("sysj", lastWeekBeforeString, lastDateString).eq("syqyid", syly.getSyqyid());int lastCount = sylyService.count(lastCountQueryWrapper);//通过两期数据算出同比增长比例float rise = ((float)count - (float)lastCount) / (float)lastCount * 100;//返回数据List<String> list = new ArrayList<>();list.add(count+"");list.add(rise+"%");return list;}@RequestMapping("/source/month")@ResponseBodypublic List<String> sourceMonth(@RequestBody Syly syly) {logger.info("/handle/source/month===> syly={}", syly);//获取今天和30天前的日期SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");String dateString = df.format(new Date());String monthBeforeString = df.format(tool.getDateBefore(new Date(), 29));//查询介于两个日期之间的总数QueryWrapper<Syly> countQueryWrapper = new QueryWrapper<>();countQueryWrapper.between("sysj", monthBeforeString, dateString).eq("syqyid", syly.getSyqyid());int count = sylyService.count(countQueryWrapper);//获取上一期的两个日期String lastDateString = df.format(tool.getDateBefore(new Date(), 30));String lastMonthBeforeString = df.format(tool.getDateBefore(new Date(), 59));//同样查询两个日期之间的总数QueryWrapper<Syly> lastCountQueryWrapper = new QueryWrapper<>();lastCountQueryWrapper.between("sysj", lastMonthBeforeString, lastDateString).eq("syqyid", syly.getSyqyid());int lastCount = sylyService.count(lastCountQueryWrapper);//通过两期数据算出同比增长比例float rise = ((float)count - (float)lastCount) / (float)lastCount * 100;//返回数据List<String> list = new ArrayList<>();list.add(count+"");list.add(rise+"%");return list;}}

如果也想学习本系统,下面领取。关注并回复:110ssm

Java项目:SSM农产品朔源管理系统相关推荐

  1. [附源码]java毕业设计智慧农产品朔源系统

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  2. Java项目:SSM红酒朔源管理系统

    作者主页:源码空间站2022 简介:Java领域优质创作者.Java项目.学习资料.技术互助 文末获取源码 项目介绍 本项目分为前后台,分为普通用户.管理员.企业用户三种角色: 普通用户无需登录,可在 ...

  3. 基于javaweb的红酒朔源管理系统(java+ssm+jsp+layui+jquery+mysql)

    基于javaweb的红酒朔源管理系统(java+ssm+jsp+layui+jquery+mysql) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse/idea ...

  4. [附源码]SSM计算机毕业设计智慧农产品朔源系统JAVA

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  5. jsp+ssm计算机毕业设计智慧农产品朔源系统【附源码】

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  6. 基于java项目ssm二手书交易平台设计与实现(论文+程序设计源码+数据库文件)

    1 绪论 4 1.1 项目开发背景 4 1.2 项目开发意义 5 1.3 项目主要的内容 5 2 相关技术介绍及系统环境开发条件 6 2.1相关技术介绍 6 2.2系统环境开发条件 7 3 系统的需求 ...

  7. 基于ssm农产品销售网站管理系统获取(java毕业设计)

    基于ssm农产品销售网站管理系统 ssm农产品销售网站管理系统基于java编程语言,mysql数据库和ssm框架设计,本系统主要分为用户和管理员两个角色,用户注册和登陆系统,查看,搜索农产品,查询农产 ...

  8. 基于java(ssm)大学生社团管理系统源码成品(java毕业设计)

    基于java(ssm)大学生社团管理系统 大学生社团管理系统是基于java编程语言,mysql数据库,ssm框架和idea工具开发,本系统分为学生,管理员,社团负责人三个角色,学生可以注册登陆系统,查 ...

  9. [附源码]计算机毕业设计JAVAjsp智慧农产品朔源系统

    [附源码]计算机毕业设计JAVAjsp智慧农产品朔源系统 项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe( ...

最新文章

  1. 【Zookeeper】Zookeeper部署笔记
  2. jmeter发送json数据,报405、400错误解决方案
  3. MySQL如何从开源中获利
  4. 《C++标准程序库》读书笔记(三)
  5. 手机拍照显示_最值得购买的4款5G手机,每款都有一技之长,有你在用的吗?
  6. java检测tomcat宕机_Tomcat意外宕机分析
  7. hibernate正向生成数据库表以及配置——Student.hbm.xml
  8. libevent: evbuffer缓冲
  9. win2012 定时自动备份mysql_SQL SERVER 2012数据库自动备份的方法
  10. 自己动手写操作系统-经典书籍
  11. 计算机打印机图标删除吗,故障之:打印图标消失及打印任务无法取消
  12. 重庆大学计算机学院研究生奖学金评定准则,重庆大学体育学院研究生学业奖学金评定办法...
  13. python父亲节快乐_一个“MacBook”新手的Python“笨办法”自学之旅 #第七章:字符串、文本、各种打印、转义序列、手动输入raw_input()...
  14. 基于 MQTT 通讯一个简单的 Java工程
  15. 第16套题目 doc.计算机,计算机二级ms实操题excel难点汇总.doc
  16. android7 显示到pc,安卓手机上的画面怎么投屏到Win7电脑上?超详细投屏方法看这里!...
  17. 深度Linux如何安装驱动程序,在Deepin 20系统下手动安装N卡闭源驱动64-440.31.run的步骤...
  18. idea 断点线程_在IntelliJ IDEA中多线程并发代码的调试方法
  19. sublime text3 安装sublimelinter以及sublimelinter-php
  20. oracle判断if函数,ORACLE判断奇偶数函数

热门文章

  1. kubelet启动失败问题
  2. 如何看待学者用鸟屎做实验发论文,讽刺石墨烯领域论文灌水?
  3. TCP/IP三次握手与四次挥手
  4. 通过IDL编辑器实现空间直角到高斯平面坐标系的转化
  5. 更改总帐科目未清项管理
  6. 企业如何通过迁移到云平台来减少开支
  7. 7-3-1 String 学号解析7-3-2 sort 字符串排序--string类的使用
  8. 区块链-闪电网络示例
  9. 路由器/交换机工作原理(RIP/OSPF协议工作原理)
  10. Elasticsearch:使用 Elasticsearch 和 BERT 构建搜索引擎 - TensorFlow