step 13 : fix time NOW ketika insert data
This commit is contained in:
@@ -53,6 +53,52 @@ type DoctorV1 struct {
|
||||
M_DoctorIsActive string `db:"M_DoctorIsActive"`
|
||||
}
|
||||
|
||||
// doctor json
|
||||
type DoctorJSONv1 struct {
|
||||
M_DoctorID int `db:"M_DoctorID"`
|
||||
M_DoctorM_TitleID int `db:"M_DoctorM_TitleID"`
|
||||
M_DoctorCode string `db:"M_DoctorCode"`
|
||||
M_DoctorPrefix string `db:"M_DoctorPrefix"`
|
||||
M_DoctorPrefix2 string `db:"M_DoctorPrefix2"`
|
||||
M_DoctorName string `db:"M_DoctorName"`
|
||||
M_DoctorSuffix string `db:"M_DoctorSuffix"`
|
||||
M_DoctorSuffix2 string `db:"M_DoctorSuffix2"`
|
||||
M_DoctorGender string `db:"M_DoctorGender"`
|
||||
M_DoctorDOB string `db:"M_DoctorDOB"`
|
||||
M_DoctorReligionCode string `db:"M_DoctorReligionCode"`
|
||||
M_DoctorReligionSystem string `db:"M_DoctorReligionSystem"`
|
||||
M_DoctorBloodTypeCode string `db:"M_DoctorBloodTypeCode"`
|
||||
M_DoctorBloodTypeSystem string `db:"M_DoctorBloodTypeSystem"`
|
||||
M_DoctorBloodRhCode string `db:"M_DoctorBloodRhCode"`
|
||||
M_DoctorBloodRhSystem string `db:"M_DoctorBloodRhSystem"`
|
||||
M_DoctorEducationCode string `db:"M_DoctorEducationCode"`
|
||||
M_DoctorEducationSystem string `db:"M_DoctorEducationSystem"`
|
||||
M_DoctorCitizenship string `db:"M_DoctorCitizenship"`
|
||||
M_DoctorEtnicCode string `db:"M_DoctorEtnicCode"`
|
||||
M_DoctorEtnicSystem string `db:"M_DoctorEtnicSystem"`
|
||||
M_DoctorIdentifierCode string `db:"M_DoctorIdentifierCode"`
|
||||
M_DoctorIdentifierSystem string `db:"M_DoctorIdentifierSystem"`
|
||||
M_DoctorIdentifierValue string `db:"M_DoctorIdentifierValue"`
|
||||
M_DoctorHp string `db:"M_DoctorHp"`
|
||||
M_DoctorEmail string `db:"M_DoctorEmail"`
|
||||
M_DoctorM_SpecialistID int `db:"M_DoctorM_SpecialistID"`
|
||||
M_DoctorAddress string `db:"M_DoctorAddress"`
|
||||
M_DoctorAddressRegionalCd string `db:"M_DoctorAddressRegionalCd"`
|
||||
M_DoctorAddressRT string `db:"M_DoctorAddressRT"`
|
||||
M_DoctorAddressRW string `db:"M_DoctorAddressRW"`
|
||||
M_DoctorAddressCity string `db:"M_DoctorAddressCity"`
|
||||
M_DoctorAddressDistrict string `db:"M_DoctorAddressDistrict"`
|
||||
M_DoctorAddressState string `db:"M_DoctorAddressState"`
|
||||
M_DoctorAddressCountry string `db:"M_DoctorAddressCountry"`
|
||||
M_DoctorIsActive string `db:"M_DoctorIsActive"`
|
||||
M_DoctorCreated string `db:"M_DoctorCreated"`
|
||||
M_DoctorCreatedUserID int `db:"M_DoctorCreatedUserID"`
|
||||
M_DoctorLastUpdated string `db:"M_DoctorLastUpdated"`
|
||||
M_DoctorLastUpdatedUserID int `db:"M_DoctorLastUpdatedUserID"`
|
||||
M_DoctorDeletedUserID int `db:"M_DoctorDeletedUserID"`
|
||||
M_DoctorDeleted string `db:"M_DoctorDeleted"`
|
||||
}
|
||||
|
||||
// title
|
||||
type TitleSapaan struct {
|
||||
M_TitleID int `db:"M_TitleID"`
|
||||
|
||||
@@ -16,6 +16,10 @@ import (
|
||||
var Handle *sql.DB
|
||||
var Handlex *sqlx.DB
|
||||
|
||||
// log
|
||||
var HandleLog *sql.DB
|
||||
var HandlexLog *sqlx.DB
|
||||
|
||||
func InitDB() {
|
||||
println(config.Data.Get("DBhost"))
|
||||
if config.Data.Get("DBhost") == "" {
|
||||
@@ -28,6 +32,15 @@ func InitDB() {
|
||||
}
|
||||
Handle = handle
|
||||
|
||||
// log handle
|
||||
handlelog, err := sql.Open("sqlite", config.Data.Get("DBnamelog"))
|
||||
if err != nil {
|
||||
// log.Fatalf("🔥 failed to connect to the database: %s", err.Error())
|
||||
log.Panic(err)
|
||||
}
|
||||
HandleLog = handlelog
|
||||
// log handle
|
||||
|
||||
db, err := sqlx.Open("sqlite", config.Data.Get("DBname"))
|
||||
|
||||
if err != nil {
|
||||
@@ -35,6 +48,16 @@ func InitDB() {
|
||||
}
|
||||
|
||||
Handlex = db
|
||||
|
||||
// log
|
||||
dblog, err := sqlx.Open("sqlite", config.Data.Get("DBnamelog"))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
HandlexLog = dblog
|
||||
// log
|
||||
} else {
|
||||
println("mysql")
|
||||
dsn := config.Data.Get("DBuser") + ":" + config.Data.Get("DBpass") + "@tcp(" + config.Data.Get("DBhost") + ":" + config.Data.Get("DBport") + ")/" + config.Data.Get("DBname")
|
||||
@@ -50,6 +73,21 @@ func InitDB() {
|
||||
}
|
||||
Handle = handle
|
||||
|
||||
// log
|
||||
dsnlog := config.Data.Get("DBuser") + ":" + config.Data.Get("DBpass") + "@tcp(" + config.Data.Get("DBhost") + ":" + config.Data.Get("DBport") + ")/" + config.Data.Get("DBnamelog")
|
||||
println(dsnlog)
|
||||
handlelog, err := sql.Open("mysql", dsnlog)
|
||||
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
if err = handlelog.Ping(); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
HandleLog = handlelog
|
||||
// log
|
||||
|
||||
// sqlx
|
||||
db, err := sqlx.Open("mysql", dsn)
|
||||
|
||||
@@ -59,6 +97,16 @@ func InitDB() {
|
||||
|
||||
Handlex = db
|
||||
|
||||
// log
|
||||
dblog, err := sqlx.Open("mysql", dsnlog)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
HandlexLog = dblog
|
||||
// log
|
||||
|
||||
}
|
||||
log.Println("🚀 Connected Successfully to the Database")
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -946,6 +947,369 @@ func (ug *ServicesMdDoctor) GetMdDoctorByID(id string) (models.DoctorV1, error)
|
||||
}
|
||||
|
||||
// PROSES ADD DOCTOR
|
||||
func (su *ServicesMdDoctor) AddMdDoctorV0(inp models.DoctorV1) (models.DoctorV1, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
var data models.DoctorV1
|
||||
var datacek []models.DoctorV1
|
||||
|
||||
defer logger.Sync()
|
||||
logger.Error("VALUE YANG DI ADD",
|
||||
zap.Any("INPUTAN VALUE", inp),
|
||||
)
|
||||
|
||||
prm := "%" + strings.TrimSpace(inp.M_DoctorName) + "%"
|
||||
qryCek := `SELECT M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorName LIKE ?
|
||||
AND M_DoctorIsActive = 'Y'`
|
||||
err := dbx.Handlex.Select(&datacek, qryCek, prm)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error cek data by doctorname",
|
||||
zap.String("doctorname", inp.M_DoctorName),
|
||||
zap.Any("datacek", datacek),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED")
|
||||
}
|
||||
if len(datacek) > 0 {
|
||||
defer logger.Sync()
|
||||
logger.Error("Doctor Name already taken by another data",
|
||||
zap.String("doctorname", inp.M_DoctorName),
|
||||
)
|
||||
return data, fmt.Errorf("doctor Name sudah dipakai")
|
||||
}
|
||||
|
||||
// VARIABLE START
|
||||
M_DoctorM_TitleID := 0
|
||||
M_DoctorCode := ""
|
||||
M_DoctorPrefix := ""
|
||||
M_DoctorPrefix2 := ""
|
||||
M_DoctorName := inp.M_DoctorName
|
||||
M_DoctorSuffix := ""
|
||||
M_DoctorSuffix2 := ""
|
||||
M_DoctorGender := inp.M_DoctorGender
|
||||
M_DoctorDOB := "0000-00-00 00:00:00"
|
||||
M_DoctorReligionCode := ""
|
||||
M_DoctorReligionSystem := ""
|
||||
M_DoctorBloodTypeCode := ""
|
||||
M_DoctorBloodTypeSystem := ""
|
||||
M_DoctorBloodRhCode := ""
|
||||
M_DoctorBloodRhSystem := ""
|
||||
M_DoctorEducationCode := ""
|
||||
M_DoctorEducationSystem := ""
|
||||
M_DoctorCitizenship := inp.M_DoctorCitizenship
|
||||
M_DoctorEtnicCode := ""
|
||||
M_DoctorEtnicSystem := ""
|
||||
M_DoctorIdentifierCode := ""
|
||||
M_DoctorIdentifierSystem := ""
|
||||
M_DoctorIdentifierValue := inp.M_DoctorIdentifierValue
|
||||
M_DoctorHp := ""
|
||||
M_DoctorEmail := ""
|
||||
M_DoctorS_SpecialistID := 0
|
||||
M_DoctorAddress := ""
|
||||
M_DoctorAddressRegionalCd := 0
|
||||
M_DoctorAddressCity := ""
|
||||
M_DoctorAddressDistrict := ""
|
||||
M_DoctorAddressState := ""
|
||||
M_DoctorAddressCountry := ""
|
||||
// VARIABLE END
|
||||
|
||||
// CHECK PARAMS
|
||||
if inp.M_DoctorM_TitleID != 0 {
|
||||
M_DoctorM_TitleID = inp.M_DoctorM_TitleID
|
||||
}
|
||||
|
||||
if inp.M_DoctorCode != "" {
|
||||
M_DoctorCode = inp.M_DoctorCode
|
||||
}
|
||||
|
||||
if inp.M_DoctorPrefix != "" {
|
||||
M_DoctorPrefix = inp.M_DoctorPrefix
|
||||
}
|
||||
|
||||
if inp.M_DoctorPrefix2 != "" {
|
||||
M_DoctorPrefix2 = inp.M_DoctorPrefix2
|
||||
}
|
||||
|
||||
if inp.M_DoctorSuffix != "" {
|
||||
M_DoctorSuffix = inp.M_DoctorSuffix
|
||||
}
|
||||
|
||||
if inp.M_DoctorSuffix2 != "" {
|
||||
M_DoctorSuffix2 = inp.M_DoctorSuffix2
|
||||
}
|
||||
|
||||
if inp.M_DoctorDOB != "" {
|
||||
M_DoctorDOB = inp.M_DoctorDOB
|
||||
}
|
||||
|
||||
if inp.M_DoctorReligionCode != "default" {
|
||||
M_DoctorReligionCode = inp.M_DoctorReligionCode
|
||||
M_DoctorReligionSystem = inp.M_DoctorReligionSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorBloodTypeCode != "default" {
|
||||
M_DoctorBloodTypeCode = inp.M_DoctorBloodTypeCode
|
||||
M_DoctorBloodTypeSystem = inp.M_DoctorBloodTypeSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorBloodRhCode != "default" {
|
||||
M_DoctorBloodRhCode = inp.M_DoctorBloodRhCode
|
||||
M_DoctorBloodRhSystem = inp.M_DoctorBloodRhSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorEducationCode != "default" {
|
||||
M_DoctorEducationCode = inp.M_DoctorEducationCode
|
||||
M_DoctorEducationSystem = inp.M_DoctorEducationSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorEtnicCode != "default" {
|
||||
M_DoctorEtnicCode = inp.M_DoctorEtnicCode
|
||||
M_DoctorEtnicSystem = inp.M_DoctorEtnicSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorIdentifierCode != "default" {
|
||||
M_DoctorIdentifierCode = inp.M_DoctorIdentifierCode
|
||||
M_DoctorIdentifierSystem = inp.M_DoctorIdentifierSystem
|
||||
}
|
||||
|
||||
if inp.M_DoctorHp != "" {
|
||||
M_DoctorHp = inp.M_DoctorHp
|
||||
}
|
||||
|
||||
if inp.M_DoctorEmail != "" {
|
||||
M_DoctorEmail = inp.M_DoctorEmail
|
||||
}
|
||||
|
||||
if inp.M_DoctorM_SpecialistID != "0" {
|
||||
M_DoctorS_SpecialistID, err = strconv.Atoi(inp.M_DoctorM_SpecialistID)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error CONVERT DOCTOR SPECIALIS",
|
||||
zap.Any("M_SpecialistID", M_DoctorS_SpecialistID),
|
||||
)
|
||||
return data, fmt.Errorf("error CONVERT DOCTOR SPECIALIS")
|
||||
}
|
||||
}
|
||||
|
||||
if inp.M_DoctorAddressRegionalCd != 0 {
|
||||
M_DoctorAddressRegionalCd = inp.M_DoctorAddressRegionalCd
|
||||
M_DoctorAddress = inp.M_DoctorAddress
|
||||
M_DoctorAddressCity = inp.M_DoctorAddressCity
|
||||
M_DoctorAddressDistrict = inp.M_DoctorAddressDistrict
|
||||
M_DoctorAddressState = inp.M_DoctorAddressState
|
||||
M_DoctorAddressCountry = inp.M_DoctorAddressCountry
|
||||
}
|
||||
|
||||
// CHECK PARAMS
|
||||
query := `INSERT INTO m_doctor
|
||||
(
|
||||
M_DoctorM_TitleID,
|
||||
M_DoctorCode,
|
||||
M_DoctorPrefix,
|
||||
M_DoctorPrefix2,
|
||||
M_DoctorName,
|
||||
M_DoctorSuffix,
|
||||
M_DoctorSuffix2,
|
||||
M_DoctorGender,
|
||||
M_DoctorDOB,
|
||||
M_DoctorReligionCode,
|
||||
M_DoctorReligionSystem,
|
||||
M_DoctorBloodTypeCode,
|
||||
M_DoctorBloodTypeSystem,
|
||||
M_DoctorBloodRhCode,
|
||||
M_DoctorBloodRhSystem,
|
||||
M_DoctorEducationCode,
|
||||
M_DoctorEducationSystem,
|
||||
M_DoctorCitizenship,
|
||||
M_DoctorEtnicCode,
|
||||
M_DoctorEtnicSystem,
|
||||
M_DoctorIdentifierCode,
|
||||
M_DoctorIdentifierSystem,
|
||||
M_DoctorIdentifierValue,
|
||||
M_DoctorHp,
|
||||
M_DoctorEmail,
|
||||
M_DoctorM_SpecialistID,
|
||||
M_DoctorAddress,
|
||||
M_DoctorAddressRegionalCd,
|
||||
M_DoctorAddressCity,
|
||||
M_DoctorAddressDistrict,
|
||||
M_DoctorAddressState,
|
||||
M_DoctorAddressCountry,
|
||||
M_DoctorIsActive,
|
||||
M_DoctorCreatedUserID,
|
||||
M_DoctorCreated
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
rst := dbx.Handlex.MustExec(query,
|
||||
M_DoctorM_TitleID,
|
||||
M_DoctorCode,
|
||||
M_DoctorPrefix,
|
||||
M_DoctorPrefix2,
|
||||
M_DoctorName,
|
||||
M_DoctorSuffix,
|
||||
M_DoctorSuffix2,
|
||||
M_DoctorGender,
|
||||
M_DoctorDOB,
|
||||
M_DoctorReligionCode,
|
||||
M_DoctorReligionSystem,
|
||||
M_DoctorBloodTypeCode,
|
||||
M_DoctorBloodTypeSystem,
|
||||
M_DoctorBloodRhCode,
|
||||
M_DoctorBloodRhSystem,
|
||||
M_DoctorEducationCode,
|
||||
M_DoctorEducationSystem,
|
||||
M_DoctorCitizenship,
|
||||
M_DoctorEtnicCode,
|
||||
M_DoctorEtnicSystem,
|
||||
M_DoctorIdentifierCode,
|
||||
M_DoctorIdentifierSystem,
|
||||
M_DoctorIdentifierValue,
|
||||
M_DoctorHp,
|
||||
M_DoctorEmail,
|
||||
M_DoctorS_SpecialistID,
|
||||
M_DoctorAddress,
|
||||
M_DoctorAddressRegionalCd,
|
||||
M_DoctorAddressCity,
|
||||
M_DoctorAddressDistrict,
|
||||
M_DoctorAddressState,
|
||||
M_DoctorAddressCountry,
|
||||
"Y",
|
||||
"1",
|
||||
time.Now(),
|
||||
)
|
||||
insertedID, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error Insert doctor",
|
||||
zap.Any("object doctoraddv1", inp),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED LastInsertId")
|
||||
}
|
||||
s := strconv.Itoa(int(insertedID))
|
||||
|
||||
// json after start
|
||||
var dataJSON models.DoctorJSONv1
|
||||
qryJson := `select *
|
||||
from m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y'
|
||||
AND M_DoctorID = ?`
|
||||
|
||||
err = dbx.HandlexLog.Get(&dataJSON, qryJson, insertedID)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get json by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
dbx.Handlex.MustBegin().Rollback()
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA JSON AFTER INSERT")
|
||||
}
|
||||
|
||||
// Mengubah slice dari struct menjadi JSON string
|
||||
jsonData, err := json.Marshal(dataJSON)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error format JSON",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED ERROR CONVERT JSON")
|
||||
}
|
||||
|
||||
// Mengubah JSON byte slice menjadi string
|
||||
jsonStringInsert := string(jsonData)
|
||||
|
||||
qryInsertLog := `INSERT INTO cpone_log
|
||||
(
|
||||
Log_DoctorM_DoctorID,
|
||||
Log_DoctorDate,
|
||||
Log_DoctorCode,
|
||||
Log_DoctorJsonBefore,
|
||||
Log_DoctorJsonAfter,
|
||||
Log_DoctorUserID
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
_, err = dbx.HandlexLog.Exec(qryInsertLog,
|
||||
insertedID,
|
||||
time.Now(),
|
||||
"ADD",
|
||||
"",
|
||||
jsonStringInsert,
|
||||
"1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error inserting query log",
|
||||
zap.Error(err),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED INSERT_LOG")
|
||||
}
|
||||
|
||||
// json after end
|
||||
data, err = su.GetMdDoctorByID(s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get doctor by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA AFTER INSERT")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
var data models.DoctorV1
|
||||
@@ -1102,7 +1466,6 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
}
|
||||
|
||||
// CHECK PARAMS
|
||||
|
||||
query := `INSERT INTO m_doctor
|
||||
(
|
||||
M_DoctorM_TitleID,
|
||||
@@ -1177,7 +1540,7 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
NOW()
|
||||
)`
|
||||
|
||||
rst := dbx.Handlex.MustExec(query,
|
||||
@@ -1215,7 +1578,6 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
M_DoctorAddressCountry,
|
||||
"Y",
|
||||
"1",
|
||||
time.Now(),
|
||||
)
|
||||
insertedID, err := rst.LastInsertId()
|
||||
if err != nil {
|
||||
@@ -1226,6 +1588,75 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e
|
||||
return data, fmt.Errorf("QUERY_FAILED LastInsertId")
|
||||
}
|
||||
s := strconv.Itoa(int(insertedID))
|
||||
|
||||
// insert cpone_log.log_doctor start
|
||||
var dataJSON models.DoctorJSONv1
|
||||
qryJson := `select *
|
||||
from m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y'
|
||||
AND M_DoctorID = ?`
|
||||
|
||||
err = dbx.Handlex.Get(&dataJSON, qryJson, s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get json by id",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
zap.Any("id last insert", s),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED GET DATA JSON AFTER INSERT")
|
||||
}
|
||||
|
||||
// Mengubah slice dari struct menjadi JSON string
|
||||
jsonData, err := json.Marshal(dataJSON)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error format JSON",
|
||||
// zap.Any("object doctoraddv1", inp),
|
||||
zap.Any("ERROR MSG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED ERROR CONVERT JSON")
|
||||
}
|
||||
|
||||
// Mengubah JSON byte slice menjadi string
|
||||
jsonStringInsert := string(jsonData)
|
||||
|
||||
qryInsertLog := `INSERT INTO log_doctor
|
||||
(
|
||||
Log_DoctorM_DoctorID,
|
||||
Log_DoctorDate,
|
||||
Log_DoctorCode,
|
||||
Log_DoctorJsonBefore,
|
||||
Log_DoctorJsonAfter,
|
||||
Log_DoctorUserID
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
NOW(),
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)`
|
||||
|
||||
_, err = dbx.HandlexLog.Exec(qryInsertLog,
|
||||
insertedID,
|
||||
"ADD",
|
||||
"",
|
||||
jsonStringInsert,
|
||||
"1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error inserting query log",
|
||||
zap.Any("ERROR MSG INSERT LOG", err.Error()),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED INSERT_LOG")
|
||||
}
|
||||
|
||||
// insert cpone_log.log_doctor end
|
||||
data, err = su.GetMdDoctorByID(s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
|
||||
Reference in New Issue
Block a user