首页 > 其他分享 >第二阶段冲刺5

第二阶段冲刺5

时间:2024-06-14 11:10:14浏览次数:13  
标签:Task return list 冲刺 task Result import 第二阶段

发布任务,和跌倒检测,处理上传图片的接口

在网页上获取obs的虚拟摄像头进行跌倒检测的功能

package com.example.teamapplication.controller;

import com.aliyun.com.viapi.FileUtils;
import com.aliyun.facebody20191230.models.RecognizeActionResponse;
import com.aliyun.facebody20191230.models.RecognizeActionResponseBody;
import com.aliyun.tea.TeaModel;
import com.example.teamapplication.common.Result;
import com.example.teamapplication.entity.Task;
import com.example.teamapplication.mapper.TaskMapper;
import com.example.teamapplication.service.TaskService;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xu
 * @since 2024-05-04
 */
@RestController
@RequestMapping("/task")
public class TaskController {
    @Resource
    private TaskService taskService;
    private TaskMapper taskMapper;

    public TaskController(TaskMapper taskMapper) {
        this.taskMapper = taskMapper;
    }


    @PostMapping("add")
    public Result Add(@RequestBody Task task){
        if(task != null){
            taskService.save(task);
            return  Result.suc();
        }
        return  Result.fail();
    }

    @PostMapping("update")
    public Result Update(@RequestParam String id,@RequestParam String receiveid){
        System.out.println(receiveid);
        List list = taskService.lambdaQuery().eq(Task::getId,id).list();
        Task task = (Task) list.get(0);
        if(task!=null && task.getSentid() != Integer.valueOf(receiveid)){
            task.setReceiveid(Integer.valueOf(receiveid));
            task.setState(1);
            taskService.saveOrUpdate(task);
            return Result.suc();
        }
        return Result.fail();
    }

    @PostMapping("finish")
    public Result Finish(@RequestParam String id,@RequestParam String receiveid){
        List list = taskService.lambdaQuery().eq(Task::getId,id).list();
        Task task = (Task) list.get(0);
        if(task!=null && task.getSentid() != Integer.valueOf(receiveid)){
            task.setReceiveid(Integer.valueOf(receiveid));
            task.setState(task.getState()+1);
            taskService.saveOrUpdate(task);
            return Result.suc();
        }
        return Result.fail();
    }

    @PostMapping("confirm")
    public Result Confitm(@RequestParam String id,@RequestParam String sentid){
        List list = taskService.lambdaQuery().eq(Task::getId,id).list();
        Task task = (Task) list.get(0);
        if(task!=null && task.getSentid() == Integer.valueOf(sentid)){
            task.setState(task.getState()+1);
            taskService.saveOrUpdate(task);
            return Result.suc();
        }
        return Result.fail();
    }

    @PostMapping("listPage")
    public Result listPage(){
        List list = taskService.lambdaQuery().list();
        ArrayList<Task> taskArrayList = new ArrayList<>();
        for(int i = 0;i<list.size();i++){
            taskArrayList.add((Task) list.get(i));
        }
        return  Result.suc(taskArrayList);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5")  Integer pageSize,
                             Task task){
        List list = taskService.lambdaQuery().list();
        List<Task> tasks = new ArrayList<>();
        for(int i = 0;i<list.size();i++){
            Task task1 = (Task) list.get(i);
            tasks.add(task1);
        }
        for (Task task1 : tasks){
            System.out.println(task1.getDescription());
        }
        PageInfo<Task> pageInfo = PageInfo.of(tasks);
        PageHelper.startPage(pageNum,pageSize);

        return Result.success(pageInfo);
    }

    @PostMapping("/uploadImage")
    public String uploadImage(@RequestBody String base64Image) {
        try {
            // 解码Base64图像数据
            byte[] decodedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image.split(",")[1]);

            System.out.println(decodedBytes);

            // 将图像保存到服务器
            File file = new File("D:\\project\\android\\stud\\picture\\image.png");
            System.out.println(file);
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(decodedBytes);
            outputStream.close();
            sync();
            return "Image uploaded successfully.";
        } catch (IOException e) {
            e.printStackTrace();
            return "Failed to upload image.";
        } catch (Exception e) {
            e.printStackTrace();
            return "Failed to judge image";
        }
    }


    @PostMapping("findByTip")
    public  Result findByTip(@RequestParam String tip){
        List list = taskService.lambdaQuery().like(Task::getTip1,tip).like(Task::getTip2,tip)
                .like(Task::getTip3,tip).list();
        ArrayList<Task> taskArrayList = new ArrayList<>();
        for(int i = 0;i<list.size();i++){
            taskArrayList.add((Task) list.get(i));
        }
        return  Result.suc(taskArrayList);
    }

    @PostMapping("sync")
    public void sync() throws Exception{
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        com.aliyun.facebody20191230.Client client = ActionController.createClient(accessKeyId, accessKeySecret);
        // 场景一,使用本地文件

        String file = "D:\\project\\android\\stud\\picture\\image.png";
        byte[] img = convertImageToByteArray(file);
        FileUtils fileUtils = FileUtils.getInstance(accessKeyId, accessKeySecret);
        String ossUrl = fileUtils.upload(file);

        com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList0 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
                .setURL(ossUrl);
        com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList1 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
                .setURL(ossUrl);
        com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList2 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
                .setURL(ossUrl);
        com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList3 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
                .setURL(ossUrl);
        com.aliyun.facebody20191230.models.RecognizeActionRequest recognizeActionRequest = new com.aliyun.facebody20191230.models.RecognizeActionRequest()
                .setType(1)
                .setURLList(java.util.Arrays.asList(
                        URLList0,
                        URLList1,
                        URLList2,
                        URLList3
                ));
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            RecognizeActionResponse recognizeActionResponse = client.recognizeActionWithOptions(recognizeActionRequest, runtime);
            // 获取整体结果


            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(recognizeActionResponse)));

            // 假设recognizeActionResponse是您从API调用中获得的响应对象
            // 假设recognizeExpressionResponse是您从API调用中获得的RecognizeExpressionResponse对象
            // 假设recognizeActionResponse是您从API调用中获得的RecognizeActionResponse对象
            RecognizeActionResponseBody body = recognizeActionResponse.getBody();

