Commit 7269d153 authored by xinglei's avatar xinglei

*)修改业务导出bug

parent 9d972b38
......@@ -364,8 +364,6 @@ public class PlanTaskController extends BaseController {
Point point = pointService.queryPointById(pointId);
List<PointInputItemVo> inputItems = pointService.queryPointClassInputItem(pointId);
Point2 point1= new Point2();
point1.setId(point.getId());
point1.setCatalogId(point.getCatalogId());
......@@ -400,15 +398,6 @@ public class PlanTaskController extends BaseController {
point1.setChargeDeptId(point.getChargeDeptId()) ;
point1.setChargePersonId(point.getChargePersonId()) ;
response.put("checkItem", inputItems);
List<PointClassify> catalogs = new ArrayList<>();
catalogs = pointService.queryPointClassify(pointId);
......@@ -440,7 +429,6 @@ public class PlanTaskController extends BaseController {
} catch (Exception e) {
return CommonResponseUtil.failure(e.getMessage());
}
}
/**
......
......@@ -27,6 +27,7 @@ import com.yeejoin.amos.patrol.service.business.vo.CheckInfoVo;
import com.yeejoin.amos.patrol.service.constants.XJConstant;
import com.yeejoin.amos.patrol.service.core.async.AsyncTask;
import com.yeejoin.amos.patrol.service.core.util.DateUtil;
import com.yeejoin.amos.patrol.service.core.util.PoiUtil;
import com.yeejoin.amos.patrol.service.core.util.ReflectUtil;
import com.yeejoin.amos.patrol.service.core.util.StringUtil;
import com.yeejoin.amos.patrol.service.remote.RemoteSecurityService;
......@@ -35,9 +36,7 @@ import net.sf.json.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -49,8 +48,6 @@ import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -1080,7 +1077,7 @@ public class CheckServiceImpl implements ICheckService {
String dep = "";
Set<String> set = new HashSet<>();
checkAnalysisVos.forEach(s -> {
if (!ObjectUtils.isEmpty(s.getName())){
if (!ObjectUtils.isEmpty(s.getName())) {
set.add(s.getName().toString());
}
});
......@@ -1088,16 +1085,17 @@ public class CheckServiceImpl implements ICheckService {
List<String> list1 = new ArrayList<>(set);
dep = String.join(",", list1);
List<LinkedHashMap> listd = remoteSecurityService.listDepartmentByDeptIds(toke, product, appKey, dep);
//新安全
checkAnalysisVos.forEach(s -> {
listd.forEach(s1 -> {
if (!ObjectUtils.isEmpty(s.getName()) && s.getName().equals(s1.get("sequenceNbr"))) {
s.setName(DeptEnum.getEnumCode(s1.get("departmentName") + ""));
}
if (!ObjectUtils.isEmpty(dep)) {
List<LinkedHashMap> listd = remoteSecurityService.listDepartmentByDeptIds(toke, product, appKey, dep);
//新安全
checkAnalysisVos.forEach(s -> {
listd.forEach(s1 -> {
if (!ObjectUtils.isEmpty(s.getName()) && s.getName().equals(s1.get("sequenceNbr"))) {
s.setName(DeptEnum.getEnumCode(s1.get("departmentName") + ""));
}
});
});
});
}
List<Map<String, Object>> result = getResult(treeBos, checkAnalysisVos, dayByMonth);
String[] split = param.getQueryMonth().split("-");
......@@ -1192,57 +1190,10 @@ public class CheckServiceImpl implements ICheckService {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(template);
//表头字体
Font headerFont = wb.createFont();
headerFont.setFontName("微软雅黑");
headerFont.setFontHeightInPoints((short) 14);
headerFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
headerFont.setColor(HSSFColor.BLACK.index);
//正文字体
Font contextFont = wb.createFont();
contextFont.setFontName("微软雅黑");
contextFont.setFontHeightInPoints((short) 10);
contextFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
contextFont.setColor(HSSFColor.BLACK.index);
//表头样式,左右上下居中
CellStyle headerStyle = wb.createCellStyle();
headerStyle.setFont(headerFont);
headerStyle.setAlignment(CellStyle.ALIGN_CENTER);// 左右居中
headerStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 上下居中
headerStyle.setLocked(true);
headerStyle.setWrapText(false);// 自动换行
headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
//内容样式
CellStyle contentStyle = wb.createCellStyle();
contentStyle.setFont(contextFont);
contentStyle.setAlignment(CellStyle.ALIGN_CENTER);// 左右居中
contentStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 上下居中
contentStyle.setLocked(true);
contentStyle.setWrapText(false);// 自动换行
contentStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
contentStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
contentStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
contentStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
//内容样式左对齐
CellStyle alignLeftStyle = wb.createCellStyle();
alignLeftStyle.setFont(contextFont);
alignLeftStyle.setAlignment(CellStyle.ALIGN_LEFT);// 左对齐
alignLeftStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 上下居中
alignLeftStyle.setLocked(true);
alignLeftStyle.setWrapText(false);// 自动换行
alignLeftStyle.setAlignment(CellStyle.ALIGN_LEFT);// 左对齐
alignLeftStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
alignLeftStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
alignLeftStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
alignLeftStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
PoiUtil.wb = wb;
CellStyle headerStyle = PoiUtil.setStyle(PoiUtil.setFont(14), CellStyle.ALIGN_CENTER);
CellStyle contentStyle = PoiUtil.setStyle(PoiUtil.setFont(10), CellStyle.ALIGN_CENTER);
CellStyle alignLeftStyle = PoiUtil.setStyle(PoiUtil.setFont(10), CellStyle.ALIGN_LEFT);
// 行号
int rowNum = 0;
......@@ -1272,18 +1223,10 @@ public class CheckServiceImpl implements ICheckService {
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, mergeNum));
//第一行
HSSFRow head = sheet.createRow(rowNum++);
head.setHeightInPoints(30);
HSSFCell hssfCell = head.createCell(0);
hssfCell.setCellValue(String.format("%s %s 每日巡检情况表", companyName, linkMap.get("departmentName").toString()));
hssfCell.setCellStyle(headerStyle);
String title = String.format("%s %s 每日巡检情况表", companyName, linkMap.get("departmentName").toString());
PoiUtil.setTitleValue(sheet.createRow(rowNum++), title, headerStyle);
//第二行
HSSFRow nextHead = sheet.createRow(rowNum++);
nextHead.setHeightInPoints(30);
HSSFCell nextHssfCell = nextHead.createCell(0);
nextHssfCell.setCellValue("巡检人:____________ 日期: 年___月___日至___日");
nextHssfCell.setCellStyle(headerStyle);
PoiUtil.setTitleValue(sheet.createRow(rowNum++), "巡检人:____________ 日期: ___年___月___日至___日", headerStyle);
HSSFRow row = sheet.createRow(rowNum++);
HSSFCell cell = null;
......@@ -1300,16 +1243,10 @@ public class CheckServiceImpl implements ICheckService {
setRow(checkInfoList, sheet, contentStyle, alignLeftStyle);
}
try {
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
PoiUtil.export(wb, response);
}
private Map<String, Object> getStateMap(String idState){
private Map<String, Object> getStateMap(String idState) {
Map<String, Object> idStateMap = Maps.newHashMap();
String[] split = idState.split(",");
for (int i = 0; i < split.length; i++) {
......@@ -1415,7 +1352,7 @@ public class CheckServiceImpl implements ICheckService {
}
row = sheet.createRow(i + 3);
HSSFCell cell = row.createCell(0);
if (ObjectUtils.isEmpty(checkInfoList.get(i).getBeginTime())){
if (ObjectUtils.isEmpty(checkInfoList.get(i).getBeginTime())) {
cell.setCellValue(DateUtil.splitDate(checkInfoList.get(i).getCheckDate()));
} else {
cell.setCellValue(DateUtil.splitDate(checkInfoList.get(i).getBeginTime()));
......
......@@ -23,7 +23,6 @@ public class PointInputItemVo extends InputItem {
private Long routePointItemId;
public String getClassifyIds() {
return classifyIds;
}
......
package com.yeejoin.amos.patrol.service.core.util;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* @Author: xinglei
* @Description:
* @Date: 2020/8/23 17:22
*/
public class PoiUtil {
public static HSSFWorkbook wb;
/**
* 设置标题字体
*/
public static Font setFont(int num) {
Font font = wb.createFont();
font.setFontName("微软雅黑");
font.setFontHeightInPoints((short) num);
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
font.setColor(HSSFColor.BLACK.index);
return font;
}
/**
* 设置标题样式
*/
public static CellStyle setStyle(Font font, short alignCenter) {
CellStyle style = wb.createCellStyle();
style.setFont(font);
style.setAlignment(alignCenter);// 左右居中
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 上下居中
style.setLocked(true);
style.setWrapText(false);// 自动换行
style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
return style;
}
/**
* 设置标题内容
*/
public static void setTitleValue(HSSFRow head, String title, CellStyle style) {
head.setHeightInPoints(30);
HSSFCell hssfCell = head.createCell(0);
hssfCell.setCellValue(title);
hssfCell.setCellStyle(style);
}
/**
* 导出(前端导出,不带文件名)
*/
public static void export( HSSFWorkbook wb, HttpServletResponse response) {
OutputStream out = null;
try {
out = response.getOutputStream();
wb.write(out);
out.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e2) {
}
}
}
}
/**
* 导出(本地导出,测试用)
*/
public static void exportLocal(HSSFWorkbook wb, String path, String name) {
try {
File file = new File(path);
OutputStream stream = new FileOutputStream(new File(file, name));
wb.write(stream);
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -210,7 +210,7 @@
<if test="orgCode!=null">and c.org_Code like concat(#{orgCode},"%")</if>
<if test="departmentId!=null">and c.dep_id = #{departmentId}</if>
</trim>
GROUP BY inputId, classifyId
GROUP BY inputId, classifyId, beginTime
ORDER BY
checkDate ASC, pointId ASC, classifyId ASC
</when>
......@@ -1832,90 +1832,167 @@
</select>
<select id="getCheckStatisticalByCheck" resultType="com.yeejoin.amos.patrol.service.business.vo.CheckAnalysisVo">
select
a.deptName name,
count(a.checkId) planTaskCount,
sum(a.finish ) checkCount,
sum(a.ok) ok,
sum(a.faild) faild,
sum(a.missed) missed,
sum(a.score) score,
sum(a.missed) / count(a.checkId) * 100 missedRate,
sum(a.faild) / count(a.checkId) * 100 faildRate,
a.checkTime
<!-- select-->
<!-- a.deptName name,-->
<!-- count(a.checkId) planTaskCount,-->
<!-- sum(a.finish ) checkCount,-->
<!-- sum(a.ok) ok,-->
<!-- sum(a.faild) faild,-->
<!-- sum(a.missed) missed,-->
<!-- sum(a.score) score,-->
<!-- sum(a.missed) / count(a.checkId) * 100 missedRate,-->
<!-- sum(a.faild) / count(a.checkId) * 100 faildRate,-->
<!-- a.checkTime-->
<!-- FROM-->
<!-- (-->
<!-- SELECT-->
<!-- CASE-->
<!-- WHEN c.plan_id = 0 THEN-->
<!-- '计划外'-->
<!-- ELSE-->
<!-- p. NAME-->
<!-- END planName,-->
<!-- c.plan_id planId,-->
<!-- r. NAME routeName,-->
<!-- r.id routeId,-->
<!-- pt. NAME pointName,-->
<!-- pt.id pointId,-->
<!-- c.user_id userId,-->
<!-- c.score,-->
<!-- c.dep_id departmentId,-->
<!-- c.dep_id deptName ,-->
<!-- c.user_id userName ,-->
<!-- c.id checkId,-->
<!-- c.plan_task_detail_id taskDetailId,-->
<!-- c.is_ok isOk,-->
<!-- c.plan_task_id,-->
<!-- DATE_FORMAT(c.check_time,'%Y-%m-%d') checkTime,-->
<!-- DATE_FORMAT(c.check_time,'%Y-%m') checkMonth,-->
<!-- CASE-->
<!-- WHEN c.is_ok = 1 THEN-->
<!-- 1-->
<!-- ELSE-->
<!-- 0-->
<!-- END ok,-->
<!-- CASE-->
<!-- WHEN c.is_ok = 2 THEN-->
<!-- 1-->
<!-- ELSE-->
<!-- 0-->
<!-- END faild,-->
<!-- CASE-->
<!-- WHEN c.is_ok = 3 THEN-->
<!-- 1-->
<!-- ELSE-->
<!-- 0-->
<!-- END missed,-->
<!-- CASE-->
<!-- WHEN c.is_ok = 3 THEN-->
<!-- 0-->
<!-- ELSE-->
<!-- 1-->
<!-- END finish-->
<!-- FROM-->
<!-- p_check c-->
<!-- LEFT JOIN p_plan p ON c.plan_id = p.id-->
<!-- LEFT JOIN p_plan_task pnt ON c.plan_task_id = pnt.id-->
<!-- LEFT JOIN p_route r ON c.route_id = r.id-->
<!-- LEFT JOIN p_point pt ON c.point_id = pt.id-->
<!-- WHERE c.org_code LIKE CONCAT(#{orgCode}, '%')-->
<!-- <if test="userName !=null and userName != '' ">and c.user_name like CONCAT('%', #{userName}, '%')</if>-->
<!-- <if test="pointNo !=null and pointNo != '' ">and pt.point_no like CONCAT('%', #{pointNo}, '%')</if>-->
<!-- <if test="pointName !=null and pointName != '' ">and pt.name like CONCAT('%', #{pointName}, '%')</if>-->
<!-- <if test="isFixed !=null and isFixed != '' ">and pt.is_fixed = #{isFixed}</if>-->
<!-- <choose>-->
<!-- <when test=" processType > 0 and processType == 4 ">-->
<!-- and <![CDATA[ c.plan_id = 0 ]]>-->
<!-- </when>-->
<!-- <when test="processType > 0 and processType != 4 ">-->
<!-- and pnt.status = #{processType}-->
<!-- </when>-->
<!-- </choose>-->
<!-- <if test="isOk !=null and isOk != '' ">and c.isOk = #{isOk}</if>-->
<!-- <if test="planId !=null and planId != '' ">and c.plan_id = #{planId}</if>-->
<!-- <if test="routeId !=null and routeId != '' ">and c.route_id = #{routeId}</if>-->
<!-- <if test="startTime !=null and startTime!= '' "> <![CDATA[ AND c.check_time >= #{startTime} ]]> </if>-->
<!-- <if test="endTime !=null and endTime!='' "><![CDATA[AND c.check_time <= #{endTime} ]]></if>-->
<!-- ) a-->
<!-- GROUP BY-->
<!-- a.deptName,-->
<!-- a.checkTime-->
SELECT
a.deptName `name`,
sum(a.planTaskCount) planTaskCount,
sum(a.finish ) checkCount,
sum(a.ok) ok,
sum(a.faild) faild,
sum(a.missed) missed,
sum(a.score) score,
sum(a.missed) / count(a.checkId) * 100 missedRate,
sum(a.faild) / count(a.checkId) * 100 faildRate,
a.checkTime
FROM
(
SELECT
CASE
WHEN c.plan_id = 0 THEN
'计划外'
ELSE
p. NAME
END planName,
c.plan_id planId,
r. NAME routeName,
r.id routeId,
pt. NAME pointName,
pt.id pointId,
c.user_id userId,
c.score,
c.dep_id departmentId,
c.dep_id deptName ,
c.user_id userName ,
c.id checkId,
c.plan_task_detail_id taskDetailId,
c.is_ok isOk,
c.plan_task_id,
DATE_FORMAT(c.check_time,'%Y-%m-%d') checkTime,
DATE_FORMAT(c.check_time,'%Y-%m') checkMonth,
CASE
WHEN c.is_ok = 1 THEN
1
ELSE
0
END ok,
CASE
WHEN c.is_ok = 2 THEN
1
ELSE
0
END faild,
CASE
WHEN c.is_ok = 3 THEN
1
ELSE
0
END missed,
CASE
WHEN c.is_ok = 3 THEN
0
ELSE
1
END finish
CASE
WHEN c.plan_id = 0 THEN
'计划外'
ELSE
p.`name`
END planName,
c.plan_id planId,
r. NAME routeName,
r.id routeId,
pt. NAME pointName,
pt.id pointId,
c.user_id userId,
c.score,
(case when c.dep_id is not null then c.dep_id else r.dept_id end) as departmentId,
(case when c.dep_id is not null then c.dep_id else r.dept_id end) as deptName,
c.user_id userName,
pnt.id checkId,
c.plan_task_detail_id taskDetailId,
c.is_ok isOk,
c.plan_task_id,
DATE_FORMAT(pnt.check_date, '%Y-%m-%d') checkTime,
DATE_FORMAT(pnt.check_date, '%Y-%m') checkMonth,
count(pt.id) planTaskCount,
CASE
WHEN c.is_ok = 1 THEN
1
ELSE
0
END ok,
CASE
WHEN c.is_ok = 2 THEN
1
ELSE
0
END faild,
CASE
WHEN c.is_ok = 3 THEN
1
ELSE
0
END missed,
CASE
WHEN c.is_ok = 3 THEN
0
ELSE
1
END finish
FROM
p_check c
p_plan_task pnt
LEFT JOIN p_route r ON r.id = pnt.route_id
LEFT JOIN p_route_point prp ON prp.route_id = r.id
LEFT JOIN p_point pt ON pt.route_id = r.id
LEFT JOIN p_check c on c.plan_task_id = pnt.id
LEFT JOIN p_plan p ON c.plan_id = p.id
LEFT JOIN p_plan_task pnt ON c.plan_task_id = pnt.id
LEFT JOIN p_route r ON c.route_id = r.id
LEFT JOIN p_point pt ON c.point_id = pt.id
WHERE c.org_code LIKE CONCAT(#{orgCode}, '%')
<if test="userName !=null and userName != '' ">and c.user_name like CONCAT('%', #{userName}, '%')</if>
<if test="pointNo !=null and pointNo != '' ">and pt.point_no like CONCAT('%', #{pointNo}, '%')</if>
<if test="pointName !=null and pointName != '' ">and pt.name like CONCAT('%', #{pointName}, '%')</if>
<if test="isFixed !=null and isFixed != '' ">and pt.is_fixed = #{isFixed}</if>
<choose>
<when test=" processType > 0 and processType == 4 ">
and <![CDATA[ c.plan_id = 0 ]]>
</when>
<when test="processType > 0 and processType != 4 ">
and pnt.status = #{processType}
</when>
</choose>
<if test="isOk !=null and isOk != '' ">and c.isOk = #{isOk}</if>
<if test="planId !=null and planId != '' ">and c.plan_id = #{planId}</if>
<if test="routeId !=null and routeId != '' ">and c.route_id = #{routeId}</if>
<if test="startTime !=null and startTime!= '' "> <![CDATA[ AND c.check_time >= #{startTime} ]]> </if>
<if test="endTime !=null and endTime!='' "><![CDATA[AND c.check_time <= #{endTime} ]]></if>
WHERE pnt.org_code LIKE CONCAT(#{orgCode}, '%')
<if test="startTime !=null and startTime!= '' "> <![CDATA[ AND pnt.check_date >= #{startTime} ]]> </if>
<if test="endTime !=null and endTime!='' "><![CDATA[AND pnt.check_date <= #{endTime} ]]></if>
GROUP BY pnt.id, c.id
) a
GROUP BY
a.deptName,
......@@ -1967,10 +2044,10 @@
0
END missed,
CASE
WHEN pnt.finish_status = 3 THEN
0
ELSE
WHEN (pnt.finish_status = 1 or pnt.finish_status = 2) THEN
1
ELSE
0
END finish
FROM
p_plan_task pnt
......
......@@ -38,7 +38,28 @@
pc.id classifyIds,
pi.order_no pOrderNo,
pi.id AS pointItemId,
ii.*
pc.order_no as orderNo,
#ii.*
ii.id as id,
ii.org_code orgCode,
ii.name name,
ii.item_type itemType,
ii.is_must isMust,
ii.is_score isScore,
ii.default_value defaultValue,
ii.is_multiline isMultiline,
ii.catalog_id catalogId,
ii.input_json inputJson,
ii.data_json dataJson,
ii.remark remark,
ii.picture_json pictureJson,
ii.create_by createBy,
ii.create_date createDate,
ii.level level,
ii.item_no itemNo,
ii.basis_json basisJson,
ii.original_id originalId,
ii.risk_desc riskDesc
FROM
p_point_inputitem pi
LEFT JOIN p_input_item ii ON ii.id = pi.input_item_id
......@@ -47,6 +68,7 @@
1 = 1
<if test="pointId!=null">AND pi.point_id = #{pointId}</if>
ORDER BY
pc.order_no,
pi.order_no
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment