• 民子哥的任务之体温上报系统


    用到的一些环境或者配置

    • maven
    • mybatis
    • spring
    • springMVC
    • layui
    • poi
    • echarts

    民子哥的要求

    • Android端上报app
    • 生成热力图
    • 导出十四日体温记录表

    大体结构

    app端获取体温等数据后通过http发送到服务端

    一些关键代码

    poi导出表格

    
    import com.alibaba.fastjson.JSON;
    import com.alice.Utils.Httpservice;
    import com.alice.pojo.Info;
    import com.alice.pojo.User;
    import com.alice.pojo.UserMap;
    import com.alice.service.InfoService;
    import com.alice.service.UserService;
    import jxl.write.WriteException;
    import org.apache.poi.ss.usermodel.*;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.io.IOException;
    import java.io.InputStream;
    
    import org.springframework.core.io.Resource;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.FileInputStream;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.List;
    
    @Controller
    @RequestMapping("/Web")
    public class Web {
        @Autowired
        @Qualifier("InfoServiceImpl")
        private InfoService infoService;
        @Qualifier("UserServiceImpl")
        private UserService userService;
        private Httpservice httpservice=new Httpservice();
        public Web(UserService userService) {
            this.userService = userService;
        }
    
        public String getTime(){
            //使用Date创建日期对象
            Date date=new Date();
            System.out.println("当前的日期是------>"+date);
    
            /**
             * 创建格式化时间日期类
             *构造入参String类型就是我们想要转换成的时间形式
             */
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
    
            System.out.println("格式化后的时间------->"+format.format(date));
            return format.format(date);
        }
        public String getDay_15(){
            //使用Date创建日期对象
            Date date=new Date();
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
    
            System.out.println("格式化后的时间------->"+format.format(date));
            return format.format(date);
        }
        @RequestMapping(value="/1",method= RequestMethod.GET,produces="text/html;charset=UTF-8")
       // @RequestMapping("/1")
        @ResponseBody
        public String getClassOne(){
            String data,part;
            List<Info>infoList= infoService.selectByTime(getTime());
            List<Info>classOne=new ArrayList<Info>();
            System.out.println(infoList.toString());
            for (Info info : infoList) {
                System.out.println("class:"+userService.selectByName(info.getName()).getClas());
                if(userService.selectByName(info.getName()).getClas().equals("1"))
                {
                    System.out.println("remove:"+info.toString());
                    classOne.add(info);
                }
            }
            System.out.println("class one size:"+classOne.size());
            System.out.println(classOne);
    
             part= JSON.toJSONString(classOne);
             data="{"code":0,"msg":"","count":1000,"data":"+part+"}";
            System.out.println(data);
            return data;
        }
        @RequestMapping(value="/2",method= RequestMethod.GET,produces="text/html;charset=UTF-8")
        @ResponseBody
        public String getClassTwo(){
            String data,part;
            List<Info>infoList= infoService.selectByTime(getTime());
            List<Info>classOne=new ArrayList<Info>();
            System.out.println(infoList.toString());
            for (Info info : infoList) {
                System.out.println("class:"+userService.selectByName(info.getName()).getClas());
                if(userService.selectByName(info.getName()).getClas().equals("2"))
                {
                    System.out.println("remove:"+info.toString());
                    classOne.add(info);
                }
            }
            System.out.println("class one size:"+classOne.size());
            System.out.println(classOne);
    
            part= JSON.toJSONString(classOne);
            data="{"code":0,"msg":"","count":1000,"data":"+part+"}";
            System.out.println(data);
            return data;
        }
        @RequestMapping("/IOtest")
        public void outputTest(HttpServletResponse response,HttpServletRequest request,String name) throws IOException, WriteException {
            System.out.println("name is:"+name);
            User user=userService.selectByName(name);
            List<Info>infoList=infoService.selectByName(name);
            List<Info>list=new ArrayList<Info>();
            for (Info info : infoList) {
                System.out.println("info:"+info.toString());
                for(int i=0;i<15;i++){
                    Date date=new Date();
                    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
                    String time=format.format(new Date(date.getTime()-i*24 * 60 * 60 * 1000));
                    System.out.println("check time :"+time);
                    if(info.getTime().contains(time)){
                        list.add(info);
                    }
                }
            }
            outputXls(response,request,"test",user,list);
    
        }
     public void outputXls(HttpServletResponse response,HttpServletRequest request,String name,User user,List<Info> infoList) throws IOException, WriteException {
    
            Resource resource=new ClassPathResource("temp.xlsx");
            InputStream inputStream=new FileInputStream(resource.getFile());
            Workbook workbook=new XSSFWorkbook(inputStream);
            Sheet sheet = workbook.getSheetAt(0);
            //得到内容的第一行的每一单元格的样式,存到数组中
            Row row = sheet.getRow(2);//从第3行开始的,索引是2
            CellStyle[] cellStyles = new CellStyle[row.getLastCellNum()];//根据该行的有内容的列数创建存储样式的数组
            for(int i = 0; i<row.getLastCellNum(); i++){
                org.apache.poi.ss.usermodel.Cell cell = (Cell) row.getCell(i);//得到单元格对象
                CellStyle cellStyle = cell.getCellStyle();//获取该单元格的格式
                cellStyles[i] = cellStyle;//把样式存储到样式数组中,索引跟列索引对应的
            }
            org.apache.poi.ss.usermodel.Cell cell=null;
            CellStyle cellStyle= cellStyles[0];
            //设置单元格内容,第一部分
                //姓名-》
                row=sheet.getRow(2);
    
                cell=row.createCell(1);
                cell.setCellValue(user.getName());
                cell.setCellStyle(cellStyle);
    
                cell=row.createCell(5);
                cell.setCellValue(user.getId());
                cell.setCellStyle(cellStyle);
    
                row=sheet.getRow(3);
                cell=row.createCell(5);
                cell.setCellValue(user.getPhone());
                cell.setCellStyle(cellStyle);
    
            String health="健康";
            for (Info info : infoList) {
                if(Float.parseFloat(info.getTemper())>38){
                    health="异常";
                }
            }
    
                cell=row.createCell(1);
                cell.setCellValue(health);
                cell.setCellStyle(cellStyle);
    
            //设置单元格第二部分
            try {
            for(int i=6;i<20;i++){
                row= sheet.getRow(i);
                temp(row,infoList.get(i-6),cellStyle,health);
                }
            } catch (Exception e){
                for (Info info : infoList) {
                    temp(row,info,cellStyle,health);
                }
            }
            //下载
            response.setHeader("Content-Disposition","attachment;filename="+"realFilename.xlsx");
            response.setContentType("application/octet-stream");
            response.setHeader("filename", "filename.xls");
            workbook.write(response.getOutputStream());
        }
        public void temp(Row row,Info info, CellStyle cellStyle,String health){
            Cell cell=null;
    
            cell=row.createCell(0);
            cell.setCellValue(info.getTime());
            cell.setCellStyle(cellStyle);
    
            cell=row.createCell(1);
            cell.setCellValue(info.getTemper());
            cell.setCellStyle(cellStyle);
    
            cell=row.createCell(2);
            cell.setCellValue(health);
            cell.setCellStyle(cellStyle);
    
            cell=row.createCell(3);
            cell.setCellValue(info.getLocation());
            cell.setCellStyle(cellStyle);
    
            cell=row.createCell(4);
            cell.setCellValue(info.getSpecial());
            cell.setCellStyle(cellStyle);
        }
    


    代码包括配置文件已经上传[大概,百度云]



  • 相关阅读:
    机器学习&深度学习资料(转载)
    深度学习相关链接
    机器学习入门之八:机器学习的思考--计算机的潜意识(转载)
    机器学习入门之七:机器学习的父类--人工智能(转载)
    机器学习入门之六:机器学习的子类--深度学习(转载)
    机器学习入门之五:机器学习的应用--大数据(转载)
    Oracle 12c 新特性之 数据库内归档(In-Database Archiving)
    Oracle 12c 新特性之 temp undo
    Oracle 12c 新特性之 PDB 级别闪回数据库
    Oracle 12c 多租户 CDB 与 PDB之 shared undo 与 Local undo 切换
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/14905585.html
Copyright © 2020-2023  润新知