123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package models_table
- import (
- "fmt"
- "reflect"
- "strings"
- "time"
- "github.com/dabory/abango-rest"
- e "github.com/dabory/abango-rest/etc"
- "github.com/go-xorm/xorm"
- "github.com/google/uuid"
- )
- func ComAddaRowDefault(y *abango.Controller, table interface{}) {
- fe := reflect.ValueOf(table).Elem()
- fieldNum := fe.NumField()
- for i := 0; i < fieldNum; i++ {
- tag := string(fe.Type().Field(i).Tag)
- name := fe.Type().Field(i).Name
- value := fe.Field(i)
- if strings.Contains(tag, "DECIMAL") && value.String() == "" {
- fe.Field(i).SetString("0.0000")
- } else if name == "CreatedOn" {
- fe.Field(i).SetInt(e.GetNowUnix())
- } else if name == "OfficialDate" {
- fe.Field(i).SetString((time.Now().Format("20060102")))
- } else if name == "OfficialTime" {
- fe.Field(i).SetString((time.Now().Format("15:04:05")))
- } else if name == "IsUnused" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Status" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Sort" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Ip" {
- fe.Field(i).SetString(y.Gtb.RemoteIp)
- } else if name == "UserId" && y.Gtb.UserId != 0 {
- fe.Field(i).SetInt(int64(y.Gtb.UserId))
- } else if name == "MemberId" && y.Gtb.MemberId != 0 {
- fe.Field(i).SetInt(int64(y.Gtb.MemberId))
- } else if name == "StorageId" {
- fe.Field(i).SetInt(int64(y.Gtb.StorageId))
- } else if name == "BranchId" {
- fe.Field(i).SetInt(int64(y.Gtb.BranchId))
- } else if name == "MemberBuyerId" && y.Gtb.MemberBuyerId != 0 {
- fe.Field(i).SetInt(int64(y.Gtb.MemberBuyerId))
- } else if name == "BuyerId" && value.String() == "" && y.Gtb.MemberBuyerId != 0 { //Pro에서 MemberBuyerId 지정되어 있으면
- fe.Field(i).SetInt(int64(y.Gtb.MemberBuyerId))
- } else if name == "ItemCode" && value.String() == "" { //UniqKey가 지정되어 있으면
- fe.Field(i).SetString(e.RandString(16))
- //ForeignId에 1 을 넣는 조건
- } else if name == "Duid" && value.String() == "" { //UniqKey가 지정되어 있으면
- uid := uuid.New()
- fe.Field(i).SetString(uid.String())
- }
- //redundunt but to make sure to have no 0 value in Ids
- if (strings.Contains(name, "MediaId") || name == "MemberId" || name == "UserId" || name == "BuyerId" || name == "SupplierId" || name == "IgroupId" || name == "CgroupId" || name == "BranchId" || name == "StorageId" || name == "AgroupId") && value.Int() == 0 {
- fe.Field(i).SetInt(int64(1))
- }
- if name == "FromBuyerId" && value.Int() == 0 {
- fe.Field(i).SetInt(int64(1))
- }
- if name == "FromBuyerId" && value.Int() == 0 {
- fmt.Println("FromBuyerId:", value.Int())
- }
- }
- }
- func EmptyTableColumn(table interface{}) { // 정리해서 연결할 것.
- fmt.Println("aaaa")
- fe := reflect.ValueOf(table).Elem()
- fmt.Println("bbbb")
- fieldNum := fe.NumField()
- fmt.Println("cccc")
- for i := 0; i < fieldNum; i++ {
- name := fe.Type().Field(i).Name
- if name == "Password" || name == "ActivateCode" || name == "ResetCode" {
- fe.Field(i).SetString("")
- }
- }
- }
- func ComEditaRowDefault(y *abango.Controller, table interface{}) {
- fe := reflect.ValueOf(table).Elem()
- fieldNum := fe.NumField()
- for i := 0; i < fieldNum; i++ {
- tag := string(fe.Type().Field(i).Tag)
- name := fe.Type().Field(i).Name
- value := fe.Field(i)
- if strings.Contains(tag, "DECIMAL") && value.String() == "" {
- fe.Field(i).SetString("0.0000")
- } else if name == "UpdatedOn" {
- fe.Field(i).SetInt(e.GetNowUnix())
- } else if name == "OfficialDate" && value.String() == "" { //직접수정시에는 변경가능
- fe.Field(i).SetString((time.Now().Format("20060102")))
- } else if name == "OfficialTime" && value.String() == "" { //직접수정시에는 변경가능
- fe.Field(i).SetString((time.Now().Format("15:04:05")))
- } else if name == "UserId" && value.String() == "" { // 수정한 관리자 입력
- fe.Field(i).SetInt(int64(y.Gtb.UserId))
- } else if name == "MemberId" && value.String() == "" { // 수정한 회원 입력
- fe.Field(i).SetInt(int64(y.Gtb.MemberId))
- } else if name == "MemberBuyerId" && value.String() == "" { // 수정한 회원 입력
- fe.Field(i).SetInt(int64(y.Gtb.MemberBuyerId))
- } else if name == "IsUnused" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Status" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Sort" && value.String() == "" {
- fe.Field(i).SetString("0")
- } else if name == "Ip" { //최종업데이트한 Ip가 들어간다.
- fe.Field(i).SetString(y.Gtb.RemoteIp)
- }
- if (strings.Contains(name, "MediaId") || name == "MemberId" || name == "UserId" || name == "BuyerId" || name == "SupplierId" || name == "IgroupId" || name == "CgroupId" || name == "BranchId" || name == "StorageId" || name == "AgroupId") && value.Int() == 0 {
- fe.Field(i).SetInt(int64(1))
- }
- }
- }
- func ComUpdateQry(y *abango.Controller, id int) *xorm.Session {
- qry := y.Db.Id(id)
- if y.UpdateFieldList != "" {
- slc := strings.Split(y.UpdateFieldList, ",")
- for _, str := range slc {
- qry = qry.Cols(str)
- }
- } else { //UpdateFieldList가 비었으면 전체 컬럼선텍
- qry = qry.AllCols()
- }
- return qry
- }
|