Compare commits

..

2 Commits

Author SHA1 Message Date
77c3c07a21 Merge remote-tracking branch 'origin/main' 2024-04-26 18:03:14 +08:00
2bc0e0eca2 订单管理代码提交 2024-04-26 18:02:54 +08:00
12 changed files with 781 additions and 2005 deletions

View File

@ -44,12 +44,12 @@ public class OmTeamApplicationController extends BaseController
public TableDataInfo listByOm(OmTeamApplication omTeamApplication) public TableDataInfo listByOm(OmTeamApplication omTeamApplication)
{ {
startPage(); startPage();
// if(StringUtils.isEmpty(omTeamApplication.getContacts())){ if(StringUtils.isEmpty(omTeamApplication.getContacts())){
// omTeamApplication.setContacts(IdUtils.fastSimpleUUID()); omTeamApplication.setContacts(IdUtils.fastSimpleUUID());
// } }
// if(StringUtils.isEmpty(omTeamApplication.getTelephone())){ if(StringUtils.isEmpty(omTeamApplication.getTelephone())){
// omTeamApplication.setTelephone(IdUtils.fastSimpleUUID()); omTeamApplication.setTelephone(IdUtils.fastSimpleUUID());
// } }
List<OmTeamApplication> list = omTeamApplicationService.selectOmTeamApplicationList(omTeamApplication); List<OmTeamApplication> list = omTeamApplicationService.selectOmTeamApplicationList(omTeamApplication);
return getDataTable(list); return getDataTable(list);
} }

View File

@ -0,0 +1,49 @@
package com.inspur.web.controller.order;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.core.page.TableDataInfo;
import com.inspur.common.enums.BusinessType;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.order.domain.OmOrderInfo;
import com.inspur.order.service.IOmOrderAnalysisService;
import com.inspur.order.service.IOmOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 运维订单信息数据分析Controller
*
* @author zhanghan11
* @date 2024-04-16
*/
@RestController
@RequestMapping("/order/analysis")
public class OmOrderAnalysisController extends BaseController {
@Autowired
private IOmOrderAnalysisService omOrderAnalysisService;
/**
* 查询运维订单信息列表
*/
@PreAuthorize("@ss.hasPermi('order:analysis:query')")
@GetMapping("/orderDataAnalysis")
public AjaxResult orderDataAnalysis() {
return AjaxResult.success(omOrderAnalysisService.orderDataAnalysis());
}
/**
* 分析报告下载
*/
@PreAuthorize("@ss.hasPermi('order:analysis:query')")
@PostMapping("/downloadReport")
public void fileDownload(HttpServletResponse response, HttpServletRequest request) {
omOrderAnalysisService.downloadReport(response);
}
}

View File

@ -35,6 +35,17 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.5.13</version> <version>4.5.13</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,39 @@
package com.inspur.order.mapper;
import com.inspur.order.domain.OmOrderCollect;
import java.util.List;
import java.util.Map;
/**
* 订单收藏Mapper接口
*
* @author inspur
* @date 2024-04-22
*/
public interface OmOrderAnalysisMapper
{
/**
* 查询总订单数量和金额
*
* @param tenantId 租户ID
* @return
*/
public Map<String,Object> selectCountAndAmount(String tenantId);
/**
* 根据类型查询订单数量和金额
*
* @param tenantId 租户ID
* @return
*/
public List<Map<String, Object>> selectCountAndAmountByType(String tenantId);
/**
* 根据实际查询订单数量和金额
*
* @param tenantId 租户ID
* @return
*/
public List<Map<String,Object>> selectCountAndAmountByDate(String tenantId);
}

View File

@ -0,0 +1,30 @@
package com.inspur.order.service;
import com.inspur.order.domain.OmOrderCollect;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 订单分析Service接口
*
* @author inspur
* @date 2024-04-22
*/
public interface IOmOrderAnalysisService
{
/**
* 查询分析数据
*
* @return 分析数据
*/
public Map<String,Object> orderDataAnalysis();
/**
* 数据报告下载
*
*/
void downloadReport(HttpServletResponse response);
}

View File

