Compare commits
2 Commits
d962d77a00
...
3d9ad4cff1
| Author | SHA1 | Date |
|---|---|---|
|
|
3d9ad4cff1 | |
|
|
1fe55d516e |
|
|
@ -7,6 +7,7 @@ import (
|
||||||
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/dto"
|
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/dto"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/query"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/query"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/repository"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/repository"
|
||||||
|
invrequestservice "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_request/service"
|
||||||
sequenceservice "github.com/Caknoooo/go-gin-clean-starter/modules/sequence/service"
|
sequenceservice "github.com/Caknoooo/go-gin-clean-starter/modules/sequence/service"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
|
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
|
||||||
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||||
|
|
@ -33,6 +34,7 @@ type inventoryIssueService struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
issueRepo repository.InventoryIssueRepository
|
issueRepo repository.InventoryIssueRepository
|
||||||
issueLineRepo repository.InventoryIssueLineRepository
|
issueLineRepo repository.InventoryIssueLineRepository
|
||||||
|
invRequestService invrequestservice.InventoryRequestService
|
||||||
sequenceService sequenceservice.SequenceService
|
sequenceService sequenceservice.SequenceService
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
@ -87,8 +89,8 @@ func (s *inventoryIssueService) GetLinesByIssueId(ctx context.Context, issueId s
|
||||||
return dtodomain.ToInventoryIssueLineResponses(lines), nil
|
return dtodomain.ToInventoryIssueLineResponses(lines), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInventoryIssueService(db *gorm.DB, issueRepo repository.InventoryIssueRepository, issueLineRepo repository.InventoryIssueLineRepository, sequenceService sequenceservice.SequenceService, log *logrus.Logger) InventoryIssueService {
|
func NewInventoryIssueService(db *gorm.DB, issueRepo repository.InventoryIssueRepository, issueLineRepo repository.InventoryIssueLineRepository, invRequestService invrequestservice.InventoryRequestService, sequenceService sequenceservice.SequenceService, log *logrus.Logger) InventoryIssueService {
|
||||||
return &inventoryIssueService{db: db, issueRepo: issueRepo, issueLineRepo: issueLineRepo, sequenceService: sequenceService, log: log}
|
return &inventoryIssueService{db: db, issueRepo: issueRepo, issueLineRepo: issueLineRepo, invRequestService: invRequestService, sequenceService: sequenceService, log: log}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.InventoryIssueCreateRequest) (dtodomain.InventoryIssueResponse, error) {
|
func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.InventoryIssueCreateRequest) (dtodomain.InventoryIssueResponse, error) {
|
||||||
|
|
@ -122,6 +124,14 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryIssueResponse{}, err
|
return dtodomain.InventoryIssueResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get inventory request line by InvRequestID
|
||||||
|
invRequestLinesResponse, err := s.invRequestService.GetLinesByRequestId(ctx, invRequestUUID.String())
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return dtodomain.InventoryIssueResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
issue := entities.TInventoryIssueEntity{
|
issue := entities.TInventoryIssueEntity{
|
||||||
DocumentNumber: docNum,
|
DocumentNumber: docNum,
|
||||||
DocumentType: req.DocumentType,
|
DocumentType: req.DocumentType,
|
||||||
|
|
@ -138,19 +148,25 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryIssueResponse{}, err
|
return dtodomain.InventoryIssueResponse{}, err
|
||||||
}
|
}
|
||||||
// Bulk create lines
|
// Bulk create lines from inv request lines InvRequestID
|
||||||
var lines []entities.TInventoryIssueLineEntity
|
var lines []entities.TInventoryIssueLineEntity
|
||||||
for _, lineReq := range req.IssueLines {
|
for _, lineReq := range invRequestLinesResponse {
|
||||||
productUUID, err := uuid.Parse(lineReq.ProductID)
|
productUUID, err := uuid.Parse(lineReq.Product.ID)
|
||||||
if err != nil && lineReq.ProductID != "" {
|
if err != nil && lineReq.Product.ID != "" {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryIssueResponse{}, err
|
return dtodomain.InventoryIssueResponse{}, err
|
||||||
}
|
}
|
||||||
warehouseUUID, err := uuid.Parse(lineReq.WarehouseID)
|
warehouseID := utils.GetWarehouseID(ctx)
|
||||||
if err != nil && lineReq.WarehouseID != "" {
|
var warehouseUUID uuid.UUID
|
||||||
|
if warehouseID == "" {
|
||||||
|
warehouseUUID = uuid.Nil
|
||||||
|
} else {
|
||||||
|
warehouseUUID, err = uuid.Parse(warehouseID)
|
||||||
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryIssueResponse{}, err
|
return dtodomain.InventoryIssueResponse{}, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
clientLineUUID, err := uuid.Parse(lineReq.ClientID)
|
clientLineUUID, err := uuid.Parse(lineReq.ClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
|
@ -158,10 +174,10 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
||||||
}
|
}
|
||||||
lines = append(lines, entities.TInventoryIssueLineEntity{
|
lines = append(lines, entities.TInventoryIssueLineEntity{
|
||||||
CurrentStock: lineReq.CurrentStock,
|
CurrentStock: lineReq.CurrentStock,
|
||||||
MinStock: lineReq.MinStock,
|
MinStock: 0,
|
||||||
RequestQuantity: lineReq.RequestQuantity,
|
RequestQuantity: lineReq.Quantity,
|
||||||
IssuedQuantity: lineReq.IssuedQuantity,
|
IssuedQuantity: 0,
|
||||||
Remarks: lineReq.Remarks,
|
Remarks: "",
|
||||||
InvIssueID: created.ID,
|
InvIssueID: created.ID,
|
||||||
ProductID: productUUID,
|
ProductID: productUUID,
|
||||||
WarehouseID: warehouseUUID,
|
WarehouseID: warehouseUUID,
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,19 @@ import (
|
||||||
|
|
||||||
type MonitoringController interface {
|
type MonitoringController interface {
|
||||||
HealthCheck(ctx *gin.Context)
|
HealthCheck(ctx *gin.Context)
|
||||||
ReadErrorLog(ctx *gin.Context)
|
ReadRouteLog(ctx *gin.Context)
|
||||||
ReadQueryLog(ctx *gin.Context)
|
ReadQueryLog(ctx *gin.Context)
|
||||||
ReadAppLog(ctx *gin.Context)
|
ReadAppLog(ctx *gin.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
type monitoringController struct{}
|
type monitoringController struct{}
|
||||||
|
|
||||||
|
var validMonths = map[string]bool{
|
||||||
|
"january": true, "february": true, "march": true, "april": true,
|
||||||
|
"may": true, "june": true, "july": true, "august": true,
|
||||||
|
"september": true, "october": true, "november": true, "december": true,
|
||||||
|
}
|
||||||
|
|
||||||
// ReadAppLog implements MonitoringController.
|
// ReadAppLog implements MonitoringController.
|
||||||
func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
||||||
// Ambil query param 'month', default ke bulan sekarang jika tidak ada
|
// Ambil query param 'month', default ke bulan sekarang jika tidak ada
|
||||||
|
|
@ -25,9 +31,12 @@ func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
||||||
if month == "" {
|
if month == "" {
|
||||||
month = time.Now().Format("January") // contoh: "December"
|
month = time.Now().Format("January") // contoh: "December"
|
||||||
} else {
|
} else {
|
||||||
// Pastikan format bulan sesuai dengan nama bulan bahasa Inggris
|
month = strings.ToLower(month)
|
||||||
// Misal: "december" -> "December"
|
if !validMonths[month] {
|
||||||
month = strings.Title(strings.ToLower(month))
|
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid month"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
month = strings.ToTitle(month)
|
||||||
}
|
}
|
||||||
|
|
||||||
logFile := strings.ToLower(month) + "_app.log" // contoh: "december_app.log"
|
logFile := strings.ToLower(month) + "_app.log" // contoh: "december_app.log"
|
||||||
|
|
@ -35,10 +44,6 @@ func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
||||||
// Cari file log di beberapa lokasi
|
// Cari file log di beberapa lokasi
|
||||||
locations := []string{
|
locations := []string{
|
||||||
"config/logs/query_log/" + logFile, // lokasi log sesuai permintaan
|
"config/logs/query_log/" + logFile, // lokasi log sesuai permintaan
|
||||||
"./logs/" + logFile,
|
|
||||||
"/tmp/" + logFile,
|
|
||||||
"/var/log/" + logFile,
|
|
||||||
"./" + logFile,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
|
|
@ -81,20 +86,19 @@ func (c *monitoringController) ReadQueryLog(ctx *gin.Context) {
|
||||||
if month == "" {
|
if month == "" {
|
||||||
month = time.Now().Format("January") // contoh: "December"
|
month = time.Now().Format("January") // contoh: "December"
|
||||||
} else {
|
} else {
|
||||||
// Pastikan format bulan sesuai dengan nama bulan bahasa Inggris
|
month = strings.ToLower(month)
|
||||||
// Misal: "december" -> "December"
|
if !validMonths[month] {
|
||||||
month = strings.Title(strings.ToLower(month))
|
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid month"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
month = strings.ToTitle(month)
|
||||||
}
|
}
|
||||||
|
|
||||||
logFile := strings.ToLower(month) + "_query.log" // contoh: "december_query.log"
|
logFile := strings.ToLower(month) + "_query.log" // contoh: "december_query.log"
|
||||||
|
|
||||||
// Lokasi file log
|
// Lokasi file log
|
||||||
locations := []string{
|
locations := []string{
|
||||||
"config/logs/query_log/" + logFile,
|
"config/logs/query_log/" + logFile, // lokasi log sesuai permintaan
|
||||||
"./logs/" + logFile,
|
|
||||||
"/tmp/" + logFile,
|
|
||||||
"/var/log/" + logFile,
|
|
||||||
"./" + logFile,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
|
|
@ -141,14 +145,11 @@ func (c *monitoringController) HealthCheck(ctx *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *monitoringController) ReadErrorLog(ctx *gin.Context) {
|
func (c *monitoringController) ReadRouteLog(ctx *gin.Context) {
|
||||||
logFile := "gin.log"
|
logFile := "gin.log"
|
||||||
|
|
||||||
// Cari file error di beberapa lokasi
|
// Cari file error di beberapa lokasi
|
||||||
locations := []string{
|
locations := []string{
|
||||||
"./logs/" + logFile,
|
|
||||||
"/tmp/" + logFile,
|
|
||||||
"/var/log/" + logFile,
|
|
||||||
"./" + logFile,
|
"./" + logFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ func RegisterRoutes(server *gin.Engine) {
|
||||||
monitoring := server.Group("/monitoring")
|
monitoring := server.Group("/monitoring")
|
||||||
{
|
{
|
||||||
monitoring.GET("/health", monitoringController.HealthCheck)
|
monitoring.GET("/health", monitoringController.HealthCheck)
|
||||||
monitoring.GET("/errors", monitoringController.ReadErrorLog)
|
monitoring.GET("/routes", monitoringController.ReadRouteLog)
|
||||||
// get log query_log and app_log
|
// get log query_log and app_log
|
||||||
monitoring.GET("/logs/query", monitoringController.ReadQueryLog)
|
monitoring.GET("/logs/query", monitoringController.ReadQueryLog)
|
||||||
monitoring.GET("/logs/app", monitoringController.ReadAppLog)
|
monitoring.GET("/logs/app", monitoringController.ReadAppLog)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ const (
|
||||||
SUPERADMIN = "superadmin"
|
SUPERADMIN = "superadmin"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
USERID = "user_id"
|
USERID = "user_id"
|
||||||
|
WAREHOUSEID = "warehouse_id"
|
||||||
CREATE = "create"
|
CREATE = "create"
|
||||||
UPDATE = "update"
|
UPDATE = "update"
|
||||||
DELETE = "delete"
|
DELETE = "delete"
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,14 @@ func GetUserID(ctx context.Context) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWarehouseID(ctx context.Context) string {
|
||||||
|
val := ctx.Value(constants.WAREHOUSEID)
|
||||||
|
if id, ok := val.(string); ok {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func FillAuditTrail(ctx context.Context, action string) entities.FullAuditTrail {
|
func FillAuditTrail(ctx context.Context, action string) entities.FullAuditTrail {
|
||||||
userID := GetUserID(ctx)
|
userID := GetUserID(ctx)
|
||||||
uid, _ := uuid.Parse(userID)
|
uid, _ := uuid.Parse(userID)
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ func RegisterDependencies(injector *do.Injector) {
|
||||||
inventoryReceiptServ := inventoryReceiptService.NewInventoryReceiptService(db, inventoryReceiptRepository, inventoryReceiptLineRepository, productRepository, uomRepository, inventoryStorageRepository, sequenceServ, log)
|
inventoryReceiptServ := inventoryReceiptService.NewInventoryReceiptService(db, inventoryReceiptRepository, inventoryReceiptLineRepository, productRepository, uomRepository, inventoryStorageRepository, sequenceServ, log)
|
||||||
assignmentServ := assignmentService.NewAssignmentService(db, assignmentRepository, assignmentUserRepository)
|
assignmentServ := assignmentService.NewAssignmentService(db, assignmentRepository, assignmentUserRepository)
|
||||||
inventoryRequestServ := inventoryRequestService.NewInventoryRequestService(db, inventoryRequestRepository, inventoryRequestLineRepository, inventoryStorageServ, sequenceServ, log)
|
inventoryRequestServ := inventoryRequestService.NewInventoryRequestService(db, inventoryRequestRepository, inventoryRequestLineRepository, inventoryStorageServ, sequenceServ, log)
|
||||||
inventoryIssueServ := inventoryIssueService.NewInventoryIssueService(db, inventoryIssueRepository, inventoryIssueLineRepository, sequenceServ, log)
|
inventoryIssueServ := inventoryIssueService.NewInventoryIssueService(db, inventoryIssueRepository, inventoryIssueLineRepository, inventoryRequestServ, sequenceServ, log)
|
||||||
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository, sequenceServ, log)
|
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository, sequenceServ, log)
|
||||||
inventoryMovementServ := inventoryMovementService.NewInventoryMovementService(db, inventoryMovementRepository, inventoryMovementLineRepository, sequenceServ, log)
|
inventoryMovementServ := inventoryMovementService.NewInventoryMovementService(db, inventoryMovementRepository, inventoryMovementLineRepository, sequenceServ, log)
|
||||||
quarantineServ := quarantineService.NewQuarantineService(db, quarantineRepository, quarantineLineRepository, productRepository, uomRepository, inventoryStorageRepository)
|
quarantineServ := quarantineService.NewQuarantineService(db, quarantineRepository, quarantineLineRepository, productRepository, uomRepository, inventoryStorageRepository)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue