1.模版下载功能添加
This commit is contained in:
parent
23a62f8992
commit
ad20e3b8b1
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.bonus.bmw.controller;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.web.util.UriUtils;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公用模版下载
|
||||||
|
* @author fly
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/download")
|
||||||
|
@Slf4j
|
||||||
|
public class DownloadController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载人员入场模版
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/workerEinTemplate")
|
||||||
|
public ResponseEntity<Resource> workerEinTemplate(HttpServletRequest request) throws IOException {
|
||||||
|
Resource resource = new ClassPathResource("templates/人员入场-模板.xlsx");
|
||||||
|
if (!resource.exists()) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
String filename = "人员入场-模板.xlsx";
|
||||||
|
return getResponseEntity(request, filename, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载人员黑名单模版
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/workerBlackTemplate")
|
||||||
|
public ResponseEntity<Resource> workerBlackTemplate(HttpServletRequest request) throws IOException {
|
||||||
|
Resource resource = new ClassPathResource("templates/失信人员-模板.xlsx");
|
||||||
|
if (!resource.exists()) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
String filename = "失信人员-模板.xlsx";
|
||||||
|
// 兼容方案:提供 fallback 文件名(如 ASCII)
|
||||||
|
return getResponseEntity(request, filename, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResponseEntity<Resource> getResponseEntity(HttpServletRequest request, String filename, Resource resource) throws UnsupportedEncodingException {
|
||||||
|
// 兼容方案:提供 fallback 文件名(如 ASCII)
|
||||||
|
String userAgent = request.getHeader("User-Agent");
|
||||||
|
String encodedFilename;
|
||||||
|
|
||||||
|
if (userAgent != null && userAgent.contains("MSIE") || Objects.requireNonNull(userAgent).contains("Trident")) {
|
||||||
|
// IE 浏览器使用 URL 编码
|
||||||
|
encodedFilename = "filename=" + URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
|
||||||
|
} else {
|
||||||
|
// 其他浏览器使用 RFC 6266
|
||||||
|
encodedFilename = "filename*=UTF-8''" + UriUtils.encode(filename, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; " + encodedFilename)
|
||||||
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -142,4 +142,8 @@ public class BmWorkerContract {
|
||||||
|
|
||||||
private List<UploadFileVo> files;
|
private List<UploadFileVo> files;
|
||||||
|
|
||||||
|
private Integer proId;
|
||||||
|
private Integer teamId;
|
||||||
|
private Integer subId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.bonus.bmw.mapper.BmWorkerContractMapper">
|
<mapper namespace="com.bonus.bmw.mapper.BmWorkerContractMapper">
|
||||||
<resultMap id="BaseResultMap" type="com.bonus.bmw.domain.vo.BmWorkerContract">
|
<resultMap id="BaseResultMap" type="com.bonus.bmw.domain.vo.BmWorkerContract">
|
||||||
<!--@mbg.generated-->
|
|
||||||
<!--@Table bm_worker_contract-->
|
|
||||||
<id column="id" property="id" />
|
<id column="id" property="id" />
|
||||||
<result column="worker_id" property="workerId" />
|
<result column="worker_id" property="workerId" />
|
||||||
<result column="contract_code" property="contractCode" />
|
<result column="contract_code" property="contractCode" />
|
||||||
|
|
@ -20,22 +18,18 @@
|
||||||
<result column="pro_name" property="proName" />
|
<result column="pro_name" property="proName" />
|
||||||
<result column="team_name" property="teamName" />
|
<result column="team_name" property="teamName" />
|
||||||
<result column="sub_name" property="subName" />
|
<result column="sub_name" property="subName" />
|
||||||
|
<result column="pro_Id" property="proId" />
|
||||||
|
<result column="team_id" property="teamId" />
|
||||||
|
<result column="sub_id" property="subId" />
|
||||||
<result column="name" property="name" />
|
<result column="name" property="name" />
|
||||||
<result column="id_number" property="idNumber" />
|
<result column="id_number" property="idNumber" />
|
||||||
<result column="isSign" property="isSign" />
|
<result column="isSign" property="isSign" />
|
||||||
<result column="is_active" property="isActive" />
|
<result column="is_active" property="isActive" />
|
||||||
<result column="einStatus" property="einStatus" />
|
<result column="einStatus" property="einStatus" />
|
||||||
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
|
||||||
<!--@mbg.generated-->
|
|
||||||
id, worker_id, contract_code, contract_term_type, contract_start_date, contract_stop_date,
|
|
||||||
wage_approved_way, wage_criterion, day_rate, contract_upload_date, contract_invalid_date,
|
|
||||||
create_user, update_user
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||||
<!--@mbg.generated-->
|
|
||||||
update bm_worker_contract set is_active = 0
|
update bm_worker_contract set is_active = 0
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
@ -46,7 +40,6 @@
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.bonus.bmw.domain.vo.BmWorkerContract" useGeneratedKeys="true">
|
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.bonus.bmw.domain.vo.BmWorkerContract" useGeneratedKeys="true">
|
||||||
<!--@mbg.generated-->
|
|
||||||
insert into bm_worker_contract (worker_id, contract_code, contract_term_type, contract_start_date,
|
insert into bm_worker_contract (worker_id, contract_code, contract_term_type, contract_start_date,
|
||||||
contract_stop_date, wage_approved_way, wage_criterion, day_rate, contract_upload_date,
|
contract_stop_date, wage_approved_way, wage_criterion, day_rate, contract_upload_date,
|
||||||
contract_invalid_date, create_user)
|
contract_invalid_date, create_user)
|
||||||
|
|
@ -79,14 +72,14 @@
|
||||||
<if test="idNumber != null">
|
<if test="idNumber != null">
|
||||||
AND pw.id_number LIKE CONCAT('%', #{idNumber}, '%')
|
AND pw.id_number LIKE CONCAT('%', #{idNumber}, '%')
|
||||||
</if>
|
</if>
|
||||||
<if test="proName != null">
|
<if test="proId != null">
|
||||||
AND bwem.pro_name LIKE CONCAT('%', #{proName}, '%')
|
AND bwem.pro_id = #{proId}
|
||||||
</if>
|
</if>
|
||||||
<if test="teamName != null">
|
<if test="teamId != null">
|
||||||
AND bwem.team_name LIKE CONCAT('%', #{teamName}, '%')
|
AND bwem.team_id = #{teamId}
|
||||||
</if>
|
</if>
|
||||||
<if test="subName != null">
|
<if test="subId != null">
|
||||||
AND bwem.sub_name LIKE CONCAT('%', #{subName}, '%')
|
AND bwem.sub_id = #{subId}
|
||||||
</if>
|
</if>
|
||||||
<if test="contractCode != null">
|
<if test="contractCode != null">
|
||||||
AND bwc.contract_code LIKE CONCAT('%', #{contractCode}, '%')
|
AND bwc.contract_code LIKE CONCAT('%', #{contractCode}, '%')
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue