| @@ -33,7 +33,7 @@ interface ShopRepository : AbstractRepository<Shop, Long> { | |||
| @Query( | |||
| nativeQuery = true, | |||
| value = """ | |||
| SELECT s.id, s.code, s.name, s.contactNo, s.contactEmail, s.contactName, s.addr1, s.addr2, s.addr3, s.type, t.TruckLanceCode, t.LoadingSequence, t.districtReference,t.Store_id, t.remark | |||
| SELECT s.id, s.code, s.name, s.contactNo, s.contactEmail, s.contactName, s.addr1, s.addr2, s.addr3, s.type, t.TruckLanceCode, t.DepartureTime as departureTime, t.LoadingSequence, t.districtReference, t.Store_id as Store_id, t.remark | |||
| FROM shop s LEFT JOIN truck t ON s.id = t.shopId | |||
| WHERE s.type = 'shop' | |||
| AND s.deleted = false; | |||
| @@ -19,4 +19,5 @@ interface ShopAndTruck { | |||
| val districtReference: Long? | |||
| val Store_id: String? | |||
| val remark: String? | |||
| val truckId: Long? | |||
| } | |||
| @@ -1,6 +1,7 @@ | |||
| package com.ffii.fpsms.modules.pickOrder.entity | |||
| import com.ffii.core.support.AbstractRepository | |||
| import com.ffii.fpsms.modules.master.entity.projections.ShopAndTruck | |||
| import org.springframework.data.jpa.repository.Query | |||
| import org.springframework.data.repository.query.Param | |||
| import org.springframework.stereotype.Repository | |||
| @@ -37,5 +38,42 @@ interface TruckRepository : AbstractRepository<Truck, Long> { | |||
| fun findByShopIdAndStoreId(shopId: Long, storeId: String): Truck? | |||
| fun findAllByShopId(shopId :Long):List<Truck> | |||
| //fun findByTruckLanceCode(truckLanceCode: String):List<Truck> | |||
| //fun deleteByTruckLanceCodeAndDepartureTimeAndLoadingSequenceAndDistrictReferenceAndStoreId(truckLanceCode: String, departureTime: LocalTime, loadingSequence: Long, districtReference: Long, storeId: Long): String | |||
| @Query( | |||
| nativeQuery = true, | |||
| value = """ | |||
| SELECT t.* | |||
| FROM truck t | |||
| INNER JOIN ( | |||
| SELECT TruckLanceCode, remark, MIN(id) as min_id | |||
| FROM truck | |||
| WHERE deleted = false | |||
| AND TruckLanceCode IS NOT NULL | |||
| GROUP BY TruckLanceCode, remark | |||
| ) AS unique_combos | |||
| ON t.id = unique_combos.min_id | |||
| WHERE t.deleted = false | |||
| ORDER BY t.TruckLanceCode, t.remark | |||
| """ | |||
| ) | |||
| fun findAllUniqueTruckLanceCodeAndRemarkCombinations(): List<Truck> | |||
| @Query( | |||
| nativeQuery = true, | |||
| value = """ | |||
| SELECT s.id as id, s.code as code, s.name as name, s.contactNo as contactNo, | |||
| s.contactEmail as contactEmail, s.contactName as contactName, | |||
| s.addr1 as addr1, s.addr2 as addr2, s.addr3 as addr3, s.type as type, | |||
| t.TruckLanceCode as truckLanceCode, t.DepartureTime as departureTime, | |||
| t.LoadingSequence as LoadingSequence, t.districtReference as districtReference, | |||
| t.Store_id as Store_id, t.remark as remark, t.id as truckId | |||
| FROM shop s INNER JOIN truck t ON s.id = t.shopId | |||
| WHERE t.TruckLanceCode = :truckLanceCode | |||
| AND ((:remark = '' AND (t.remark IS NULL OR t.remark = '')) | |||
| OR (:remark != '' AND t.remark = :remark)) | |||
| AND t.deleted = false | |||
| AND s.deleted = false; | |||
| """ | |||
| ) | |||
| fun findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse(@Param("truckLanceCode") truckLanceCode: String, @Param("remark") remark: String): List<ShopAndTruck> | |||
| } | |||
| @@ -12,7 +12,9 @@ import com.ffii.fpsms.modules.pickOrder.web.models.SaveTruckRequest | |||
| import java.time.LocalTime | |||
| import java.time.format.DateTimeFormatter | |||
| import com.ffii.fpsms.modules.master.entity.ShopRepository | |||
| import com.ffii.fpsms.modules.master.entity.projections.ShopAndTruck | |||
| import com.ffii.fpsms.modules.pickOrder.web.models.SaveTruckLane | |||
| import com.ffii.fpsms.modules.pickOrder.web.models.UpdateLoadingSequenceRequest | |||
| import jakarta.transaction.Transactional | |||
| @@ -187,7 +189,7 @@ open class TruckService( | |||
| } | |||
| open fun findAllByShopId(shopId: Long): List<Truck> { | |||
| return truckRepository.findAllByShopId(shopId) | |||
| return truckRepository.findByShopIdAndDeletedFalse(shopId) | |||
| } | |||
| @Transactional | |||
| @@ -212,7 +214,10 @@ open class TruckService( | |||
| @Transactional | |||
| open fun deleteById(id: Long): String { | |||
| truckRepository.deleteById(id) | |||
| val deleteTruck = truckRepository.findById(id).orElseThrow().apply { | |||
| deleted = true | |||
| } | |||
| truckRepository.save(deleteTruck) | |||
| return "Truck deleted successfully with id: $id" | |||
| } | |||
| @@ -241,4 +246,22 @@ open class TruckService( | |||
| return truckRepository.save(truck) | |||
| } | |||
| open fun findAllUniqueTruckLanceCodeAndRemarkCombinations(): List<Truck> { | |||
| return truckRepository.findAllUniqueTruckLanceCodeAndRemarkCombinations() | |||
| } | |||
| open fun findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse(truckLanceCode: String, remark: String): List<ShopAndTruck> { | |||
| return truckRepository.findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse(truckLanceCode, remark) | |||
| } | |||
| @Transactional | |||
| open fun updateLoadingSequence(request: UpdateLoadingSequenceRequest): Truck { | |||
| val truck = truckRepository.findById(request.id).orElseThrow { | |||
| IllegalArgumentException("Truck not found with id: ${request.id}") | |||
| } | |||
| truck.loadingSequence = request.loadingSequence | |||
| return truckRepository.save(truck) | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.ffii.fpsms.modules.pickOrder.web | |||
| import com.ffii.fpsms.modules.master.entity.projections.ShopAndTruck | |||
| import com.ffii.fpsms.modules.master.web.models.MessageResponse | |||
| import com.ffii.fpsms.modules.pickOrder.entity.Truck | |||
| import org.springframework.web.bind.ServletRequestBindingException | |||
| @@ -15,6 +16,7 @@ import com.ffii.fpsms.modules.pickOrder.service.TruckService | |||
| import com.ffii.fpsms.modules.pickOrder.entity.TruckRepository | |||
| import com.ffii.fpsms.modules.pickOrder.web.models.SaveTruckLane | |||
| import com.ffii.fpsms.modules.pickOrder.web.models.deleteTruckLane | |||
| import com.ffii.fpsms.modules.pickOrder.web.models.UpdateLoadingSequenceRequest | |||
| import jakarta.validation.Valid | |||
| @RestController | |||
| @@ -173,4 +175,42 @@ class TruckController( | |||
| ) | |||
| } | |||
| } | |||
| @GetMapping("/findAllUniqueTruckLanceCodeAndRemarkCombinations") | |||
| fun findAllUniqueTruckLanceCodeAndRemarkCombinations(): List<Truck> { | |||
| return truckService.findAllUniqueTruckLanceCodeAndRemarkCombinations() | |||
| } | |||
| @GetMapping("/findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse") | |||
| fun findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse(@RequestParam truckLanceCode: String, @RequestParam remark: String): List<ShopAndTruck> { | |||
| return truckService.findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse(truckLanceCode, remark) | |||
| } | |||
| @PostMapping("/updateLoadingSequence") | |||
| fun updateLoadingSequence(@Valid @RequestBody request: UpdateLoadingSequenceRequest): MessageResponse { | |||
| try { | |||
| val truck = truckService.updateLoadingSequence(request) | |||
| return MessageResponse( | |||
| id = truck.id, | |||
| name = truck.shopName, | |||
| code = truck.truckLanceCode, | |||
| type = "truck", | |||
| message = "Loading sequence updated successfully", | |||
| errorPosition = null, | |||
| entity = truck | |||
| ) | |||
| } catch (e: Exception) { | |||
| return MessageResponse( | |||
| id = null, | |||
| name = null, | |||
| code = null, | |||
| type = "truck", | |||
| message = "Error: ${e.message}", | |||
| errorPosition = null, | |||
| entity = null | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| @@ -24,3 +24,7 @@ data class SaveTruckLane( | |||
| data class deleteTruckLane( | |||
| val id: Long | |||
| ) | |||
| data class UpdateLoadingSequenceRequest( | |||
| val id: Long, | |||
| val loadingSequence: Int | |||
| ) | |||