com.cy.driver.user.action.ReceiveUploadFileAction.java Source code

Java tutorial

Introduction

Here is the source code for com.cy.driver.user.action.ReceiveUploadFileAction.java

Source

package com.cy.driver.user.action;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cy.common.action.BaseJsonAction;
import com.cy.common.bo.DriverUserInfoBo;
import com.cy.common.bo.OperationLogInfoBo;
import com.cy.driver.operationLog.service.OperationLogService;
import com.cy.driver.user.service.DriverUserCargoInfoService;

/**
 * 
 * @author haoyong
 *
 */
public class ReceiveUploadFileAction extends BaseJsonAction {

    /**
     * 
     */
    private static final long serialVersionUID = -3891740206865317177L;
    private DriverUserCargoInfoService driverUserCargoInfoService;
    private Logger log = LoggerFactory.getLogger(getClass());
    //   
    private File file;//   
    private String fileContentType;//   
    private String fileFileName;// name  
    private String imgPath;

    @Override
    protected void execMethod() throws Exception {

    }

    @Override
    public String exec() {
        DriverUserInfoBo bo = new DriverUserInfoBo();
        String path = "";
        StringBuilder sb = new StringBuilder();
        sb.append(imgPath);
        try {
            String id = request.getParameter("driverId");

            String type = request.getParameter("type");//
            if (StringUtils.isBlank(id)) {
                log.info("?");
                sendResponseToJson("-9", "?");
                return ERROR;
            }
            int accFlag = operationLogService.checkUser(id);
            if (accFlag == 1) {
                log.info("?");
                sendResponseToJson("-9", "?");
                return ERROR;
            } else if (accFlag == 11) {
                log.info("");
                sendResponseToJson("-9", "");
                return ERROR;
            }
            log2Db(id);

            if (StringUtils.isBlank(type)) {
                log.info("??");
                sendResponseToJson("-8", "");
                return ERROR;
            }
            sb.append("APP").append("/");
            sb.append(id).append("/").append(fileFileName);
            path = sb.toString();
            bo.setId(Integer.parseInt(id));
            if ("1".equals(type)) {
                bo.setIdentityLicenseNumFront(path);
            } else if ("2".equals(type)) {
                bo.setIdentityLicenseNumContrary(path);
            } else if ("3".equals(type)) {
                bo.setDriversLicense(path);
            } else if ("4".equals(type)) {
                bo.setDrivingLicense(path);
            } else if ("5".equals(type)) {
                bo.setOperatingLicense(path);
            } else if ("6".equals(type)) {
                bo.setHeadPortrait(path);
            }
            //??
            bo.setAuditFlag("0");
            bo.setSubmitType("1");
            int i = driverUserCargoInfoService.updateDriverUserInfo(bo);
            if (i == 1) {
                log.info("?");
                sendResponseToJson("1", "?");
                uploadFile(path);
            } else {
                log.info("");
                sendResponseToJson("0", "");
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            try {
                sendResponseToJson("-8", e.getMessage());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }

        return SUCCESS;
    }

    private void uploadFile(String path) throws Exception {
        File currFile = new File(path);
        log.info("======>" + currFile.getAbsolutePath());
        FileUtils.copyFile(this.file, currFile);// struts2????   
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getFileContentType() {
        return fileContentType;
    }

    public void setFileContentType(String fileContentType) {
        this.fileContentType = fileContentType;
    }

    public String getFileFileName() {
        return fileFileName;
    }

    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

    public void setDriverUserCargoInfoService(DriverUserCargoInfoService driverUserCargoInfoService) {
        this.driverUserCargoInfoService = driverUserCargoInfoService;
    }

    private OperationLogService operationLogService;

    private void log2Db(String driverId) {
        OperationLogInfoBo bo = new OperationLogInfoBo();
        bo.setOperationName("uploadFile");
        bo.setOperationType(20);
        bo.setRemark("");
        if (StringUtils.isNotBlank(driverId)) {
            bo.setUserDriverId(Integer.parseInt(driverId));
        }
        operationLogService.insertOperationLog(bo);
    }

    public void setOperationLogService(OperationLogService operationLogService) {
        this.operationLogService = operationLogService;
    }
}