// 获取Elements列表
            List<RecognizeActionResponseBody.RecognizeActionResponseBodyDataElements> elements = body.getData().elements;

// 遍历Elements列表,获取Labels属性,即标签信息
            for (RecognizeActionResponseBody.RecognizeActionResponseBodyDataElements element : elements) {
                List<String> labels = element.getLabels();
                for (String label : labels) {
                    if(label.equals("跌倒")){
                        System.out.println("成功");
                        //添加新的任务
                        Task task = new Task();
                        task.setSentid(10);
                        task.setName("跌倒");
                        task.setDescription("有人跌倒了,请尽快前往");
                        task.setTip1("医疗");
                        task.setPosition("教学楼");
                        task.setTime(LocalDateTime.now());
                        task.setBlob(img);
                        taskService.saveOrUpdate(task);
                        System.out.println("成功");
                    }
                    System.out.println("标签: " + label);
                }
            }
        } catch (com.aliyun.tea.TeaException teaException) {
            // 获取整体报错信息
            // 获取单个字段
            System.out.println(teaException.getCode());
        }
    }


    public static byte[] convertImageToByteArray(String filePath) throws IOException {
        File file = new File(filePath);
        FileInputStream fis = new FileInputStream(file);
        byte[] imageData = new byte[(int) file.length()];
        fis.read(imageData);
        fis.close();
        return imageData;
    }

}

 

标签:Task,return,list,冲刺,task,Result,import,第二阶段
From: https://www.cnblogs.com/azure011328/p/18247445

相关文章

  • 结对冲刺12
    实现SignActivity1packagecom.example.chatapptest.activities;23importandroidx.appcompat.app.AppCompatActivity;45importandroid.content.Intent;6importandroid.os.Bundle;7importandroid.util.Patterns;8importandroid.view.View;......
  • 结对冲刺13
    实现SignUpActivity1packagecom.example.chatapptest.activities;23importandroidx.activity.result.ActivityResultLauncher;4importandroidx.activity.result.contract.ActivityResultContracts;5importandroidx.appcompat.app.AppCompatActivity;......
  • OOP第二阶段题集总结
    一.前言知识点:考察继承和多态为多,其中还涉及迭代器的使用,在每个题集中都有一个综合性题目设计多方面知识点考试,有List类和HashMap的使用以及正则表达式的运用,并且注重考查设计,理解类与类之间的关系进行合理设计,其中也要遵循我们所学的单一职责,开闭原则,迪米特法则等。题量:第四次......
  • 第二阶段PTA总结
    前言本阶段面向对象程序设计又进行了三次PTA训练,第一次(总第四次)还是接续上轮训练的试卷判分系统的程序设计,后两次都是新的电路设计训练题目。相对来说,第二次电路设计的第一次练习最为简单,第一次和第三次相对复杂。在这个阶段,我已经适应了PTA训练的题量和训练模式,并且设计起来更加......
  • 2024/6/2 第二阶段冲刺
    1packagecom.example.chatapptest.activities;23importandroidx.appcompat.app.AppCompatActivity;45importandroid.content.Intent;6importandroid.os.Bundle;7importandroid.view.View;89importcom.example.chatapptest.R;10importcom.e......
  • OOP课第二阶段总结
    OOP课第二阶段总结前言作为第二次3+1的总结,明显感受到了此次题目集越来越复杂,结合了实际的物理知识来解决现实中的电路问题。因为电路可以一直扩展下去,情况千变万化,难以像上次题目集一样找到一个呆板的做法。这次题目集,让很多人连题目都无法理解,代码也是无从下手,因为这些人......
  • 原理冲刺笔记
    本文成文于2024/4/8(技能高考前夜),谨以此文章纪念我三年的中职生涯基础动画设计属于数据处理MP3不支持多声道音频显示器UHD超高清4K(3840x2160),也可以指代8K(7680x4320)OSWin10组成内容:内核、用户界面、内存管理、文件系统FreeDSB:类Unix操作系统Solaris:专有的Unix操作......
  • 敏捷冲刺-总结
    敏捷冲刺-Day-08-阶段总结所属课程软件工程2024作业要求团队作业4—项目冲刺作业目标完成Scrum冲刺总结冲刺日志集合贴https://www.cnblogs.com/YXCS-cya/p/181788031.项目燃尽图1.1第八日-5月13日进度项目收尾2.会议记录2.1会议主题第8天......
  • 第一次冲刺,贡献度反思
    在近期项目中的团队协作中,我的个人贡献拼未达到预期水平。经过深入的自省,我明确了导致这一现象的具体原因,并制定了相应的提升策略,以下是我对个人贡献度不足原因的分析,以及我计划采取的改进措施。个人贡献值不足的原因分析:缺乏持续的投入:我意识到,在这次的项目中,我有时会表现出......
  • 敏捷冲刺day6--数字工匠队
    这个作业属于哪个课程软件工程这个作业的要求是什么项目冲刺这个作业的目标冲刺日志6站立式会议照片工作困难要讨论哪一种界面效果合适昨日完成工作界面优化今日计划工作完善任务的删除编辑项目燃尽图每日总结陆靖:冲刺快结束了()简浩辉:倒数第二天......