package com.product.patch.controller; import com.product.core.config.CoreConst; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.module.sys.version.ApiVersion; import com.product.patch.config.ErrorCode; import com.product.patch.service.idel.IPatchImportService; import com.product.util.BaseUtil; import com.product.util.support.AbstractBaseController; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.util.Map; /** * @Author cheng * @Date 2024/10/24 18:22 * @Desc 补丁导入 */ @RestController @RequestMapping("/api/patch/import") public class PatchImportController extends AbstractBaseController { @Resource public IPatchImportService patchImportService; @PostMapping("/upload/{version}") @ApiVersion(1) public String upload(HttpServletRequest request) { try { RequestParameterEntity rpe = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { rpe = (RequestParameterEntity) bean; } FieldSetEntity fse = rpe.getFormData(); String fileName = fse.getString("patchFile"); if (rpe == null || rpe.getFormData() == null || rpe.getFiles() == null || rpe.getFiles().isEmpty() || rpe.getFiles().get(fileName) == null) { throw new BaseException(ErrorCode.SYSTEM_FORM_COUNT); } File patchFile = rpe.getFiles().get(fileName); IPatchImportService service = (IPatchImportService) getProxyInstance(patchImportService); Map result = service.uploadPatchFile(patchFile); return BaseUtil.success(result); } catch (BaseException e) { e.printStackTrace(); return error(e); } catch (Exception e) { e.printStackTrace(); return error(ErrorCode.EXTRACT_FAIL, e); } } }