package com.mortals.xhx.module.project.web;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.module.project.model.ProjectEntity;
import com.mortals.xhx.module.project.service.ProjectService;
import java.util.Map;
import java.util.List;
/**
* ProjectController
*
* 构建工程信息 控制器
*
* @author zxfei
* @date 2021-11-03
*/
@RestController
@RequestMapping("project")
public class ProjectController extends BaseCRUDJsonMappingController<ProjectService,ProjectForm,ProjectEntity,Long> {

    @Autowired
    private UploadService uploadService;

    public ProjectController(){
        super.setFormClass(ProjectForm.class);
        super.setModuleDesc( "构建工程信息");
    }

    @Override
    protected void init(HttpServletRequest request, HttpServletResponse response, ProjectForm form, Map<String, Object> model, Context context) {
        super.init(request, response, form, model, context);
    }

    @Override
    protected void doListBefore(HttpServletRequest request, HttpServletResponse response, ProjectForm form, Map<String, Object> model, Context context) throws AppException {

        super.doListBefore(request, response, form, model, context);
    }

    /**
     * 工程文件下载
     *
     * @param
     */
    @PostMapping("filedownload")
    public void download(@RequestParam(value="filepath") String filepath, HttpServletResponse response) {
        try {
            uploadService.uploadDownload(filepath, response);
        } catch (Exception e) {
            log.error("下载文件失败:", e);
        }
    }

}