@ -0,0 +1,274 @@
package com.inspur.order.service.impl;
import com.inspur.common.utils.SecurityUtils;
import com.inspur.order.mapper.OmOrderAnalysisMapper;
import com.inspur.order.service.IOmOrderAnalysisService;
import com.inspur.order.utils.OmConstant;
import org.apache.commons.math3.optim.InitialGuess;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 订单收藏Service业务层处理
*
* @author inspur
* @date 2024-04-22
*/
@Service
public class OmOrderAnalysisServiceImpl implements IOmOrderAnalysisService {
@Autowired
private OmOrderAnalysisMapper omOrderAnalysisMapper;
/**
* 查询分析数据
*
* @return 分析数据
*/
@Override
public Map<String, Object> orderDataAnalysis() {
Map<String, Object> map = new HashMap<>();
// 订单总数据
Map<String, Object> orderMap = omOrderAnalysisMapper.selectCountAndAmount(SecurityUtils.getTenantId());
map.put("orderMap", orderMap);
// 分时间订单金额
map.put("dateOrderMap", getDateData());
// 分类订单数据
List<Map<String, Object>> typeOrderMap = omOrderAnalysisMapper.selectCountAndAmountByType(SecurityUtils.getTenantId());
map.put("typeOrderMap", typeOrderMap);
return map;
}
private Map<String, Object> getDateData() {
Map<String, Object> typeOrderMap = new HashMap<>();
List<Map<String, Object>> list = omOrderAnalysisMapper.selectCountAndAmountByDate(SecurityUtils.getTenantId());
// 获取最近三年
// 今年
int thisYear = LocalDate.now().getYear();
// 去年
int lastYear = LocalDate.now().minusYears(1).getYear();
// 前年
int theYearBeafor = LocalDate.now().minusYears(2).getYear();
// 初始化数据
List<Object> numList1 = new ArrayList<>();
List<Object> numList2 = new ArrayList<>();
List<Object> numList3 = new ArrayList<>();
List<Object> amountList1 = new ArrayList<>();
List<Object> amountList2 = new ArrayList<>();
List<Object> amountList3 = new ArrayList<>();
// 进行初始化
for (String month : OmConstant.MONTH_ARRAY) {
numList1.add(0);
numList2.add(0);
numList3.add(0);
amountList1.add(0.00);
amountList2.add(0.00);
amountList3.add(0.00);
}
// 数据变量处理
for (Map<String, Object> map : list) {
int year = Integer.parseInt(String.valueOf(map.get("date_year")));
if (year == thisYear) {
numList1.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("num"));
amountList1.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("amount"));
}
if (year == lastYear) {
numList2.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("num"));
amountList2.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("amount"));
}
if (year == theYearBeafor) {
numList3.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("num"));
amountList3.set(Integer.parseInt(String.valueOf(map.get("date_month"))) - 1, map.get("amount"));
}
}
Map<String, Object> numMap = new HashMap<>();
Map<String, Object> amountMap = new HashMap<>();
numMap.put(thisYear + "", numList1);
numMap.put(lastYear + "", numList2);
numMap.put(theYearBeafor + "", numList3);
amountMap.put(thisYear + "", amountList1);
amountMap.put(lastYear + "", amountList2);
amountMap.put(theYearBeafor + "", amountList3);
typeOrderMap.put("numMap", numMap);
typeOrderMap.put("amountMap", amountMap);
typeOrderMap.put("year", new int[]{theYearBeafor, lastYear, thisYear});
typeOrderMap.put("month", OmConstant.MONTH_ARRAY);
return typeOrderMap;
}
/**
* 数据报告下载
*/
@Override
public void downloadReport(HttpServletResponse response) {
Map<String, Object> map = orderDataAnalysis();
// 创建图表
JFreeChart dateNumChart = createLineChart((Map<String, Object>) map.get("dateOrderMap"), "近三年月订单数统计", "num");
JFreeChart dateAmountChart = createLineChart((Map<String, Object>) map.get("dateOrderMap"), "近三年月订单金额统计", "amount");
JFreeChart typeNumChart = createPieChart((List<Map<String, Object>>) map.get("typeOrderMap"), "年度订单数量业务类型分布", "num");
JFreeChart typeAmountChart = createPieChart((List<Map<String, Object>>) map.get("typeOrderMap"), "年度订单金额业务类型分布", "amount");
// 将图表渲染为BufferedImage
BufferedImage dateNumChartImage = dateNumChart.createBufferedImage(800, 600);
BufferedImage dateAmountChartImage = dateAmountChart.createBufferedImage(800, 600);
BufferedImage typeNumChartImage = typeNumChart.createBufferedImage(800, 600);
BufferedImage typeAmountChartImage = typeAmountChart.createBufferedImage(800, 600);
// 插入图片到Word文档
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
XWPFRun r = p.createRun();
// 将BufferedImage转换为字节数组
try {
ByteArrayOutputStream dateNumChartBaos = new ByteArrayOutputStream();
ImageIO.write(dateNumChartImage, "png", dateNumChartBaos);
byte[] dateNumChartBytes = dateNumChartBaos.toByteArray();
ByteArrayOutputStream dateAmountChartBaos = new ByteArrayOutputStream();
ImageIO.write(dateNumChartImage, "png", dateAmountChartBaos);
byte[] dateAmountChartBytes = dateAmountChartBaos.toByteArray();
ByteArrayOutputStream typeNumChartBaos = new ByteArrayOutputStream();
ImageIO.write(dateNumChartImage, "png", typeNumChartBaos);
byte[] typeNumChartBytes = typeNumChartBaos.toByteArray();
ByteArrayOutputStream typeAmountChartBaos = new ByteArrayOutputStream();
ImageIO.write(dateNumChartImage, "png", typeAmountChartBaos);
byte[] typeAmountChartBytes = typeAmountChartBaos.toByteArray();
r.addPicture(new ByteArrayInputStream(dateNumChartBytes), XWPFDocument.PICTURE_TYPE_PNG, "dateNumChart", Units.toEMU(500), Units.toEMU(500)); // 设置图片大小和位置
r.addPicture(new ByteArrayInputStream(dateAmountChartBytes), XWPFDocument.PICTURE_TYPE_PNG, "dateAmountChart", Units.toEMU(500), Units.toEMU(500)); // 设置图片大小和位置
r.addPicture(new ByteArrayInputStream(typeNumChartBytes), XWPFDocument.PICTURE_TYPE_PNG,"typeNumChart", Units.toEMU(500), Units.toEMU(500)); // 设置图片大小和位置
r.addPicture(new ByteArrayInputStream(typeAmountChartBytes), XWPFDocument.PICTURE_TYPE_PNG, "typeAmountChart", Units.toEMU(500), Units.toEMU(500)); // 设置图片大小和位置
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 文档下载
//设置响应信息
response.setContentType("application/octet-stream");
// filename为文件下载后保存的文件名可自行设置但是注意文件名后缀要和原来的保持一致
response.setHeader("Content-Disposition", "attachment;");
response.setCharacterEncoding("utf-8");
OutputStream out = null;
try {
out = response.getOutputStream();
ByteArrayOutputStream docOut = new ByteArrayOutputStream();
doc.write(docOut);
byte[] bytes = docOut.toByteArray();
// 输出到客户端
if (bytes != null) {
out.write(bytes);
}
// 清理资源
doc.close();
docOut.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private JFreeChart createLineChart(Map<String, Object> map, String title, String type) {
XYSeriesCollection dataset = new XYSeriesCollection();
String yLabel = "";
int[] year = (int[]) map.get("year");
for (int yearItem : year) {
XYSeries series = new XYSeries(yearItem + "");
Map<String, Object> dataMap = new HashMap<>();
switch (type) {
case "num":
dataMap = (Map<String, Object>) map.get("numMap");
yLabel = "数量";
break;
case "amount":
dataMap = (Map<String, Object>) map.get("amountMap");
yLabel = "金额";
break;
default:
break;
}
List<String> list = (List<String>) dataMap.get(yearItem + "");
if (!list.isEmpty()) {
for (int i = 0; i < 12; i++) {
switch (type) {
case "num":
series.add(i + 1, Integer.parseInt(String.valueOf(list.get(i))));
break;
case "amount":
series.add(i + 1, Double.parseDouble(String.valueOf(list.get(i))));
break;
default:
break;
}
}
}
dataset.addSeries(series);
}
StandardChartTheme sct = new StandardChartTheme("CN");
sct.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
sct.setRegularFont(new Font("隶书", Font.BOLD, 20));
sct.setLargeFont(new Font("隶书", Font.BOLD, 20));
ChartFactory.setChartTheme(sct);
return ChartFactory.createXYLineChart(
title, // 图表标题
"月份", // x轴标签
yLabel, // y轴标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向
true, // 是否显示图例
true, // 是否生成工具提示
false // 是否生成URL链接
);
}
private JFreeChart createPieChart(List<Map<String, Object>> list, String title, String type) {
StandardChartTheme sct = new StandardChartTheme("CN");
sct.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
sct.setRegularFont(new Font("隶书", Font.BOLD, 20));
sct.setLargeFont(new Font("隶书", Font.BOLD, 20));
ChartFactory.setChartTheme(sct);
DefaultPieDataset dataset = new DefaultPieDataset();
for (Map<String, Object> map : list) {
switch (type) {
case "num":
dataset.setValue(String.valueOf(map.get("type")), Integer.parseInt(String.valueOf(map.get("num"))));
break;
case "amount":
dataset.setValue(String.valueOf(map.get("type")), Double.parseDouble(String.valueOf(map.get("amount"))));
break;
default:
break;
}
}
return ChartFactory.createPieChart(title, dataset,
true, true, true);
}
}

View File

@ -119,4 +119,8 @@ public class OmConstant {
*/ */
public static final String PLAN_STATUS_COMPLETE_OPERATION="4"; public static final String PLAN_STATUS_COMPLETE_OPERATION="4";
/**
* 月份列表
*/
public static final String [] MONTH_ARRAY =new String[] {"1","2","3","4","5","6","7","8","9","10","11","12"};
} }

View File

@ -0,0 +1,42 @@
<?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.inspur.order.mapper.OmOrderAnalysisMapper">
<select id="selectCountAndAmount" resultType="map" parameterType="string">
SELECT COUNT(0) totalNum,
IFNULL(ROUND(SUM(service_fees), 2), 0) totalAmount,
(SELECT COUNT(0) FROM `sys_user` WHERE tenant_id = #{tenantId} AND del_flag = '0') totalPerson
FROM `om_order_quotation`
WHERE tenant_id = #{tenantId}
</select>
<select id="selectCountAndAmountByType" resultType="map" parameterType="string">
SELECT d.dict_label type,
IFNULL(s.num, 0) num,
ROUND(IFNULL(s.amount, 0), 2) amount
FROM (SELECT dict_label, dict_value FROM `sys_dict_data` WHERE dict_type = 'om_business_type') d
LEFT JOIN (
SELECT i.business_type,
COUNT(0) num,
SUM(q.service_fees) amount
FROM (SELECT *
FROM `om_order_quotation`
WHERE tenant_id = #{tenantId} AND YEAR (create_time) = YEAR (SYSDATE())) q
LEFT JOIN `om_order_info` i ON q.order_id = i.order_id
GROUP BY i.business_type ) s
ON d.dict_value = s.business_type
</select>
<select id="selectCountAndAmountByDate" resultType="map" parameterType="string">
SELECT DATE_FORMAT(create_time, '%Y-%m') AS date_year_month,
COUNT(0) num,
(YEAR (create_time)) AS date_year,
(MONTH (create_time)) AS date_month,
ROUND(SUM(service_fees), 2) amount
FROM `om_order_quotation`
WHERE tenant_id = #{tenantId}
AND (YEAR (create_time))
> (YEAR (SYSDATE()) - 3)
GROUP BY date_year_month
</select>
</mapper>

View File

@ -0,0 +1,9 @@
import request from "@/utils/request";
// 分析数据查询
export function getData() {
return request({
url: "/order/analysis/orderDataAnalysis",
method: "get",
});
}

File diff suppressed because it is too large Load Diff

View File

@ -270,7 +270,7 @@
<span>{{ parseTime(scope.row.serviceEndTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span> <span>{{ parseTime(scope.row.serviceEndTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <!-- <el-table-column
show-overflow-tooltip show-overflow-tooltip
label="状态" label="状态"
align="center" align="center"
@ -282,7 +282,7 @@
:value="scope.row.status" :value="scope.row.status"
/> />
</template> </template>
</el-table-column> </el-table-column> -->
<el-table-column <el-table-column
label="操作" label="操作"
align="center" align="center"

View File

@ -102,7 +102,7 @@
:gutter="10" :gutter="10"
class="mb8" class="mb8"
> >
<el-col :span="1.5"> <!-- <el-col :span="1.5">
<el-button <el-button
type="primary" type="primary"
plain plain
@ -111,7 +111,7 @@
@click="handleAdd" @click="handleAdd"
v-hasPermi="['order:info:add']" v-hasPermi="['order:info:add']"
>新增</el-button> >新增</el-button>
</el-col> </el-col> -->
<!-- <el-col :span="1.5"> <!-- <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"