package com.terra.system.controller.all; import com.terra.system.annotation.SysLog; import com.terra.system.entity.all.ResponseMsg; import com.terra.system.entity.all.StaticData; import com.terra.system.entity.data.DirEntity; import com.terra.system.entity.data.MetaEntity; import com.terra.system.helper.HttpHelper; import com.terra.system.helper.StringHelper; import com.terra.system.service.data.DirService; import com.terra.system.service.data.FmeService; import com.terra.system.service.data.MetaService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import javax.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; /** * CRDS系统接口 * @author WWW */ @Api(tags = "系统对接\\CRDS") @RestController @RequestMapping("/crds") public class CrdsController extends BaseController { @Resource DirService dirService; @Resource FmeService fmeService; @Resource MetaService metaService; @SysLog() @ApiOperation(value = "查询项目") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "西") }) @GetMapping(value = "/selectProject") public ResponseMsg> selectProject(String name) { try { List list = dirService.selectProject(name); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询项目目录树") @GetMapping(value = "/selectDirsForPrj") public ResponseMsg> selectDirsForPrj() { try { List list = dirService.selectDirsForPrj(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询任务状态") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "任务ID", dataType = "String", paramType = "query", example = "29db09ee-2aae-4c62-bec0-0b5c5d8084e4") }) @GetMapping(value = "/selectTaskStatus") public Object selectTaskStatus(String id, HttpServletRequest req) { try { if (StringHelper.isEmpty(id)) { return fail("id不能为空"); } return fmeService.getTaskStatus(id, req); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "请求打包") @ApiImplicitParams({ @ApiImplicitParam(name = "dirCode", value = "目录编码", dataType = "String", paramType = "01"), @ApiImplicitParam(name = "major", value = "专业", dataType = "String", paramType = "穿跨越"), @ApiImplicitParam(name = "isCut", value = "是否裁剪", dataType = "String", paramType = "NO") }) @GetMapping(value = "/uploadReqPackaging") public ResponseMsg uploadReqPackaging(String dirCode, String major, String isCut, HttpServletRequest req) { try { boolean isMajor = StaticData.CROSSING.equals(major) || StaticData.ROUTE.equals(major); if (!isMajor) { return fail("专业只能是“穿跨越”或“线路”"); } boolean bCut = StaticData.YES.equals(isCut) || StaticData.NO.equals(isCut); if (!bCut) { return fail("是否裁剪只能是“YES”或“NO”"); } if (StringHelper.isEmpty(dirCode)) { return fail("目录编码不能为空"); } DirEntity dir = dirService.selectByCode(dirCode); if (null == dir) { return fail("目录编码为" + dirCode + "的目录不存在"); } String id = fmeService.crdsPackaging(dirCode, major, isCut, req); return success(id); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "下载文件") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "任务ID", dataType = "String", paramType = "query", example = "29db09ee-2aae-4c62-bec0-0b5c5d8084e4") }) @GetMapping(value = "/downloadFile") public void downloadResult(String id, HttpServletRequest req, HttpServletResponse res) { try { if (!StringHelper.isEmpty(id)) { String url = fmeService.getDownloadUrl(id, req); HttpHelper httpHelper = new HttpHelper(); httpHelper.service(req, res, url, null); } } catch (Exception ex) { log.error(ex.getMessage(), ex); } } @SysLog() @ApiOperation(value = "根据目录编码查询元数据文件") @ApiImplicitParams({ @ApiImplicitParam(name = "dircode", value = "目录编码", dataType = "String", paramType = "query", example = "01") }) @GetMapping(value = "/selectMetasByDirCode") public ResponseMsg selectMetasByDirCode(String dircode) { try { if (StringHelper.isEmpty(dircode)) { return fail("目录编码不能为空"); } List list = metaService.selectMetasByDirCode(dircode); return success(null == list ? 0 : list.size(), list); } catch (Exception ex) { return fail(ex, null); } } }