diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/Staff.java b/src/main/java/com/ffii/tsms/modules/data/entity/Staff.java index 01ee6ba..a72fb00 100644 --- a/src/main/java/com/ffii/tsms/modules/data/entity/Staff.java +++ b/src/main/java/com/ffii/tsms/modules/data/entity/Staff.java @@ -66,7 +66,7 @@ public class Staff extends BaseEntity { @NotNull @ManyToOne - @JoinColumn(name = "salaryId") + @JoinColumn(name = "salaryId", referencedColumnName="salaryPoint") private Salary salary; @ManyToOne diff --git a/src/main/java/com/ffii/tsms/modules/data/service/SalaryService.kt b/src/main/java/com/ffii/tsms/modules/data/service/SalaryService.kt index 37cefce..33a6929 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/SalaryService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/SalaryService.kt @@ -4,6 +4,7 @@ import com.ffii.core.support.AbstractBaseEntityService import com.ffii.core.support.AbstractIdEntityService import com.ffii.core.support.JdbcDao import com.ffii.core.utils.ExcelUtils +import com.ffii.core.utils.NumberUtils import com.ffii.tsms.modules.data.entity.Salary import com.ffii.tsms.modules.data.entity.SalaryRepository import com.ffii.tsms.modules.data.entity.projections.SalarySearchInfo @@ -25,7 +26,7 @@ open class SalaryService( open fun combo(args: Map): List> { val sql = StringBuilder("select" - + " id, " + + " salaryPoint as id, " + " concat(salaryPoint, ' (', lowerLimit,' - ', upperLimit, ') ') as label " + " from salary s " ) @@ -50,19 +51,26 @@ open class SalaryService( "SET FOREIGN_KEY_CHECKS = 1" ) + val resetAutoIncrement = StringBuilder( + "ALTER TABLE salary AUTO_INCREMENT = 1" + ) + jdbcDao.executeUpdate(disableForeignKeyChecks.toString()) + jdbcDao.executeUpdate(resetAutoIncrement.toString()) jdbcDao.executeUpdate(deleteDataInSalary.toString()) val sheet: Sheet = workbook.getSheetAt(0) // val sheetValues: MutableList> = ArrayList() + val evaluator = sheet.workbook.creationHelper.createFormulaEvaluator() for (i in 2..sheet.lastRowNum){ val salary = Salary().apply { + salaryPoint = ExcelUtils.getIntValue(ExcelUtils.getCell(sheet, i, 0)) - lowerLimit = ExcelUtils.getIntValue(ExcelUtils.getCell(sheet, i, 1)) - upperLimit = ExcelUtils.getIntValue(ExcelUtils.getCell(sheet, i, 2)) + lowerLimit = evaluator.evaluate(ExcelUtils.getCell(sheet, i, 1)).numberValue.toInt() + upperLimit = evaluator.evaluate(ExcelUtils.getCell(sheet, i, 2)).numberValue.toInt() increment = ExcelUtils.getIntValue(ExcelUtils.getCell(sheet, i, 3)) - hourlyRate = ExcelUtils.getDecimalValue(ExcelUtils.getCell(sheet, i, 4)) + hourlyRate = evaluator.evaluate(ExcelUtils.getCell(sheet, i, 4)).numberValue.toBigDecimal() } saveAndFlush(salary) // println("Lower Limit: " + ExcelUtils.getIntValue(ExcelUtils.getCell(sheet, i, 1))) diff --git a/src/main/java/com/ffii/tsms/modules/data/web/SalaryController.kt b/src/main/java/com/ffii/tsms/modules/data/web/SalaryController.kt index 85b03f9..8bea0d4 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/SalaryController.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/SalaryController.kt @@ -2,6 +2,7 @@ package com.ffii.tsms.modules.data.web import com.ffii.core.response.RecordsRes import com.ffii.core.utils.CriteriaArgsBuilder +import com.ffii.tsms.modules.data.entity.Salary import com.ffii.tsms.modules.data.entity.projections.SalarySearchInfo import com.ffii.tsms.modules.data.service.DepartmentService import com.ffii.tsms.modules.data.service.SalaryService @@ -65,8 +66,8 @@ class SalaryController( @PostMapping("/export") @Throws(ServletRequestBindingException::class, IOException::class) fun exportSalaryList(): ResponseEntity { - - val reportResult: ByteArray = excelReportService.exportSalaryList() + val salarys: List = salaryService.listAll() + val reportResult: ByteArray = excelReportService.exportSalaryList(salarys) // val mediaType: MediaType = MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") return ResponseEntity.ok() // .contentType(mediaType) diff --git a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt index a8b74a9..f707f3e 100644 --- a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt @@ -1,5 +1,7 @@ package com.ffii.tsms.modules.report.service +import com.ffii.tsms.modules.data.entity.Salary +import com.ffii.tsms.modules.data.entity.projections.SalarySearchInfo import com.ffii.tsms.modules.project.entity.Invoice import com.ffii.tsms.modules.project.entity.Project import org.apache.poi.ss.usermodel.Sheet @@ -36,9 +38,9 @@ open class ReportService { } @Throws(IOException::class) - fun exportSalaryList(): ByteArray { + fun exportSalaryList(salarys: List): ByteArray { // Generate the Excel report with query results - val workbook: Workbook = createSalaryList(SALART_LIST_TEMPLATE) + val workbook: Workbook = createSalaryList(salarys, SALART_LIST_TEMPLATE) // Write the workbook to a ByteArrayOutputStream val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() @@ -174,13 +176,37 @@ open class ReportService { @Throws(IOException::class) private fun createSalaryList( + salarys : List, templatePath: String, ): Workbook { + val resource = ClassPathResource(templatePath) val templateInputStream = resource.inputStream val workbook: Workbook = XSSFWorkbook(templateInputStream) + val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") + val sheet: Sheet = workbook.getSheetAt(0) + var rowIndex = 2 + + salarys.forEachIndexed { index, salary -> + + sheet.getRow(rowIndex++).apply { + + getCell(0).setCellValue(salary.salaryPoint.toDouble()) + when (index){ + 0 -> getCell(1).setCellValue(salary.lowerLimit.toDouble()) + + else -> getCell(1).cellFormula = "(C{previousRow}+1)".replace("{previousRow}", (rowIndex - 1).toString()) + } + getCell(2).cellFormula = "(B{currentRow}+D{currentRow})-1".replace("{currentRow}", rowIndex.toString()) +// getCell(2).cellStyle.dataFormat = accountingStyle + getCell(3).setCellValue(salary.increment.toDouble()) + getCell(4).cellFormula = "(((C{currentRow}+B{currentRow})/2)/20)/8".replace("{currentRow}", rowIndex.toString()) +// getCell(4).cellStyle.dataFormat = accountingStyle + } + } +// println(salarys.size) return workbook } diff --git a/src/main/resources/db/changelog/changes/20240507_01_jasonT/02_alter_salary_alterhourlyRate.sql b/src/main/resources/db/changelog/changes/20240507_01_jasonT/02_alter_salary_alterhourlyRate.sql new file mode 100644 index 0000000..d41653d --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240507_01_jasonT/02_alter_salary_alterhourlyRate.sql @@ -0,0 +1,4 @@ +-- liquibase formatted sql +-- changeset jasonT:alter_hourlyRate + +ALTER TABLE tsmsdb.salary MODIFY COLUMN hourlyRate decimal(7,2) NULL; \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/20240507_01_jasonT/03_change_FK_staff.sql b/src/main/resources/db/changelog/changes/20240507_01_jasonT/03_change_FK_staff.sql new file mode 100644 index 0000000..e0bfc7a --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240507_01_jasonT/03_change_FK_staff.sql @@ -0,0 +1,12 @@ +-- liquibase formatted sql +-- changeset jasonT:Update_FK + +ALTER TABLE tsmsdb.staff DROP FOREIGN KEY FK_STAFF_ON_SALARYID; + +ALTER TABLE tsmsdb.salary_effective DROP FOREIGN KEY FK_SALARY_EFFECTIVE_ON_SALARYID; + +ALTER TABLE `tsmsdb`.`salary` CHANGE COLUMN `id` `id` INT NOT NULL ; + +CREATE INDEX idx_referenced_column ON salary(salaryPoint); + +ALTER TABLE staff ADD CONSTRAINT FK_STAFF_ON_SALARYID FOREIGN KEY (salaryId) REFERENCES salary(salaryPoint); \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/20240507_01_jasonT/04_salary_data.sql b/src/main/resources/db/changelog/changes/20240507_01_jasonT/04_salary_data.sql new file mode 100644 index 0000000..5bf9851 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240507_01_jasonT/04_salary_data.sql @@ -0,0 +1,6 @@ +-- liquibase formatted sql + +-- changeset wayne:salary_data + +UPDATE salary +SET hourlyRate = (lowerLimit + upperLimit) / 2 / 20 / 8; \ No newline at end of file