def build(self, params): areaId = params.get('areaId', None) endDate = params.get('endDate', QtCore.QDate()) addressType = params.get('addressType', 0) isDetailByDepartment = params.get('detailByDepartment', False) isDetailByAge = params.get('detailByAge', False) rowNumber = [1] employableColBases = { 19: 10, 24: 12, 29: 14, 34: 16, 39: 18, 44: 20, 49: 22, 54: 24, 59: 26, 64: 28, 69: 30, 74: 32, 79: 34 } #Количество столбцов с данными (за исключением столбцов "Категория населения", "№": 10 на детские возраста, 28 или 4 на взрослые и 1 на поле "Всего") reportRowSize = [39 if isDetailByAge else 15] def insertDataInTable(reportTable, reportData, charFormat=None): for rowIndex, rowName in enumerate( [u'ИТОГО', u'работающие', u'неработающие']): i = reportTable.addRow() reportTable.setText(i, 0, rowName, charFormat=charFormat) reportTable.setText(i, 1, rowNumber[0], charFormat=charFormat) rowNumber[0] += 1 for j in xrange(len(reportData[rowIndex])): reportTable.setText(i, 2 + j, reportData[rowIndex][j], charFormat=charFormat) #end insertDataInTable def getData(areaId, endDate, addressType, isDetailByAge=False): if areaId: areaIdList = getOrgStructureDescendants(areaId) else: areaIdList = getOrgStructures(QtGui.qApp.currentOrgId()) query = selectData(endDate, areaIdList, addressType) reportData = [[0] * reportRowSize[0] for row in xrange(3)] self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() cnt = forceInt(record.value('cnt')) age = forceInt(record.value('clientAge')) sex = forceInt(record.value('clientSex')) busy = forceBool(record.value('busy')) if age < 1: colBase = 0 elif age == 1: colBase = 2 elif age <= 6: colBase = 4 elif age <= 14: colBase = 6 elif age <= 17: colBase = 8 else: if isDetailByAge: minAgeHigh = 150 colBase = 36 for ageHigh in employableColBases.keys(): if age <= ageHigh and ageHigh < minAgeHigh: minAgeHigh = ageHigh colBase = employableColBases[ageHigh] else: if (sex == 1 and age < 60) or (sex != 1 and age < 55): colBase = 10 else: colBase = 12 cols = [colBase + (0 if sex == 1 else 1), reportRowSize[0] - 1] rows = [0, 1 if busy else 2] if cols[0] < 0 or cols[0] > reportRowSize[0] - 1: print cols[0] for row in rows: for col in cols: reportData[row][col] += cnt return reportData #end getData def detailByDepartment(reportTable, areaId, endDate, addressType, isDetailByAge, progressDialog=None): subAreaIdList = [] db = QtGui.qApp.db tableOrgStructure = db.table('OrgStructure') whereCond = [] if areaId: #Если указан отдельный участок или группа участков whereCond.append(tableOrgStructure['parent_id'].eq(areaId)) else: #Если в качестве участка указан весь ЛПУ whereCond.append(tableOrgStructure['parent_id'].isNull()) whereCond.append(tableOrgStructure['organisation_id'].eq( QtGui.qApp.currentOrgId())) subAreaIdList = db.getIdList(table=tableOrgStructure, where=whereCond) if subAreaIdList: for subAreaId in subAreaIdList: row = reportTable.addRow() reportTable.mergeCells(row, 0, 1, reportRowSize[0] + 3) charFormat = QtGui.QTextCharFormat() charFormat.setFontWeight(QtGui.QFont.Bold) subAreaName = getOrgStructureFullName(subAreaId) reportTable.setText(row, 0, subAreaName, charFormat=charFormat, blockFormat=CReportBase.AlignLeft) if progressDialog: progressDialog.setWindowTitle(u'Обработка %s' % subAreaName) progressDialog.step() QtGui.qApp.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) detailByDepartment(reportTable, subAreaId, endDate, addressType, isDetailByAge, progressDialog) else: insertDataInTable( reportTable, getData(areaId, endDate, addressType, isDetailByAge)) #end detailByDepartment # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('15?', [u'Категории населения', u''], CReportBase.AlignLeft), ('5?', [u'№ стр.', u''], CReportBase.AlignRight), ('5?', [ u'Численность прикреплённого населения по возрастному составу', u'дети', u'', u'до 1 года', u'М' ], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'1 год', u'М'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'2-6 лет', u'М'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'7-14 лет', u'М'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'15-17 лет', u'М'], CReportBase.AlignRight), ('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight) ] if isDetailByAge: ageHighKeys = employableColBases.keys() ageHighKeys.sort() for ageHigh in ageHighKeys: index = ageHighKeys.index(ageHigh) if index <= 0: startAge = '18' else: startAge = '%d' % (ageHighKeys[index - 1] + 1) ageRangeText = u'%s - %d лет' % (startAge, ageHigh) ageState = u'взрослые' if ageHigh == 19 else u'' employableState = u'трудосп. возраста' if ageHigh == 59 else u'' tableColumns.append( ('5?', [u'', ageState, employableState, ageRangeText, u'М'], CReportBase.AlignRight)) employableState = u'нетрудосп. возраста' if ageHigh == 59 else u'' tableColumns.append( ('5?', [u'', u'', employableState, u'', u'Ж'], CReportBase.AlignRight)) tableColumns.append(('5?', [u'', u'', u'', u'80 и ст.', u'М'], CReportBase.AlignRight)) tableColumns.append(('5?', [u'', u'', u'', u'', u'Ж'], CReportBase.AlignRight)) else: tableColumns.append( ('5?', [u'', u'взрослые', u'трудосп. возраста', u'18-59 лет', u'М'], CReportBase.AlignRight)) tableColumns.append(('5?', [u'', u'', u'', u'18-54 лет', u'Ж'], CReportBase.AlignRight)) tableColumns.append( ('5?', [u'', u'', u'нетрудосп. возраста', u'60 и ст.', u'М'], CReportBase.AlignRight)) tableColumns.append(('5?', [u'', u'', u'', u'55 и ст.', u'Ж'], CReportBase.AlignRight)) tableColumns.append(('5?', [ u'Всего', ], CReportBase.AlignRight)) table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 4, 1) # Категории населения table.mergeCells(0, 1, 4, 1) # № стр. table.mergeCells(0, 2, 1, reportRowSize[0] - 1) # Численность... table.mergeCells(1, 2, 2, 10) # дети table.mergeCells(3, 2, 1, 2) # <1 table.mergeCells(3, 4, 1, 2) # 1 table.mergeCells(3, 6, 1, 2) # 2-6 table.mergeCells(3, 8, 1, 2) # 7-14 table.mergeCells(3, 10, 1, 2) # 15-17 if isDetailByAge: for i in xrange(27): table.mergeCells(3, 12 + i * 2, 1, 2) table.mergeCells(3, 12 + i * 2 + 1, 1, 2) table.mergeCells(1, 12, 1, 28) # взрослые table.mergeCells(2, 12, 1, 17) # тр. table.mergeCells(2, 29, 1, 11) # нетр. table.mergeCells(0, 40, 4, 1) # всего else: table.mergeCells(1, 12, 1, 4) # взрослые table.mergeCells(2, 12, 1, 2) # тр. table.mergeCells(2, 14, 1, 2) # нетр. table.mergeCells(0, 16, 4, 1) # всего reportData = getData(areaId, endDate, addressType, isDetailByAge) charFormat = None if isDetailByDepartment: if areaId: areaIdList = getOrgStructureDescendants(areaId) else: areaIdList = getOrgStructures(QtGui.qApp.currentOrgId()) progressBar = CProgressBar( ) #QtGui.QProgressDialog(u'Обработка данных по участкам', 'Отмена', 0, len(areaIdList)) progressBar.setMinimum(0) progressBar.setMaximum(len(areaIdList)) parentCenter = QtGui.QDesktopWidget().availableGeometry().center() progressBar.setWindowFlags(progressBar.windowFlags() | QtCore.Qt.WindowCloseButtonHint) progressBar.setGeometry(parentCenter.x() - 250, parentCenter.y() - 40, 500, 80) progressBar.setText('%v/%m') progressBar.show() QtGui.qApp.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents) detailByDepartment(table, areaId, endDate, addressType, isDetailByAge, progressBar) progressBar.hide() charFormat = QtGui.QTextCharFormat() charFormat.setFontWeight(QtGui.QFont.Bold) row = table.addRow() table.mergeCells(row, 0, 1, reportRowSize[0] + 3) table.setText(row, 0, getOrgStructureFullName(areaId), charFormat=charFormat, blockFormat=CReportBase.AlignLeft) insertDataInTable(table, reportData, charFormat=charFormat) return doc
class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(604, 150) self.gridLayout = QtGui.QGridLayout(Dialog) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self._2 = QtGui.QHBoxLayout() self._2.setMargin(0) self._2.setSpacing(6) self._2.setObjectName(_fromUtf8("_2")) self.lblLoadFrom = QtGui.QLabel(Dialog) self.lblLoadFrom.setObjectName(_fromUtf8("lblLoadFrom")) self._2.addWidget(self.lblLoadFrom) self.edtFileName = QtGui.QLineEdit(Dialog) self.edtFileName.setObjectName(_fromUtf8("edtFileName")) self._2.addWidget(self.edtFileName) self.btnSelectFile = QtGui.QToolButton(Dialog) self.btnSelectFile.setObjectName(_fromUtf8("btnSelectFile")) self._2.addWidget(self.btnSelectFile) self.gridLayout.addLayout(self._2, 0, 0, 1, 1) self.progressBar = CProgressBar(Dialog) self.progressBar.setMaximum(1) self.progressBar.setProperty("value", 0) self.progressBar.setOrientation(QtCore.Qt.Horizontal) self.progressBar.setFormat(_fromUtf8("")) self.progressBar.setObjectName(_fromUtf8("progressBar")) self.gridLayout.addWidget(self.progressBar, 1, 0, 1, 1) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.chkAgree = QtGui.QCheckBox(Dialog) self.chkAgree.setEnabled(False) self.chkAgree.setObjectName(_fromUtf8("chkAgree")) self.horizontalLayout_2.addWidget(self.chkAgree) self.chkImportExternal = QtGui.QCheckBox(Dialog) self.chkImportExternal.setEnabled(False) self.chkImportExternal.setObjectName(_fromUtf8("chkImportExternal")) self.horizontalLayout_2.addWidget(self.chkImportExternal) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_2.addItem(spacerItem) self.gridLayout.addLayout(self.horizontalLayout_2, 2, 0, 1, 1) self.hboxlayout = QtGui.QHBoxLayout() self.hboxlayout.setMargin(0) self.hboxlayout.setSpacing(6) self.hboxlayout.setObjectName(_fromUtf8("hboxlayout")) self.btnImport = QtGui.QPushButton(Dialog) self.btnImport.setEnabled(False) self.btnImport.setObjectName(_fromUtf8("btnImport")) self.hboxlayout.addWidget(self.btnImport) spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.hboxlayout.addItem(spacerItem1) self.lblNum = QtGui.QLabel(Dialog) self.lblNum.setObjectName(_fromUtf8("lblNum")) self.hboxlayout.addWidget(self.lblNum) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.hboxlayout.addItem(spacerItem2) self.btnClose = QtGui.QPushButton(Dialog) self.btnClose.setObjectName(_fromUtf8("btnClose")) self.hboxlayout.addWidget(self.btnClose) self.gridLayout.addLayout(self.hboxlayout, 3, 0, 1, 1) spacerItem3 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout.addItem(spacerItem3, 4, 0, 1, 1) self.logBrowser = QtGui.QTextBrowser(Dialog) self.logBrowser.setEnabled(True) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.logBrowser.sizePolicy().hasHeightForWidth()) self.logBrowser.setSizePolicy(sizePolicy) self.logBrowser.setObjectName(_fromUtf8("logBrowser")) self.gridLayout.addWidget(self.logBrowser, 5, 0, 1, 1) self.retranslateUi(Dialog) QtCore.QObject.connect(self.chkAgree, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.btnImport.setEnabled) QtCore.QObject.connect(self.btnClose, QtCore.SIGNAL(_fromUtf8("clicked()")), Dialog.close) QtCore.QMetaObject.connectSlotsByName(Dialog) Dialog.setTabOrder(self.edtFileName, self.btnSelectFile) Dialog.setTabOrder(self.btnSelectFile, self.chkAgree) Dialog.setTabOrder(self.chkAgree, self.chkImportExternal) Dialog.setTabOrder(self.chkImportExternal, self.btnImport) Dialog.setTabOrder(self.btnImport, self.btnClose) Dialog.setTabOrder(self.btnClose, self.logBrowser) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Импорт данных ФЛК", None)) self.lblLoadFrom.setText(_translate("Dialog", "Загрузить из", None)) self.btnSelectFile.setText(_translate("Dialog", "...", None)) self.chkAgree.setText( _translate("Dialog", "С протоколом ознакомлен", None)) self.chkImportExternal.setText( _translate("Dialog", "Загружать инокраевых", None)) self.btnImport.setText( _translate("Dialog", "начать импортирование", None)) self.lblNum.setText( _translate("Dialog", "всего обновлённых записей в источнике:", None)) self.btnClose.setText(_translate("Dialog", "закрыть", None))