本文主要是介绍【计算机毕业设计】乐享田园系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Java SpringBoot乐享田园系统
项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Springboot + mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
环境需要
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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后端:Springboot mybatis
前端:vue+css+javascript+jQuery+easyUI+highcharts
使用说明
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3.管理员账号:abo 密码:abo
4.开发环境为Eclipse/idea,数据库为mysql 使用java语言开发。
5.运行SpringbootSchemaApplication.java 即可打开首页
6.数据库连接src\main\resources\application.yml中修改
7.maven包版本apache-maven-3.3.9.
8.后台路径地址:localhost:8080/项目名称/admin
Java SpringBoot乐享田园系统,基于SpringBoot框架进行开发,前端页面效果通过使用Vue进行编码实现,实现了用户、农民跟管理员这三类用户角色,实现了用户管理、基础数据管理等功能。
# Tomcat
server:tomcat:uri-encoding: UTF-8port: 8080servlet:context-path: /lexiangtianyuanspring:datasource:driverClassName: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/lexiangtianyuan?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8username: rootpassword: rootservlet:multipart:max-file-size: 1000MBmax-request-size: 1000MBresources:static-locations: classpath:static/,file:static/#mybatis
mybatis-plus:mapper-locations: classpath*:mapper/*.xml#实体扫描,多个package用逗号或者分号分隔typeAliasesPackage: com.entityglobal-config:#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";id-type: 1#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"field-strategy: 2#驼峰下划线转换db-column-underline: true#刷新mapper 调试神器refresh-mapper: true#逻辑删除配置logic-delete-value: -1logic-not-delete-value: 0#自定义SQL注入器sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjectorconfiguration:map-underscore-to-camel-case: truecache-enabled: falsecall-setters-on-nulls: true#springboot 项目mybatis plus 设置 jdbcTypeForNull (oracle数据库需配置JdbcType.NULL, 默认是Other)jdbc-type-for-null: 'null'#打印sql语句
logging:level:com.dao: debug
// var webpack = require('webpack');
const path = require('path')
function resolve(dir) {return path.join(__dirname, dir)
}
function publicPath(){if (process.env.NODE_ENV == 'production') {return "././";} else {return "/";}
}
// vue.config.js
module.exports = {// publicPath:"././",publicPath: publicPath(),// 国际化配置 使用其它语言,默认情况下中文语言包依旧是被引入的configureWebpack: {// plugins: [// new webpack.NormalModuleReplacementPlugin(/element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/, 'element-ui/lib/locale/lang/en')// ]devtool: 'source-map',resolve: {alias: {'@': resolve('src')}}},
lintOnSave: false,devServer: {host: "0.0.0.0", //指定使用一个 host。默认是 localhost,这里默认值即可port: 8081, //指定端口hot: true, // 开启热更新https: false, // 是否开启https模式proxy: { // 请求代理服务器'/lexiangtianyuan': { //带上api前缀的target: 'http://localhost:8080/lexiangtianyuan/', //代理目标地址changeOrigin: true,secure: false,pathRewrite: { // 在发出请求后将/api替换为''空值,这样不影响接口请求'^/lexiangtianyuan': ''}}}},
chainWebpack(config) {config.module.rule('svg').exclude.add(resolve('src/icons')).end()config.module.rule('icons').test(/\.svg$/).include.add(resolve('src/icons')).end().use('svg-sprite-loader').loader('svg-sprite-loader').options({symbolId: 'icon-[name]'}).end()
}
}
package com.ServletContextListener;import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.DictionaryEntity;
import com.service.DictionaryService;
import com.thread.MyThreadMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** 字典初始化监视器 用的是服务器监听,每次项目启动,都会调用这个类*/
@WebListener
public class DictionaryServletContextListener implements ServletContextListener {private static final Logger logger = LoggerFactory.getLogger(DictionaryServletContextListener.class);private MyThreadMethod myThreadMethod;@Overridepublic void contextDestroyed(ServletContextEvent sce) {logger.info("----------服务器停止----------");}@Overridepublic void contextInitialized(ServletContextEvent sce) {ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());logger.info("----------字典表初始化开始----------");DictionaryService dictionaryService = (DictionaryService)appContext.getBean("dictionaryService");List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());Map<String, Map<Integer,String>> map = new HashMap<>();for(DictionaryEntity d :dictionaryEntities){Map<Integer, String> m = map.get(d.getDicCode());if(m ==null || m.isEmpty()){m = new HashMap<>();}m.put(d.getCodeIndex(),d.getIndexName());map.put(d.getDicCode(),m);}sce.getServletContext().setAttribute("dictionaryMap", map);logger.info("----------字典表初始化完成----------");logger.info("----------线程执行开始----------");if (myThreadMethod == null) {myThreadMethod = new MyThreadMethod();myThreadMethod.start(); // servlet 上下文初始化时启动线程myThreadMethod}logger.info("----------线程执行结束----------");}}
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("/shangjia")
public class ShangjiaController {private static final Logger logger = LoggerFactory.getLogger(ShangjiaController.class);@Autowiredprivate ShangjiaService shangjiaService;@Autowiredprivate TokenService tokenService;@Autowiredprivate DictionaryService dictionaryService;//级联表service@Autowiredprivate YonghuService yonghuService;/*** 后端列表*/@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("shangjiaId",request.getSession().getAttribute("userId"));params.put("shangjiaDeleteStart",1);params.put("shangjiaDeleteEnd",1);if(params.get("orderBy")==null || params.get("orderBy")==""){params.put("orderBy","id");}PageUtils page = shangjiaService.queryPage(params);//字典表数据转换List<ShangjiaView> list =(List<ShangjiaView>)page.getList();for(ShangjiaView 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);ShangjiaEntity shangjia = shangjiaService.selectById(id);if(shangjia !=null){//entity转viewShangjiaView view = new ShangjiaView();BeanUtils.copyProperties( shangjia , view );//把实体数据重构到view中//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody ShangjiaEntity shangjia, HttpServletRequest request){logger.debug("save方法:,,Controller:{},,shangjia:{}",this.getClass().getName(),shangjia.toString());String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永远不会进入");Wrapper<ShangjiaEntity> queryWrapper = new EntityWrapper<ShangjiaEntity>().eq("username", shangjia.getUsername()).or().eq("shangjia_phone", shangjia.getShangjiaPhone()).andNew().eq("shangjia_delete", 1);logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiaEntity shangjiaEntity = shangjiaService.selectOne(queryWrapper);if(shangjiaEntity==null){shangjia.setShangjiaDelete(1);shangjia.setCreateTime(new Date());shangjia.setPassword("123456");shangjiaService.insert(shangjia);return R.ok();}else {return R.error(511,"账户或者联系方式已经被使用");}}/*** 后端修改*/@RequestMapping("/update")public R update(@RequestBody ShangjiaEntity shangjia, HttpServletRequest request){logger.debug("update方法:,,Controller:{},,shangjia:{}",this.getClass().getName(),shangjia.toString());String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");//根据字段查询是否有相同数据Wrapper<ShangjiaEntity> queryWrapper = new EntityWrapper<ShangjiaEntity>().notIn("id",shangjia.getId()).andNew().eq("username", shangjia.getUsername()).or().eq("shangjia_phone", shangjia.getShangjiaPhone()).andNew().eq("shangjia_delete", 1);logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiaEntity shangjiaEntity = shangjiaService.selectOne(queryWrapper);if("".equals(shangjia.getShangjiaPhoto()) || "null".equals(shangjia.getShangjiaPhoto())){shangjia.setShangjiaPhoto(null);}if(shangjiaEntity==null){shangjiaService.updateById(shangjia);//根据id更新return R.ok();}else {return R.error(511,"账户或者联系方式已经被使用");}}/*** 删除*/@RequestMapping("/delete")public R delete(@RequestBody Integer[] ids){logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());ArrayList<ShangjiaEntity> list = new ArrayList<>();for(Integer id:ids){ShangjiaEntity shangjiaEntity = new ShangjiaEntity();shangjiaEntity.setId(id);shangjiaEntity.setShangjiaDelete(2);list.add(shangjiaEntity);}if(list != null && list.size() >0){shangjiaService.updateBatchById(list);}return R.ok();}/*** 批量上传*/@RequestMapping("/batchInsert")public R save( String fileName){logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);try {List<ShangjiaEntity> shangjiaList = 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){//循环ShangjiaEntity shangjiaEntity = new ShangjiaEntity();
// shangjiaEntity.setUsername(data.get(0)); //账户 要改的
// //shangjiaEntity.setPassword("123456");//密码
// shangjiaEntity.setShangjiaName(data.get(0)); //农民名称 要改的
// shangjiaEntity.setShangjiaPhone(data.get(0)); //联系方式 要改的
// shangjiaEntity.setShangjiaEmail(data.get(0)); //邮箱 要改的
// shangjiaEntity.setShangjiaPhoto("");//照片
// shangjiaEntity.setShangjiaXingjiTypes(Integer.valueOf(data.get(0))); //农民信用类型 要改的
// shangjiaEntity.setNewMoney(data.get(0)); //现有余额 要改的
// shangjiaEntity.setShangjiaContent("");//照片
// shangjiaEntity.setShangjiaDelete(1);//逻辑删除字段
// shangjiaEntity.setCreateTime(date);//时间shangjiaList.add(shangjiaEntity);//把要查询是否重复的字段放入map中//账户if(seachFields.containsKey("username")){List<String> username = seachFields.get("username");username.add(data.get(0));//要改的}else{List<String> username = new ArrayList<>();username.add(data.get(0));//要改的seachFields.put("username",username);}//联系方式if(seachFields.containsKey("shangjiaPhone")){List<String> shangjiaPhone = seachFields.get("shangjiaPhone");shangjiaPhone.add(data.get(0));//要改的}else{List<String> shangjiaPhone = new ArrayList<>();shangjiaPhone.add(data.get(0));//要改的seachFields.put("shangjiaPhone",shangjiaPhone);}}//查询是否重复//账户List<ShangjiaEntity> shangjiaEntities_username = shangjiaService.selectList(new EntityWrapper<ShangjiaEntity>().in("username", seachFields.get("username")).eq("shangjia_delete", 1));if(shangjiaEntities_username.size() >0 ){ArrayList<String> repeatFields = new ArrayList<>();for(ShangjiaEntity s:shangjiaEntities_username){repeatFields.add(s.getUsername());}return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());}//联系方式List<ShangjiaEntity> shangjiaEntities_shangjiaPhone = shangjiaService.selectList(new EntityWrapper<ShangjiaEntity>().in("shangjia_phone", seachFields.get("shangjiaPhone")).eq("shangjia_delete", 1));if(shangjiaEntities_shangjiaPhone.size() >0 ){ArrayList<String> repeatFields = new ArrayList<>();for(ShangjiaEntity s:shangjiaEntities_shangjiaPhone){repeatFields.add(s.getShangjiaPhone());}return R.error(511,"数据库的该表中的 [联系方式] 字段已经存在 存在数据为:"+repeatFields.toString());}shangjiaService.insertBatch(shangjiaList);return R.ok();}}}}catch (Exception e){return R.error(511,"批量插入数据异常,请联系管理员");}}/*** 登录*/@IgnoreAuth@RequestMapping(value = "/login")public R login(String username, String password, String captcha, HttpServletRequest request) {ShangjiaEntity shangjia = shangjiaService.selectOne(new EntityWrapper<ShangjiaEntity>().eq("username", username));if(shangjia==null || !shangjia.getPassword().equals(password))return R.error("账号或密码不正确");else if(shangjia.getShangjiaDelete() != 1)return R.error("账户已被删除");// // 获取监听器中的字典表// ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();// Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");// Map<Integer, String> role_types = dictionaryMap.get("role_types");// role_types.get(.getRoleTypes());String token = tokenService.generateToken(shangjia.getId(),username, "shangjia", "农民");R r = R.ok();r.put("token", token);r.put("role","农民");r.put("username",shangjia.getShangjiaName());r.put("tableName","shangjia");r.put("userId",shangjia.getId());return r;}/*** 注册*/@IgnoreAuth@PostMapping(value = "/register")public R register(@RequestBody ShangjiaEntity shangjia){
// ValidatorUtils.validateEntity(user);Wrapper<ShangjiaEntity> queryWrapper = new EntityWrapper<ShangjiaEntity>().eq("username", shangjia.getUsername()).or().eq("shangjia_phone", shangjia.getShangjiaPhone()).andNew().eq("shangjia_delete", 1);ShangjiaEntity shangjiaEntity = shangjiaService.selectOne(queryWrapper);if(shangjiaEntity != null)return R.error("账户或者联系方式已经被使用");shangjia.setShangjiaXingjiTypes(1);shangjia.setNewMoney(0.0);shangjia.setShangjiaDelete(1);shangjia.setCreateTime(new Date());shangjiaService.insert(shangjia);return R.ok();}/*** 重置密码*/@GetMapping(value = "/resetPassword")public R resetPassword(Integer id){ShangjiaEntity shangjia = new ShangjiaEntity();shangjia.setPassword("123456");shangjia.setId(id);shangjiaService.updateById(shangjia);return R.ok();}/*** 忘记密码*/@IgnoreAuth@RequestMapping(value = "/resetPass")public R resetPass(String username, HttpServletRequest request) {ShangjiaEntity shangjia = shangjiaService.selectOne(new EntityWrapper<ShangjiaEntity>().eq("username", username));if(shangjia!=null){shangjia.setPassword("123456");boolean b = shangjiaService.updateById(shangjia);if(!b){return R.error();}}else{return R.error("账号不存在");}return R.ok();}/*** 获取用户的session用户信息*/@RequestMapping("/session")public R getCurrShangjia(HttpServletRequest request){Integer id = (Integer)request.getSession().getAttribute("userId");ShangjiaEntity shangjia = shangjiaService.selectById(id);if(shangjia !=null){//entity转viewShangjiaView view = new ShangjiaView();BeanUtils.copyProperties( shangjia , view );//把实体数据重构到view中//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 退出*/@GetMapping(value = "logout")public R logout(HttpServletRequest request) {request.getSession().invalidate();return R.ok("退出成功");}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));// 没有指定排序字段就默认id倒序if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){params.put("orderBy","id");}PageUtils page = shangjiaService.queryPage(params);//字典表数据转换List<ShangjiaView> list =(List<ShangjiaView>)page.getList();for(ShangjiaView 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);ShangjiaEntity shangjia = shangjiaService.selectById(id);if(shangjia !=null){//entity转viewShangjiaView view = new ShangjiaView();BeanUtils.copyProperties( shangjia , view );//把实体数据重构到view中//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody ShangjiaEntity shangjia, HttpServletRequest request){logger.debug("add方法:,,Controller:{},,shangjia:{}",this.getClass().getName(),shangjia.toString());Wrapper<ShangjiaEntity> queryWrapper = new EntityWrapper<ShangjiaEntity>().eq("username", shangjia.getUsername()).or().eq("shangjia_phone", shangjia.getShangjiaPhone()).andNew().eq("shangjia_delete", 1);logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiaEntity shangjiaEntity = shangjiaService.selectOne(queryWrapper);if(shangjiaEntity==null){shangjia.setShangjiaDelete(1);shangjia.setCreateTime(new Date());shangjia.setPassword("123456");shangjiaService.insert(shangjia);return R.ok();}else {return R.error(511,"账户或者联系方式已经被使用");}}}
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("/shangjiajianyi")
public class ShangjiajianyiController {private static final Logger logger = LoggerFactory.getLogger(ShangjiajianyiController.class);@Autowiredprivate ShangjiajianyiService shangjiajianyiService;@Autowiredprivate TokenService tokenService;@Autowiredprivate DictionaryService dictionaryService;//级联表service@Autowiredprivate ShangjiaService shangjiaService;@Autowiredprivate YonghuService yonghuService;/*** 后端列表*/@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("shangjiaId",request.getSession().getAttribute("userId"));if(params.get("orderBy")==null || params.get("orderBy")==""){params.put("orderBy","id");}PageUtils page = shangjiajianyiService.queryPage(params);//字典表数据转换List<ShangjiajianyiView> list =(List<ShangjiajianyiView>)page.getList();for(ShangjiajianyiView 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);ShangjiajianyiEntity shangjiajianyi = shangjiajianyiService.selectById(id);if(shangjiajianyi !=null){//entity转viewShangjiajianyiView view = new ShangjiajianyiView();BeanUtils.copyProperties( shangjiajianyi , view );//把实体数据重构到view中//级联表ShangjiaEntity shangjia = shangjiaService.selectById(shangjiajianyi.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段view.setShangjiaId(shangjia.getId());}//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody ShangjiajianyiEntity shangjiajianyi, HttpServletRequest request){logger.debug("save方法:,,Controller:{},,shangjiajianyi:{}",this.getClass().getName(),shangjiajianyi.toString());String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永远不会进入");else if("农民".equals(role))shangjiajianyi.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));Wrapper<ShangjiajianyiEntity> queryWrapper = new EntityWrapper<ShangjiajianyiEntity>().eq("shangjia_id", shangjiajianyi.getShangjiaId()).eq("shangjiajianyi_name", shangjiajianyi.getShangjiajianyiName());logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiajianyiEntity shangjiajianyiEntity = shangjiajianyiService.selectOne(queryWrapper);if(shangjiajianyiEntity==null){shangjiajianyi.setInsertTime(new Date());shangjiajianyi.setCreateTime(new Date());shangjiajianyiService.insert(shangjiajianyi);return R.ok();}else {return R.error(511,"表中有相同数据");}}/*** 后端修改*/@RequestMapping("/update")public R update(@RequestBody ShangjiajianyiEntity shangjiajianyi, HttpServletRequest request){logger.debug("update方法:,,Controller:{},,shangjiajianyi:{}",this.getClass().getName(),shangjiajianyi.toString());String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
// else if("农民".equals(role))
// shangjiajianyi.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));//根据字段查询是否有相同数据Wrapper<ShangjiajianyiEntity> queryWrapper = new EntityWrapper<ShangjiajianyiEntity>().notIn("id",shangjiajianyi.getId()).andNew().eq("shangjia_id", shangjiajianyi.getShangjiaId()).eq("shangjiajianyi_name", shangjiajianyi.getShangjiajianyiName());logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiajianyiEntity shangjiajianyiEntity = shangjiajianyiService.selectOne(queryWrapper);if(shangjiajianyiEntity==null){shangjiajianyiService.updateById(shangjiajianyi);//根据id更新return R.ok();}else {return R.error(511,"表中有相同数据");}}/*** 删除*/@RequestMapping("/delete")public R delete(@RequestBody Integer[] ids){logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());shangjiajianyiService.deleteBatchIds(Arrays.asList(ids));return R.ok();}/*** 批量上传*/@RequestMapping("/batchInsert")public R save( String fileName){logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);try {List<ShangjiajianyiEntity> shangjiajianyiList = 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){//循环ShangjiajianyiEntity shangjiajianyiEntity = new ShangjiajianyiEntity();
// shangjiajianyiEntity.setShangjiaId(Integer.valueOf(data.get(0))); //农民 要改的
// shangjiajianyiEntity.setShangjiajianyiName(data.get(0)); //建议标题 要改的
// shangjiajianyiEntity.setShangjiajianyiContent("");//照片
// shangjiajianyiEntity.setInsertTime(date);//时间
// shangjiajianyiEntity.setCreateTime(date);//时间shangjiajianyiList.add(shangjiajianyiEntity);//把要查询是否重复的字段放入map中}//查询是否重复shangjiajianyiService.insertBatch(shangjiajianyiList);return R.ok();}}}}catch (Exception e){return R.error(511,"批量插入数据异常,请联系管理员");}}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));// 没有指定排序字段就默认id倒序if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){params.put("orderBy","id");}PageUtils page = shangjiajianyiService.queryPage(params);//字典表数据转换List<ShangjiajianyiView> list =(List<ShangjiajianyiView>)page.getList();for(ShangjiajianyiView 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);ShangjiajianyiEntity shangjiajianyi = shangjiajianyiService.selectById(id);if(shangjiajianyi !=null){//entity转viewShangjiajianyiView view = new ShangjiajianyiView();BeanUtils.copyProperties( shangjiajianyi , view );//把实体数据重构到view中//级联表ShangjiaEntity shangjia = shangjiaService.selectById(shangjiajianyi.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段view.setShangjiaId(shangjia.getId());}//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody ShangjiajianyiEntity shangjiajianyi, HttpServletRequest request){logger.debug("add方法:,,Controller:{},,shangjiajianyi:{}",this.getClass().getName(),shangjiajianyi.toString());Wrapper<ShangjiajianyiEntity> queryWrapper = new EntityWrapper<ShangjiajianyiEntity>().eq("shangjia_id", shangjiajianyi.getShangjiaId()).eq("shangjiajianyi_name", shangjiajianyi.getShangjiajianyiName());logger.info("sql语句:"+queryWrapper.getSqlSegment());ShangjiajianyiEntity shangjiajianyiEntity = shangjiajianyiService.selectOne(queryWrapper);if(shangjiajianyiEntity==null){shangjiajianyi.setInsertTime(new Date());shangjiajianyi.setCreateTime(new Date());shangjiajianyiService.insert(shangjiajianyi);return R.ok();}else {return R.error(511,"表中有相同数据");}}}
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("/tudi")
public class TudiController {private static final Logger logger = LoggerFactory.getLogger(TudiController.class);@Autowiredprivate TudiService tudiService;@Autowiredprivate TokenService tokenService;@Autowiredprivate DictionaryService dictionaryService;//级联表service@Autowiredprivate ShangjiaService shangjiaService;@Autowiredprivate YonghuService yonghuService;/*** 后端列表*/@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("shangjiaId",request.getSession().getAttribute("userId"));params.put("tudiDeleteStart",1);params.put("tudiDeleteEnd",1);if(params.get("orderBy")==null || params.get("orderBy")==""){params.put("orderBy","id");}PageUtils page = tudiService.queryPage(params);//字典表数据转换List<TudiView> list =(List<TudiView>)page.getList();for(TudiView 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);TudiEntity tudi = tudiService.selectById(id);if(tudi !=null){//entity转viewTudiView view = new TudiView();BeanUtils.copyProperties( tudi , view );//把实体数据重构到view中//级联表ShangjiaEntity shangjia = shangjiaService.selectById(tudi.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段view.setShangjiaId(shangjia.getId());}//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody TudiEntity tudi, HttpServletRequest request){logger.debug("save方法:,,Controller:{},,tudi:{}",this.getClass().getName(),tudi.toString());String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永远不会进入");else if("农民".equals(role))tudi.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));Wrapper<TudiEntity> queryWrapper = new EntityWrapper<TudiEntity>().eq("shangjia_id", tudi.getShangjiaId()).eq("tudi_name", tudi.getTudiName()).eq("tudi_address", tudi.getTudiAddress()).eq("tudi_types", tudi.getTudiTypes()).eq("tudi_shumu_types", tudi.getTudiShumuTypes()).eq("tudi_haohuai_types", tudi.getTudiHaohuaiTypes()).eq("tudi_clicknum", tudi.getTudiClicknum()).eq("tudi_zulin_types", tudi.getTudiZulinTypes()).eq("shangxia_types", tudi.getShangxiaTypes()).eq("tudi_delete", tudi.getTudiDelete());logger.info("sql语句:"+queryWrapper.getSqlSegment());TudiEntity tudiEntity = tudiService.selectOne(queryWrapper);if(tudiEntity==null){tudi.setTudiClicknum(1);tudi.setShangxiaTypes(1);tudi.setTudiDelete(1);tudi.setCreateTime(new Date());tudiService.insert(tudi);return R.ok();}else {return R.error(511,"表中有相同数据");}}/*** 后端修改*/@RequestMapping("/update")public R update(@RequestBody TudiEntity tudi, HttpServletRequest request){logger.debug("update方法:,,Controller:{},,tudi:{}",this.getClass().getName(),tudi.toString());String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
// else if("农民".equals(role))
// tudi.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));//根据字段查询是否有相同数据Wrapper<TudiEntity> queryWrapper = new EntityWrapper<TudiEntity>().notIn("id",tudi.getId()).andNew().eq("shangjia_id", tudi.getShangjiaId()).eq("tudi_name", tudi.getTudiName()).eq("tudi_address", tudi.getTudiAddress()).eq("tudi_types", tudi.getTudiTypes()).eq("tudi_shumu_types", tudi.getTudiShumuTypes()).eq("tudi_haohuai_types", tudi.getTudiHaohuaiTypes()).eq("tudi_clicknum", tudi.getTudiClicknum()).eq("tudi_zulin_types", tudi.getTudiZulinTypes()).eq("shangxia_types", tudi.getShangxiaTypes()).eq("tudi_delete", tudi.getTudiDelete());logger.info("sql语句:"+queryWrapper.getSqlSegment());TudiEntity tudiEntity = tudiService.selectOne(queryWrapper);if("".equals(tudi.getTudiPhoto()) || "null".equals(tudi.getTudiPhoto())){tudi.setTudiPhoto(null);}if("".equals(tudi.getTudiFile()) || "null".equals(tudi.getTudiFile())){tudi.setTudiFile(null);}if(tudiEntity==null){tudiService.updateById(tudi);//根据id更新return R.ok();}else {return R.error(511,"表中有相同数据");}}/*** 删除*/@RequestMapping("/delete")public R delete(@RequestBody Integer[] ids){logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());ArrayList<TudiEntity> list = new ArrayList<>();for(Integer id:ids){TudiEntity tudiEntity = new TudiEntity();tudiEntity.setId(id);tudiEntity.setTudiDelete(2);list.add(tudiEntity);}if(list != null && list.size() >0){tudiService.updateBatchById(list);}return R.ok();}/*** 批量上传*/@RequestMapping("/batchInsert")public R save( String fileName){logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);try {List<TudiEntity> tudiList = 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){//循环TudiEntity tudiEntity = new TudiEntity();
// tudiEntity.setShangjiaId(Integer.valueOf(data.get(0))); //农民 要改的
// tudiEntity.setTudiName(data.get(0)); //土地名称 要改的
// tudiEntity.setTudiPhoto("");//照片
// tudiEntity.setTudiFile(data.get(0)); //合同 要改的
// tudiEntity.setTudiAddress(data.get(0)); //所在地址 要改的
// tudiEntity.setTudiTypes(Integer.valueOf(data.get(0))); //土地类型 要改的
// tudiEntity.setTudiShumuTypes(Integer.valueOf(data.get(0))); //有无树 要改的
// tudiEntity.setTudiHaohuaiTypes(Integer.valueOf(data.get(0))); //土地状态 要改的
// tudiEntity.setTudiOldMoney(data.get(0)); //土地原价/月 要改的
// tudiEntity.setTudiNewMoney(data.get(0)); //现价/月 要改的
// tudiEntity.setTudiClicknum(Integer.valueOf(data.get(0))); //点击次数 要改的
// tudiEntity.setTudiContent("");//照片
// tudiEntity.setTudiZulinTypes(Integer.valueOf(data.get(0))); //是否租赁 要改的
// tudiEntity.setShangxiaTypes(Integer.valueOf(data.get(0))); //是否上架 要改的
// tudiEntity.setTudiDelete(1);//逻辑删除字段
// tudiEntity.setCreateTime(date);//时间tudiList.add(tudiEntity);//把要查询是否重复的字段放入map中}//查询是否重复tudiService.insertBatch(tudiList);return R.ok();}}}}catch (Exception e){return R.error(511,"批量插入数据异常,请联系管理员");}}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));// 没有指定排序字段就默认id倒序if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){params.put("orderBy","id");}PageUtils page = tudiService.queryPage(params);//字典表数据转换List<TudiView> list =(List<TudiView>)page.getList();for(TudiView 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);TudiEntity tudi = tudiService.selectById(id);if(tudi !=null){//点击数量加1tudi.setTudiClicknum(tudi.getTudiClicknum()+1);tudiService.updateById(tudi);//entity转viewTudiView view = new TudiView();BeanUtils.copyProperties( tudi , view );//把实体数据重构到view中//级联表ShangjiaEntity shangjia = shangjiaService.selectById(tudi.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段view.setShangjiaId(shangjia.getId());}//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody TudiEntity tudi, HttpServletRequest request){logger.debug("add方法:,,Controller:{},,tudi:{}",this.getClass().getName(),tudi.toString());Wrapper<TudiEntity> queryWrapper = new EntityWrapper<TudiEntity>().eq("shangjia_id", tudi.getShangjiaId()).eq("tudi_name", tudi.getTudiName()).eq("tudi_address", tudi.getTudiAddress()).eq("tudi_types", tudi.getTudiTypes()).eq("tudi_shumu_types", tudi.getTudiShumuTypes()).eq("tudi_haohuai_types", tudi.getTudiHaohuaiTypes()).eq("tudi_clicknum", tudi.getTudiClicknum()).eq("tudi_zulin_types", tudi.getTudiZulinTypes()).eq("shangxia_types", tudi.getShangxiaTypes()).eq("tudi_delete", tudi.getTudiDelete());logger.info("sql语句:"+queryWrapper.getSqlSegment());TudiEntity tudiEntity = tudiService.selectOne(queryWrapper);if(tudiEntity==null){tudi.setTudiDelete(1);tudi.setCreateTime(new Date());tudiService.insert(tudi);return R.ok();}else {return R.error(511,"表中有相同数据");}}}
这篇关于【计算机毕业设计】乐享田园系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!