작성자 | SHA1 | 메시지 | 날짜 |
---|---|---|---|
|
8d7bbaab7b | Merge branch 'master' of https://git.2fi-solutions.com/derek/FPSMS-backend | 3 달 전 |
|
aee3300440 | [rough schedule update] update fetch fg and avg sales from db | 3 달 전 |
@@ -10,6 +10,8 @@ import com.ffii.fpsms.modules.master.web.models.NewItemRequest | |||
import org.springframework.stereotype.Service | |||
import org.springframework.transaction.annotation.Transactional | |||
import java.io.IOException | |||
import java.time.LocalDateTime | |||
import java.time.format.DateTimeFormatter | |||
@Service | |||
open class ItemsService( | |||
@@ -25,6 +27,48 @@ open class ItemsService( | |||
return items | |||
} | |||
open fun getRoughScheduleList(): List<Map<String, Any>> { | |||
val now = LocalDateTime.now() | |||
val lastMonthStart = now.minusMonths(1).withDayOfMonth(1) // Start of last month | |||
val lastMonthEnd = now.minusDays(now.dayOfMonth.toLong()).withHour(23).withMinute(59).withSecond(59) // End of last month | |||
val curMonthStart = now.withDayOfMonth(1) // Start of last month | |||
val curMonthEnd = now.withDayOfMonth(31).withHour(23).withMinute(59).withSecond(59) // End of last month | |||
// Format dates if needed | |||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | |||
//TODO: change back to use last month for production | |||
val args = mapOf( | |||
"lastMonthStart" to curMonthStart.format(formatter), | |||
"lastMonthEnd" to curMonthEnd.format(formatter) | |||
) | |||
println("lastMonthStart:" + args.get("lastMonthStart")) | |||
println("lastMonthEnd:" + args.get("lastMonthEnd")) | |||
val sql = StringBuilder( | |||
" SELECT " | |||
+ " pol.itemId, " | |||
+ " i.name AS itemName, " | |||
+ " pol.itemNo, " | |||
+ " 0 AS openBalance, " | |||
+ " COUNT(DISTINCT pol.purchaseOrderId) AS orderCount, " | |||
+ " SUM(IFNULL(pol.qty, 0)) AS totalQty, " | |||
+ " SUM(IFNULL(pol.qty, 0)) / COUNT(DISTINCT pol.purchaseOrderId) AS lastMonthAvgSalesCount, " | |||
+ " 22000 - IFNULL(i.maxQty , 0) AS fgProductionLimit " | |||
+ " FROM purchase_order po " | |||
+ " LEFT JOIN purchase_order_line pol ON pol.purchaseOrderId = po.id " | |||
+ " LEFT JOIN items i ON i.id = pol.itemId " | |||
+ " WHERE po.deleted = false " | |||
+ " AND po.estimatedArrivalDate >= :lastMonthStart " | |||
+ " AND po.estimatedArrivalDate <= :lastMonthEnd " | |||
+ " AND po.`type` LIKE \"shop\" " | |||
+ " GROUP BY pol.itemId, pol.itemNo, i.name " | |||
); | |||
return jdbcDao.queryForList(sql.toString(), args); | |||
} | |||
open fun getItemsByPage(args: Map<String, Any>): List<Map<String, Any>> { | |||
// Extract parameters from the DTO | |||
val sql = StringBuilder( | |||
@@ -3,30 +3,39 @@ package com.ffii.fpsms.modules.master.service | |||
import com.ffii.core.support.AbstractBaseEntityService | |||
import com.ffii.core.support.JdbcDao | |||
import com.ffii.fpsms.modules.master.entity.* | |||
import com.ffii.fpsms.modules.master.web.models.MessageResponse | |||
import org.springframework.core.io.ClassPathResource | |||
import org.springframework.stereotype.Service | |||
import com.google.gson.Gson | |||
import org.springframework.transaction.annotation.Transactional | |||
import java.io.BufferedReader | |||
import java.io.IOException | |||
import java.io.InputStreamReader | |||
import java.nio.charset.StandardCharsets | |||
import java.sql.DriverManager.println | |||
import java.time.LocalDateTime | |||
import java.time.format.DateTimeFormatter | |||
import java.util.* | |||
import java.util.regex.Pattern | |||
import kotlin.math.roundToLong | |||
import kotlin.collections.component1 | |||
import kotlin.collections.component2 | |||
import kotlin.math.ceil | |||
@Service | |||
open class SchedulingService( | |||
private val jdbcDao: JdbcDao, | |||
private val uomConversionRepository: UomConversionRepository, | |||
private val itemService: ItemsService, | |||
): AbstractBaseEntityService<UomConversion, Long, UomConversionRepository>(jdbcDao, uomConversionRepository) { | |||
// do mapping with projection | |||
open fun convertToFinishedGoodList(): ArrayList<FinishedGood> { | |||
val roughScheduleList = itemService.getRoughScheduleList() // Retrieve the list from your existing method | |||
val finishedGoodList = ArrayList<FinishedGood>() | |||
for (item in roughScheduleList) { | |||
val finishedGood = FinishedGood( | |||
id = item["itemId"].toString().toLong(), // Cast to Long | |||
name = item["itemName"] as String?, // Cast to String | |||
receipeId = 0, // Assuming itemNo is a Long | |||
openBalance = 0.0, // Set default value or calculate if needed | |||
lastMonthAvgSalesCount = item["lastMonthAvgSalesCount"].toString().toDouble(), // Cast to Double | |||
fgProductionLimit = item["fgProductionLimit"].toString().toDouble() // Default production limit | |||
) | |||
finishedGoodList.add(finishedGood) | |||
} | |||
return finishedGoodList | |||
} | |||
open fun generateRoughScheduleByWeek(fgList : ArrayList<FinishedGood>): HashMap<RoughScheduleObj, Double> { | |||
val roughScheduleOutput: HashMap<RoughScheduleObj, Double> = HashMap(); | |||
@@ -110,10 +119,10 @@ open class SchedulingService( | |||
//debug use | |||
for ((roughScheduleRecord, totalDifference) in sortedEntries){ | |||
kotlin.io.println("[RUN" + i + "][index:" + totalDifference + "] - " + roughScheduleRecord.fgDetail?.name + " - " + roughScheduleRecord.productionSchedule[i]); | |||
println("[RUN" + i + "][index:" + totalDifference + "] - " + roughScheduleRecord.fgDetail?.name + " - " + roughScheduleRecord.productionSchedule[i]); | |||
} | |||
kotlin.io.println("Total Production Count $accProductionCount"); | |||
kotlin.io.println("========================================"); | |||
println("Total Production Count $accProductionCount"); | |||
println("========================================"); | |||
} | |||
@@ -17,7 +17,7 @@ import kotlin.collections.component2 | |||
@RequestMapping("/uomConversion") | |||
class UomConversionController( | |||
private val uomConversionService: UomConversionService, | |||
private val schedulingService: SchedulingService | |||
private val schedulingService: SchedulingService, | |||
) { | |||
// @GetMapping | |||
// fun allItems(): List<Items> { | |||
@@ -45,7 +45,7 @@ class UomConversionController( | |||
@RequestMapping(value = ["/testRoughSchedule"], method = [RequestMethod.GET]) | |||
fun generateRoughSchedule(request: HttpServletRequest?): List<HashMap<RoughScheduleObj, Double>> { | |||
try { | |||
val demoFGList = arrayListOf<FinishedGood>( | |||
val demoFGList_old = arrayListOf<FinishedGood>( | |||
FinishedGood( | |||
1, | |||
"豆腐花 - Tofu pudding", | |||
@@ -112,6 +112,8 @@ class UomConversionController( | |||
), | |||
); | |||
val demoFGList = schedulingService.convertToFinishedGoodList(); | |||
val result: HashMap<RoughScheduleObj, Double> = schedulingService.generateRoughScheduleByWeek(demoFGList) | |||
val sortedEntries = result.entries.sortedBy { it.value } | |||