table_vacuate_info.py 2.4 KB
# author:        4N
# createtime:    2021/1/27
# email:         nheweijun@sina.com


from ..models import Table,TableVacuate,Task
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.VacuateConf import VacuateConf


import copy
class Api(ApiTemplate):
    api_name = "抽稀info"
    def process(self):

        res = {}
        try:

            lonlat_gridsize = VacuateConf.lonlat_gridsize
            project_gridsize = VacuateConf.project_gridsize
            table_guid = self.para.get("guid")

            table: Table = Table.query.filter_by(guid=table_guid).one_or_none()
            if not table:
                raise Exception("数据不存在!")
            tvs = TableVacuate.query.filter_by(table_guid=table_guid).all()
            dat = {}
            info = {}

            if float(table.extent.split(",")[0]) < 180:
                grid_size = copy.copy(lonlat_gridsize)
            else:
                grid_size = copy.copy(project_gridsize)

            now_grid = [tv.pixel_distance for tv in tvs]

            grid_size.reverse()

            # 正在精华的任务
            task_running = Task.query.filter_by(task_type=2, table_guid=table_guid, state=0).all()
            grid_running = []

            for t in task_running:
                grid_running.extend(t.parameter.split(","))

            info["type"] = "m"
            for grid in grid_size:
                if grid in now_grid:
                    dat[str(grid)] = 1
                else:
                    dat[str(grid)] = 0
                if str(grid) in grid_running:
                    dat[str(grid)] = 2
                # 特殊处理一下
                if grid == 0.00008:
                    dat["0.00008"] = dat[str(grid)]
                    del dat[str(grid)]
                    info["type"] = "d"
            info["info"] = dat

            res["data"] = info
            res["result"] = True

        except Exception as e:
            raise e
        return res

    api_doc = {
        "tags": ["管理接口"],
        "parameters": [
            {"name": "guid",
             "in": "formData",
             "type": "string",
             "description": "表guid", "required": "true"},
        ],
        "responses": {
            200: {
                "schema": {
                    "properties": {
                    }
                }
            }
        }
    }