• Java项目:SSM农产品朔源管理系统


    作者主页:夜未央5788

     简介: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

    运行截图

    普通用户界面

     

    管理员用户界面

     

     

     

     

    企业用户界面

     

     

     

     

     

     

    代码相关

    农产品管理控制器

    1. @Controller
    2. @RequestMapping("/handle")
    3. public class NcpController {
    4. protected Logger logger = LoggerFactory.getLogger(this.getClass());
    5. @Autowired
    6. private INcpService ncpService;
    7. @Autowired
    8. private IEwmService ewmService;
    9. /**
    10. * 新增农产品(生成二维码数据,插入二维码表)
    11. * @param ncp
    12. * @return
    13. */
    14. @RequestMapping("/product/add")
    15. @ResponseBody
    16. public boolean productAdd(@RequestBody Ncp ncp, HttpServletRequest request) {
    17. logger.info("/handle/product/add===> ncp={}", ncp);
    18. QueryWrapper queryWrapper = new QueryWrapper<>();
    19. //设置农产品id
    20. queryWrapper.eq("qyid", ncp.getQyid());
    21. int num = ncpService.count(queryWrapper) + 1;
    22. String ncpid = "ncp";
    23. while(ncp.getNcpid() == null) {
    24. if(num /10 == 0) {
    25. ncpid = ncpid.concat("00" + num);
    26. } else if(num / 10 >= 1 && num / 10 < 10) {
    27. ncpid = ncpid.concat("0" + num);
    28. } else {
    29. ncpid = ncpid.concat("" + num);
    30. }
    31. ncpid = ncpid.concat("-" + ncp.getQyid());
    32. //查询数据库是否存在相同的ncpid,存在则num+1,继续循环
    33. QueryWrapper ncpidQueryWrapper = new QueryWrapper<>();
    34. ncpidQueryWrapper.eq("ncpid", ncpid);
    35. int isExist = ncpService.count(ncpidQueryWrapper);
    36. if(isExist > 0) {
    37. num += 1;
    38. ncpid = "ncp";
    39. continue;
    40. } else {
    41. break;
    42. }
    43. }
    44. ncp.setNcpid(ncpid);
    45. //生成二维码id
    46. QueryWrapper ewmQueryWrapper = new QueryWrapper<>();
    47. ewmQueryWrapper.likeLeft("ewmid", ncp.getQyid());
    48. //int num2 = ewmService.count(ewmQueryWrapper) + 1;
    49. int num2 = num;
    50. String ewmid = "ewm";
    51. while(ncp.getEwmid() == null) {
    52. if(num2 /10 == 0) {
    53. ewmid = ewmid.concat("00" + num2);
    54. } else if(num2 / 10 >= 1 && num2 / 10 < 10) {
    55. ewmid = ewmid.concat("0" + num2);
    56. } else {
    57. ewmid = ewmid.concat("" + num2);
    58. }
    59. ewmid = ewmid.concat("-" + ncpid);
    60. //查询数据库是否存在相同的ewmid,存在则num+1,继续循环
    61. QueryWrapper ewmidQueryWrapper = new QueryWrapper<>();
    62. ewmidQueryWrapper.eq("ewmid", ewmid);
    63. int isExist = ewmService.count(ewmidQueryWrapper);
    64. if(isExist > 0) {
    65. num2 += 1;
    66. ewmid = "ewm";
    67. continue;
    68. } else {
    69. break;
    70. }
    71. }
    72. //获取服务器地址、端口、项目名
    73. HttpServletRequest httpRequest=(HttpServletRequest)request;
    74. String baseUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + httpRequest.getContextPath();
    75. //插入二维码表
    76. String ewmsj = baseUrl + "/info/product-info?ncpid=" + ncpid;
    77. Ewm ewm = new Ewm();
    78. ewm.setEwmid(ewmid);
    79. ewm.setEwmsj(ewmsj);
    80. boolean flag = ewmService.save(ewm);
    81. //如果二维码表插入成功,则插入ncp表
    82. //在插入农产品表的时候可能会出错导致插入失败,这样上面插入的二维码表字段就作废了,所以在这里catch紅酒表的错误,并把上面二维码表字段删除
    83. try {
    84. if(flag) {
    85. ncp.setEwmid(ewmid);
    86. boolean flag2 = ncpService.save(ncp);
    87. return flag2;
    88. } else {
    89. return flag;
    90. }
    91. } catch (Exception e) {
    92. ewmQueryWrapper.eq("ewmid", ewm.getEwmid());
    93. ewmService.remove(ewmQueryWrapper);
    94. e.printStackTrace();
    95. return false;
    96. }
    97. }
    98. /**
    99. * 农产品列表
    100. * @param ncp
    101. * @param page
    102. * @param limit
    103. * @return
    104. * @throws Exception
    105. */
    106. @RequestMapping("/product/list")
    107. @ResponseBody
    108. public Map productList(Ncp ncp, @RequestParam int page, @RequestParam int limit) throws Exception {
    109. logger.info("/handle/product/list===> ncp={}", ncp);
    110. logger.info("page = {}", page);
    111. logger.info("limit = {}", limit);
    112. QueryWrapper ncpQueryWrapper = new QueryWrapper<>();
    113. //遍历ncp对象的属性
    114. Field field[] = ncp.getClass().getDeclaredFields();
    115. for(int i = 0; i < field.length; i++) {
    116. //获取属性名
    117. String name = field[i].getName();
    118. //将属性的首字符大写,方便构造get,set方法
    119. String getterName = name.substring(0,1).toUpperCase()+name.substring(1);
    120. //获取属性的类型
    121. String type = field[i].getGenericType().toString();
    122. //根据类型做操作
    123. if (type.equals("class java.lang.String")) {
    124. //获得getter方法
    125. Method m = ncp.getClass().getMethod("get" + getterName);
    126. //调用getter方法
    127. String value = (String) m.invoke(ncp);
    128. //如果非空,则加入查询条件
    129. if (value != null) {
    130. ncpQueryWrapper.eq(name, value);
    131. }
    132. }
    133. }
    134. List ncpList = ncpService.list(ncpQueryWrapper);
    135. logger.info("=========={}", ncpList);
    136. //查询到的总量,返回数据要用
    137. int count = ncpList.size();
    138. //list截取分页的索引
    139. int fromIndex = (page-1)*limit;
    140. int toIndex = page * limit;
    141. //截取分页数据
    142. if(page*limit > count) {
    143. toIndex = count;
    144. }
    145. ncpList = ncpList.subList(fromIndex, toIndex);
    146. Map response = new HashMap();
    147. response.put("code", 0);
    148. response.put("msg", "");
    149. response.put("count", count);
    150. response.put("data", ncpList);
    151. return response;
    152. }
    153. /**
    154. * 获取农产品表一个数据
    155. * @param ncp
    156. * @return
    157. */
    158. @RequestMapping("/product/getone")
    159. @ResponseBody
    160. public Ncp productGetone(@RequestBody Ncp ncp) {
    161. logger.info("/handle/product/getone===> ncp={}", ncp);
    162. QueryWrapper ncpQueryWrapper = new QueryWrapper<>();
    163. ncpQueryWrapper.eq("ncpid", ncp.getNcpid());
    164. ncp = ncpService.getOne(ncpQueryWrapper);
    165. return ncp;
    166. }
    167. @RequestMapping("/product/modify")
    168. @ResponseBody
    169. public boolean productModify(@RequestBody Ncp ncp) {
    170. logger.info("/handle/product/modify===> ncp={}", ncp);
    171. QueryWrapper ncpQueryWrapper = new QueryWrapper<>();
    172. ncpQueryWrapper.eq("ncpid", ncp.getNcpid());
    173. Ncp ncpEntity = ncpService.getOne(ncpQueryWrapper);
    174. ncp.setQyid(ncpEntity.getQyid());
    175. ncp.setEwmid(ncpEntity.getEwmid());
    176. UpdateWrapper ncpUpdateWrapper = new UpdateWrapper<>();
    177. ncpUpdateWrapper.eq("ncpid", ncp.getNcpid());
    178. boolean flag = ncpService.update(ncp, ncpUpdateWrapper);
    179. return flag;
    180. }
    181. /**
    182. * 删除农产品
    183. * @param ncp
    184. * @return
    185. */
    186. @RequestMapping("/product/delete")
    187. @ResponseBody
    188. public boolean productDelete(@RequestBody Ncp ncp) {
    189. logger.info("/handle/product/list===> ncp={}", ncp);
    190. QueryWrapper queryWrapper = new QueryWrapper<>();
    191. queryWrapper.eq("ncpid", ncp.getNcpid());
    192. ncp = ncpService.getOne(queryWrapper);
    193. boolean flag = ncpService.remove(queryWrapper);
    194. if(flag) {
    195. QueryWrapper ewmQueryWrapper = new QueryWrapper<>();
    196. ewmQueryWrapper.eq("ewmid", ncp.getEwmid());
    197. boolean flag2 = ewmService.remove(ewmQueryWrapper);
    198. return flag2;
    199. } else {
    200. return flag;
    201. }
    202. }
    203. }

     溯源管理控制器

    1. @Controller
    2. @RequestMapping("/handle")
    3. public class SylyController {
    4. protected Logger logger = LoggerFactory.getLogger(this.getClass());
    5. @Autowired
    6. private ISylyService sylyService;
    7. @Autowired
    8. private SylyMapper sylyMapper;
    9. private static Tool tool = new Tool();
    10. /**
    11. * 溯源来源计数
    12. * @param syly
    13. * @param request
    14. * @return
    15. */
    16. @RequestMapping("/source/count")
    17. @ResponseBody
    18. public boolean sourceCount(@RequestBody Syly syly, HttpServletRequest request) {
    19. logger.info("/handle/source/count===> syly={}", syly);
    20. //查询syly总数,即溯源总数
    21. QueryWrapper countQueryWrapper = new QueryWrapper<>();
    22. countQueryWrapper.eq("syqyid", syly.getSyqyid());
    23. int count = sylyService.count(countQueryWrapper) + 1;
    24. //获取当前日期,设置溯源时间
    25. Date now = new Date();
    26. syly.setSysj(now);
    27. //设置溯源id
    28. SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    29. String newNo = df.format(now);
    30. String syid = "syly-" + newNo + "-" + count;
    31. syly.setSyid(syid);
    32. //设置溯源ip
    33. String syip = request.getRemoteAddr();
    34. syly.setSyip(syip);
    35. boolean flag = sylyService.save(syly);
    36. return flag;
    37. }
    38. /**
    39. * 溯源列表
    40. * @param syly
    41. * @param page
    42. * @param limit
    43. * @return
    44. * @throws Exception
    45. */
    46. @RequestMapping("/source/list")
    47. @ResponseBody
    48. public Map sourceList(Syly syly, @RequestParam int page, @RequestParam int limit) throws Exception {
    49. logger.info("/handle/source/list===> syly={}", syly);
    50. logger.info("page = {}", page);
    51. logger.info("limit = {}", limit);
    52. QueryWrapper sylyQueryWrapper = new QueryWrapper<>();
    53. //遍历syly对象的属性
    54. Field field[] = syly.getClass().getDeclaredFields();
    55. for(int i = 0; i < field.length; i++) {
    56. //获取属性名
    57. String name = field[i].getName();
    58. //将属性的首字符大写,方便构造get,set方法
    59. String getterName = name.substring(0,1).toUpperCase()+name.substring(1);
    60. //获取属性的类型
    61. String type = field[i].getGenericType().toString();
    62. //根据类型做操作
    63. if (type.equals("class java.lang.String")) {
    64. //获得getter方法
    65. Method m = syly.getClass().getMethod("get" + getterName);
    66. //调用getter方法
    67. String value = (String) m.invoke(syly);
    68. //如果非空,则加入查询条件
    69. if (value != null) {
    70. sylyQueryWrapper.eq(name, value);
    71. }
    72. }
    73. }
    74. List sylyList = sylyService.list(sylyQueryWrapper);
    75. logger.info("=========={}", sylyList);
    76. //查询到的总量,返回数据要用
    77. int count = sylyList.size();
    78. //list截取分页的索引
    79. int fromIndex = (page-1)*limit;
    80. int toIndex = page * limit;
    81. //截取分页数据
    82. if(page*limit > count) {
    83. toIndex = count;
    84. }
    85. sylyList = sylyList.subList(fromIndex, toIndex);
    86. Map response = new HashMap();
    87. response.put("code", 0);
    88. response.put("msg", "");
    89. response.put("count", count);
    90. response.put("data", sylyList);
    91. return response;
    92. }
    93. /**
    94. * 获取7天溯源数据
    95. * @param syly
    96. * @return
    97. */
    98. @RequestMapping("/source/line")
    99. @ResponseBody
    100. public Map sourceChart(@RequestBody Syly syly) {
    101. logger.info("/handle/source/line===> syly={}", syly);
    102. //groud by 溯源时间查询list
    103. QueryWrapper sylyQueryWrapper = new QueryWrapper<>();
    104. //map对象用来储存返回数据
    105. Map map = new HashMap();
    106. //新建sysjList和counts,用于保存时间和访问数
    107. List sysjList = new ArrayList<>();
    108. List countList = new ArrayList<>();
    109. for(int i = 6; i >= 0; i--) {
    110. //获取i天前日期对象
    111. Date date = tool.getDateBefore(new Date(), i);
    112. //溯源时间转字符串
    113. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    114. String sysjString = df.format(date);
    115. //查询i天前溯源数量
    116. QueryWrapper countQueryWrapper = new QueryWrapper<>();
    117. countQueryWrapper.eq("sysj", sysjString).eq("syqyid", syly.getSyqyid());
    118. int count = sylyService.count(countQueryWrapper);
    119. //将结果插入list
    120. countList.add(count);
    121. sysjList.add(sysjString);
    122. }
    123. map.put("sysjList", sysjList);
    124. map.put("counts",countList);
    125. return map;
    126. }
    127. /**
    128. * 获取溯源农产品分布数据
    129. * @param syly
    130. * @return
    131. */
    132. @RequestMapping("/source/pie")
    133. @ResponseBody
    134. public Map sourcePie(@RequestBody Syly syly) {
    135. logger.info("/handle/source/pie===> syly={}", syly);
    136. //获取溯源总数
    137. QueryWrapper sylyQueryWrapper = new QueryWrapper<>();
    138. sylyQueryWrapper.eq("syqyid", syly.getSyqyid());
    139. int count = sylyService.count(sylyQueryWrapper);
    140. int alreadyGet = 0;
    141. //获取最大溯源量的4个ncp
    142. List dataList = sylyMapper.selectSylyCountNcpGroupByNcpid(syly.getSyqyid());
    143. //新建两个列表对象储存返回数据
    144. List ncpmcList = new ArrayList<>();
    145. List countList = new ArrayList<>();
    146. //插入查询到的数据到list
    147. for(SylyCountNcpGroupByNcpid item : dataList) {
    148. ncpmcList.add(item.getNcpmc());
    149. countList.add(item.getCount());
    150. alreadyGet += item.getCount();
    151. }
    152. ncpmcList.add("其他");
    153. countList.add(count-alreadyGet);
    154. Map map = new HashMap();
    155. map.put("ncpmcList", ncpmcList);
    156. map.put("countList", countList);
    157. return map;
    158. }
    159. /**
    160. * 获取总溯源数
    161. * @param syly
    162. * @return
    163. */
    164. @RequestMapping("/source/total")
    165. @ResponseBody
    166. public List sourceTotal(@RequestBody Syly syly) {
    167. logger.info("/handle/source/total===> syly={}", syly);
    168. //获取溯源总数
    169. QueryWrapper sylyQueryWrapper = new QueryWrapper<>();
    170. sylyQueryWrapper.eq("syqyid", syly.getSyqyid());
    171. int count = sylyService.count(sylyQueryWrapper);
    172. List list = new ArrayList<>();
    173. list.add(count+"");
    174. return list;
    175. }
    176. /**
    177. * 获取当日溯源数和同比增长比例
    178. * @param syly
    179. * @return
    180. */
    181. @RequestMapping("/source/today")
    182. @ResponseBody
    183. public List sourceToday(@RequestBody Syly syly) {
    184. logger.info("/handle/source/today===> syly={}", syly);
    185. //获取今天日期
    186. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    187. String todayString = df.format(new Date());
    188. //获取昨天日期
    189. SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
    190. String yesterdayString = df.format(new Date(new Date().getTime()-86400000L));
    191. //查询今天总数
    192. QueryWrapper todayQueryWrapper = new QueryWrapper<>();
    193. todayQueryWrapper.eq("syqyid", syly.getSyqyid()).eq("sysj", todayString);
    194. int todayCount = sylyService.count(todayQueryWrapper);
    195. //查询昨天总数
    196. QueryWrapper yesterdayQueryWrapper = new QueryWrapper<>();
    197. yesterdayQueryWrapper.eq("syqyid", syly.getSyqyid()).eq("sysj", yesterdayString);
    198. int yesterdayCount = sylyService.count(yesterdayQueryWrapper);
    199. //算出同比增长比例
    200. float rise = ((float)todayCount - (float)yesterdayCount) / (float)yesterdayCount * 100;
    201. List list = new ArrayList<>();
    202. list.add(todayCount+"");
    203. list.add(rise+"%");
    204. return list;
    205. }
    206. /**
    207. * 获取7天溯源人数和同比增长比例
    208. * @param syly
    209. * @return
    210. */
    211. @RequestMapping("/source/week")
    212. @ResponseBody
    213. public List sourceWeek(@RequestBody Syly syly) {
    214. logger.info("/handle/source/week===> syly={}", syly);
    215. //获取今天和七天前的日期
    216. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    217. String dateString = df.format(new Date());
    218. String weekBeforeString = df.format(tool.getDateBefore(new Date(), 6));
    219. //查询介于两个日期之间的总数
    220. QueryWrapper countQueryWrapper = new QueryWrapper<>();
    221. countQueryWrapper.between("sysj", weekBeforeString, dateString).eq("syqyid", syly.getSyqyid());
    222. int count = sylyService.count(countQueryWrapper);
    223. //获取上一期的两个日期
    224. String lastDateString = df.format(tool.getDateBefore(new Date(), 7));
    225. String lastWeekBeforeString = df.format(tool.getDateBefore(new Date(), 13));
    226. //同样查询两个日期之间的总数
    227. QueryWrapper lastCountQueryWrapper = new QueryWrapper<>();
    228. lastCountQueryWrapper.between("sysj", lastWeekBeforeString, lastDateString).eq("syqyid", syly.getSyqyid());
    229. int lastCount = sylyService.count(lastCountQueryWrapper);
    230. //通过两期数据算出同比增长比例
    231. float rise = ((float)count - (float)lastCount) / (float)lastCount * 100;
    232. //返回数据
    233. List list = new ArrayList<>();
    234. list.add(count+"");
    235. list.add(rise+"%");
    236. return list;
    237. }
    238. @RequestMapping("/source/month")
    239. @ResponseBody
    240. public List sourceMonth(@RequestBody Syly syly) {
    241. logger.info("/handle/source/month===> syly={}", syly);
    242. //获取今天和30天前的日期
    243. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    244. String dateString = df.format(new Date());
    245. String monthBeforeString = df.format(tool.getDateBefore(new Date(), 29));
    246. //查询介于两个日期之间的总数
    247. QueryWrapper countQueryWrapper = new QueryWrapper<>();
    248. countQueryWrapper.between("sysj", monthBeforeString, dateString).eq("syqyid", syly.getSyqyid());
    249. int count = sylyService.count(countQueryWrapper);
    250. //获取上一期的两个日期
    251. String lastDateString = df.format(tool.getDateBefore(new Date(), 30));
    252. String lastMonthBeforeString = df.format(tool.getDateBefore(new Date(), 59));
    253. //同样查询两个日期之间的总数
    254. QueryWrapper lastCountQueryWrapper = new QueryWrapper<>();
    255. lastCountQueryWrapper.between("sysj", lastMonthBeforeString, lastDateString).eq("syqyid", syly.getSyqyid());
    256. int lastCount = sylyService.count(lastCountQueryWrapper);
    257. //通过两期数据算出同比增长比例
    258. float rise = ((float)count - (float)lastCount) / (float)lastCount * 100;
    259. //返回数据
    260. List list = new ArrayList<>();
    261. list.add(count+"");
    262. list.add(rise+"%");
    263. return list;
    264. }
    265. }

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

  • 相关阅读:
    2023CCPC重庆经验小结
    【JVM】JVM的垃圾回收机制与垃圾回收器的选择
    Spark之UDF失效
    10道高频Vuex面试题快问快答
    10月最新外贸进出口情况,外贸整体向好
    x86: perf_events内核初始化
    解决Windows 10更新安装失败的问题
    asp毕业设计——基于asp+sqlserver的工艺品销售系统设计与实现(毕业论文+程序源码)——工艺品销售系统
    2023-9-8 求组合数(二)
    How to install mongodb 7.0 to Ubuntu 22.04
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126613539