基于javaweb的SSM+Maven农产品溯源管理系统(java+ssm+jsp+layui+jquery+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

502123490307

110023162402

120023162402

130023162402

140023162402

150023162402

160023162402

150023162403

160023162404

基于javaweb的SSM+Maven农产品溯源管理系统(java+ssm+jsp+layui+jquery+mysql)

项目介绍

本项目分为前后台,分为普通用户、管理员、企业用户三种角色; 普通用户无需登录,可在前台直接进行溯源查询,管理员、企业用户可登录后台进行管理; 超级管理员角色包含以下功能: 登录,管理企业,设置管理员,增加管理员,删除管理员等功能。 用户角色包含以下功能: 用户首页,用户进行溯源查询,溯源结果等功能。 企业角色包含以下功能: 注册,登录,企业登录后主页,增删改查农产品列表,新增农产品,二维码列表查看,溯源列表,查看近期溯源人数,修改企业信息,查看溯源二维码等功能。

环境需要

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	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")
@ResponseBody
public 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;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
		//查询i天前溯源数量
QueryWrapper<Syly> countQueryWrapper = new QueryWrapper<>();
countQueryWrapper.eq("sysj", sysjString).eq("syqyid", syly.getSyqyid());
int count = sylyService.count(countQueryWrapper);
//将结果插入list
countList.add(count);
sysjList.add(sysjString);
}
map.put("sysjList", sysjList);
map.put("counts",countList);
return map;
}

/**
* 获取溯源农产品分布数据
* @param syly
* @return
*/
@RequestMapping("/source/pie")
@ResponseBody
public 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个ncp
List<SylyCountNcpGroupByNcpid> dataList = sylyMapper.selectSylyCountNcpGroupByNcpid(syly.getSyqyid());
//新建两个列表对象储存返回数据
List<String> ncpmcList = new ArrayList<>();
List<Integer> countList = new ArrayList<>();
//插入查询到的数据到list
for(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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	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 ewmsj = baseUrl+ httpRequest.getContextPath() + "/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;
}
}

/**
* 农产品列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 * 前端控制器
* </p>
*
*/
@Controller
@RequestMapping("/handle")
public class QyController {

protected Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private IQyService qyService;

/**
* 注册
*
* @param qy
* @return
*/
@RequestMapping("/register")
@ResponseBody
public boolean register(@RequestBody Qy qy) {
logger.info("/handle/register===> Qy={}", qy);
// 获取企业表里企业数量,+1
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
int num = qyService.count(queryWrapper) + 1;
// 拼接企业id("qy" + 0的个数 + num)
String qyid = "qy";
while(true) {
if (num / 10 == 0) {
qyid = qyid.concat("00" + num);
} else if (num / 10 >= 1 && num / 10 < 10) {
qyid = qyid.concat("0" + num);
} else {
qyid = qyid.concat("" + num);
}
QueryWrapper<Qy> qyQueryWrapper = new QueryWrapper<>();
qyQueryWrapper.eq("qyid", qyid);
int isExist = qyService.count(qyQueryWrapper);
if(isExist > 0) {
num += 1;
qyid = "qy";
continue;
} else {
break;
}
}
// 将企业信息保存到数据库
qy.setQyid(qyid);
boolean flag = qyService.save(qy);
return flag;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36



/**
* <p>
* 前端控制器
* </p>
*
*/
@Controller
@RequestMapping("/handle")
public class EwmController {

protected Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private IEwmService ewmService;

@Autowired
private EwmMapper ewmMapper;

@RequestMapping("/qrcode/list")
@ResponseBody
public Map qrcodeList(Ncp ncp, @RequestParam int page, @RequestParam int limit) throws Exception {
logger.info("/handle/qrcode/list===> ncp={}", ncp);
QueryWrapper<Ncp> ncpQueryWrapper = new QueryWrapper<>();
List<EwmNcpVo> dataList = ewmMapper.selectEwmNcpList(ncp.getQyid());
logger.info("=========={}", dataList);
//查询到的总量,返回数据要用
int count = dataList.size();
//list截取分页的索引
int fromIndex = (page-1)*limit;
int toIndex = page * limit;
//截取分页数据
if(page*limit > count) {
toIndex = count;


项目链接:
https://javayms.github.io?id=262322092805200me
https://javayms.pages.dev?id=262322092805200me