基于SSM的乡镇自来水收费系统

末尾获取源码
开发语言:Java
Java开发工具:JDK1.8
后端框架:SSM
前端:采用JSP技术开发
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是


目录

一、项目简介

二、论文截图

三、系统项目截图

3.1管理员功能

3.2用户功能实现

四、核心代码

4.1用户信息实现代码

4.2留言信息实现代码

4.3封装


一、项目简介

互联网发展至今,无论是其理论还是技术都已经成熟,而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播,搭配信息管理工具可以很好地为人们提供服务。针对乡镇自来水收费信息管理混乱,出错率高,信息安全性差,劳动强度大,费时费力等问题,采用乡镇自来水收费系统可以有效管理,使信息管理能够更加科学和规范。

乡镇自来水收费系统在Eclipse环境中,使用Java语言进行编码,使用Mysql创建数据表保存本系统产生的数据。系统可以提供信息显示和相应服务,其管理员管理水表,审核用户更换水表的请求,管理用户水费,包括抄表以及水费缴费,管理公告,管理留言和用户信息。用户可以申请更换水表,可以完成水费缴费,公告查看,留言发布以及个人信息更改等操作。

总之,乡镇自来水收费系统集中管理信息,有着保密性强,效率高,存储空间大,成本低等诸多优点。它可以降低信息管理成本,实现信息管理计算机化。


二、论文截图



三、系统项目截图

3.1管理员功能

管理员进入指定功能操作区之后可以管理水费信息。其页面见下图。管理员可以查看各个用户的水费信息,完成用户水表抄表,完成用户水费的线上缴费操作。

管理员进入指定功能操作区之后可以处理水表信息。其页面见下图。管理员添加水表,批量删除或针对性删除水表信息,修改水表信息。

 

管理员进入指定功能操作区之后可以查看用户申请更换的水表信息。其页面见下图。管理员在本页面可以选择同意更换水表或取消用户更换水表的请求。

 

管理员进入指定功能操作区之后可以管理用户。其页面见下图。本功能就是为了方便管理员增加用户,修改用户,批量删除用户而设置的。

 

管理员进入指定功能操作区之后可以管理留言。其页面见下图。管理员批量删除留言,回答用户的留言。

 

3.2用户功能实现

用户进入指定功能操作区之后可以发布留言。其页面见下图。用户直接提交留言即可,管理员会及时接收到用户的留言。

用户进入指定功能操作区之后可以查看水费并缴费。其页面见下图。用户点击缴费即可完成对应水费的缴费操作。

 

用户进入指定功能操作区之后可以更换水表。其页面见下图。当用户提交了水表更换信息之后,在管理员未审核前,用户可以自行取消更换水表的请求。

 

用户进入指定功能操作区之后可以查看公告。其页面见下图。公告信息太多时,可以使用公告查询功能快速获取指定的公告。

 


四、核心代码

4.1用户信息实现代码

package com.controller;

import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;

import com.annotation.IgnoreAuth;
import com.entity.UserEntity;
import com.entity.YonghuxinxiEntity;
import com.service.TokenService;
import org.apache.commons.lang3.StringUtils;
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.YonghuxinxiEntity;

import com.service.YonghuxinxiService;
import com.utils.PageUtils;
import com.utils.R;

/**
 * 
 * 后端接口
 * @author
 * @email
 * @date 2021-01-30
*/
@RestController
@Controller
@RequestMapping("/yonghuxinxi")
public class YonghuxinxiController {
    private static final Logger logger = LoggerFactory.getLogger(YonghuxinxiController.class);

    @Autowired
    private YonghuxinxiService yonghuxinxiService;

    @Autowired
    private TokenService tokenService;

    /**
     * 登录
     */
    @IgnoreAuth
    @PostMapping(value = "/login")
    public R login(String username, String password, String role, HttpServletRequest request) {
        YonghuxinxiEntity user = yonghuxinxiService.selectOne(new EntityWrapper<YonghuxinxiEntity>().eq("account", username));
        if(user != null){
            if(!user.getRole().equals(role)){
                return R.error("权限不正常");
            }
            if(user==null || !user.getPassword().equals(password)) {
                return R.error("账号或密码不正确");
            }
            String token = tokenService.generateToken(user.getId(),user.getName(), "users", user.getRole());
            return R.ok().put("token", token);
        }else{
            return R.error("账号、密码或权限不正确");
        }
    }

