com.smart.smartrestfulw.controller.FileDepotController.java Source code

Java tutorial

Introduction

Here is the source code for com.smart.smartrestfulw.controller.FileDepotController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.smart.smartrestfulw.controller;

import com.smart.common.SignVerify.SignCommon;
import com.smart.common.SignVerify.SignInformationModel;
import com.smart.smartrestfulw.prepare.ReponseFormat;
import com.smart.common.DBHelper;
import com.smart.common.DeployInfo;
import com.smart.common.FileHelper;
import com.smart.common.FormationResult;
import com.smart.common.RSLogger;
import com.smart.common.UtileSmart;
import com.smart.common.model.DepotFileDetailModel;
import com.smart.common.model.ExecuteResultParam;
import com.smart.common.model.FileDepotParamModel;
import com.smart.common.model.ResponseResultCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;
import java.util.HashSet;

import java.io.File;

/**
 * REST Web Service
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/fileDepot")
public class FileDepotController {

    //  private final FormationResult formationResult = new FormationResult();
    private final ReponseFormat responseFormat = new ReponseFormat();

    /**
     * Creates a new instance of FileDepotRS
     */
    public FileDepotController() {
    }

    //    @RequestMapping(value = "/UpLoadFile", method = RequestMethod.POST, consumes = {org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE}, produces = {org.springframework.http.MediaType.APPLICATION_JSON_VALUE})
    //    @ResponseBody
    //    public String UpLoadFile(@RequestPart("param") String param, @RequestPart("file") MultipartFile jarFile) {
    //
    //        FileDepotParamModel paramModel = new FileDepotParamModel();
    //        paramModel.ownid = pownid;
    //        paramModel.rsid = pRSID;
    //        paramModel.token = ptoken;
    //        paramModel.fileDetaile = new HashSet<DepotFileDetailModel>();
    //        DepotFileDetailModel detailModel = new DepotFileDetailModel();
    //        detailModel.fileName = pfilename;
    //        detailModel.fileOwnType = pfileType;
    //        paramModel.fileDetaile.add(detailModel);
    //
    //        return SaveUpLoadFile(formFileData, paramModel, false);
    //    }
    /**
     * ?
     *
     * @param strParam
     * @param uploadFiles
     * @return
     */
    @RequestMapping(value = "/UpLoadFileParam", method = RequestMethod.POST, consumes = {
            org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE }, produces = {
                    org.springframework.http.MediaType.APPLICATION_JSON_VALUE })
    @ResponseBody
    public String UpLoadFileParam(@RequestParam("param") String strParam,
            @RequestParam("file") List<MultipartFile> uploadFiles) {
        FileDepotParamModel paramModel = null;
        try {
            paramModel = analyzeUpLoadFileJsonStr(strParam, false);
            System.out.println(uploadFiles.toString());
            return SaveUpLoadFile(uploadFiles, paramModel, false);
        } catch (Exception ex) {
            RSLogger.ErrorLogInfo(
                    String.format("UpLoadFileParamError:%s,param%s", ex.getLocalizedMessage(), strParam), ex);
            return responseFormat.formationResultToString(ResponseResultCode.Error, ex);
            //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(ex.getLocalizedMessage(), paramModel == null ? null : paramModel.toStringInformation()));
        }

    }

    @RequestMapping(value = "/ModifyBase64File", method = RequestMethod.POST, consumes = {
            org.springframework.http.MediaType.APPLICATION_JSON_VALUE }, produces = {
                    org.springframework.http.MediaType.APPLICATION_JSON_VALUE })
    @ResponseBody
    public String ModifyBase64File(@RequestParam("param") String param) {
        String strUpFileName = null, strSvcFileLocalName = null;
        StringBuffer sbFilePathTemp = new StringBuffer(), sbTemp = new StringBuffer();
        boolean bSvcFileExist;
        ExecuteResultParam resultParam = null;
        List<String> strSqls = new ArrayList<String>();
        int saveFlag = 1;
        FileDepotParamModel paramModel = null;
        try {
            //??
            paramModel = analyzeBase64Param(param);

            if (paramModel == null) {
                return responseFormat.formationResultToString(ResponseResultCode.ErrorParam, "paramError");
            }

            SignInformationModel signModel = SignCommon.verifySign(paramModel.getToken(), false);
            if (signModel == null) {
                return responseFormat.formationResultToString(ResponseResultCode.ErrorSignToken, "no authorize");
            }

            if (paramModel.fileDetaile == null || paramModel.fileDetaile.isEmpty()) {
                // return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam("base64", param));
                return responseFormat.formationResultToString(ResponseResultCode.ErrorBase64Error,
                        "base64");
            }

            for (DepotFileDetailModel fileDetaile : paramModel.fileDetaile) {
                //?
                strUpFileName = fileDetaile.fileName;
                //  root/rsid/date(yymmddhh)/Type
                //
                sbFilePathTemp.append(paramModel.rsid);
                sbTemp.append(DeployInfo.GetDeployFilePath()).append(File.separator).append(paramModel.rsid);
                FileHelper.CheckFileExist(sbTemp.toString());
                //
                sbFilePathTemp.append(File.separator).append(UtileSmart.getCurrentDate());
                sbTemp.append(File.separator).append(UtileSmart.getCurrentDate());
                FileHelper.CheckFileExist(sbTemp.toString());

                sbFilePathTemp.append(File.separator).append(fileDetaile.fileOwnType);
                sbTemp.append(File.separator).append(fileDetaile.fileOwnType);
                FileHelper.CheckFileExist(sbTemp.toString());
                //?
                sbFilePathTemp.append(File.separator).append(strUpFileName).toString();
                strSvcFileLocalName = sbTemp.append(File.separator).append(strUpFileName).toString();
                bSvcFileExist = FileHelper.CheckFileExist(strSvcFileLocalName, false);
                if (bSvcFileExist) {

                    return responseFormat.formationResultToString(ResponseResultCode.ErrorFileExist,
                            "file exist can not change .please contact system manger");
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam("????", param));
                }

                //?? ownid  fpath???????
                resultParam = DBHelper.ExecuteSqlOnceSelect(DeployInfo.MasterRSID,
                        String.format(
                                "SELECT COUNT(*) AS ROWSCOUNT FROM FILEDEPOT WHERE OWNID<>'%s' AND FPATH='%s'",
                                paramModel.ownid, sbFilePathTemp.toString()));
                if (resultParam.ResultCode != 0) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, resultParam.errMsg);
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("????%s", resultParam.errMsg), param));
                }
                //ROWSCOUNT ?0?? ROWSCOUNT ?0???????
                if (resultParam.ResultJsonObject != null) {
                    if (Integer.parseInt(resultParam.ResultJsonObject.getJSONObject(DeployInfo.ResultDataTag)
                            .getString("ROWSCOUNT")) > 0) {
                        return responseFormat.formationResultToString(ResponseResultCode.ErrorFileRepeat,
                                "file binded ");
                        //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("%s,?????????????", strUpFileName), param));
                    }
                }
                //? (File.separator) 
                if (fileDetaile.fileOwnType.indexOf(File.separator) > 0) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorFileType,
                            "file type error. ");
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("??", strUpFileName), paramModel.toStringInformation()));
                }
                //?
                int baseIndex = fileDetaile.fileBase64Value.indexOf(";base64,");
                if (!FileHelper.ConvertBase64ToImage(
                        fileDetaile.fileBase64Value.substring(baseIndex + 8, fileDetaile.fileBase64Value.length()),
                        strSvcFileLocalName)) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorBase64ConvertFile,
                            String.format("%s: convert image failed", fileDetaile.fileName));
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("%s: convert image failed", fileDetaile.fileName), param));
                }
                //??????
                fileDetaile.fileLocalPath = strSvcFileLocalName;

                if (fileDetaile.fileId != null && !fileDetaile.fileId.isEmpty()) {

                    strSqls.add(String.format(
                            "insert into FILEDEPOT_LS (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE) select  FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE from FILEDEPOT  as t_f where t_f.OWNID='%s'  and t_f.FID ='%s' ",
                            paramModel.ownid, fileDetaile.fileId));

                    //?sql????
                    strSqls.add(String.format(
                            "update FILEDEPOT set FNAME='%s',FPATH='%s',OWNFILETYPE='%s',UPLOADDATE=getdate()  where FID='%s' and OWNID='%s'",
                            strUpFileName, sbFilePathTemp.toString(), fileDetaile.fileOwnType, fileDetaile.fileId,
                            paramModel.ownid));
                } else {
                    strSqls.add(String.format(
                            "INSERT INTO FILEDEPOT (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE) VALUES ('%s','%s','%s','%s','%s','%s')",
                            UUID.randomUUID().toString(), strUpFileName, sbFilePathTemp.toString(), "md5",
                            paramModel.ownid, fileDetaile.fileOwnType));

                }

                sbTemp.delete(0, sbTemp.length());
                sbFilePathTemp.delete(0, sbFilePathTemp.length());
            }
            //???
            resultParam = DBHelper.ExecuteSql(DeployInfo.MasterRSID, strSqls);
            if (resultParam.ResultCode >= 0) {
                saveFlag = 0;
                //????
                resultParam = SelectDepotFileByOwn(new FileDepotParamModel(paramModel.ownid));
                // return formationResult.formationResult(ResponseResultCode.Success, new ExecuteResultParam(resultParam.ResultJsonObject));
                return responseFormat.formationSuccessResultToString(resultParam.ResultJsonObject);
            } else {
                //TODO ??????
                return responseFormat.formationResultToString(ResponseResultCode.Error, resultParam.errMsg);
            }
        } catch (Exception e) {
            return responseFormat.formationResultToString(ResponseResultCode.Error, e);
        } finally {
            if (saveFlag == 1 && paramModel != null) {
                DeleteFile(paramModel.fileDetaile);
            }
            UtileSmart.FreeObjects(strUpFileName, strSvcFileLocalName, sbFilePathTemp, sbTemp, resultParam, strSqls,
                    paramModel);
        }

    }

    public FileDepotParamModel analyzeBase64Param(String strJson) throws Exception {
        JSONObject jsonObj = null;
        JSONObject jsonHead = null;
        JSONObject jsonBody = null;
        JSONArray arrayBase64 = null;
        JSONObject jsonTempBase64 = null;
        FileDepotParamModel paramModel = null;
        DepotFileDetailModel tempDetailModel = null;
        try {
            jsonObj = JSONObject.fromObject(strJson);
            paramModel = new FileDepotParamModel();
            jsonHead = jsonObj.getJSONObject("head");
            jsonBody = jsonObj.getJSONObject("body");

            paramModel.rsid = jsonHead.getString(DeployInfo.paramRSIDKey);
            paramModel.token = jsonHead.getString(DeployInfo.paramtokenKey);
            paramModel.ownid = jsonBody.getString("ownid");
            arrayBase64 = jsonBody.getJSONArray("base64");
            paramModel.fileDetaile = new HashSet<DepotFileDetailModel>();
            for (Object arrayBase641 : arrayBase64) {
                jsonTempBase64 = ((JSONObject) arrayBase641);
                tempDetailModel = new DepotFileDetailModel();
                tempDetailModel.fileBase64Value = jsonTempBase64.getString("base64value");
                if (jsonTempBase64.containsKey("filename")) {
                    tempDetailModel.fileName = jsonTempBase64.getString("filename");
                }
                if (jsonTempBase64.containsKey("fileId")) {
                    tempDetailModel.fileId = jsonTempBase64.getString("fileId");
                }
                tempDetailModel.fileOwnType = jsonTempBase64.getString("fileType");
                paramModel.fileDetaile.add(tempDetailModel);
            }
            return paramModel;
        } catch (Exception e) {
            throw new Exception(String.format("analyzeBase64Param error :%s", e.getLocalizedMessage()));
        } finally {
            UtileSmart.FreeObjects(jsonBody, jsonHead, jsonObj, jsonTempBase64, arrayBase64, tempDetailModel);
        }

    }

    /**
     * ?json
     *
     * @param strJson
     * @return
     * @throws Exception
     */
    public FileDepotParamModel analyzeUpLoadFileJsonStr(String strJson, boolean isModify) throws Exception {

        FileDepotParamModel paramModel = null;
        JSONObject jsonObj = null, jsonBody = null, jsonHead = null, jsonTempFile = null;
        JSONArray jsonFileDes = null;
        try {
            jsonObj = JSONObject.fromObject(strJson);
            paramModel = new FileDepotParamModel();

            jsonHead = jsonObj.getJSONObject("head");
            jsonBody = jsonObj.getJSONObject("body");
            paramModel.rsid = jsonHead.getString(DeployInfo.paramRSIDKey);
            paramModel.token = jsonHead.getString(DeployInfo.paramtokenKey);

            paramModel.ownid = jsonBody.getString("ownid");

            jsonFileDes = jsonBody.getJSONArray("fileDes");
            for (Object jsonFileDe : jsonFileDes) {
                jsonTempFile = (JSONObject) jsonFileDe;
                if (isModify) {
                    paramModel.addFileDetail(jsonTempFile.getString("filename"), jsonTempFile.getString("fileType"),
                            jsonTempFile.getString("fileOverlay"), jsonTempFile.getString("fileId"));
                } else {
                    DepotFileDetailModel detailModel = new DepotFileDetailModel();
                    detailModel.fileName = jsonTempFile.getString("filename");
                    detailModel.fileOwnType = jsonTempFile.getString("fileType");
                    paramModel.addFileDetail(detailModel);
                }
            }
            return paramModel;
        } catch (Exception e) {
            throw new Exception("analyze FileParamModel error.:" + e.getLocalizedMessage());
        } finally {
            UtileSmart.FreeObjects(paramModel, jsonObj, jsonBody, jsonHead, jsonTempFile, jsonFileDes);
        }
    }

    /**
     * ?json
     *
     * @param strJson
     * @return
     * @throws Exception
     */
    public FileDepotParamModel analyzeNormalJsonStr(String strJson) throws Exception {

        FileDepotParamModel paramModel = null;
        JSONObject jsonObj = null, jsonBody = null, jsonHead = null, jsonTempFile = null;
        JSONArray jsonFileDes = null;
        DepotFileDetailModel fileDetailModel = null;
        try {
            jsonObj = JSONObject.fromObject(strJson);
            paramModel = new FileDepotParamModel();

            jsonHead = jsonObj.getJSONObject("head");
            jsonBody = jsonObj.getJSONObject("body");
            paramModel.rsid = jsonHead.getString(DeployInfo.paramRSIDKey);
            paramModel.token = jsonHead.getString(DeployInfo.paramtokenKey);

            paramModel.ownid = jsonBody.getString("ownid");
            if (jsonBody.containsKey("fileIds")) {
                jsonFileDes = jsonBody.getJSONArray("fileIds");
                for (int i = 0; i < jsonFileDes.size(); i++) {
                    paramModel.addFileDetail(jsonFileDes.getString(i));
                }
                paramModel.selectFlag = 1;
            } else if (jsonBody.containsKey("fileTypes")) {
                jsonFileDes = jsonBody.getJSONArray("fileTypes");
                for (int i = 0; i < jsonFileDes.size(); i++) {
                    fileDetailModel = new DepotFileDetailModel();
                    fileDetailModel.fileOwnType = jsonFileDes.getString(i);
                    paramModel.fileDetaile.add(fileDetailModel);
                }
                paramModel.selectFlag = 2;
            }

            return paramModel;
        } catch (Exception e) {
            throw new Exception("analyze FileParamModel error.:" + e.getLocalizedMessage());
        } finally {
            UtileSmart.FreeObjects(paramModel, jsonObj, jsonBody, jsonHead, jsonTempFile, jsonFileDes,
                    fileDetailModel);
        }
    }

    /**
     * ??
     *
     * @param formFileData
     * @param strJson
     * @param isModify ???
     * @return
     */
    private String SaveUpLoadFile(List<MultipartFile> uploadFiles, FileDepotParamModel paramModel, boolean isModify)
            throws Exception {

        String strSvcFileLocalName = null, strUpFileName = null, strTempFilePath = null;
        StringBuffer sbTemp = new StringBuffer();
        StringBuffer sbFilePathTemp = new StringBuffer();
        boolean bSvcFileExist = false;
        Set<String> setStrSqls = new HashSet<String>();
        ExecuteResultParam resultParam = null;
        DepotFileDetailModel tempFileDetailModel = null;
        int saveFlag = 1;
        if (paramModel == null) {
            return responseFormat.formationResultToString(ResponseResultCode.ErrorParam, "paramError");
        }

        SignInformationModel signModel = SignCommon.verifySign(paramModel.getToken(), false);
        if (signModel == null) {
            return responseFormat.formationResultToString(ResponseResultCode.ErrorSignToken, "no authorize");
        }

        try {

            for (MultipartFile tempFile : uploadFiles) {
                strUpFileName = tempFile.getOriginalFilename();
                //  root/rsid/date(yymmddhh)/Type
                //
                sbFilePathTemp.append(paramModel.rsid);
                sbTemp.append(DeployInfo.GetDeployFilePath()).append(File.separator).append(paramModel.rsid);
                FileHelper.CheckFileExist(sbTemp.toString());
                //
                sbFilePathTemp.append(File.separator).append(UtileSmart.getCurrentDate());
                sbTemp.append(File.separator).append(UtileSmart.getCurrentDate());
                FileHelper.CheckFileExist(sbTemp.toString());
                tempFileDetailModel = paramModel.getFileDetailModel(strUpFileName);
                if (tempFileDetailModel == null) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorParam, "param error."); // return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("? %s?", strUpFileName), paramModel.toStringInformation()));
                }
                //? (File.separator) 
                if (tempFileDetailModel.fileOwnType.indexOf(File.separator) > 0) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorFileType,
                            "file type error"); // return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("? %s?", strUpFileName), paramModel.toStringInformation()));
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("??", strUpFileName), paramModel.toStringInformation()));
                }
                sbFilePathTemp.append(File.separator).append(tempFileDetailModel.fileOwnType);
                sbTemp.append(File.separator).append(tempFileDetailModel.fileOwnType);
                FileHelper.CheckFileExist(sbTemp.toString());
                //?
                sbFilePathTemp.append(File.separator).append(strUpFileName).toString();
                strSvcFileLocalName = sbTemp.append(File.separator).append(strUpFileName).toString();
                bSvcFileExist = FileHelper.CheckFileExist(strSvcFileLocalName, false);
                if (bSvcFileExist && isModify == false) {
                    return responseFormat.formationResultToString(ResponseResultCode.ErrorFileExist, "file exist");
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("????%s", strUpFileName), paramModel.toStringInformation()));
                }
                //?? ownid  fpath???????
                resultParam = DBHelper.ExecuteSqlOnceSelect(DeployInfo.MasterRSID,
                        String.format(
                                "SELECT COUNT(*) AS ROWSCOUNT FROM FILEDEPOT WHERE OWNID<>'%s' AND FPATH='%s'",
                                paramModel.ownid, sbFilePathTemp.toString()));
                if (resultParam.ResultCode != 0) {

                    return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, resultParam.errMsg);
                    //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("????%s : Msg : %s", strUpFileName, resultParam.errMsg), paramModel.toStringInformation()));
                }
                //ROWSCOUNT ?0?? ROWSCOUNT ?0???????
                if (resultParam.ResultJsonObject != null) {
                    if (Integer.parseInt(resultParam.ResultJsonObject.getJSONObject(DeployInfo.ResultDataTag)
                            .getString("ROWSCOUNT")) > 0) {
                        return responseFormat.formationResultToString(ResponseResultCode.ErrorFileRepeat,
                                "file binded ");
                        //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("%s,?????????????", strUpFileName), paramModel.toStringInformation()));
                    }
                }
                tempFile.transferTo(new File(strSvcFileLocalName));

                //??????
                tempFileDetailModel.fileLocalPath = strSvcFileLocalName;
                //?sql????
                if (isModify) {
                    //todo   ?sql??
                    // 1,??
                    // 2? uuid ????
                    //3? uuid ?
                    setStrSqls.add(String.format(
                            "INSERT INTO FILEDEPOT (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE) VALUES ('%s','%s','%s','%s','%s','%s')",
                            UUID.randomUUID().toString(), strUpFileName, sbFilePathTemp.toString(), "md5",
                            paramModel.ownid, tempFileDetailModel.fileOwnType));
                } else {
                    setStrSqls.add(String.format(
                            "INSERT INTO FILEDEPOT (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE) VALUES ('%s','%s','%s','%s','%s','%s')",
                            UUID.randomUUID().toString(), strUpFileName, sbFilePathTemp.toString(), "md5",
                            paramModel.ownid, tempFileDetailModel.fileOwnType));
                }

                sbTemp.delete(0, sbTemp.length());
                sbFilePathTemp.delete(0, sbFilePathTemp.length());
            }
            //???
            resultParam = DBHelper.ExecuteSql(DeployInfo.MasterRSID, setStrSqls);
            if (resultParam.ResultCode >= 0) {
                saveFlag = 0;
                //????
                resultParam = SelectDepotFileByOwn(new FileDepotParamModel(paramModel.ownid));
                //return formationResult.formationResult(ResponseResultCode.Success, new ExecuteResultParam(resultParam.ResultJsonObject));
                return responseFormat.formationSuccessResultToString(resultParam.ResultJsonObject);

            } else {
                return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, resultParam.errMsg);
                //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(String.format("??%s", resultParam.errMsg), paramModel.toStringInformation()));
            }
        } catch (Exception e) {
            return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, e);
            // return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(e.getLocalizedMessage(), paramModel.toStringInformation(), e));
        } finally {
            if (saveFlag == 1) {
                DeleteFile(paramModel.fileDetaile);
            }
            UtileSmart.FreeObjects(strSvcFileLocalName, strUpFileName, strTempFilePath, sbTemp, sbFilePathTemp,
                    setStrSqls, resultParam, paramModel, tempFileDetailModel);
        }

    }

    /**
     * 
     *
     * @param fileDetailModels
     */
    private void DeleteFile(Set<DepotFileDetailModel> fileDetailModels) {
        if (fileDetailModels != null && !fileDetailModels.isEmpty()) {
            for (DepotFileDetailModel fileDetailModel : fileDetailModels) {
                if (fileDetailModel.fileLocalPath != null && !fileDetailModel.fileLocalPath.isEmpty()) {
                    FileHelper.deleteFile(fileDetailModel.fileLocalPath);
                }
            }
        }

    }

    /**
     * ?own own???
     *
     * @param strParam
     * @return
     */
    @POST
    @Path("InvalidDepotFileByOwn")
    public String InvalidDepotFileByOwn(String strParam) {
        //sbTemp.append(DeployInfo.GetDeployFilePath()).append(sbFilePathTemp);
        FileDepotParamModel paramModel = null;
        ExecuteResultParam resultModel = null;
        try {
            paramModel = analyzeNormalJsonStr(strParam);

            SignInformationModel signModel = SignCommon.verifySign(paramModel.getToken(), false);
            if (signModel == null) {
                return responseFormat.formationResultToString(ResponseResultCode.ErrorSignToken, "no authorize");
            }

            resultModel = InvalidDepotFile(paramModel);
            if (resultModel.ResultCode >= 0) {
                // return formationResult.formationResult(ResponseResultCode.Success, new ExecuteResultParam(resultModel.ResultJsonObject));

                return responseFormat.formationSuccessResultToString(resultModel.ResultJsonObject);
            } else {
                //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(resultModel.errMsg, strParam));

                return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, resultModel.errMsg);
            }
        } catch (Exception e) {

            return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, e);
            //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(e.getLocalizedMessage(), strParam, e));
        }
    }

    private ExecuteResultParam InvalidDepotFile(FileDepotParamModel paramModel) throws Exception {
        StringBuffer sbSql = new StringBuffer();
        StringBuffer sbSqlDelete = new StringBuffer();
        List<String> lsSql = null;
        try {
            sbSql.append(String.format(
                    "insert into FILEDEPOT_LS (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE) select  FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE from FILEDEPOT  as t_f where t_f.OWNID='%s' ",
                    paramModel.ownid));
            sbSqlDelete.append(String.format("delete FILEDEPOT  where OWNID='%s' ", paramModel.ownid));
            if (paramModel.fileDetaile != null && paramModel.fileDetaile.size() > 0) {
                if (paramModel.selectFlag == 1) {
                    sbSql.append(" and t_f.FID in (");
                    sbSqlDelete.append(" and FID in (");
                } else if (paramModel.selectFlag == 2) {
                    sbSql.append(" and t_f.OWNFILETYPE in ( ");
                    sbSqlDelete.append(" and OWNFILETYPE in ( ");
                } else {
                    return new ExecuteResultParam(-1,
                            "?json????");
                }
                for (DepotFileDetailModel paramModelTemp : paramModel.fileDetaile) {
                    if (paramModel.selectFlag == 1) {
                        sbSql.append("'").append(paramModelTemp.fileId).append("'");
                        sbSqlDelete.append("'").append(paramModelTemp.fileId).append("'");
                    } else if (paramModel.selectFlag == 2) {
                        sbSql.append("'").append(paramModelTemp.fileOwnType).append("'");
                        sbSqlDelete.append("'").append(paramModelTemp.fileOwnType).append("'");
                    } else {
                        return new ExecuteResultParam(-1,
                                "?json????");
                    }
                    sbSql.append(',');
                    sbSqlDelete.append(",");
                }
                sbSql.deleteCharAt(sbSql.length() - 1);
                sbSql.append(")");

                sbSqlDelete.deleteCharAt(sbSqlDelete.length() - 1);
                sbSqlDelete.append(")");
            }
            lsSql = new ArrayList<String>();

            lsSql.add(sbSql.toString());
            lsSql.add(sbSqlDelete.toString());
            return DBHelper.ExecuteSql(DeployInfo.MasterRSID, lsSql);
        } catch (Exception e) {
            throw new Exception(e.getLocalizedMessage());
        } finally {
            UtileSmart.FreeObjects(paramModel, sbSql, sbSqlDelete);
        }
    }

    /**
     * ?ownown
     *
     * @param strParam
     * @return
     */
    @POST
    @Path("SelectDepotFileByOwn")
    public String SelectDepotFileByOwn(String strParam) {
        FileDepotParamModel paramModel = null;
        ExecuteResultParam resultModel = null;
        try {
            paramModel = analyzeNormalJsonStr(strParam);

            SignInformationModel signModel = SignCommon.verifySign(paramModel.getToken(), false);
            if (signModel == null) {
                return responseFormat.formationResultToString(ResponseResultCode.ErrorSignToken, "no authorize");
            }

            resultModel = SelectDepotFileByOwn(paramModel);
            if (resultModel.ResultCode >= 0) {
                //return formationResult.formationResult(ResponseResultCode.Success, new ExecuteResultParam(resultModel.ResultJsonObject));

                return responseFormat.formationSuccessResultToString(resultModel.ResultJsonObject);
            } else {

                return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, resultModel.errMsg);
                //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(resultModel.errMsg, strParam));
            }
        } catch (Exception e) {

            return responseFormat.formationResultToString(ResponseResultCode.ErrorDB, e);
            //return formationResult.formationResult(ResponseResultCode.Error, new ExecuteResultParam(e.getLocalizedMessage(), strParam, e));
        }
    }

    private ExecuteResultParam SelectDepotFileByOwn(FileDepotParamModel paramModel) throws Exception {
        List<String> urlColumns = null;
        StringBuffer sbSql = new StringBuffer();
        try {
            sbSql.append(String.format("select * from FILEDEPOT where OWNID='%s' ", paramModel.ownid));

            if (paramModel.fileDetaile != null && paramModel.fileDetaile.size() > 0) {
                if (paramModel.selectFlag == 1) {
                    sbSql.append(" and FID in (");
                } else if (paramModel.selectFlag == 2) {
                    sbSql.append(" and OWNFILETYPE in (");
                } else {
                    return new ExecuteResultParam(-1,
                            "?json????");
                }
                for (DepotFileDetailModel paramModelTemp : paramModel.fileDetaile) {
                    if (paramModel.selectFlag == 1) {
                        sbSql.append("'").append(paramModelTemp.fileId).append("'");
                    } else if (paramModel.selectFlag == 2) {
                        sbSql.append("'").append(paramModelTemp.fileOwnType).append("'");
                    } else {
                        return new ExecuteResultParam(-1,
                                "?json????");
                    }
                    sbSql.append(',');
                }
                sbSql.deleteCharAt(sbSql.length() - 1);
                sbSql.append(")");
            }
            urlColumns = new ArrayList<String>();
            urlColumns.add("FPATH");
            return DBHelper.ExecuteSqlSelect(DeployInfo.MasterRSID, sbSql.toString(), urlColumns);
        } catch (Exception e) {
            throw new Exception(e.getLocalizedMessage());
        } finally {
            UtileSmart.FreeObjects(paramModel, sbSql, urlColumns);
        }
    }
}