feat: 月度数据-报表生成前后端

This commit is contained in:
LokerL 2024-09-11 16:51:55 +08:00
parent 3af5658a0e
commit f0bcc70eb3
8 changed files with 508 additions and 14 deletions

View File

@ -7,14 +7,13 @@ import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.oil.domain.ThDeviceReportMonth;
import com.ruoyi.project.oil.domain.monitor.ThDevice;
import com.ruoyi.project.oil.domain.monitor.ThDeviceReport;
import com.ruoyi.project.oil.service.IOilThDeviceService;
import com.ruoyi.project.oil.service.ThDeviceReportMonthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@ -30,6 +29,9 @@ public class OilStatisticsController extends BaseController {
@Autowired
private IOilThDeviceService oilThDeviceService;
@Autowired
private ThDeviceReportMonthService thDeviceReportMonthService;
@GetMapping(value = "/getDeviceList/{id}")
public TableDataInfo getDeviceList(@PathVariable("id") Long id) {
startPage();
@ -95,4 +97,21 @@ public class OilStatisticsController extends BaseController {
LocalDate lastMonthDate = date.minus(1, ChronoUnit.MONTHS);
return lastMonthDate.format(formatter);
}
@GetMapping("/getDeviceReportMonthList")
public TableDataInfo getDeviceReportMonthList(Long deptId, String year, String month, int pageNum, int pageSize) {
Page<Object> page = PageHelper.startPage(pageNum, pageSize);
List<Map<String, Object>> result = thDeviceReportMonthService.selectThDeviceReportMonthList(deptId, year, month);
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setRows(result);
rspData.setMsg("查询成功");
rspData.setTotal(page.getTotal());
return rspData;
}
@PostMapping("/updateDeviceReportMonth")
public AjaxResult updateDeviceReportMonth(@RequestBody ThDeviceReportMonth thDeviceReportMonth) {
return toAjax(thDeviceReportMonthService.updateThDeviceReportMonth(thDeviceReportMonth));
}
}

View File

@ -0,0 +1,125 @@
package com.ruoyi.project.oil.domain;
import java.io.Serializable;
/**
* 设备月表
* @TableName TH_DEVICE_REPORT_MONTH1
*/
public class ThDeviceReportMonth implements Serializable {
/**
* 设备编号
*/
private String sn;
/**
*
*/
private Long id;
/**
*
*/
private Long deptId;
/**
*
*/
private String year;
/**
*
*/
private String month;
/**
* 设备平均值
*/
private String avgValue;
private static final long serialVersionUID = 1L;
/**
* 设备编号
*/
public String getSn() {
return sn;
}
/**
* 设备编号
*/
public void setSn(String sn) {
this.sn = sn;
}
/**
*
*/
public Long getId() {
return id;
}
/**
*
*/
public void setId(Long id) {
this.id = id;
}
/**
*
*/
public Long getDeptId() {
return deptId;
}
/**
*
*/
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
/**
*
*/
public String getYear() {
return year;
}
/**
*
*/
public void setYear(String year) {
this.year = year;
}
/**
*
*/
public String getMonth() {
return month;
}
/**
*
*/
public void setMonth(String month) {
this.month = month;
}
/**
* 设备平均值
*/
public String getAvgValue() {
return avgValue;
}
/**
* 设备平均值
*/
public void setAvgValue(String avgValue) {
this.avgValue = avgValue;
}
}

View File

@ -0,0 +1,32 @@
package com.ruoyi.project.oil.mapper;
import com.ruoyi.project.oil.domain.ThDeviceReportMonth;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* @author Lenovo
* @description 针对表TH_DEVICE_REPORT_MONTH(设备月表)的数据库操作Mapper
* @createDate 2024-09-11 13:44:21
* @Entity com.ruoyi.project.oil.domain.ThDeviceReportMonth
*/
public interface ThDeviceReportMonthMapper {
/**
* 查询列表
*/
@MapKey("deptId")
List<Map<String, Object>> selectThDeviceReportMonthList(@Param("deptId") Long deptId, @Param("year") String year, @Param("month") String month);
/**
* 更新
*/
int updateThDeviceReportMonth(ThDeviceReportMonth thDeviceReportMonth);
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.project.oil.service;
import com.ruoyi.project.oil.domain.ThDeviceReportMonth;
import java.util.List;
import java.util.Map;
/**
* @author Lenovo
* @description 针对表TH_DEVICE_REPORT_MONTH1(设备月表)的数据库操作Service
* @createDate 2024-09-11 13:44:21
*/
public interface ThDeviceReportMonthService {
/**
* 查询列表
*/
List<Map<String, Object>> selectThDeviceReportMonthList(Long deptId, String year, String month);
/**
* 更新
*/
int updateThDeviceReportMonth(ThDeviceReportMonth thDeviceReportMonth);
}

View File

@ -0,0 +1,60 @@
package com.ruoyi.project.oil.service.impl;
import com.ruoyi.project.oil.domain.ThDeviceReportMonth;
import com.ruoyi.project.oil.mapper.ThDeviceReportMonthMapper;
import com.ruoyi.project.oil.service.ThDeviceReportMonthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Lenovo
* @description 针对表TH_DEVICE_REPORT_MONTH1(设备月表)的数据库操作Service实现
* @createDate 2024-09-11 13:44:21
*/
@Service
public class ThDeviceReportMonthServiceImpl implements ThDeviceReportMonthService {
@Autowired
private ThDeviceReportMonthMapper thDeviceReportMonthMapper;
@Override
public List<Map<String, Object>> selectThDeviceReportMonthList(Long deptId, String year, String month) {
// return thDeviceReportMonthMapper.selectThDeviceReportMonthList(deptId, year, month);
List<Map<String, Object>> result = new ArrayList<>();
List<Map<String, Object>> list = thDeviceReportMonthMapper.selectThDeviceReportMonthList(deptId, year, month);
for (Map<String, Object> map : list) {
Map<String, Object> lowerCaseMap = new HashMap<>();
for (String key : map.keySet()) {
lowerCaseMap.put(toLowerCaseCamelCase(key.toLowerCase()), map.get(key));
}
result.add(lowerCaseMap);
}
return result;
}
@Override
public int updateThDeviceReportMonth(ThDeviceReportMonth thDeviceReportMonth) {
return thDeviceReportMonthMapper.updateThDeviceReportMonth(thDeviceReportMonth);
}
public static String toLowerCaseCamelCase(String input) {
StringBuilder output = new StringBuilder();
String[] words = input.split("_");
output.append(words[0]);
for (int i = 1; i < words.length; i++) {
output.append(Character.toUpperCase(words[i].charAt(0)));
output.append(words[i].substring(1).toLowerCase());
}
return output.toString();
}
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.oil.mapper.ThDeviceReportMonthMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.project.oil.domain.ThDeviceReportMonth">
<result property="sn" column="sn" jdbcType="VARCHAR"/>
<result property="id" column="id" jdbcType="DECIMAL"/>
<result property="deptId" column="dept_id" jdbcType="DECIMAL"/>
<result property="year" column="year" jdbcType="VARCHAR"/>
<result property="month" column="month" jdbcType="VARCHAR"/>
<result property="avgValue" column="avg_value" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
select m.sn,
m.id,
m.dept_id,
m.year,
m.month,
m.avg_value,
p.dept_name,
p.ancestors,
pp.dept_name as "gangqu"
from th_device_report_month1 m
left join sys_dept p on m.dept_id = p.dept_id
left join sys_dept pp on p.parent_id = pp.dept_id
</sql>
<select id="selectThDeviceReportMonthList" parameterType="map" resultType="map">
<include refid="Base_Column_List"/>
WHERE m.dept_id IN (
SELECT dept_id
FROM sys_dept START WITH dept_id = #{deptId}
CONNECT BY PRIOR dept_id = parent_id
)
<if test="year != null and year != ''">
AND m.year = #{year}
</if>
<if test="month != null and month != ''">
AND m.month = #{month}
</if>
ORDER BY m.dept_id, m.year, m.month ASC
</select>
<update
id="updateThDeviceReportMonth"
parameterType="com.ruoyi.project.oil.domain.ThDeviceReportMonth"
>
update th_device_report_month1
<set>
<if test="avgValue != null and avgValue != ''">avg_value = #{avgValue},</if>
</set>
where id = #{id}
</update>
</mapper>

View File

@ -0,0 +1,17 @@
import request from '@/utils/request'
export function getDeviceReportMonthList(params) {
return request({
url: '/statistics/getDeviceReportMonthList',
params: params,
method: 'get',
})
}
export function updateDeviceReportMonth(params) {
return request({
url: '/statistics/updateDeviceReportMonth',
data: params,
method: 'post',
})
}

View File

@ -5,24 +5,74 @@
<dept-tree @deptChange="handleDeptChange" :showQuickGroup="true" />
</el-col>
<el-col :span="6" style="margin-top: 10px; margin-bottom: 10px">
<!-- 时间范围选择 -->
<!-- 月份选择 格式化为 2024-7 -->
<el-date-picker
v-model="dateValue"
type="monthrange"
format="yyyy-MM"
value-format="yyyy-MM"
start-placeholder="开始月份"
end-placeholder="结束月份"
type="month"
format="yyyy-M"
value-format="yyyy-M"
placeholder="选择月份"
@change="handleDateChange"
>
</el-date-picker>
</el-col>
</el-row>
<el-row :gutter="10">
<el-table
:data="tableData"
style="width: 100%"
border
:max-height="tableHeight"
v-loading="loading"
>
<el-table-column prop="gangqu" label="归属港区" />
<el-table-column prop="deptName" label="归属企业" />
<el-table-column prop="deptId" label="部门编码" />
<el-table-column prop="year" label="年份" />
<el-table-column prop="month" label="月份" />
<el-table-column prop="avgValue" label="平均值">
<template slot-scope="scope">
<div @dblclick="changeAvgValue(scope.$index, scope.row)">
<span v-show="!scope.row.enable_edit">{{
scope.row.avgValue
}}</span>
<el-input
:ref="'changeAvgValue' + scope.$index"
@blur="changeAvgValueBlur(scope.$index, scope.row)"
@keyup.enter.native="$event.target.blur"
clearable
v-show="scope.row.enable_edit"
size="mini"
v-model="scope.row.avgValue"
placeholder="请输入内容"
></el-input>
</div>
</template>
</el-table-column>
</el-table>
<div class="page-ele">
<el-pagination
layout="sizes, prev, pager, next, total"
:total="total"
:page-size="pageSize"
:page-sizes="[10, 20, 30, 40]"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
>
</el-pagination>
</div>
</el-row>
</div>
</template>
<script>
import DeptTree from "@/components/DeptTree/index.vue";
import {
getDeviceReportMonthList,
updateDeviceReportMonth,
} from "@/api/statistics/monthData.js";
export default {
name: "CreateReport",
components: {
@ -31,25 +81,130 @@ export default {
data() {
return {
deptId: "",
dateValue: [],
dateValue: "",
pageNum: 1,
pageSize: 10,
total: 0,
tableData: [],
loading: false,
oldValue: "",
};
},
created() {
this.initDate();
},
computed: {
tableHeight() {
return window.innerHeight - 300;
},
},
methods: {
handleDeptChange(value) {
this.deptId = value.deptId;
console.log(value);
this.queryData();
},
handleDateChange(value) {
console.log(value);
this.queryData();
},
handleCurrentChange(val) {
this.pageNum = val;
this.queryData();
},
handleSizeChange(val) {
this.pageSize = val;
this.queryData();
},
initDate() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
this.dateValue = [`${year}-${month}`, `${year}-${month}`];
this.dateValue = `${year}-${month}`;
},
changeAvgValue(index, row) {
this.$set(row, "enable_edit", true);
this.oldValue = row.avgValue;
this.$nextTick(() => {
this.$refs["changeAvgValue" + index].focus();
});
},
changeAvgValueBlur(index, row) {
this.$set(row, "enable_edit", false);
if (row.avgValue === "") {
this.$message.error("平均值不能为空");
this.queryData();
return;
}
if (isNaN(row.avgValue)) {
this.$message.error("平均值必须为数字");
this.queryData();
return;
}
if (row.avgValue < 0) {
this.$message.error("平均值不能小于0");
this.queryData();
return;
}
if (this.oldValue === row.avgValue) {
return;
}
this.$confirm(`是否修改数据?${this.oldValue}${row.avgValue}`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
const params = {
id: row.id,
avgValue: row.avgValue,
};
updateDeviceReportMonth(params)
.then((res) => {
if (res.code !== 200) {
this.$message.error("修改失败");
} else {
this.$message({
type: "success",
message: "修改成功!",
});
}
})
.catch((error) => {
console.error(error);
this.$message.error("修改失败");
})
.finally(() => {
this.queryData();
});
})
.catch(() => {
row.avgValue = this.oldValue;
this.$message({
type: "info",
message: "取消修改",
});
});
// this.tableData[index].enable_edit = !this.tableData[index].enable_edit;
// this.tableData = [...this.tableData];
},
queryData() {
this.loading = true;
const params = {
deptId: this.deptId,
year: this.dateValue.split("-")[0],
month: this.dateValue.split("-")[1],
pageNum: this.pageNum,
pageSize: this.pageSize,
};
getDeviceReportMonthList(params)
.then((res) => {
if (res.code === 200) {
this.tableData = res.rows;
this.total = res.total;
}
})
.finally(() => {
this.loading = false;
});
},
},
};
@ -59,4 +214,8 @@ export default {
.create-report {
min-height: 50vh;
}
.page-ele {
margin-top: 10px;
text-align: right;
}
</style>