基于javaweb+mysql的ssm+maven农产品溯源管理系统(java+ssm+jsp+layui+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的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项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+LayUI+jQuery
使用说明
- 使用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
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")
@ResponseBody
public 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;
}
}
}
package com.suzhuoke.ncpsy.controller;
public Map qyList(@RequestParam int page, @RequestParam int limit) throws Exception {
List<Qy> dataList = qyService.list(null);
logger.info("=========={}", dataList);
// 查询到的总量,返回数据要用
int count = dataList.size();
// list截取分页的索引
int fromIndex = (page - 1) * limit;
int toIndex = page * limit;
// 截取分页数据
if (page * limit > count) {
toIndex = count;
}
dataList = dataList.subList(fromIndex, toIndex);
Map response = new HashMap();
response.put("code", 0);
response.put("msg", "");
response.put("count", count);
response.put("data", dataList);
return response;
}
/**
* 删除企业
*
* @param qy
* @return
*/
@RequestMapping("/user/delete")
@ResponseBody
public boolean qyDelete(@RequestBody Qy qy) {
logger.info("/handle/user/delete===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
return qyService.remove(queryWrapper);
}
/**
* 修改企业信息
* @param qy
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
* @return
*/
@RequestMapping("/source/total")
@ResponseBody
public 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")
@ResponseBody
public 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);
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;
}
/**
@Autowired
private SylyMapper sylyMapper;
private static Tool tool = new Tool();
/**
* 溯源来源计数
* @param syly
* @param request
* @return
*/
@RequestMapping("/source/count")
@ResponseBody
public 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);
//设置溯源id
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newNo = df.format(now);
String syid = "syly-" + newNo + "-" + count;
syly.setSyid(syid);
//设置溯源ip
String syip = request.getRemoteAddr();
syly.setSyip(syip);
boolean flag = sylyService.save(syly);
return flag;
}
/**
* 溯源列表
* @param syly
* </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;
}
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;
}
}
package com.suzhuoke.ncpsy.controller;
@RequestMapping("/user/get")
@ResponseBody
public Qy get(@RequestBody Qy qy) {
logger.info("/handle/user/get===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
qy = qyService.getOne(queryWrapper);
return qy;
}
/**
* 查询企业列表
* @param page
* @param limit
* @return
* @throws Exception
*/
@RequestMapping("/user/getlist")
@ResponseBody
public Map qyList(@RequestParam int page, @RequestParam int limit) throws Exception {
List<Qy> dataList = qyService.list(null);
logger.info("=========={}", dataList);
// 查询到的总量,返回数据要用
int count = dataList.size();
// list截取分页的索引
int fromIndex = (page - 1) * limit;
int toIndex = page * limit;
// 截取分页数据
if (page * limit > count) {
toIndex = count;
}
dataList = dataList.subList(fromIndex, toIndex);
Map response = new HashMap();
response.put("code", 0);
response.put("msg", "");
response.put("count", count);
response.put("data", dataList);
return response;
}
/**
* 删除企业
*
}
}
// 将企业信息保存到数据库
qy.setQyid(qyid);
boolean flag = qyService.save(qy);
return flag;
}
/**
* 登录
*
* @param qy
* @return
*/
@RequestMapping("/login")
@ResponseBody
public Qy login(@RequestBody Qy qy) {
logger.info("/handle/login===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("zh", qy.getZh()).eq("mm", qy.getMm());
Qy qyEntity = qyService.getOne(queryWrapper);
return qyEntity;
}
@RequestMapping("/user/get")
@ResponseBody
public Qy get(@RequestBody Qy qy) {
logger.info("/handle/user/get===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
qy = qyService.getOne(queryWrapper);
return qy;
}
/**
* 查询企业列表
* @param page
* @param limit
* @return
* @throws Exception
*/
@RequestMapping("/user/getlist")
@RequestMapping("/admin/login")
@ResponseBody
public Cjgly adminLogin(@RequestBody Cjgly cjgly) {
logger.info("/handle/admin/login===> cjgly={}", cjgly);
QueryWrapper<Cjgly> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("zh", cjgly.getZh()).eq("mm", cjgly.getMm());
Cjgly cjglyEntity = cjglyService.getOne(queryWrapper);
return cjglyEntity;
}
/**
* 删除超级管理员
*
* @param cjgly
* @return
*/
@RequestMapping("/admin/delete")
@ResponseBody
public boolean adminDelete(@RequestBody Cjgly cjgly) {
logger.info("/handle/admin/delete===> cjgly={}", cjgly);
QueryWrapper<Cjgly> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", cjgly.getId());
return cjglyService.remove(queryWrapper);
}
/**
* 删除超级管理员
*
* @param cjgly
* @return
*/
@RequestMapping("/admin/select")
@ResponseBody
public boolean adminSelect(@RequestBody Cjgly cjgly) {
logger.info("/handle/admin/delete===> cjgly={}", cjgly);
QueryWrapper<Cjgly> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", cjgly.getId());
return cjglyService.remove(queryWrapper);
public String register(Model model) {
logger.info("访问user/register页面");
return "user/register";
}
@RequestMapping("/home")
public String home(Model model) {
logger.info("访问user/home页面");
return "user/home";
}
@RequestMapping("/setting")
public String setting(Model model) {
logger.info("访问user/setting页面");
return "user/setting";
}
@RequestMapping("/user/index")
public String userIndex(Model model) {
logger.info("访问user/index");
return "user/index";
}
@RequestMapping("/product/list")
public String productList(Model model) {
logger.info("访问product/list页面");
return "product/list";
}
@RequestMapping("/product/add")
public String productAdd(Model model) {
logger.info("访问product/add页面");
return "product/add";
}
@RequestMapping("/product/modify")
public String productModify(Model model) {
logger.info("访问product/modify页面");
return "product/modify";
}
@RequestMapping("/product/info")
// 查询到的总量,返回数据要用
int count = dataList.size();
// list截取分页的索引
int fromIndex = (page - 1) * limit;
int toIndex = page * limit;
// 截取分页数据
if (page * limit > count) {
toIndex = count;
}
dataList = dataList.subList(fromIndex, toIndex);
Map response = new HashMap();
response.put("code", 0);
response.put("msg", "");
response.put("count", count);
response.put("data", dataList);
return response;
}
/**
* 删除企业
*
* @param qy
* @return
*/
@RequestMapping("/user/delete")
@ResponseBody
public boolean qyDelete(@RequestBody Qy qy) {
logger.info("/handle/user/delete===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
return qyService.remove(queryWrapper);
}
/**
* 修改企业信息
* @param qy
* @return
*/
@RequestMapping("/user/stqy")
@ResponseBody
public boolean qy_modifiy(@RequestBody Qy qy) {
logger.info("/handle/user/stqy===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
@RequestMapping("/user/delete")
@ResponseBody
public boolean qyDelete(@RequestBody Qy qy) {
logger.info("/handle/user/delete===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
return qyService.remove(queryWrapper);
}
/**
* 修改企业信息
* @param qy
* @return
*/
@RequestMapping("/user/stqy")
@ResponseBody
public boolean qy_modifiy(@RequestBody Qy qy) {
logger.info("/handle/user/stqy===> Qy={}", qy);
QueryWrapper<Qy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("qyid", qy.getQyid());
return qyService.update(qy, queryWrapper);
}
}
package com.suzhuoke.ncpsy.controller;
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
* @return
*/
@RequestMapping("/source/total")
@ResponseBody
public 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")
@ResponseBody
public List<String> sourceToday(@RequestBody Syly syly) {
logger.info("/handle/source/today===> syly={}", syly);
//获取今天日期
@Controller
public class ViewsController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/")
public String index(Model model) {
logger.info("访问index页面");
return "index";
}
@RequestMapping("/index")
public String index2(Model model) {
logger.info("访问index页面");
return "index";
}
@RequestMapping("/login")
public String login(Model model) {
logger.info("访问user/login页面");
return "user/login";
}
@RequestMapping("/register")
public String register(Model model) {
logger.info("访问user/register页面");
return "user/register";
}
@RequestMapping("/home")
public String home(Model model) {
logger.info("访问user/home页面");
return "user/home";
}
@RequestMapping("/setting")
public String setting(Model model) {
logger.info("访问user/setting页面");
return "user/setting";
}
@RequestMapping("/user/index")
public String userIndex(Model model) {
logger.info("访问user/index");
return "user/index";
}
@RequestMapping("/product/list")
public String productList(Model model) {
return flag2;
} else {
return flag;
}
}
}
package com.suzhuoke.ncpsy.controller;
/**
* <p>
* 前端控制器
* </p>
*
*/
@Controller
@RequestMapping("/handle")
public class QyController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private IQyService qyService;
/**
* 注册
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")
@ResponseBody
public 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("/product/list")
public String productList(Model model) {
logger.info("访问product/list页面");
return "product/list";
}
@RequestMapping("/product/add")
public String productAdd(Model model) {
logger.info("访问product/add页面");
return "product/add";
}
@RequestMapping("/product/modify")
public String productModify(Model model) {
logger.info("访问product/modify页面");
return "product/modify";
}
@RequestMapping("/product/info")
public String productDelete(Model model) {
logger.info("访问product/info页面");
return "product/info";
}
@RequestMapping("/qrcode/list")
public String qrcodeList(Model model) {
logger.info("访问qrcode/list页面");
return "qrcode/list";
}
@RequestMapping("/qrcode/info")
public String qrcodeInfo(Model model) {
logger.info("访问qrcode/info页面");
return "qrcode/info";
}
@RequestMapping("/source/list")
public String sourceList(Model model) {
logger.info("访问source/list页面");
* 获取总溯源数
* @param syly
* @return
*/
@RequestMapping("/source/total")
@ResponseBody
public 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")
@ResponseBody
public 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;
}
/**
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
* @return
*/
@RequestMapping("/source/total")
@ResponseBody
public 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;
}
/**
qy = qyService.getOne(queryWrapper);
return qy;
}
/**
* 查询企业列表
* @param page
* @param limit
* @return
* @throws Exception
*/
@RequestMapping("/user/getlist")
@ResponseBody
public Map qyList(@RequestParam int page, @RequestParam int limit) throws Exception {
List<Qy> dataList = qyService.list(null);
logger.info("=========={}", dataList);
// 查询到的总量,返回数据要用
int count = dataList.size();
// list截取分页的索引
int fromIndex = (page - 1) * limit;
int toIndex = page * limit;
// 截取分页数据
if (page * limit > count) {
toIndex = count;
}
dataList = dataList.subList(fromIndex, toIndex);
Map response = new HashMap();
response.put("code", 0);
response.put("msg", "");
response.put("count", count);
response.put("data", dataList);
return response;
}
/**
* 删除企业
*
* @param qy
* @return
*/
@RequestMapping("/user/delete")
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
* @return
*/
@RequestMapping("/source/total")
@ResponseBody
public 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")
@ResponseBody
public 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());
return response;
}
}
package com.suzhuoke.ncpsy.controller;
/**
* <p>
* 页面控制器
* </p>
*
*/
@Controller
public class ViewsController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/")
public String index(Model model) {
logger.info("访问index页面");
return "index";
}
@RequestMapping("/index")
public String index2(Model model) {
logger.info("访问index页面");
return "index";
}
@RequestMapping("/login")
public String login(Model model) {
logger.info("访问user/login页面");
return "user/login";
}
@RequestMapping("/register")
public String register(Model model) {
logger.info("访问user/register页面");
return "user/register";
list.add(rise+"%");
return list;
}
@RequestMapping("/source/month")
@ResponseBody
public 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;
}
}
package com.suzhuoke.ncpsy.controller;
//如果二维码表插入成功,则插入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")
@ResponseBody
public 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();
@RequestMapping("/admin/select")
@ResponseBody
public boolean adminSelect(@RequestBody Cjgly cjgly) {
logger.info("/handle/admin/delete===> cjgly={}", cjgly);
QueryWrapper<Cjgly> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", cjgly.getId());
return cjglyService.remove(queryWrapper);
}
@RequestMapping("/admin/add")
@ResponseBody
public boolean adminAdd(@RequestBody Cjgly cjgly) {
logger.info("/handle/admin/add===> cjgly={}", cjgly);
// QueryWrapper<Cjgly> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("id",cjgly.getId());
if (cjgly.getId() == null || "".equals(cjgly.getId()) || cjgly.getMc() == null || "".equals(cjgly.getMc())
|| cjgly.getMm() == null || "".equals(cjgly.getMm()) || cjgly.getZh() == null
|| "".equals(cjgly.getZh())) {
return false;
}
return cjglyService.save(cjgly);
}
/**
* 查询超级管理员列表
*
* @param page
* @param limit
* @return
* @throws Exception
*/
@RequestMapping("/admin/list")
@ResponseBody
public Map adminList(@RequestParam int page, @RequestParam int limit) throws Exception {
// QueryWrapper<Cjgly> ncpQueryWrapper = new QueryWrapper<>();
List<Cjgly> dataList = cjglyService.list(null);
logger.info("=========={}", dataList);
// 查询到的总量,返回数据要用
int count = dataList.size();
// list截取分页的索引
int fromIndex = (page - 1) * limit;
int toIndex = page * limit;
// 截取分页数据
if (page * limit > count) {
toIndex = count;
}
dataList = dataList.subList(fromIndex, toIndex);
Map response = new HashMap();
response.put("code", 0);
response.put("msg", "");
response.put("count", count);
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")
@ResponseBody
public Map sourceChart(@RequestBody Syly syly) {
logger.info("/handle/source/line===> syly={}", syly);
//groud by 溯源时间查询list
QueryWrapper<Syly> sylyQueryWrapper = new QueryWrapper<>();
//map对象用来储存返回数据
Map map = new HashMap();
//新建sysjList和counts,用于保存时间和访问数