基于javaweb+mysql的springboot+mybatis社区疫情防控人员流动管理系统(java+springboot+ssm+thymeleaf+html+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
住户、高风险住户、住户出入、访客出入、体温录入、用户等管理
技术框架
SpringBoot SpringMVC MyBatis Shiro Thymeleaf HTML JavaScript Layui……
基于javaweb+mysql的SpringBoot+MyBatis社区疫情防控人员流动管理系统(java+springboot+ssm+thymeleaf+html+mysql)
/**
*/
public class CookieUtil {
/**
* 设置cookie
*/
public static void setCookie(String key, String value, String domain,
HttpServletResponse response) {
}
/**
* 查找cookie
* @return
*/
public static String getCookieValue(HttpServletRequest request, String key) {
Cookie[] cookies= request.getCookies();
Cookie cookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals(key))
{
cookie = cookies[i];
}
}
}
if (cookie != null)
{
try {
return URLDecoder.decode(cookie.getValue(),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
{
return usersaltService.addSalt(count,role);
}
@PostMapping("/deleteSalt")
public Result deleteSalt(Integer[] ids)
{
System.out.println(ids);
return usersaltService.deleteSalt(ids);
}
@PostMapping("/updateSalt")
public Result updateSalt(UsersaltDto usersaltDto)
{
return Result.ok();
}
}
/**
* <p>
* 主要负责用户的密码找回和注册功能
*/
@Slf4j
@RestController
@RequestMapping("/User")
@Api(tags = "登录相关接口")
public class UserLoginController {
@Autowired
private UserService userService;
JsonObject<RecordDto> object = new JsonObject<>();
if (queryParams != null) {
JSONObject jsonObject = JSON.parseObject(queryParams);
String keyword = jsonObject.getString("keyword");
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, keyword);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
} else {
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}
}
@PostMapping("/addRecord")
public Result addRecords(RecordDto recordDto) {
return recordService.addRecord(recordDto);
}
@PostMapping("/deleteRecords")
public Result deleteRecord(Integer[] ids) {
return recordService.deleteRecord(ids);
}
@PostMapping("/updateRecords")
public Result updateRecords(RecordDto recordDto) {
return recordService.updateRecord(recordDto);
}
}
}
/**
* <p>
* 登记记录表 前端控制器
* </p>
*
*/
@Api(tags = "进出记录接口")
@RestController
@RequestMapping("/records")
@RequiresRoles(value = {"user", "admin"}, logical = Logical.OR)
public class RecordController {
@Autowired
private RecordService recordService;
@GetMapping("/getRecordByParam")
public JsonObject getRecords(@RequestParam("page") Integer currentPage, @RequestParam("limit") Integer limit,
@RequestParam(name = "params", required = false) String queryParams) {
JsonObject<RecordDto> object = new JsonObject<>();
if (queryParams != null) {
JSONObject jsonObject = JSON.parseObject(queryParams);
String keyword = jsonObject.getString("keyword");
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, keyword);
//开启RememberMe
token.setRememberMe(remeber);
try {
//进行登录的认证
subject.login(token);
//登录认证成功后,将shiro中保存的用户对象取出,放到session中
String userAccount = (String) subject.getPrincipal();
UserDto user = userService.queryUserDtoByAccount(userAccount);
//将用户对象的ID放到session域中
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("userSession", user);
return Result.ok("登录成功", user);
} catch (UnknownAccountException e) {
return Result.fail("账号不存在!");
} catch (IncorrectCredentialsException e) {
return Result.fail("密码错误!");
} catch (ExcessiveAttemptsException e) {
return Result.fail("登录失败!");
}
}
//修改密码
@PostMapping("/pwdSubmit")
@ResponseBody
public Result pwdSubmit(HttpServletRequest request, @RequestParam String oldPwd,
@RequestParam String newPwd) {
String account = CookieUtil.getCookieValue(request, "account");
UserDto user = userService.queryUserDtoByAccount(account);
String updateUserPwd = userService.updateUserPwd(user.getAccount(), oldPwd, newPwd);
if ("true".equals(updateUserPwd)) {
//修改密码后需要将当前用户shiro缓存中的数据清空
shiroRealm.clearCachedAuthenticationInfo(SecurityUtils.getSubject().getPrincipals());
//清除授权信息
shiroRealm.clearCachedAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
return Result.ok(user.getUserName() + "密码修改成功");
} else {
return Result.fail(updateUserPwd);
}
}
@PostMapping("/infoSubmit")
@ResponseBody
public Result infoSubmit(UserDto userDto) {
Boolean info = userService.updateUserInfo(userDto);
/**
* 设置cookie
*/
public static void setCookie(String key, String value, String domain,
HttpServletResponse response) {
}
/**
* 查找cookie
* @return
*/
public static String getCookieValue(HttpServletRequest request, String key) {
Cookie[] cookies= request.getCookies();
Cookie cookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals(key))
{
cookie = cookies[i];
}
}
}
if (cookie != null)
{
try {
return URLDecoder.decode(cookie.getValue(),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
}
//发送验证码
@PostMapping("/sendSms")
public Result sendSms(@RequestParam String account,
@RequestParam String userPhone) {
return userService.sendSms(account, userPhone);
}
//验证验证码
@PostMapping("/lookForPwdSubmit")
public Result lookForPwd(RetrievePwdDto retrievePwdDto) {
return userService.checkVesCode(retrievePwdDto);
}
//重置密码
@PostMapping("/retrievePwdSubmit")
public Result retrievePwdSubmit(RetrievePwdDto retrievePwdDto) {
System.out.println(retrievePwdDto);
return userService.updateUserPwd(retrievePwdDto.getAccount(), retrievePwdDto.getNewPwd());
}
//用户注册
@PostMapping("/registerUser")
public Result registerUser(UserDto userDto) {
return userService.registerUser(userDto);
}
}
}
/**
*/
@RestController
@RequestMapping("/main")
public class MainController {
@Autowired
private ResidentService residentService;
@Autowired
private RecordService recordService;
@Autowired
private VisitorService visitorService;
@Autowired
private AddressService addressService;
/**
* 首页 数据展示
*
* 获取住户总数,地址总数,获取今日进出记录数,获取今日访客数
*/
@PostMapping("datas")
public Result showDatas(){
//住户相关
Result result = residentService.queryResCountl();
Object data = result.getData();
//地址相关
long addTotal = addressService.queryAddressByParam().getTotal();
//访客相关
long visTotal = visitorService.queryVistorByParam().getTotal();
//记录相关
long recTotal = recordService.queryRecordByParam().getTotal();
HashMap<String, Object> map = new HashMap<>(10);
map.put("resCount",data);
map.put("addCount",addTotal);
map.put("visCount",visTotal);
public static Logger logger = LoggerFactory.getLogger(ExcelController.class);
@Resource
private ResidentService residentService;
@Resource
private AddressService addressService;
@PostMapping("/uploadRes")
public Result upload(@RequestParam MultipartFile file) {
InputStream fileInputStream = null;
try {
fileInputStream = file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return Result.fail("上传文件异常");
}
try {
EasyExcel.read(fileInputStream, ResidentDto.class, new ExcelListener(residentService)).sheet().doRead();
return Result.ok("上传文件成功");
} catch (Exception e) {
e.printStackTrace();
}
return Result.fail("未知错误");
}
@PostMapping("/uploadAdd")
public Result uploadd(@RequestParam MultipartFile file) {
InputStream fileInputStream = null;
try {
fileInputStream = file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return Result.fail("上传文件异常");
}
try {
EasyExcel.read(fileInputStream, AddressDto.class, new AddExcelListener(addressService)).sheet().doRead();
return Result.ok("上传文件成功");
} catch (Exception e) {
e.printStackTrace();
}
return Result.fail("未知错误");
}
/**
* <p>
* 登记记录表 前端控制器
* </p>
*
*/
@Api(tags = "进出记录接口")
@RestController
@RequestMapping("/records")
@RequiresRoles(value = {"user", "admin"}, logical = Logical.OR)
public class RecordController {
@Autowired
private RecordService recordService;
@GetMapping("/getRecordByParam")
public JsonObject getRecords(@RequestParam("page") Integer currentPage, @RequestParam("limit") Integer limit,
@RequestParam(name = "params", required = false) String queryParams) {
JsonObject<RecordDto> object = new JsonObject<>();
if (queryParams != null) {
JSONObject jsonObject = JSON.parseObject(queryParams);
String keyword = jsonObject.getString("keyword");
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, keyword);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
} else {
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@RequestMapping("/residents")
@RequiresRoles(value={"user","admin"},logical= Logical.OR)
@Api(value = "住户管理相关接口",tags ="住户管理相关接口" )
public class ResidentController {
@Autowired
private ResidentService residentService;
/**
* 查找登记信息
* @param currentPage 当前页
* @param limit 页面大小
* @param queryParams 查询条件,可以为null
* @return
*/
@GetMapping("/residentsByParams")
public JsonObject residentList(@RequestParam("page")Integer currentPage, @RequestParam("limit")Integer limit,
@RequestParam(name = "params",required = false) String queryParams)
{
JsonObject<ResidentDto> object = new JsonObject<>();
if (queryParams == null){
IPage<ResidentDto> dtoIPage = residentService.residentsByParams(currentPage,limit,null,null,null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}else {
JSONObject jsonObject=JSON.parseObject(queryParams);
@Resource
private MenuService menuService;
@ApiOperation(value = "通过登录的用户ID获取菜单信息", notes = "通过登录的用户ID获取菜单信息")
@GetMapping("")
public String listMenus() {
//获取当前用户的菜单列表
UserDto userSession = (UserDto) SecurityUtils.getSubject().getSession().getAttribute("userSession");
JSONObject jsonObject = new JSONObject();
List<MenuDTO> list = menuService.listByUserId(userSession.getUserId());
return JSONObject.toJSONString(list);
}
}
/**
*/
public class CookieUtil {
/**
* 设置cookie
*/
public static void setCookie(String key, String value, String domain,
HttpServletResponse response) {
}
/**
* 查找cookie
* @return
*/
public static String getCookieValue(HttpServletRequest request, String key) {
Cookie[] cookies= request.getCookies();
Cookie cookie = null;
if (cookies != null)
{
JsonObject<RecordDto> object = new JsonObject<>();
if (queryParams != null) {
JSONObject jsonObject = JSON.parseObject(queryParams);
String keyword = jsonObject.getString("keyword");
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, keyword);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
} else {
IPage<RecordDto> dtoIPage = recordService.queryRecordByParam(currentPage, limit, null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}
}
@PostMapping("/addRecord")
public Result addRecords(RecordDto recordDto) {
return recordService.addRecord(recordDto);
}
@PostMapping("/deleteRecords")
public Result deleteRecord(Integer[] ids) {
return recordService.deleteRecord(ids);
}
@PostMapping("/updateRecords")
public Result updateRecords(RecordDto recordDto) {
return recordService.updateRecord(recordDto);
}
}
@RequiresRoles(value={"user","admin"},logical= Logical.OR)
@Api(value = "住户管理相关接口",tags ="住户管理相关接口" )
public class ResidentController {
@Autowired
private ResidentService residentService;
/**
* 查找登记信息
* @param currentPage 当前页
* @param limit 页面大小
* @param queryParams 查询条件,可以为null
* @return
*/
@GetMapping("/residentsByParams")
public JsonObject residentList(@RequestParam("page")Integer currentPage, @RequestParam("limit")Integer limit,
@RequestParam(name = "params",required = false) String queryParams)
{
JsonObject<ResidentDto> object = new JsonObject<>();
if (queryParams == null){
IPage<ResidentDto> dtoIPage = residentService.residentsByParams(currentPage,limit,null,null,null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}else {
JSONObject jsonObject=JSON.parseObject(queryParams);
String keyword = jsonObject.getString("keyword");
String addHouse = jsonObject.getString("addHouse");
String addUnit = jsonObject.getString("addUnit");
IPage<ResidentDto> dtoIPage = residentService.residentsByParams(currentPage,limit,keyword,addHouse,addUnit);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}
}
/**
* @param residentDto
* @return
* 新增登记信息
*/
@PostMapping("/addResSubmit")
/**
* <p>
* 来访客人登记表 前端控制器
* </p>
*
*/
@RestController
@RequestMapping("/visitors")
@RequiresRoles(value={"user","admin"},logical= Logical.OR)
public class VisitorController {
@Autowired
private VisitorService visitorService;
@GetMapping("/queryVisByParam")
public JsonObject queryVisByParam(@RequestParam("page")Integer currentPage, @RequestParam("limit")Integer limit,
@RequestParam(name = "params",required = false) String queryParams)
{
JsonObject<VistorDto> object = new JsonObject<>();
IPage<VistorDto> dtoIPage = visitorService.queryVistorByParam(currentPage,limit,queryParams);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}
@PostMapping("/addVisitor")
public Result addVistor(VistorDto vistorDto)
{
return visitorService.addVistor(vistorDto);
}
@PostMapping("/deleteVisitors")
public Result deleteVistors(Integer[] ids){
return visitorService.deleteVistors(ids);
}
@PostMapping("/updateVisitor")
public Result updateVistor(VistorDto vistorDto){
return visitorService.updateVistor(vistorDto);
}
}
/**
* <p>
* 前端控制器
* </p>
*
*
* 注册码相关
*/
@RestController
@RequestMapping("/Usalt")
@RequiresRoles(value = "admin" , logical = Logical.OR)
public class UsersaltController {
//添加注册码
@Autowired
private UsersaltService usersaltService;
@GetMapping("/querySaltByParam")
public JsonObject queryUserByParam(@RequestParam("page")Integer currentPage, @RequestParam("limit")Integer limit)
{
JsonObject<UsersaltDto> object = new JsonObject<>();
IPage<UsersaltDto> dtoIPage = usersaltService.querySaltByParam(currentPage,limit,null);
object.setCode(0);
object.setMsg("ok");
object.setCount(dtoIPage.getTotal());
object.setData(dtoIPage);
return object;
}
@PostMapping("/addSalt")
public Result addSalt(Integer count, Integer role)
{
return usersaltService.addSalt(count,role);
}
@PostMapping("/deleteSalt")
public Result deleteSalt(Integer[] ids)
{
System.out.println(ids);
return usersaltService.deleteSalt(ids);
}
@PostMapping("/updateSalt")
public Result updateSalt(UsersaltDto usersaltDto)
{
return Result.ok();
}
return "page/salt/userSalt";
}
@RequestMapping("/404")
public String exceptionPage() {
return "page/sys/404";
}
}
/**
* @desc: excel导入数据库
*/
@Api(value = "文件上传", tags = "文件上传相关接口")
@RestController
@RequestMapping("/api/excel")
public class ExcelController {
public static Logger logger = LoggerFactory.getLogger(ExcelController.class);
@Resource