Пример #1
0
    def add_doctype(self):
        url = '/v1/doc-type/'

        resp = proxy.get(url)
        if resp.status_code != 200:
            flash('暂时无法更新支持的文档资料列表', 'error')
            return redirect(self.get_url('.index'))

        # 原来支持的
        support_doctypes = resp.json()['items'] or []
        # 现在更新的
        doc_type = request.form.get('doc_type', None)
        if not doc_type:
            flash('文档资料类别不能为空。', 'error')
            return redirect(self.get_url('.index'))

        supported = set([item['id'] for item in support_doctypes])
        update = set(doc_type.split(','))

        if update < supported:
            flash('文档库资料类别只能新增或重置', 'error')
            return redirect(self.get_url('.index'))

        try:
            new_add = update - supported
            for item in new_add:
                doc_type = dict(id=item, value=item)
                proxy.create(doc_type, url)
        except:
            raise BackendServiceError(
                'Update support doctype occured failure.')
        flash('文档资料类别更新成功。', 'success')
        return redirect(self.get_url('.index'))
Пример #2
0
    def _before_custom_action(self, model, action, **kwargs):
        if action == Finish:
            # 执行远端请求

            # WUJG: 确保model.jcTime的值为时间戳字符串
            timestamp = int(model.jcTime)
            bounded_id = model.boundedid

            if model.jcType == '航线检查' or model.jcType == '停放检查':
                return;

            if int(time.mktime(datetime.today().timetuple())) < timestamp:
                raise ValueError('完成时间为何大于今天?')

            if model.contextDesc is None:
                raise ValueError('请输入“检查内容”')

            if ',' in bounded_id:
                bounded_id = bounded_id.split(",")
                data = [{'boundedId': x, 'finishTime': int(timestamp), 'remark': ''} for x in bounded_id]
            elif bounded_id:
                data = [{'boundedId': bounded_id, 'finishTime': int(timestamp), 'remark': ''}]
            else:
                raise ValueError('数据有误,请联系管理员?')

            proxy.create(data, '/v1/mxm/accomplish?batch=1')
Пример #3
0
 def download_view(self):
     key = request.args.get('key')
     post = {"key": key}
     url = "/v1/file-access/download"
     resp = proxy.create(post, url)
     acc_url = resp.json().get('url')
     return redirect(acc_url, 301)
Пример #4
0
 def generate_data(self, data):
     info = {"docType": "维修方案",
             "fileName": data.filename}
     url = "/v1/file-access/upload"
     resp = proxy.create(info, url)
     if resp.status_code != 200:
         raise BackendServiceError("file-access api has someting wrong")
     token = resp.json().get("token")
     key = resp.json().get("key")
     save_key = resp.json().get("saveKey")
     return {'data': data, 'token': token, 'key': key, 'save_key': save_key}
Пример #5
0
 def _save_file(self, data, file_name=None):
     if file_name:
         info = {"docType": "维修方案", "fileName": file_name}
         url = "/v1/file-access/upload"
         resp = proxy.create(info, url)
         try:
             self.token = resp.json().get("token")
             self.key = resp.json().get("key")
             self.save_key = resp.json().get("saveKey")
             ret, info = put_data(self.token, self.key, data)
         except:
             raise Exception("Please contact the service maintainer.")
Пример #6
0
 def _save_file(self, data, file_name):
     if file_name:
         info = self.get_info(file_name)
         url = "/v1/file-access/upload"
         resp = proxy.create(info, url)
         if resp.status_code != 200:
             raise BackendServiceError("file-access api has someting wrong")
         token = resp.json().get("token")
         key = resp.json().get("key")
         save_key = resp.json().get("saveKey")
         ret, info = put_data(token, key, bytes(data.stream.read()))
         if info.status_code != 200:
             logging.warn(token)
             logging.warn(save_key)
             logging.warn(ret)
             logging.warn(info)
             raise QiNiuServiceError("qiniu service have something wrong")
         self.store.append({'name': file_name, 'key': save_key})
         return file_name
Пример #7
0
    def commit_log(self, date_str):

        def prepare_commit(data):
            self._custom_action(data, dict(), action='finish',
                                direct_commit=False)
            self.session.add(data)
            return data.to_api_data()

        try:
            exists = FlightLog.get_all_data_by_day(date_str)
            status = [data.status for data in exists]
            if Finished in status:
                return (400, '当天的日志已经提交了,你可能提交的是旧数据?', {})

            # 这个地方进行判断数据是否有相同的flightlogId 如果有,则报错
            log_ids = [data.flightlogId for data in exists]
            logId_count = collections.Counter(log_ids)
            if logId_count.values().count(1) != len(logId_count.values()):
                return (400, '当天的日志的编号有相同的,请从新填写,再提交', {})

            commit_datas = [prepare_commit(data) for data in exists]

            # 执行远程REQUEST请求
            # TODO: 写死的机型
            resp = proxy.create(commit_datas, '/v1/y5b/flightlog/?batch=1')
            if resp.status_code != 200 and resp.status_code != 201:
                raise ValueError(resp.json()['message'])

            if resp.json()['count'] != len(commit_datas):
                raise ValueError('\n'.join(resp.json()['uninserted']))

            self.session.commit()
        except Exception as ex:
            self.session.rollback()
            return (400, unicode(ex), {})

        return (200, 'ok', {'username': current_user.realName,
                            'timestamp': date.today().strftime('%Y-%m-%d')})