班组管理
This commit is contained in:
parent
6b14a697e2
commit
4e67f58655
|
|
@ -17,4 +17,10 @@ public class ParamDto {
|
|||
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "班组名称")
|
||||
private String teamName;
|
||||
|
||||
@ApiModelProperty(value = "班组长")
|
||||
private String teamLeader;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,44 @@
|
|||
<groupId>com.securitycontrol</groupId>
|
||||
<artifactId>securitycontrol-commons-entity</artifactId>
|
||||
</dependency>
|
||||
<!-- easypoi相关的jar包 -->
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-base</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-web</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-annotation</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>20.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.30</version>
|
||||
<!-- <scope>provided</scope>-->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package com.securitycontrol.background.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import com.securitycontrol.background.export.entity.TeamExportVo;
|
||||
import com.securitycontrol.background.export.util.ExcelStyleUtil;
|
||||
import com.securitycontrol.background.service.TeamService;
|
||||
import com.securitycontrol.common.log.annotation.Log;
|
||||
import com.securitycontrol.common.log.enums.OperationType;
|
||||
import com.securitycontrol.entity.background.dto.ParamDto;
|
||||
import com.securitycontrol.entity.background.vo.TeamManageVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-03-11-14:55
|
||||
* @version:1.0
|
||||
* @description:导出文件-web层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/back/export/")
|
||||
@Slf4j
|
||||
public class ExportFileController {
|
||||
|
||||
@Resource(name = "TeamService")
|
||||
private TeamService service;
|
||||
|
||||
@GetMapping("exportTeamData")
|
||||
@Log(title = "人车管理", menu = "人车管理->班组管理", grade = OperationType.EXPORT_BUSINESS, details = "导出班组", type = "业务日志")
|
||||
public void exportData(HttpServletRequest request, HttpServletResponse response, ParamDto dto) {
|
||||
try {
|
||||
List<TeamExportVo> teamExportVoList = new ArrayList<>();
|
||||
List<TeamManageVo> teamLists = service.getTeamLists(dto);
|
||||
for (int i = 0; i < teamLists.size(); i++) {
|
||||
teamLists.get(i).setTeamId((i + 1) + "");
|
||||
TeamExportVo exportVo = new TeamExportVo();
|
||||
BeanUtils.copyProperties(teamLists.get(i), exportVo);
|
||||
teamExportVoList.add(exportVo);
|
||||
}
|
||||
ExportParams exportParams = new ExportParams("班组列表", "班组列表", ExcelType.XSSF);
|
||||
exportParams.setStyle(ExcelStyleUtil.class);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, TeamExportVo.class, teamExportVoList);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("班组列表" + ".xlsx", "UTF-8"));
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
workbook.close();
|
||||
} catch (Exception e) {
|
||||
log.error("导出班组", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.securitycontrol.background.export.entity;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-03-12-14:21
|
||||
* @version:1.0
|
||||
* @description:班组导出-vo
|
||||
*/
|
||||
@Data
|
||||
public class TeamExportVo {
|
||||
|
||||
@Excel(name = "序号", width = 10.0, orderNum = "0")
|
||||
private String teamId;
|
||||
|
||||
@Excel(name = "所属工程", width = 20.0, orderNum = "1")
|
||||
private String proName;
|
||||
|
||||
@Excel(name = "班组名称", width = 20.0, orderNum = "2")
|
||||
private String teamName;
|
||||
|
||||
@Excel(name = "班组长", width = 20.0, orderNum = "3")
|
||||
private String teamLeader;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
package com.securitycontrol.background.export.util;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
|
||||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
/**
|
||||
* @author 10488
|
||||
* @Auther: ccw
|
||||
* @Date: 2022/05/12/16:22
|
||||
* @description: easypoi 导出表格样式
|
||||
*/
|
||||
public class ExcelStyleUtil implements IExcelExportStyler {
|
||||
private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT");
|
||||
private static final short FONT_SIZE_TEN = 10;
|
||||
private static final short FONT_SIZE_ELEVEN = 11;
|
||||
private static final short FONT_SIZE_TWELVE = 12;
|
||||
|
||||
/**
|
||||
* 大标题样式
|
||||
*/
|
||||
private CellStyle headerStyle;
|
||||
|
||||
/**
|
||||
* 每列标题样式
|
||||
*/
|
||||
private CellStyle titleStyle;
|
||||
|
||||
/**
|
||||
* 数据行样式
|
||||
*/
|
||||
private CellStyle styles;
|
||||
|
||||
public ExcelStyleUtil(Workbook workbook) {
|
||||
this.init(workbook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化样式
|
||||
*
|
||||
* @param workbook
|
||||
*/
|
||||
private void init(Workbook workbook) {
|
||||
this.headerStyle = initHeaderStyle(workbook);
|
||||
this.titleStyle = initTitleStyle(workbook);
|
||||
this.styles = initStyles(workbook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大标题样式
|
||||
*
|
||||
* @param color
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public CellStyle getHeaderStyle(short color) {
|
||||
return headerStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每列标题样式
|
||||
*
|
||||
* @param color
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public CellStyle getTitleStyle(short color) {
|
||||
return titleStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据行样式
|
||||
*
|
||||
* @param parity 可以用来表示奇偶行
|
||||
* @param entity 数据内容
|
||||
* @return 样式
|
||||
*/
|
||||
|
||||
@Override
|
||||
|
||||
public CellStyle getStyles(boolean parity, ExcelExportEntity entity) {
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取样式方法
|
||||
*
|
||||
* @param dataRow 数据行
|
||||
* @param obj 对象
|
||||
* @param data 数据
|
||||
*/
|
||||
|
||||
@Override
|
||||
|
||||
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) {
|
||||
return getStyles(true, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板使用的样式设置
|
||||
*/
|
||||
|
||||
@Override
|
||||
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化--大标题样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
|
||||
private CellStyle initHeaderStyle(Workbook workbook) {
|
||||
CellStyle style = getBaseCellStyle(workbook);
|
||||
style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true));
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化--每列标题样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
|
||||
private CellStyle initTitleStyle(Workbook workbook) {
|
||||
CellStyle style = getBaseCellStyle(workbook);
|
||||
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
|
||||
//背景色
|
||||
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
return style;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化--数据行样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
private CellStyle initStyles(Workbook workbook) {
|
||||
CellStyle style = getBaseCellStyle(workbook);
|
||||
style.setFont(getFont(workbook, FONT_SIZE_TEN, false));
|
||||
style.setDataFormat(STRING_FORMAT);
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础样式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
private CellStyle getBaseCellStyle(Workbook workbook) {
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
//下边框
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
//左边框
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
//上边框
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
//右边框
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
//水平居中
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
//上下居中
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
//设置自动换行
|
||||
style.setWrapText(true);
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字体样式
|
||||
*
|
||||
* @param size 字体大小
|
||||
* @param isBold 是否加粗
|
||||
* @return
|
||||
*/
|
||||
|
||||
private Font getFont(Workbook workbook, short size, boolean isBold) {
|
||||
Font font = workbook.createFont();
|
||||
//字体样式
|
||||
font.setFontName("宋体");
|
||||
//是否加粗
|
||||
font.setBold(isBold);
|
||||
//字体大小
|
||||
font.setFontHeightInPoints(size);
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,10 +57,11 @@
|
|||
FROM tb_work_team twt
|
||||
LEFT JOIN tb_project tp on twt.bid_code = tp.bid_code
|
||||
<where>
|
||||
<if test="keyWord !=null and keyWord!=''">
|
||||
AND (
|
||||
INSTR(twt.team_leader,#{keyWord}) > 0
|
||||
)
|
||||
<if test="teamName !=null and teamName!=''">
|
||||
AND INSTR(twt.team_name,#{teamName}) > 0
|
||||
</if>
|
||||
<if test="teamLeader !=null and teamLeader!=''">
|
||||
AND INSTR(twt.team_leader,#{teamLeader}) > 0
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue