peng
2026-03-18 e59a0201057ba67cad425fed804c82ff4ba0c6f1
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package com.tievd.jyz.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tievd.cube.commons.annotations.AutoLog;
import com.tievd.cube.commons.annotations.DictApi;
import com.tievd.cube.commons.base.CubeController;
import com.tievd.cube.commons.base.Result;
import com.tievd.cube.commons.mybatisplus.QueryGenerator;
import com.tievd.jyz.entity.OilRecord;
import com.tievd.jyz.entity.vo.OilVolumeVo;
import com.tievd.jyz.service.IOilRecordService;
import com.tievd.jyz.util.MultiMinioUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
 
/**
 * OilRecord
 *
 * @author      cube
 * @since       2023-02-27
 * @version     V2.0.0
 */
@Slf4j
@DictApi
@RestController
@RequestMapping("/jyz/oilRecord")
@Tag(name = "加油记录相关接口")
public class OilRecordController extends CubeController<OilRecord, IOilRecordService> {
 
  @Autowired
  private IOilRecordService oilRecordService;
  
  /**
   * 分页列表查询
   */
  @GetMapping("/list")
  @Operation(summary = "一车一档加油记录分页")
  public Result<IPage<OilRecord>> queryPageList(OilRecord oilRecord,
                    @RequestParam(defaultValue="1") Integer pageNo,
                    @RequestParam(defaultValue="10") Integer pageSize,
                    HttpServletRequest req) {
    QueryWrapper<OilRecord> queryWrapper = QueryGenerator.initQueryWrapper(oilRecord, req.getParameterMap());
    Page<OilRecord> page = new Page<>(pageNo, pageSize);
    queryWrapper.orderByDesc("start_time");
    IPage<OilRecord> pageList = oilRecordService.page(page, queryWrapper);
    for(OilRecord tmpOilRecord:pageList.getRecords()){
      try{
        if(StringUtils.isNotEmpty(tmpOilRecord.getImgPath())){
          String[] arr = tmpOilRecord.getImgPath().split(":");
          tmpOilRecord.setImgPath(MultiMinioUtil.getObjectURL(arr[0],arr[1],3600));
        }
        if(StringUtils.isNotEmpty(tmpOilRecord.getOutImgPath())){
          String[] arr = tmpOilRecord.getOutImgPath().split(":");
          tmpOilRecord.setOutImgPath(MultiMinioUtil.getObjectURL(arr[0],arr[1],3600));
        }
      }catch (Exception ex){
        log.error("生成s3资源链接地址失败",ex);
      }
    }
    return Result.ok(pageList);
  }
  
  @GetMapping("/getStatisData")
  @Operation(summary = "一车一档加油记录页统计图")
  @ApiResponse(description = "result: {oilPosition:[], oilCountByMonth:[], oilCountByHour:[], oilCountByStayTime:[]}",
          content = {@Content(examples = {
                  @ExampleObject(name = "oilPosition", description = "加油位统计", value = "[{'count':'2','oilPosition':'加油位1'}]"),
                  @ExampleObject(name = "oilCountByHour", description = "每小时出现次数",  value = "[{'14':'1','count':'2'},{'15':'2','count':'1'}]"),
                  @ExampleObject(name = "oilCountByMonth", description = "每月出现次数",  value = "[{'months':'1','count':'2'},{'months':'2','count':'1'}]"),
                  @ExampleObject(name = "oilCountByStayTime", description = "停留时间出现次数",  value = "[{'stayTime':'1(5分钟内)','count':'2'},{'stayTime':'2(10分钟内)','count':'1'}]")
          })}
          )
  public Result<Map> getStatisData(@RequestParam String licenseNum, @RequestParam String orgCode) {
    Map oilPosition = oilRecordService.statisOilPosition(licenseNum, orgCode);
    Map oilCountByMonth = oilRecordService.statisByMonth(licenseNum, orgCode);
    Map oilCountByHour = oilRecordService.statisByHour(licenseNum, orgCode);
    Map oilCountByStayTime = oilRecordService.statisByStayTime(licenseNum, orgCode);
    Map res = new HashMap();
    res.put("oilPosition", oilPosition);
    res.put("oilCountByMonth", oilCountByMonth);
    res.put("oilCountByHour", oilCountByHour);
    res.put("oilCountByStayTime", oilCountByStayTime);
    return Result.ok(res);
  }
  
  @GetMapping("/getStatisOilVolume")
  @Operation(summary = "加油量统计分页")
  @ApiResponse(description = "result: [{oilPosition:'加油位', oilCount:'次数', OilVolume:'加油量'},{}]")
  public Result<IPage<Map>> getStatisOilVolume(@RequestParam String orgCode,
                                               @RequestParam(required = false) String dateMonth,
                                               @RequestParam(defaultValue="1") Integer pageNo,
                                               @RequestParam(defaultValue="10") Integer pageSize) {
    IPage page = new Page(pageNo, pageSize);
    IPage<Map> oilVolume = oilRecordService.getStatisOilVolume(page, orgCode, dateMonth);
    return Result.ok(oilVolume);
  }
  
  @GetMapping("/getOilVolumeTotal")
  @Operation(summary = "加油量统计页总数")
  @ApiResponse(description = "result: {oilCountTotal:'总次数', OilVolumeTotal:'总加油量'}")
  public Result<Map> getOilVolumeTotal(@RequestParam String orgCode, @RequestParam(required = false) String dateMonth) {
    Map oilVolume = oilRecordService.getOilVolumeTotal(orgCode, dateMonth);
    return Result.ok(oilVolume);
  }
  
  @GetMapping("/descOilVolume")
  @Parameter(in = ParameterIn.QUERY, name = "oilPosition", description = "加油位")
  @Parameter(in = ParameterIn.QUERY, name = "orgCode", description = "机构代码")
  @Parameter(in = ParameterIn.QUERY, name = "dateMonth", description = "年-月")
  @Parameter(in = ParameterIn.QUERY, name = "dateDay", description = "年-月-日")
  @Operation(summary = "加油量详情")
  public Result<IPage<OilVolumeVo>> descOilVolume(@RequestParam @Parameter(hidden = true) Map map,
                                                 @RequestParam(defaultValue="1") Integer pageNo,
                                                 @RequestParam(defaultValue="10") Integer pageSize) {
    IPage page = new Page(pageNo, pageSize);
    IPage<OilVolumeVo> oilDescList = oilRecordService.descOilVolumeList(page, map);
    return Result.ok(oilDescList);
  }
  
  
  /**
   * 添加
   */
  @AutoLog("OilRecord-添加")
  @PostMapping("/add")
  public Result<?> add(@RequestBody OilRecord oilRecord) {
    oilRecordService.save(oilRecord);
    return Result.ok();
  }
  
  /**
   * 编辑
   */
  @AutoLog("OilRecord-编辑")
  @PutMapping("/edit")
  public Result<?> edit(@RequestBody OilRecord oilRecord) {
    oilRecordService.updateById(oilRecord);
    return Result.ok();
  }
  
  /**
   * 通过id删除
   */
  @AutoLog("OilRecord-通过id删除")
  @DeleteMapping("/delete")
  public Result<?> delete(@RequestParam String id) {
    oilRecordService.removeById(id);
    return Result.ok();
  }
  
  /**
   * 批量删除
   */
  @AutoLog("OilRecord-批量删除")
  @DeleteMapping("/deleteBatch")
  public Result<?> deleteBatch(@RequestParam String ids) {
    this.oilRecordService.removeByIds(Arrays.asList(ids.split(",")));
    return Result.ok();
  }
  
  /**
   * 通过id查询
   */
  @GetMapping("/queryById")
  public Result<?> queryById(@RequestParam String id) {
    OilRecord oilRecord = oilRecordService.getById(id);
    return Result.ok(oilRecord);
  }
 
  /**
   * 导出excel
   */
  @RequestMapping("/exportXls")
  public void exportXls(HttpServletRequest request, HttpServletResponse response, OilRecord oilRecord)  throws IOException {
      super.exportXls(request, response, oilRecord, "OilRecord");
  }
 
  /**
   * 通过excel导入数据
   */
  @PostMapping("/importExcel")
  public Result<?> importExcel(HttpServletRequest request) throws Exception {
      return super.importExcel(request, OilRecord.class);
  }
}