栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

IEMS

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IEMS

目录

后端获取数据:

在ScoresController中的addd:

识别结果处理:

SampleTwo中的identity方法:


后端获取数据:

在ScoresController中的addd:

这个方法主要完成的工作包括:

1、解析前端传来的json,包括该课程的课程编号cs_id、课序号les_ord、图片对象数组imgimg。然后再对图片数组进行处理,提取数组中的图片对象对应的base64信息。

因为前端传的数据imgimg也是字符串格式,所以用字符串切割的处理方式,用picbase64=作为分隔符来进行字符串切割,进而获取每个图片的base64;

2、将处理后的base64信息图片传递给识别接口SampleTwo中的identify方法,该方法再完成识别的同时进行成绩的计算工作,然后将成绩返回给addd方法;

3、再由addd方法完成数据库update的调用,进而完成学生成绩的插入工作。

    
    @AutoLog(value = "临时的临时成绩-添加-图片上传")
    @ApiOperation(value="临时的临时成绩-添加-图片上传", notes="临时的临时成绩-添加-图片上传")
    @PostMapping(value = "/addd")    
    public Result addd(@RequestBody Map map) {
        //scoresService.save(scores);
        System.out.println("-----------test图片上传--------");

        String url = new String();
        String cs_id = new String();
        String les_ord = new String();
        String ScrMeth = new String();

        List base64arr = new ArrayList();
        Pic pic = new Pic();
        String base64 = "";
        int picnum = 0;
        String substr[] = new String[10];
        String picbase64[] = new String[10];

        if (map.containsKey("url")){
            url = map.get("url").toString();
            System.out.println(url);
        }
        if (map.containsKey("filename")){
            String filename = map.get("filename").toString();
            System.out.println(filename);
        }
        if (map.containsKey("imgimg")){

            Object list = map.get("imgimg");
            String liststr = list.toString();
            //System.out.println(liststr);

            String str[] = liststr.split("picuid");
            picnum = str.length-1;
            System.out.println("picnum = "+picnum);
            for(int i=0;i> Slist = SampleTwo.identify(path65,test_percent,usual_percent);
            //List> Slist = SampleTwo.identify(path_pic);
            //识别结果处理
            List scorelist = new ArrayList();
            Scores scores = new Scores();
            int Sl_lenth = Slist.size();
            for (int i = 0; i < Sl_lenth; i++) {
                scorelist = Slist.get(i);

                String stu_name = (String) scorelist.get(0);
                String stu_id = (String) scorelist.get(1);
                int exam_score = (int) scorelist.get(2);
                int usual_score = (int) scorelist.get(3);
                int test_score = (int) scorelist.get(4);
                int scr = (int) scorelist.get(5);

                String score = scr + "";

                if (ScrMeth.equals("评级制")) {
                    score = UtilClass.ScrChange(score);
                }

                boolean a = scoresService.updateExamScores(exam_score, cs_id, les_ord, stu_id);
                boolean b = scoresService.updateUsualScores(usual_score, cs_id, les_ord, stu_id);
                boolean c = scoresService.updateTestScores(test_score, cs_id, les_ord, stu_id);
                boolean d = scoresService.updateScores(score, cs_id, les_ord, stu_id);
                if (a && b && c && d) {
                    System.out.println(stu_id + " " + stu_name + " 同学的成绩插入成功");
                }
            }
        }

        return Result.OK("添加成功!");
    } 
    

    

    
    

 

从前端获取到的图片的base64信息需要进行格式转换,方法如下:

    public static String ChangeForm(String basestr){
        String data = basestr;
        // System.out.println("data = "+data);
        String base64Data =  data.split(",")[1];
        // System.out.println("base64Data = "+base64Data);
        
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] bytes = decoder.decode(base64Data);
        
        FileOutputStream fos = null;
        try {
            try {
                fos = new FileOutputStream("D:\aaa.jpg");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            try {
                fos.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return base64Data;
        } finally {
            if (fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

识别结果处理:

上传的图片经过识别后是json格式的字符串,所以下面可以根据字符串的处理方式来对获得结果进行处理,进而获取我们想要的信息;

SampleTwo中的identity方法:
public class SampleTwo {
    //设置APPID/AK/SK
    public static final String APP_ID = "26041291";
    public static final String API_KEY = "3zSCXcXcHcw7KEHlk5SLOxug";
    public static final String SECRET_KEY = "z2HRbmgH7LNxH7AII2EmdLheKoHsj7aj";
……
}

identify方法主要完成的工作包括:

1、调用百度文字识别API,对ScoresControll中获得的图片进行识别,获取到识别结果的json形式的字符串;

2、对字符串进行处理:

需要考虑上传图片的格式不同的问题

3、将获取到的学生信息和对应成绩存入Scores实体的list中

再此过程中需要完成对成绩的计算工作,利用出入该方法的参数(平时成绩占比、实验成绩占比)算出学生的最终成绩score ;

    public static List> identify(String path,double test_percent,double usual_percent){
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 可选:设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选:设置代理服务器地址, http和socket二选一,或者均不设置
        //client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
        //client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 可选:设置log4j日志输出格式,若不设置,则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");

        // 调用接口
      
        JSONObject res = client.basicGeneral(path, new HashMap());
        String string = "";
        List> Slist = new ArrayList>();

        try {
            int length = res.length();
            System.out.println("length = "+length);
            int num = res.getInt("words_result_num");

           // int num = Integer.parseInt(res.getString("word_result_num"));
            int row = num/5;

            System.out.println("num = "+num+", row = "+row);

            String s = res.toString();
            String str = s.substring(16);
            String strm = "";
            String stri = "";
            int m = 0;
            String stu_name = "";
            String stu_id = "";
            String score_exam = "";
            String score_usual = "";
            String score_lab = "";
            int sc_exam = 0;
            int sc_usual = 0;
            int sc_lab = 0;
            int score = 0;
            double a = test_percent;
            double b = usual_percent;
            double c = 1-a-b;

            String substr1 = str.split(":")[1];
            System.out.println("substr1 = "+substr1);
            String title = "报表";
            boolean withtitle = substr1.contains(title);
            System.out.println("withtitle = "+withtitle);
            String substr3 = str.split(":")[3];
            String header = "姓名";
            System.out.println("substr3 = "+substr3);
            boolean withheaderandtitle = substr3.contains(header);
            boolean withonlyheader = substr1.contains(header);

            for(int i=0;i
转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号