    /**
     * 注册
     */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody YonghuxinxiEntity user){
//    	ValidatorUtils.validateEntity(user);
        if(yonghuxinxiService.selectOne(new EntityWrapper<YonghuxinxiEntity>().eq("account", user.getAccount())) !=null) {
            return R.error("用户已存在");
        }
        yonghuxinxiService.insert(user);
        return R.ok();
    }

    /**
     * 退出
     */
    @GetMapping(value = "logout")
    public R logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return R.ok("退出成功");
    }

    /**
     * 密码重置
     */
    @IgnoreAuth
    @RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request){
        YonghuxinxiEntity user = yonghuxinxiService.selectOne(new EntityWrapper<YonghuxinxiEntity>().eq("account", username));
        if(user==null) {
            return R.error("账号不存在");
        }
        user.setPassword("123456");
        yonghuxinxiService.update(user,null);
        return R.ok("密码已重置为:123456");
    }

    /**
     * 获取用户的session用户信息
     */
    @RequestMapping("/session")
    public R getCurrUser(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        YonghuxinxiEntity user = yonghuxinxiService.selectById(id);
        return R.ok().put("data", user);
    }


    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("Controller:"+this.getClass().getName()+",page方法");
        Object role = request.getSession().getAttribute("role");
        PageUtils page = null;
        if(role.equals("用户")){
            params.put("yh",request.getSession().getAttribute("userId"));
            page = yonghuxinxiService.queryPage(params);
        }else{
            page = yonghuxinxiService.queryPage(params);
        }
        return R.ok().put("data", page);
    }
    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        logger.debug("Controller:"+this.getClass().getName()+",info方法");
        YonghuxinxiEntity yonghuxinxi = yonghuxinxiService.selectById(id);
        if(yonghuxinxi!=null){
            return R.ok().put("data", yonghuxinxi);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @IgnoreAuth
    @RequestMapping("/save")
    public R save(@RequestBody YonghuxinxiEntity yonghuxinxi){
        logger.debug("Controller:"+this.getClass().getName()+",save");
        Wrapper<YonghuxinxiEntity> queryWrapper = new EntityWrapper<YonghuxinxiEntity>()
            .eq("name", yonghuxinxi.getName())
            .eq("account", yonghuxinxi.getAccount());
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YonghuxinxiEntity yonghuxinxiEntity = yonghuxinxiService.selectOne(queryWrapper);
        if("".equals(yonghuxinxi.getImgPhoto()) || "null".equals(yonghuxinxi.getImgPhoto())){
            yonghuxinxi.setImgPhoto(null);
        }
        yonghuxinxi.setRole("用户");
        yonghuxinxi.setSbTypes(1);
        yonghuxinxi.setCredit(0);
        if(yonghuxinxiEntity==null){
            yonghuxinxiService.insert(yonghuxinxi);
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody YonghuxinxiEntity yonghuxinxi, HttpServletRequest request){
        logger.debug("Controller:"+this.getClass().getName()+",update");
        //根据字段查询是否有相同数据
        Wrapper<YonghuxinxiEntity> queryWrapper = new EntityWrapper<YonghuxinxiEntity>()
            .notIn("id",yonghuxinxi.getId())
            .eq("name", yonghuxinxi.getName())
            .eq("account", yonghuxinxi.getAccount());
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YonghuxinxiEntity yonghuxinxiEntity = yonghuxinxiService.selectOne(queryWrapper);
        if("".equals(yonghuxinxi.getImgPhoto()) || "null".equals(yonghuxinxi.getImgPhoto())){
                yonghuxinxi.setImgPhoto(null);
        }
        if(yonghuxinxiEntity==null){
            yonghuxinxiService.updateById(yonghuxinxi);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
     * 缴费
     */
    @RequestMapping("/payment")
    public R payment(@RequestBody Double money, HttpServletRequest request){
        logger.debug("Controller:"+this.getClass().getName()+",delete");
        YonghuxinxiEntity yonghuxinxi = yonghuxinxiService.selectById(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
        Double q = yonghuxinxi.getBalance() - money;
        if(q != null && q >= 0){
            yonghuxinxi.setBalance(q);
            yonghuxinxi.setCredit(+1);
            yonghuxinxiService.updateById(yonghuxinxi);
        }else {
            return R.error("余额不足");
        }
        return R.ok();
    }


    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        logger.debug("Controller:"+this.getClass().getName()+",delete");
        yonghuxinxiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

4.2留言信息实现代码

package com.controller;

import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;

import com.entity.YonghuxinxiEntity;
import com.service.YonghuxinxiService;
import org.apache.commons.lang3.StringUtils;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

import com.entity.LiuyanxinxiEntity;

import com.service.LiuyanxinxiService;
import com.utils.PageUtils;
import com.utils.R;

/**
 * 
 * 后端接口
 * @author
 * @email
 * @date 2021-01-30
*/
@RestController
@Controller
@RequestMapping("/liuyanxinxi")
public class LiuyanxinxiController {
    private static final Logger logger = LoggerFactory.getLogger(LiuyanxinxiController.class);

    @Autowired
    private LiuyanxinxiService liuyanxinxiService;

    @Autowired
    private YonghuxinxiService yonghuxinxiService;

    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){
        logger.debug("Controller:"+this.getClass().getName()+",page方法");
        PageUtils page = liuyanxinxiService.queryPage(params);
        return R.ok().put("data", page);
    }
    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        logger.debug("Controller:"+this.getClass().getName()+",info方法");
        LiuyanxinxiEntity liuyanxinxi = liuyanxinxiService.selectById(id);
        if(liuyanxinxi!=null){
            return R.ok().put("data", liuyanxinxi);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody LiuyanxinxiEntity liuyanxinxi, HttpServletRequest request){
        logger.debug("Controller:"+this.getClass().getName()+",save");
        String username = (String) request.getSession().getAttribute("username");
            liuyanxinxi.setYhnote(username);
            liuyanxinxi.setNoteTime(new Date());
            liuyanxinxiService.insert(liuyanxinxi);
            return R.ok();
    }

    /**
    * 修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody LiuyanxinxiEntity liuyanxinxi, HttpServletRequest request){
        logger.debug("Controller:"+this.getClass().getName()+",update");
        //根据字段查询是否有相同数据
        String username = (String) request.getSession().getAttribute("username");
            liuyanxinxi.setGlreply(username);
            liuyanxinxi.setReplyTime(new Date());
        liuyanxinxiService.updateById(liuyanxinxi);//根据id更新
        return R.ok();
    }


    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        logger.debug("Controller:"+this.getClass().getName()+",delete");
        liuyanxinxiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

4.3封装

package com.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		put("code", 0);
	}
	
	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}
	
	public static R error(String msg) {
		return error(500, msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值