From d2008fc35a45ff00b0f37939a13b792ab12e8c6f Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期四, 21 十一月 2024 10:25:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/OrgDepartmentQueryController.java | 103 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 80 insertions(+), 23 deletions(-)
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/OrgDepartmentQueryController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/OrgDepartmentQueryController.java
index c7e9675..5b3a1bb 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/OrgDepartmentQueryController.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/OrgDepartmentQueryController.java
@@ -1,20 +1,31 @@
package com.vci.frameworkcore.controller;
+import com.vci.dto.OrgDepartmentDTO;
import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI;
-import com.vci.frameworkcore.model.dto.OrgDepartmentDTO;
-import com.vci.frameworkcore.pagemodel.OrgDepartmentVO;
+import com.vci.constant.FrameWorkLangCodeConstant;
+import com.vci.pagemodel.OrgDepartmentVO;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.*;
+import com.vci.starter.web.util.ControllerUtil;
+import com.vci.starter.web.util.LangBaseUtil;
+import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.util.Func;
-import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
import java.util.List;
/**
@@ -24,7 +35,6 @@
*/
@RestController
@RequestMapping("/departmentQueryController")
-@Slf4j
public class OrgDepartmentQueryController {
/**
@@ -32,6 +42,11 @@
*/
@Autowired
private OrgDeptQueryServiceI deptQueryService;
+
+ /**
+ * 鏃ュ織
+ */
+ private Logger logger = LoggerFactory.getLogger(getClass());
/**
* 閮ㄩ棬鐨勬爲褰㈠弬鐓э紝閮ㄩ棬绠$悊涔熺敤鐨勮繖涓煡璇㈡帴鍙�
@@ -46,9 +61,9 @@
return BaseResult.tree(deptTreeList);
}catch (Exception e) {
e.printStackTrace();
- String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
- log.error("閮ㄩ棬鏍戞煡璇㈡椂鍑虹幇閿欒锛屽師鍥狅細" + exceptionMessage);
- return BaseResult.fail("閮ㄩ棬鏍戞煡璇㈡椂鍑虹幇閿欒锛屽師鍥狅細" + e.getMessage());
+ String exceptionMessage = "閮ㄩ棬鏍戞煡璇㈡椂鍑虹幇閿欒锛屽師鍥狅細" + VciBaseUtil.getExceptionMessage(e);
+ logger.error(exceptionMessage);
+ return BaseResult.fail(exceptionMessage);
}
}
@@ -73,15 +88,15 @@
public BaseResult saveUsersDepts(String[] userOIds, String deptId){
//涓嶈兘鍚屾椂涓虹┖
if(Func.isEmpty(userOIds) && Func.isBlank(deptId)){
- return BaseResult.fail("瑙掕壊涓婚敭鍜岄儴闂ㄤ富閿紝鍙傛暟涓嶈兘鍚屾椂涓虹┖!");
+ return BaseResult.fail("鍙傛暟銆愮敤鎴蜂富閿�戝拰銆愰儴闂ㄤ富閿�戯紝涓嶈兘鍚屾椂涓虹┖!");
}
try {
return deptQueryService.saveUsersDept(userOIds,deptId) ? BaseResult.success("閮ㄩ棬鍒嗛厤鎴愬姛锛�"):BaseResult.fail("閮ㄩ棬鍒嗛厤澶辫触锛�");
}catch (Exception e){
e.printStackTrace();
- String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
- log.error("鍏宠仈鐨勯儴闂ㄦ椂鍑虹幇閿欒锛屽師鍥狅細" + exceptionMessage);
- return BaseResult.fail("鍏宠仈鐨勯儴闂ㄦ椂鍑虹幇閿欒锛屽師鍥狅細" + exceptionMessage);
+ String exceptionMessage = "鍏宠仈閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+ logger.error(exceptionMessage);
+ return BaseResult.fail(exceptionMessage);
}
}
@@ -91,15 +106,14 @@
* @return
*/
@RequestMapping(value = "/addDept",method = RequestMethod.POST)
- @VciUnCheckRight
public BaseResult addDept(@RequestBody OrgDepartmentDTO orgDepartmentDTO){
try {
return deptQueryService.addDept(orgDepartmentDTO) ? BaseResult.success("閮ㄩ棬娣诲姞鎴愬姛锛�"):BaseResult.fail("閮ㄩ棬娣诲姞澶辫触锛�");
}catch (Exception e){
e.printStackTrace();
- String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
- log.error("娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
- return BaseResult.fail("娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
+ String exceptionMessage = "娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+ logger.error(exceptionMessage);
+ return BaseResult.fail(exceptionMessage);
}
}
@@ -109,15 +123,14 @@
* @return
*/
@RequestMapping(value = "/updateDept",method = RequestMethod.PUT)
- @VciUnCheckRight
public BaseResult updateRole(@RequestBody OrgDepartmentDTO orgDepartmentDTO){
try {
return deptQueryService.updateDept(orgDepartmentDTO) ? BaseResult.success("閮ㄩ棬淇敼鎴愬姛锛�"):BaseResult.fail("閮ㄩ棬淇敼澶辫触锛�");
}catch (Exception e){
e.printStackTrace();
- String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
- log.error("淇敼閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
- return BaseResult.fail("淇敼閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
+ String exceptionMessage = "淇敼閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+ logger.error(exceptionMessage);
+ return BaseResult.fail(exceptionMessage);
}
}
@@ -127,15 +140,59 @@
* @return
*/
@RequestMapping(value = "/deleteDept",method = RequestMethod.DELETE)
- @VciUnCheckRight
public BaseResult deleteDept(String[] ids){
try {
return deptQueryService.deleteDept(ids) ? BaseResult.success("鍒犻櫎閮ㄩ棬鎴愬姛锛�"):BaseResult.fail("鍒犻櫎閮ㄩ棬澶辫触锛�");
}catch (Exception e){
e.printStackTrace();
- String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
- log.error("娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
- return BaseResult.fail("娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + exceptionMessage);
+ String exceptionMessage = "娣诲姞閮ㄩ棬鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+ logger.error(exceptionMessage);
+ return BaseResult.fail(exceptionMessage);
+ }
+ }
+
+ /**
+ * 涓嬭浇浜哄憳瀵煎叆妯℃澘
+ * @param downloadFileName
+ * @param response
+ */
+ @RequestMapping(value = "/downloadImportTemplate",method = RequestMethod.GET)
+ public void downloadImportTemplate(String downloadFileName, HttpServletResponse response){
+ try {
+ String excelPath = deptQueryService.downloadImportTemplate(downloadFileName);
+ ControllerUtil.writeFileToResponse(response,excelPath);
+ } catch (Exception e) {
+ String msg = "涓嬭浇閮ㄩ棬瀵煎叆妯℃澘鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + LangBaseUtil.getErrorMsg(e);
+ try {
+ e.printStackTrace();
+ ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
+ } catch (IOException ioException) {
+ ioException.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 閮ㄩ棬瀵煎叆
+ * @param file
+ * @return
+ */
+ @RequestMapping(value = "/importDept",method = RequestMethod.POST)
+ @VciUnCheckRight
+ public BaseResult importUser(MultipartFile file){
+ String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
+ File file1 = new File(excelFileName);
+ try {
+ file.transferTo(new File(excelFileName));
+ if (file != null) {
+ return deptQueryService.importDept(file1);
+ } else {
+ return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"});
+ }
+ }catch (Throwable e) {
+ throw new VciBaseException(e.getMessage(),new String[0],e);
+ }finally {
+ file1.delete();
}
}
--
Gitblit v1.9.3