def getCurrentData(): ''' 第一次最上面公告 获取pid:origin ,pid 对应的json进行组装成新的json。 将最新版和授权版进行返回 :param shenqingh: :param documentType: :return: 组装后的json ''' shenqingh = request.values.get('shenqingh') documentType = request.values.get('wenjianlx') if shenqingh is None or documentType is None: raise InvalidUsage("shenqingh or documentType is None", status_code=401) #1.获取整体json key = utils.getKey(shenqingh, documentType) value = redisUtils.getStrValue(client, key) context = {} context['lastVersion'] = [] if value is not None and value != 0: valueDict = json.loads(value) #路径添加前缀 context['lastVersion'] = valueDict['lastVersion'] ImagePathUtils.currentPreffixHandle(context, 'addPrefix') result = json.dumps(context, ensure_ascii=False, encoding='utf-8') return result, {'Content-Type': 'application/json'}
def getThrumbImgs(): ''' :return: 原始版和授权版 ''' paramJson = request.get_json() if paramJson is None: raise InvalidUsage('get params exception', status_code=401) result = {} for key in paramJson.keys(): #0申请号、1文献类型 arr = paramJson[key] shenqinghKey = arr[0] + '_' + arr[1] context = {} context['origin'] = [] context['authVersion'] = {} originKey = utils.getKey(arr[0], arr[1], 'origin') originDict = redisUtils.getHashValues(client, originKey) for key in originDict.keys(): fidContext = {} fidContext['fid'] = key fidData = json.loads(originDict[key]) ImagePathUtils.originPreffixHandle(fidData, 'addPrefix') fidContext['data'] = fidData['data'] # fidContext['date'] = fidData['date'] context['origin'].append(fidContext) authKey = utils.getKey(arr[0], arr[1], 'auth') authStr = redisUtils.getStrValue(client, authKey) if authStr is not None and authStr != 0: authJson = json.loads(authStr) ImagePathUtils.authPreffixHandle(authJson, 'addPrefix') context['authVersion'] = authJson result[shenqinghKey] = context return json.dumps(result, ensure_ascii=False, encoding='utf-8'), { 'Content-Type': 'application/json' }
def modifyImg(): ''' ?结构中图片版本如何更新 直接提交修改图片和修改信息 ?前端如何维护图片的版本号 ~A :return: ''' try: shenqingh = request.values.get('shenqingh') documentType = request.values.get('wenjianlx') pic_name = request.values.get('pic_name') #img path pic_version = request.values.get('pic_version') #img 修改版本 rotate_desc = request.values.get('rotate_desc') if shenqingh is None or documentType is None or pic_name is None or pic_version is None: raise InvalidUsage("get params is None", status_code=401) try: img_str = request.values.get('image_data') except Exception as e: logger.info(traceback.format_exc()) raise InvalidUsage('Invalid "img" param, must be a blob string', status_code=431) #1.获取图片最新版本号并加1 date, fid, imgId = appLogic.parsePath(pic_name) # 从json获取图片版本号并加一 key = utils.getKey(shenqingh, documentType) value = redisUtils.getStrValue(client, key) if value is not None and value != 0: value = json.loads(value) lastVersionData = value['lastVersion'] for context in lastVersionData: if context['date'] == date and context['fid'] == fid: path, rotateInfo = getVersionPath(context['data'], imgId, pic_version, rotate_desc) redisUtils.setStrValue( client, key, json.dumps(value, ensure_ascii=False, encoding='utf-8')) index1 = path.rfind('.') index2 = path.rfind('~') version = path[index2 + 1:index1] imgdata = base64.b64decode(img_str) file = open(path, 'wb') file.write(imgdata) #生成缩略图 logger.info('thrumb path : ' + path) appLogic.thrumbImg(path, thumbSizeList) break except Exception as e: logger.info(traceback.format_exc()) raise InvalidUsage('save update image fail ', status_code=432) out = {'version': version, "rotateInfo": rotateInfo} response = make_response(jsonify(out)) response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Methods'] = 'POST' response.headers[ 'Access-Control-Allow-Headers'] = 'x-requested-with,content-type' return response
def deleteAuthDir(client, authKey): authJson = redisUtils.getStrValue(client, authKey) if authJson == 0: return False if authJson is not None: authDic = json.loads(authJson) oldPath = authDic["path"] logger.info("delete old dir: " + authKey + " , " + oldPath) #删除旧文件 if os.path.exists(oldPath): shutil.rmtree(oldPath) #删除redis中数据 redisUtils.deleteKey(client, authKey) return True
def getAuthImgs(): shenqingh = request.values.get('shenqingh') documentType = request.values.get('wenjianlx') if shenqingh is None or documentType is None: raise InvalidUsage('get params exception', status_code=401) authKey = utils.getKey(shenqingh, documentType, 'auth') value = redisUtils.getStrValue(client, authKey) res = {} res['authVersion'] = '' if value is not None and value != 0: valueLoad = json.loads(value) ImagePathUtils.authPreffixHandle(valueLoad, 'addPrefix') res['authVersion'] = valueLoad result = json.dumps(res, ensure_ascii=False, encoding='utf-8') return result, {'Content-Type': 'application/json'}
def loadData(): ''' 第一次最上面公告 获取pid:origin ,pid 对应的json进行组装成新的json。 将最新版和授权版进行返回 :param shenqingh: :param documentType: :return: 组装后的json ''' shenqingh = request.values.get('shenqingh') documentType = request.values.get('wenjianlx') if shenqingh is None or documentType is None: raise InvalidUsage("shenqingh or documentType is None", status_code=401) #1.获取当前版json key = utils.getKey(shenqingh, documentType) value = redisUtils.getStrValue(client, key) resultJson = {} if value is not None and value != 0: resultJson = json.loads(value) ImagePathUtils.currentPreffixHandle(resultJson, 'addPrefix') authKey = utils.getKey(shenqingh, documentType, 'auth') #2.获取授权版 authValue = redisUtils.getStrValue(client, authKey) if authValue is not None and authValue != 0: authJson = json.loads(authValue) ImagePathUtils.authPreffixHandle(authJson, 'addPrefix') resultJson['authVersion'] = authJson result = json.dumps(resultJson, ensure_ascii=False, encoding='utf-8') response = make_response(result) response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Methods'] = 'POST' response.headers[ 'Access-Control-Allow-Headers'] = 'x-requested-with,content-type' return response
def uploadXMLCase(): ''' 从ftp服务器下载zip压缩包,解压到原始文件夹, 将文件夹中的图片生成缩略图 解析xml为originJson,currentJson, 将生成的json保存到redis中 公告图以最后一个fid为准 :return: 同一案件该接口支持重复入库 ''' #1.获取ftp列表json jsonData = request.get_json() logger.info("upload: " + str(jsonData)) if jsonData is None: logger.info("获取参数错误:" + str(jsonData)) return jsonify({'status': 0}) if 'cases' in jsonData.keys(): cases = jsonData['cases'] for case in cases: if appLogic.validCase(case) == 0: return jsonify({'status': 0}) currentDir, zipDir, zipFile = appLogic.getZipFilePath(case) if os.path.isfile(zipFile): logger.info("文件已经存在,跳过") continue try: shenqingh = case['shenqingh'] documentType = case['wenjianlx'] fid = case['fid'] #2.从ftp服务器下载zip到origin,并解压到origin文件夹下 #下载、解压、缩略图、复制 flag = appLogic.ftpDownload(case) if flag == 0: appLogic.deleteAll(case) logger.info('申请号:' + shenqingh + ' ,文件类型: ' + documentType + ' ,fid: ' + fid + ' : download Failed!') return jsonify({'status': 0}) #4.解析xml文件为json结构 originJson, currentJson, noticePath = appLogic.parseXmlToJson(case) if len(originJson) == 0 or len(currentJson) == 0: appLogic.deleteAll(case) logger.info('申请号:' + shenqingh + ' ,文件类型: ' + documentType + ' ,fid: ' + fid + ' : xml parse exception!') return jsonify({'status': 0}) # 原始结构添加公告图 originJson['notice'] = noticePath # 将原始数据保存到redis originKey = utils.getKey(shenqingh, documentType, 'origin') originValueStr = json.dumps(originJson, ensure_ascii=False, encoding='utf-8') success = redisUtils.setHashField(client, originKey, fid, originValueStr) if success == 0: appLogic.deleteAll(case) return jsonify({'status': 0}) #组合当前版json =>生成原始时同时生成当前版 #获取以前的当前版json currentKey = utils.getKey(shenqingh, documentType, '') oldCurrent = redisUtils.getStrValue(client, currentKey) if oldCurrent == 0: appLogic.deleteAll(case) return jsonify({'status': 0}) if oldCurrent is None: context = {} context['pid'] = shenqingh + '_' + documentType context['notice'] = noticePath lastVersion = [] lastVersion.append(currentJson) context['lastVersion'] = lastVersion contextStr = json.dumps(context, ensure_ascii=False, encoding='utf-8') else: oldCurrentDict = json.loads(oldCurrent) if noticePath != '': oldCurrentDict['notice'] = noticePath oldCurrentData = oldCurrentDict['lastVersion'] oldCurrentData.append(currentJson) contextStr = json.dumps(oldCurrentDict, ensure_ascii=False, encoding='utf-8') success = redisUtils.setStrValue(client, currentKey, contextStr) if success == 0: appLogic.deleteAll(case) return jsonify({'status': 0}) except Exception as e: appLogic.deleteAll(case) logger.info('申请号:' + shenqingh + ' ,文件类型: ' + documentType + ' ,fid: ' + fid + ' : exception!') logger.info(traceback.format_exc()) return jsonify({'status': 0})
print 'failed, parse xml failed and delete all,origin path: ' + originPath return # 原始结构添加公告图 originJson['notice'] = noticePath # 将原始数据保存到redis originKey = utils.getKey(shenqingh, documentType, 'origin') originValueStr = json.dumps(originJson, ensure_ascii=False, encoding='utf-8') success = redisUtils.setHashField(client, originKey, fid, originValueStr) if success == 0: appLogic.deleteAll(case) print 'failed, redis set failed and delete all,origin path: ' + originPath return # 组合当前版json =>生成原始时同时生成当前版 # 获取以前的当前版json currentKey = utils.getKey(shenqingh, documentType, '') oldCurrent = redisUtils.getStrValue(client, currentKey) if oldCurrent == 0: appLogic.deleteAll(case) print 'failed, redis get failed and delete all,origin path: ' + originPath return if oldCurrent is None: context = {} context['pid'] = shenqingh + '_' + documentType context['notice'] = noticePath lastVersion = [] lastVersion.append(currentJson) context['lastVersion'] = lastVersion contextStr = json.dumps(context, ensure_ascii=False, encoding='utf-8') else: oldCurrentDict = json.loads(oldCurrent) if noticePath != '':