3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.landtool.lanbase.modules.log.controller;
 
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONObject;
import com.landtool.lanbase.common.utils.PageUtils;
import com.landtool.lanbase.common.utils.Query;
import com.landtool.lanbase.common.utils.Result;
import com.landtool.lanbase.modules.log.entity.LogAction;
import com.landtool.lanbase.modules.log.entity.LogKettleJob;
import com.landtool.lanbase.modules.log.entity.LogKettleStepcount;
import com.landtool.lanbase.modules.log.entity.LogKettleStepcountJoinYear;
import com.landtool.lanbase.modules.log.service.LogActionService;
import com.landtool.lanbase.modules.log.service.LogKettleStepcountService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/log/kettlestepcount")
@Api(value = "", tags = {"日志"})
public class LogKettleStepcountController extends AbstractController{
 
    @Autowired
    private LogKettleStepcountService logKettleStepcountService;
 
    /**
     * 列表
     */
    @com.landtool.lanbase.common.annotation.LogAction("数据抽取,抽取日志,抽取日志列表查询,查询")
    @RequestMapping(value="/list",method ={RequestMethod.POST, RequestMethod.GET})
    @RequiresPermissions("org_user_admin")
    @ApiOperation(
            value = "系统模块操作日志",
            notes = "系统模块操作日志列表"
    )
    public Result list(@ApiParam(name="params",value="",required=true)@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<LogKettleStepcount> actionList = logKettleStepcountService.queryList(query);
        actionList.stream().forEach(s->{
            long endTime = s.getEndDate().getTime();
            long startTime = s.getStartDate().getTime();
            Double totalTime=((double) (endTime-startTime)/1000/60);//不足0.5取值0.5 ,大于0.5小于1 取值 1
            if(totalTime.compareTo(0.50)>=0&&totalTime.compareTo(1.0)<=0){
                totalTime=1.0;
            }else if(totalTime.compareTo(0.5)<0){
                totalTime=0.5;
            }else {  //大于 1.0 的取值保留小数点后2位
                totalTime = new BigDecimal(totalTime.toString()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            s.setTotalTime(totalTime);
        });
        int total = logKettleStepcountService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(actionList, total, query.getLimit(), query.getPage());
        return Result.ok().put("page", pageUtil);
    }
 
    /**
     * 信息
     */
    @GetMapping("/info/{channelid}")
    public Result info(@ApiParam(name="channelid",value="",required=true)@PathVariable("channelid") String channelid){
        LogKettleStepcount logKettleStepcount = logKettleStepcountService.queryObject(channelid);
        String result = "";
        if (logKettleStepcount != null) {
            result = logKettleStepcount.getLogfield();
        }
        return Result.ok().put("result", result);
    }
 
    @RequestMapping(value="/getechartdata",method ={RequestMethod.POST})
    public Result getechartdata(@ApiParam(name="params",value="",required=true)@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        Integer yearBeg = DateTime.now().year()-9;
        Integer yearFin = DateTime.now().year();
        if(params.get("logdatebegin").equals("") && params.get("logdatefinish").equals("")){
            params.put("logdatebegin", DateTime.now().year()-9);
        }
        if(!params.get("logdatebegin").equals("") && !params.get("logdatefinish").equals("")){
            yearBeg = Integer.valueOf(params.get("logdatebegin").toString());
            yearFin = Integer.valueOf(params.get("logdatefinish").toString());
        }
        if(!params.get("logdatebegin").equals("") && params.get("logdatefinish").equals("")){
            yearBeg = Integer.valueOf(params.get("logdatebegin").toString());
            yearFin = yearBeg + 9;
            params.replace("logdatefinish",yearFin);
        }
        if(!params.get("logdatefinish").equals("") && params.get("logdatebegin").equals("")){
            yearFin = Integer.valueOf(params.get("logdatefinish").toString());
            yearBeg = yearFin-9;
            params.replace("logdatebegin",yearBeg);
        }
        List<LogKettleStepcountJoinYear> list = logKettleStepcountService.queryLinesByYear(query);
        String legendData = "";
        String inData = "";
        String outData = "";
        String rsb = "";
        for (int i = yearBeg; i <= yearFin; i++)
        {
            legendData += "'" + i + "年',";
            boolean isExits = false;
            for (int j=0;j<list.size();j++){
                if(list.get(j).getYear() == i){
                    inData += list.get(j).getSuminput() + ",";
                    outData += list.get(j).getSumoutput() + ",";
                    isExits = true;
                    break;
                }
            }
            if(!isExits){
                inData += "0" + ",";
                outData += "0" + ",";
            }
        }
        legendData = legendData.substring(0,legendData.length()-1);
        inData = inData.length() > 0 ? inData.substring(0,inData.length()-1):inData;
        outData = outData.length() > 0 ? outData.substring(0,outData.length()-1):outData;
        rsb = "{legendData:[" + legendData + "],seriesData:[[" + inData + "],[" + outData + "]]}";
        return Result.ok().put("data",rsb);
    }
}