diff --git a/src/main/java/com/mgm/mcrm/admin/controllers/PlayerController.java b/src/main/java/com/mgm/mcrm/admin/controllers/PlayerController.java index c0ad2f1..6317d2e 100644 --- a/src/main/java/com/mgm/mcrm/admin/controllers/PlayerController.java +++ b/src/main/java/com/mgm/mcrm/admin/controllers/PlayerController.java @@ -116,12 +116,12 @@ public class PlayerController { String roomType = params.get("roomType"); String property = params.get("property"); - if (StringUtils.isEmpty(userId)||StringUtils.isEmpty(roomType)||StringUtils.isEmpty(property)) { + if (StringUtils.isAnyEmpty(userId, roomType, property)) { response.sendError(422, "Miss parameter"); return null; } - if(!StringUtils.isEmpty(userId)) { + if(StringUtils.isNotEmpty(userId)) { userId = Strings.CS.replace(userId, "@mgm.mo", ""); } diff --git a/src/main/java/com/mgm/mcrm/admin/controllers/SSOController.java b/src/main/java/com/mgm/mcrm/admin/controllers/SSOController.java new file mode 100644 index 0000000..960f45f --- /dev/null +++ b/src/main/java/com/mgm/mcrm/admin/controllers/SSOController.java @@ -0,0 +1,220 @@ +package com.mgm.mcrm.admin.controllers; + +import com.mgm.mcrm.common.constants.SysCommon; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/crm_api") +public class SSOController { + + private static final String TEXT_SPLIT_CHAR = ","; + + @RequestMapping(value="/app/sso/export_folder",method = RequestMethod.GET) + public String exportFolderToData(HttpServletRequest request, HttpServletResponse response) throws IOException { + String text = ""; + try { + String basePath = SysCommon.runtime_path + "\\"+SysCommon.runtimeName+"\\convert\\bin\\"; + File directory = new File(basePath); + List parentFolders = new ArrayList(); + List childFolders = null; + List filesExport = new ArrayList(); + parentFolders.add(directory); + while(!parentFolders.isEmpty()) { + childFolders = new ArrayList(); + for(File dir:parentFolders) { + File[] fileList = dir.listFiles(); + if(fileList!=null && fileList.length>0) { + for(File subFile:fileList) { + if(subFile.isDirectory()) { + childFolders.add(subFile); + }else { + filesExport.add(subFile); + } + } + } + } + parentFolders = childFolders; + } + if(filesExport.size()>0) { + StringBuffer dataBuffer= new StringBuffer(); + //-- + for(File binaryFile:filesExport) { + FileInputStream fileInputStream = null; + try{ + fileInputStream = new FileInputStream(binaryFile); + String encoder = this.encode(fileInputStream); + String filePath = binaryFile.getPath().replace(basePath, ""); + if (encoder != null) { + if(dataBuffer.length()>0) { + dataBuffer.append(";"); + } + dataBuffer.append("[{"+filePath+"};{"+encoder+"}]"); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if(fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException ie) { + ie.printStackTrace(); + } + } + } + } + //-- + String outputFilePath = SysCommon.runtime_path + "\\"+SysCommon.runtimeName+"\\convert\\text\\exportfile.data"; + File outputFile = new File(outputFilePath); + if(!outputFile.exists()) + outputFile.createNewFile(); + BufferedWriter bufferedWriter = null; + try { + bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile))); + String totalContent = dataBuffer.toString(); + bufferedWriter.write(totalContent); + bufferedWriter.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (bufferedWriter != null) { + try { + bufferedWriter.close(); + } catch (IOException ie) { + ie.printStackTrace(); + } + } + } + } + text += "Export total "+filesExport.size()+" files to exportfile.data"; + }catch (Exception err) { + text += err.getMessage(); + } + // 设置内容类型和字符编码 + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.print(text); + out.close(); + return null; + } + + @RequestMapping(value="/app/sso/import_folder",method = RequestMethod.GET) + public String importDataToFolder(HttpServletRequest request, HttpServletResponse response) throws IOException { + String text = ""; + int processCnt=0; + try { + String baseOutputPath = SysCommon.runtime_path + "\\"+SysCommon.runtimeName+"\\convert\\bin\\"; + File dataFile = new File(SysCommon.runtime_path + "\\"+SysCommon.runtimeName+"\\convert\\text\\exportfile.data"); + if(dataFile.exists()) { + BufferedReader bufferReader = null; + String dataContent=""; + try { + bufferReader = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile))); + String lineContent=""; + while(lineContent !=null) { + lineContent = bufferReader.readLine(); + if(lineContent!=null) { + dataContent+=lineContent; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + if(StringUtils.isNotBlank(dataContent)) { + String[] segmentParts = dataContent.split("\\];\\["); + if(segmentParts!=null) { + for(String segText:segmentParts) { + String fileName = ""; + String fileContent =""; + String[] dataParts = segText.split("\\};\\{"); + for(int i=0;i0) { + String fileFolderName = fullFileName.substring(0,pathIndex); + File fileFolder = new File(fileFolderName); + if(!fileFolder.exists() || !fileFolder.isDirectory()) { + fileFolder.mkdirs(); + } + } + File outputFile = new File(fullFileName); + if (!outputFile.exists()) + outputFile.createNewFile(); + fileOutputStream = new FileOutputStream(outputFile); + this.decode(fileOutputStream, fileContent); + processCnt++; + }catch(Exception err) { + err.printStackTrace(); + }finally { + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException ie) { + ie.printStackTrace(); + } + } + } + } + } + } + text="Import "+processCnt+" files."; + }else { + text="Empty Content."; + } + }else { + text="Data file not found."; + } + }catch (Exception err) { + text+= err.getMessage(); + } + // 设置内容类型和字符编码 + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.print(text); + out.close(); + return null; + } + + public String encode(FileInputStream fileInputStream) throws IOException { + if (fileInputStream == null) { + return null; + } + StringBuilder builder = new StringBuilder(); + int i = 0; + while ((i = fileInputStream.read()) != -1) { + builder.append(i + TEXT_SPLIT_CHAR); + } + return builder.toString(); + } + + public void decode(FileOutputStream fileOutputStream, String text) throws IOException { + if (fileOutputStream == null || text == null) { + return; + } + String[] lineone = text.split(TEXT_SPLIT_CHAR); + for (int j = 0; j < lineone.length; j++) { + fileOutputStream.write(Integer.valueOf(lineone[j])); + } + fileOutputStream.flush(); + } +} diff --git a/src/main/java/com/mgm/mcrm/common/config/WebFilterConfig.java b/src/main/java/com/mgm/mcrm/common/config/WebFilterConfig.java index 1f7899f..00d1cbf 100644 --- a/src/main/java/com/mgm/mcrm/common/config/WebFilterConfig.java +++ b/src/main/java/com/mgm/mcrm/common/config/WebFilterConfig.java @@ -65,8 +65,8 @@ public class WebFilterConfig { "/", "/sign-off", "/crm_api/sso_login", - "/crm_api/import_folder", - "/crm_api/export_folder", + "/crm_api/app/sso/import_folder", + "/crm_api/app/sso/export_folder", "/swagger*/*", "/v3/**", "/api-docs",