import { Validation } from "../core" ; import { Body , Controller , Get , Post , Query } from "../core/decorator" ; import { DatasourceDto , ScreenDto } from "../dto" ; import ScreenService from "../service/ScreenService" ; import BaseController from "./BaseController" ; @ Controller ( "/screen" ) export default class ScreenController extends BaseController { constructor ( private readonly service ) { super ( ) ; } param dto @ Post ( "/add" ) async add ( @ Body ( new Validation ( { groups : [ "add" ] } ) ) dto ) { dto . name = dto . name . replace ( "/" , "" ) ; if ( ! dto . name ) { return this . fail ( "添加失败" ) ; } const relId = await this . service . add ( dto ) ; if ( relId ) return this . success ( relId ) ; return this . fail ( "添加失败" ) ; } param projectId @ Get ( "/list" ) async list ( @ Query ( "projectId" ) projectId ) { const rel = await this . service . findByProject ( projectId ) ; return this . success ( rel ) ; } param name @ Get ( "/list/projectName" ) async listByProjectName ( @ Query ( "name" ) name ) { const rel = await this . service . findByProjectName ( name ) ; return this . success ( rel ) ; } param dto @ Post ( "/update" ) async update ( @ Body ( new Validation ( { groups : [ "update" ] } ) ) dto ) { dto . name = dto . name . replace ( "/" , "" ) ; if ( ! dto . name ) { return this . fail ( "更新失败" ) ; } const rel = await this . service . update ( dto ) ; if ( rel ) return this . success ( null ) ; return this . fail ( "更新失败" ) ; } param dto @ Post ( "/update/layer" ) async updateLayer ( @ Body ( new Validation ( { groups : [ "updateLayer" ] } ) ) dto ) { const rel = await this . service . updateScreen ( dto ) ; if ( rel ) return this . success ( null ) ; return this . fail ( "图层更新失败" ) ; } param dto @ Post ( "/update/cover" ) async updateCover ( @ Body ( new Validation ( { groups : [ "coverImg" ] } ) ) dto ) { const rel = await this . service . updateCover ( dto . id , dto . coverImg ! ) ; if ( rel ) return this . success ( null ) ; return this . fail ( "更新失败" ) ; } param id @ Get ( "/delete" ) async delete ( @ Query ( "id" ) id ) { const rel = await this . service . delete ( id ) ; if ( rel ) { return this . success ( null ) ; } return this . fail ( "删除失败" ) ; } param id @ Get ( "/detail" ) async detail ( @ Query ( "id" ) id ) { const rel = await this . service . findDetailById ( id ) ; return rel ? this . success ( rel ) : this . fail ( "页面不存在" ) ; } param dto @ Post ( "/view/detail" ) async previewDetail ( @ Body ( ) dto ) { const rel = dto . screenName && dto . projectName ? await this . service . findByName ( dto . projectName , dto . screenName ) : null ; return rel ? this . success ( rel ) : this . fail ( "页面不存在" ) ; } param dto returns @ Post ( "/datasource/add" ) async addDatasource ( @ Body ( new Validation ( { groups : [ "add" ] } ) ) dto ) { const rel = await this . service . addDatasource ( dto . screenId , dto ) ; return rel ? this . success ( rel ) : this . fail ( "添加失败" ) ; } param dto returns @ Post ( "/datasource/delete" ) async delDatasource ( @ Body ( new Validation ( { groups : [ "delete" ] } ) ) dto ) { const rel = dto . id ? await this . service . delDatasource ( dto . screenId , dto . id ) : false ; return rel ? this . success ( rel ) : this . fail ( "删除失败" ) ; } }