diff --git a/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/controller/DownloadController.java b/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/controller/DownloadController.java new file mode 100644 index 0000000..217f70d --- /dev/null +++ b/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/controller/DownloadController.java @@ -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 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 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 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); + } + +} diff --git a/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/domain/vo/BmWorkerContract.java b/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/domain/vo/BmWorkerContract.java index 00246a7..5a19d70 100644 --- a/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/domain/vo/BmWorkerContract.java +++ b/bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/domain/vo/BmWorkerContract.java @@ -142,4 +142,8 @@ public class BmWorkerContract { private List files; + private Integer proId; + private Integer teamId; + private Integer subId; + } \ No newline at end of file diff --git a/bonus-modules/bonus-bmw/src/main/resources/mapper/bmw/BmWorkerContractMapper.xml b/bonus-modules/bonus-bmw/src/main/resources/mapper/bmw/BmWorkerContractMapper.xml index b86db77..950b6f6 100644 --- a/bonus-modules/bonus-bmw/src/main/resources/mapper/bmw/BmWorkerContractMapper.xml +++ b/bonus-modules/bonus-bmw/src/main/resources/mapper/bmw/BmWorkerContractMapper.xml @@ -2,8 +2,6 @@ - - @@ -20,22 +18,18 @@ + + + - - - - 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 - + - update bm_worker_contract set is_active = 0 where id = #{id} @@ -46,8 +40,7 @@ - - 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_invalid_date, create_user) values (#{workerId}, #{contractCode}, #{contractTermType}, #{contractStartDate}, @@ -79,14 +72,14 @@ AND pw.id_number LIKE CONCAT('%', #{idNumber}, '%') - - AND bwem.pro_name LIKE CONCAT('%', #{proName}, '%') + + AND bwem.pro_id = #{proId} - - AND bwem.team_name LIKE CONCAT('%', #{teamName}, '%') + + AND bwem.team_id = #{teamId} - - AND bwem.sub_name LIKE CONCAT('%', #{subName}, '%') + + AND bwem.sub_id = #{subId} AND bwc.contract_code LIKE CONCAT('%', #{contractCode}, '%') diff --git a/bonus-modules/bonus-bmw/src/main/resources/templates/人员入场-模版.xlsx b/bonus-modules/bonus-bmw/src/main/resources/templates/人员入场-模版.xlsx new file mode 100644 index 0000000..a766b69 Binary files /dev/null and b/bonus-modules/bonus-bmw/src/main/resources/templates/人员入场-模版.xlsx differ diff --git a/bonus-modules/bonus-bmw/src/main/resources/templates/失信人员-模板.xlsx b/bonus-modules/bonus-bmw/src/main/resources/templates/失信人员-模板.xlsx new file mode 100644 index 0000000..fa4a54e Binary files /dev/null and b/bonus-modules/bonus-bmw/src/main/resources/templates/失信人员-模板.xlsx differ