SpringBoot实现云监测平台

项目背景:

云监测平台主要应用于大型设备温度,油管流量,湿度,水箱温度,电机信号等监测和测量

1.开发工具

eclipse/IDEA+mysql

2.技术架构

SpringBoot+jpa+mysql+html+websocket+thymeleaf

3.主要核心功能(演示地址在最底部)

监测大厅、选项配置、用户管理、账号管理、角色管理、模块管理、角色配置、日志管理、审批配置

4.部分代码展示

文件相关

@Controller
@RequestMapping(value = "/upload")
public class AttachmentController extends BaseController {

    @Autowired
    private AttachmentService attachmentService;
    
    
    String filesRoot="c:/upload";    

    /**
     * 附件下载,显示所有附件 用于实体中只有一类附件,返回所有附件
     * 
     * @param model
     * @param parentId
     *            附件所在实体ID
     * @param groupId
     *            附件名称,如:方案附件
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/{parentId}/{groupId}/{del}", method = RequestMethod.GET)
    public String listUploadedFiles(Model model, @PathVariable String del, @PathVariable String parentId,
            @PathVariable String groupId) {
        model.addAttribute("del", del);
        List<Attachment> a=attachmentService.getByParentId(parentId, groupId);
        model.addAttribute("files", attachmentService.getByParentId(parentId, groupId));
        model.addAttribute("groupId", groupId);
        return "attachment/downloadlist";
    }

    /**
     * @param filename
     * @return 通过存储时的UUID文件名下载单个附件
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/files/{filename:.+}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<Resource> serveFile(@PathVariable String filename) throws UnsupportedEncodingException {

        Resource file = attachmentService.loadAsResource(filename);
        Attachment a = attachmentService.getRepository().findBySavedFileName(filename);
        /*
         * if(null==a){ return ResponseEntity .notFound()
         * .header(HttpHeaders.CONTENT_TYPE,"") .body(file); }
         */
        String originalFileName = a.getOriginalFileName();
        return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION,
                "attachment; charset=UTF-8;filename=\"" + java.net.URLEncoder.encode(originalFileName, "UTF-8") + "\"")
                .body(file);
    }

    
    
    /**
     * 附件上传处理 *
     */
    @RequestMapping(value = "/{parentId}/{groupId}",method = RequestMethod.POST)
    public @ResponseBody String handleFileUploadMultiple(@RequestParam("file") MultipartFile file,
            HttpServletRequest request, @PathVariable String parentId, @PathVariable String groupId,
            RedirectAttributes redirectAttributes) {

        Account account = (Account) request.getSession().getAttribute("account");
        String sender = "";
        if (null != account)
            sender = account.getUser().getName();
        attachmentService.save(file, sender, parentId, groupId);
        redirectAttributes.addFlashAttribute("files", attachmentService.getByParentId(parentId, groupId));

        return "redirect:/upload/" + parentId + "/" + groupId;
    }

    /**
     * 附件上传处理 mobile *
     */
    @RequestMapping(value = "/{parentId}/{groupId}/json", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> handleFileUploadMultipleMobile(@RequestParam("file") MultipartFile file,
            @PathVariable String parentId, @PathVariable String groupId) {

        Map<String, Object> map = new HashMap<>();
        String getlist=request.getParameter("getlist");
        map.put("code", -1);
        Account account = this.getMyAccount();
        String sender = "";
        if (null != account)
            sender = account.getUser().getName();
        attachmentService.save(file, sender, parentId, groupId);
        if(StringUtils.hasText(getlist) && getlist.equals("1")){
            List<Attachment> list=new ArrayList<>();
            list=attachmentService.getRepository().findByParentIdAndGroupId(parentId, groupId);
            map.put("data", list);
        }
        map.put("code", 0);
        return map;
    }

    /*
     * 获得附件,mobile
     */
    @RequestMapping(value = "/{parentId}/{groupId}/json", method = RequestMethod.GET)
    public @ResponseBody Map<String,Object> getAList(@PathVariable String parentId, @PathVariable String groupId) {
        List<Attachment> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();

        list = attachmentService.getRepository().findByParentIdAndGroupId(parentId, groupId);

        map.put("data", list);
        map.put("code", 0);
        return map;
    }

    @RequestMapping(value = "/files/delete/{id}", method = RequestMethod.POST)
    public @ResponseBody String deleteAFile(@PathVariable String id) {
        if (null != id) {
            attachmentService.deleteA(id);
        }
        return "ok";
    }

    /**删除文件
     * @param ParentId 存储记录的ParentId;
     * @return
     */
    @RequestMapping(value = "/files/deleteByParentId/{parentId}", method = RequestMethod.POST)
    @ResponseBody 
    public String deleteFileBySaveFileName(@PathVariable String parentId) {
        if (null != parentId) {
            attachmentService.deleteFileByParentId(parentId);
        }
        return "ok";
    }
    /**删除文件
     * @param parentId 存储记录的ParentId;
     * @param groupId 分组Id;
     * @return
     */
    @RequestMapping(value = "/files/deleteByParentIdAndGroupId/{parentId}/{groupId}", method = RequestMethod.POST)
    @ResponseBody 
    public String deleteFileBySaveFileName(@PathVariable String parentId,@PathVariable String groupId) {
        if (null != parentId) {
            attachmentService.deleteFileByParentIdAndGroupId(parentId,groupId);
        }
        return "ok";
    }
    
    /**
     * 附件上传下载演示
     * 
     * @return
     */
    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    public ModelAndView demo() {

        ModelAndView mv = this.createLayoutView("attachment/demo");
        return mv;
    }

    @ExceptionHandler(StorageFileNotFoundException.class)
    public ResponseEntity handleStorageFileNotFound(StorageFileNotFoundException exc) {
        return ResponseEntity.notFound().build();
    }

    /*
     * 获得附件的个数,根据parentId
     */
    @RequestMapping(value = "/attachmentNum/{parentId}/{groupId}", method = RequestMethod.POST)
    public @ResponseBody long getANum(@PathVariable String parentId, @PathVariable String groupId) {
        long count = 0;
        if (null != parentId) {
            List<Attachment> a = attachmentService.getRepository().findByParentIdAndGroupId(parentId, groupId);
            count = a.size();
        }
        return count;
    }
    
     //通过用户id得到其在文件上传文件夹中的头像文件,返回文件流,适用于小的图片文件
    @RequestMapping(value="/avatar/{id}",method=RequestMethod.GET,produces=MediaType.ALL_VALUE)
    @ResponseBody public byte[] getImage(@PathVariable String id,HttpServletRequest request, HttpServletResponse response)
    {            
        byte[] b =null;
        try {
            
            File file=attachmentService.getUniqueNameFile(filesRoot, id);
            if(null==file) return null;
            RandomAccessFile f = new RandomAccessFile(file,"r");
            if(f==null) return null;
             b = new byte[(int)f.length()];            
                f.readFully(b);
                f.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }         
            return b;
    } 
    @RequestMapping(value="/tempfiles/delete/{id}",method=RequestMethod.GET,produces=MediaType.ALL_VALUE)
    @ResponseBody public Map<String,Object> delete(@PathVariable String id)
    {            
        Map<String,Object> map=new HashMap<>();
        map.put("code", -1);
        
        File file=attachmentService.getUniqueNameFile(filesRoot, id);
        if(null!=file){
            if(true==file.delete())
                map.put("code", 0);
        }
    
        return map;
    } 
   
    

}
 

首页

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org">
<head>
<title>首页</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <div class="container" id="content">
        <!-- Main content -->
        <section class="content">
            <div class="row" style="margin-left: 0px; margin-right: 0px">
                <div class="col-md-9">
                    <div class="block1">
                        <div class="titlePic">
                            <img src="/cmp/index/image/home_user.png" width="72" height="64" />
                            <div>
                                <span th:text="${session.account.user.name}">个人信息</span>

                            </div>
                            <div>
                                (<span th:text="${session.account.role.name}">个人信息</span>)
                            </div>
                        </div>
                    </div>

                    <div class="block3">
                        <div class="titlePic">
                            <img src="/cmp/index/image/home_tp3.png" width="72" height="64">
                            <div>
                                <span>我的文件</span>
                            </div>
                        </div>

                    </div>
                    <div class="block4">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp4.png" width="72" height="64">
                            <div>
                                <span>我的试验</span>
                            </div>
                        </div>
                    </div>
                    <div class="block5">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp5.png" width="72" height="64">
                            <div>
                                <span>我的消息</span>
                                <span class="label label-danger">4</span>
                            </div>
                        </div>
                    </div>
                    <div class="block6">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp6.png" width="72" height="64">
                            <div>
                                <span>我的待办</span>
                                <span class="label  bg-yellow">5</span>
                            </div>
                        </div>
                    </div>
                    <div class="block7">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp7.png" width="72" height="64">
                            <div>
                                <span>视频广场</span>
                            </div>
                        </div>
                    </div>
                    <div class="block8">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp8.png" width="72" height="64">
                            <div>
                                <span>环境监测</span>
                            </div>
                        </div>
                    </div>
                    <div class="block9">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp9.png" width="72" height="64">
                            <div>
                                <span>试验申请</span>
                            </div>
                        </div>
                    </div>
                    <div class="block10">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp11.png" width="72" height="64">
                            <div>
                                <span>试验过程</span>
                            </div>
                        </div>
                    </div>
                    <div class="block11">
                        <div class="titlePic">
                            <img src="/cmp/index/image/tp10.png" width="72" height="64">
                            <div>
                                <span>试验监控</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    
                </div>
            </div>
        </section>

        <link rel="stylesheet" type="text/css" media="all"
            th:href="@{/index/indexcss/index.css}" />
        <script th:src="@{/index/index.js}"></script>
    </div>

</body>
</html>

 

演示地址:

链接:https://pan.baidu.com/s/1RX5c0MXs5poJWqxO54XHsw 
提取码:7sz9

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
本项目非常适合SpringBoot学完之后的小型项目,用来练手的刚刚好。 本项目就是把房内住客统一在网上进行管理。合家项目底下一共有五个模块,分别是个人办公,楼盘管理,业主信息,费项设置,个人中心等。 该项目主要致力于提高物业管理的服务质量,提高客户体验开发的一套自动化,高效率,简洁方便的物业管理服务平台平台可以满足大多数用户的需要,同时减少公司处理问题的速度和效率,节省人力成本,非常方便的将物业与数据结合在一起,极大的降低了物业管理的难度。 1. 安全管理包括用户进行账户注册、登录、密码修改,退出系统,个人中心; 2. 楼盘管理分为住宅小区,和商业地产两部分,住宅小区和商业地产底下又各自分为新增住 宅向导,批量增加楼宇,住宅维护,住宅查询四部分; 3. 业主信息又分为业主个人信息,业主验房,业主装修,业主入住,请修管理,业主加建等部分组成,其中业主信息包括装修录入,装修审批,装修作废,装修验收,装修查询五部分; 4. 费项设置又分为常规费项,公摊费项,便捷费项,便捷费项,客服组设置,打印单据设定等。 —————————————————————————————— 本项目非常适合SpringBoot学完之后的小型项目,用来练手的刚刚好,难度稍大。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值