def prhlmcQuery(request): params = request.GET prhlmc = params.get("prhlmc") pwks = get_pwkQuery_set(request).filter(prhlmc=prhlmc).values( "id", "bd_jd", "bd_wd", "psxz", "zzqk", "fspfl", "pwkmc") for pwk in pwks: pwk["psxz"] = psxzbm2name(pwk["psxz"]) pwk["calSize"] = calSize(pwk["fspfl"]) return render(request, 'pwk/prhlQuery.html', { "pwks": pwks, })
def pwk_query(request): form = QueryListForm(request.POST or None) dthlChoice(request, form) pwkmc = "" xz = "" zzqk = "" prhlmc = "" psqk = "" psxz = "" qrqk = '' if request.method == "POST" and form.is_valid(): queryDict = form.cleaned_data pwkmc = queryDict["pwkmc"] xz = queryDict["xz"] zzqk = queryDict['zzqk'] prhlmc = queryDict['prhlmc'] psqk = queryDict['psqk'] psxz = queryDict['psxz'] qrqk = queryDict['qrqk'] # 查询条件,如果都为空表示不做限制 pwks = get_pwkQuery_set(request).all().order_by("id") # 查询排入河流名称 if pwkmc: pwks = pwks.filter(pwkmc__icontains=pwkmc) if xz: pwks = pwks.filter(xz=xz) if zzqk: pwks = pwks.filter(zzqk=zzqk) if prhlmc: pwks = pwks.filter(prhlmc=prhlmc) if psqk: if psqk == "有排水": pwks = pwks.filter(fspfl__gt=0) else: pwks = pwks.filter(fspfl__lte=0) if psxz: pwks = pwks.filter(psxz=psxz) if not qrqk == "": if qrqk == "1": # 调整为溯源情况 pwks = pwks.filter(syPwkbz=qrqk) else: pwks = pwks.exclude(syPwkbz='1') # 范围查询 request.session["pwk_page"] = pwks request.session["pwk_form"] = form
def dthlChoice(request, form): hl_choice = [("", "排入河流--全部")] hlmcs = get_pwkQuery_set(request).values("prhlmc") for item in hlmcs: newItem = (item["prhlmc"], item["prhlmc"]) if newItem in hl_choice: pass else: hl_choice.append(newItem) form.fields['prhlmc'].choices = hl_choice # 处理乡镇的内容 xzqhdm = getxzcode(request) if xzqhdm[0]: xz = [] xz.append(xzqhdm) form.fields['xz'].choices = xz
def pwk_map_list(request): form = IndexForm(request.POST or None) dthlChoice(request, form) pwkmc = "" xz = "" zzqk = "" prhlmc = "" psqk = "" if request.method == "POST" and form.is_valid(): queryDict = form.cleaned_data pwkmc = queryDict["pwkmc"] xz = queryDict["xz"] zzqk = queryDict['zzqk'] prhlmc = queryDict['prhlmc'] psqk = queryDict['psqk'] # 查询条件,如果都为空表示不做限制 pwks = get_pwkQuery_set(request).all() # 查询排入河流名称 if pwkmc: pwks = pwks.filter(pwkmc__icontains=pwkmc) if xz: pwks = pwks.filter(xz=xz) if zzqk: pwks = pwks.filter(zzqk=zzqk) if prhlmc: pwks = pwks.filter(prhlmc=prhlmc) if psqk: if psqk == "有排水": pwks = pwks.filter(fspfl__gt=0) else: pwks = pwks.filter(fspfl__lte=0) pwks = pwks.values("id", "bd_jd", "bd_wd", "zzqk", "fspfl", "pwkmc") pwkList = [] for pwk in pwks: pwk["calSize"] = calSize(pwk["fspfl"]) pwkList.append(json.dumps(pwk, ensure_ascii=False)) returnDict = { "pwks": pwkList, } return JsonResponse(returnDict, safe=False)
def sypwk(request): # 增加权限,只有区县的才能确认 userRole = getxzcode(request) message = "" status = "" if not userRole[0]: # 为区县用户可以修改 id = request.GET['id'] pwk = get_pwkQuery_set(request).get(id=id) if pwk.syPwkbz and pwk.syPwkbz == "是": pwk.syPwkbz = "否" status = "否" else: pwk.syPwkbz = "是" status = "是" pwk.save() message = pwk.pwkmc + "修改成为:" + status + " 溯源排污口." else: message = "只有区县用户才能操作!" outString = {"message": message, "status": status} return JsonResponse(outString, safe=False)
def qrpwk(request): # 增加权限,只有区县的才能确认 userRole = getxzcode(request) message = "" status = "" if not userRole[0]: # 为区县用户可以修改 id = request.GET['id'] pwk = get_pwkQuery_set(request).get(id=id) if pwk.qrqk: pwk.qrqk = 0 status = "未确认" else: pwk.qrqk = 1 status = "已确认" pwk.save() message = pwk.pwkmc + "修改成为:" + status + "." else: message = "只有区县用户才能操作!" outString = {"message": message, "status": status} return JsonResponse(outString, safe=False)
def pwk_tjbb(request): # 各乡镇总排污口数量 xz_count = get_pwkQuery_set(request).values("xz").annotate( pwks=Count("id")) # 各乡镇溯源排污口数 xz_sy_count=get_pwkQuery_set(request).filter(syPwkbz="1")\ .values("xz").annotate(pwks=Count("id")) # 各乡镇新增排污口数--新增 xz_xz_count=get_pwkQuery_set(request).exclude(syPwkbz="1")\ .values("xz").annotate(pwks=Count("id")) # 各乡镇排污口治理情况 xz_zl_count=get_pwkQuery_set(request)\ .values("xz","zzqk").annotate(pwks=Count("id")) # 对已治理的排污口根据整治类别进行分类 xz_yzl_count=get_pwkQuery_set(request).filter(zzqk="已治理")\ .values("xz","zlfs_lb").annotate(pwks=Count("id")) tj_result = {} # 开始拼装数据--总排口数量 for item in xz_count: tj_result[item["xz"]] = {"zpksl": item["pwks"]} # 溯源排污口数 for item in xz_sy_count: tj_result[item["xz"]]["sypksl"] = item["pwks"] # 新增排污口 for item in xz_xz_count: tj_result[item["xz"]]["xzpwk"] = item["pwks"] # 整治情况 for item in xz_zl_count: if item["zzqk"] == "已治理": tj_result[item["xz"]]["yzl_gj"] = item["pwks"] if item["zzqk"] == "正在治理": tj_result[item["xz"]]["zzzl"] = item["pwks"] if item["zzqk"] == "计划治理": tj_result[item["xz"]]["jhzl"] = item["pwks"] # 已治理的排污口分类 for item in xz_yzl_count: if item['zlfs_lb'] == "雨水": tj_result[item["xz"]]["ys"] = item['pwks'] if item['zlfs_lb'] == "退水口": tj_result[item["xz"]]["tsk"] = item['pwks'] if item['zlfs_lb'] == "入河口": tj_result[item["xz"]]["rhk"] = item['pwks'] if item['zlfs_lb'] == "供水泄水口": tj_result[item["xz"]]["gsxsk"] = item['pwks'] if item['zlfs_lb'] == "封堵": tj_result[item["xz"]]["fd"] = item['pwks'] if item['zlfs_lb'] == "截污纳管": tj_result[item["xz"]]["jwng"] = item['pwks'] if item['zlfs_lb'] == "拆迁清除": tj_result[item["xz"]]["cqqc"] = item['pwks'] if item['zlfs_lb'] == "废弃": tj_result[item["xz"]]["fc"] = item['pwks'] if item['zlfs_lb'] == "经污水处理设施排放": tj_result[item["xz"]]["wscl"] = item['pwks'] if item['zlfs_lb'] == "集中收集抽运": tj_result[item["xz"]]["jzsjcy"] = item['pwks'] #合计值 hz = {} hz["zpksl"] = get_pwkQuery_set(request).count() hz["sypksl"] = get_pwkQuery_set(request).filter(syPwkbz="1").count() hz["xz"] = get_pwkQuery_set(request).exclude(syPwkbz="1").count() hz["yzl_gj"] = get_pwkQuery_set(request).filter(zzqk="已治理").count() hz["ys"] = get_pwkQuery_set(request).filter(zzqk="已治理")\ .filter(zlfs_lb="雨水").count() hz["tsk"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="退水口").count() hz["rhk"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="入河口").count() hz["gsxsk"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="供水泄水口").count() hz["fd"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="封堵").count() hz["jwng"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="截污纳管").count() hz["cqqc"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="拆迁清除").count() hz["fc"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="废弃").count() hz["wscl"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="经污水处理设施排放").count() hz["jzsjcy"] = get_pwkQuery_set(request).filter(zzqk="已治理") \ .filter(zlfs_lb="集中收集抽运").count() hz["zzzl"] = get_pwkQuery_set(request).filter(zzqk="正在治理").count() hz["jhzl"] = get_pwkQuery_set(request).filter(zzqk="计划治理").count() # 乡镇 xz = {} for item in XZ_CHOICE: xz[item[0]] = item[1] for k, item in tj_result.items(): item["xzmc"] = xz[k] return render(request, "pwk/pwk_tjbb.html", { "result": tj_result, "xz": xz, "hz": hz })
def pwk_chart(request): # 根据乡镇分组查询排污口数量 xz_count = get_pwkQuery_set(request).values("xz", "zzqk").annotate(Count("id")) # X轴 x = [] x_bm = [] count_xz = [] # 正在治理 zzzl = [] # 已治理 yzl = [] # 计划治理 jhzl = [] # 河流已治理 # 把所有乡镇编码取出来 for item in xz_count: xzbm = item['xz'] if xzbm in x_bm: pass else: x_bm.append(xzbm) x.append(xzbm2name(xzbm)) # 拼装数据 for idx, xz in enumerate(x_bm): for item in xz_count: if item['xz'] == xz: if item['zzqk'] == '已治理': yzl.append(item['id__count']) elif item['zzqk'] == '正在治理': zzzl.append(item['id__count']) else: jhzl.append(item['id__count']) # 没有数字的用0来填充 if len(zzzl) != idx + 1: zzzl.append(0) if len(yzl) != idx + 1: yzl.append(0) if len(jhzl) != idx + 1: jhzl.append(0) count_xz.append({ "xz": x[idx], "pwks": zzzl[idx] + yzl[idx] + jhzl[idx], "yzl": yzl[idx], "jhzl": jhzl[idx], "zzzl": zzzl[idx] }) xj_count = {} xj_count["zzzl"] = sum(zzzl) xj_count["yzl"] = sum(yzl) xj_count["jhzl"] = sum(jhzl) xj_count["pwk"] = xj_count["zzzl"] + xj_count["yzl"] + xj_count["jhzl"] # 把乡镇编码转换为名称 return render( request, "pwk/pwk_chart.html", { "xAxis": x, "yzl": yzl, "zzzl": zzzl, "jhzl": jhzl, "count_xz": count_xz, "xj_count": xj_count, })
def get_queryset(self): queryset = get_pwkQuery_set(self.request) queryset = self._queryDict_(queryset) return queryset