fix 修改审批中画展包的逻辑
This commit is contained in:
parent
aec05feaea
commit
d29b55b318
@ -7,7 +7,8 @@ RUN go env -w GO111MODULE=on && \
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app/fonchain-approval
|
||||
|
||||
COPY fonchain-approval /app/fonchain-approval
|
||||
|
||||
WORKDIR /app/fonchain-approval
|
||||
RUN go mod download
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -28,13 +28,19 @@ service Approval {
|
||||
rpc UpdateType(CreateTypeRequest) returns (TypeResponse) {};
|
||||
rpc AllType(CommonRequest) returns (AllTypeResponse) {};
|
||||
rpc RemoveType(RemoveRequest) returns (StatusResponse) {};
|
||||
}
|
||||
|
||||
message KeyInfo {
|
||||
string ApprovalKey = 1 [json_name = "approvalKey"];
|
||||
string ApprovalName = 2 [json_name = "approvalName"];
|
||||
string ApprovalType = 3 [json_name = "approvalType"];
|
||||
string ApprovalValue = 4 [json_name = "approvalValue"];
|
||||
}
|
||||
|
||||
message UpdateEhApplyIDRequest {
|
||||
string Domain = 1 [json_name = "domain"];
|
||||
uint64 ApprovalID = 2 [json_name = "approvalID"];
|
||||
uint64 ApplyId = 3 [json_name = "applyId"];
|
||||
string ApplyId = 3 [json_name = "applyId"];
|
||||
}
|
||||
|
||||
message UpdateEhApplyIDResponse {
|
||||
@ -73,6 +79,8 @@ message CreateTypeRequest {
|
||||
string Title = 3 [json_name = "title"];
|
||||
string Remark = 5 [json_name = "remark"];
|
||||
string KeyWord = 6 [json_name = "keyWord"];
|
||||
repeated KeyInfo KeyInfos = 7 [json_name = "keyInfos"];
|
||||
uint64 IsCustom = 8 [json_name = "isCustom"];
|
||||
}
|
||||
|
||||
message TypeResponse {
|
||||
@ -175,10 +183,11 @@ message ApprovalExhibition {
|
||||
uint64 ExhibitionID =2 [json_name = "exhibitionID"];
|
||||
uint64 ApprovalID =3 [json_name = "approvalID"];
|
||||
string PackageName =4 [json_name = "packageName"];
|
||||
uint64 PackageID =5 [json_name = "packageID"];
|
||||
string PackageID =5 [json_name = "packageID"];
|
||||
uint64 PackageSize =6 [json_name = "packageSize"];
|
||||
string PackageNumber =7 [json_name = "packageNumber"];
|
||||
string Address =8 [json_name = "address"];
|
||||
string ShowDate =9 [json_name = "showDate"];
|
||||
}
|
||||
|
||||
message Exhibition {
|
||||
@ -188,7 +197,7 @@ message Exhibition {
|
||||
uint64 PidApprovalID =4 [json_name = "pidApprovalID"];
|
||||
repeated ApprovalExhibition ApprovalExhibitions = 5 [json_name = "approvalExhibitions"];
|
||||
uint64 Num = 6 [json_name = "num"];
|
||||
uint64 ApplyID = 7 [json_name = "applyID"];
|
||||
string ApplyID = 7 [json_name = "applyID"];
|
||||
}
|
||||
|
||||
message CreateRequest {
|
||||
@ -215,6 +224,8 @@ message CreateRequest {
|
||||
uint64 Level = 23 [json_name = "level"];
|
||||
uint64 NowLevel = 24 [json_name = "nowLevel"];
|
||||
string CreatedAt = 25 [json_name = "createdAt"];
|
||||
repeated KeyInfo CustomizeInfo = 26 [json_name = "customizeInfo"];
|
||||
uint64 IsCustom = 27 [json_name = "isCustom"];
|
||||
}
|
||||
|
||||
message WorkFlow {
|
||||
@ -292,6 +303,8 @@ message SettingRequest {
|
||||
repeated CopyUser CopyUsers = 6 [json_name = "copyUsers"];
|
||||
repeated ApprovalUser ApprovalUsers = 9 [json_name = "approvalUsers"];
|
||||
string Domain = 10 [json_name = "domain"];
|
||||
repeated KeyInfo CustomizeInfo = 11 [json_name = "customizeInfo"];
|
||||
uint64 IsCustom = 12 [json_name = "isCustom"];
|
||||
}
|
||||
|
||||
message DetailSettingRequest {
|
||||
|
@ -16,6 +16,9 @@ var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func (this *KeyInfo) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *UpdateEhApplyIDRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
@ -38,6 +41,13 @@ func (this *CommonRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *CreateTypeRequest) Validate() error {
|
||||
for _, item := range this.KeyInfos {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("KeyInfos", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *TypeResponse) Validate() error {
|
||||
@ -188,6 +198,13 @@ func (this *CreateRequest) Validate() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, item := range this.CustomizeInfo {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("CustomizeInfo", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *WorkFlow) Validate() error {
|
||||
@ -235,6 +252,13 @@ func (this *SettingRequest) Validate() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, item := range this.CustomizeInfo {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("CustomizeInfo", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *DetailSettingRequest) Validate() error {
|
||||
|
11
docs/env/dev/conf.ini
vendored
11
docs/env/dev/conf.ini
vendored
@ -1,13 +1,16 @@
|
||||
[system]
|
||||
mode = dev #正式prod #测试dev
|
||||
|
||||
[mysql]
|
||||
Db = mysql
|
||||
DbHost = 106.13.166.247
|
||||
DbHost = mysql
|
||||
DbPort = 3306
|
||||
DbUser = admin
|
||||
DbPassWord = EgdNF8
|
||||
DbUser = root
|
||||
DbPassWord = 123456
|
||||
DbName = fontree-approval
|
||||
|
||||
[redis]
|
||||
RedisDB =
|
||||
RedisAddr = redis:6379
|
||||
RedisPW =
|
||||
RedisDBNAme =
|
||||
RedisDBNAme =
|
||||
|
2
docs/env/dev/dubbogo.yaml
vendored
2
docs/env/dev/dubbogo.yaml
vendored
@ -2,7 +2,7 @@ dubbo:
|
||||
registries:
|
||||
demoZK:
|
||||
protocol: zookeeper
|
||||
address: ${Nacos_host}:2181
|
||||
address: zookeeper:2181
|
||||
protocols:
|
||||
triple:
|
||||
name: tri
|
||||
|
5
docs/env/local/conf.ini
vendored
5
docs/env/local/conf.ini
vendored
@ -1,3 +1,6 @@
|
||||
[system]
|
||||
mode = dev #正式prod #测试dev
|
||||
|
||||
[mysql]
|
||||
Db = mysql
|
||||
DbHost = 127.0.0.1
|
||||
@ -10,4 +13,4 @@ DbName = fontree-approval
|
||||
RedisDB =
|
||||
RedisAddr = 127.0.0.1:6379
|
||||
RedisPW =
|
||||
RedisDBNAme =
|
||||
RedisDBNAme =
|
||||
|
4
docs/env/prod/conf.ini
vendored
4
docs/env/prod/conf.ini
vendored
@ -3,8 +3,8 @@ mode = prod #正式prod #测试dev
|
||||
|
||||
[mysql]
|
||||
Db = mysql
|
||||
DbHost = 172.16.100.22
|
||||
DbPort = 9005
|
||||
DbHost = mysql
|
||||
DbPort = 3306
|
||||
DbUser = fonchain
|
||||
DbPassWord = C250PflXIWv2SQm
|
||||
DbName = fontree-approval
|
||||
|
2
docs/env/prod/dubbogo.yaml
vendored
2
docs/env/prod/dubbogo.yaml
vendored
@ -2,7 +2,7 @@ dubbo:
|
||||
registries:
|
||||
demoZK:
|
||||
protocol: zookeeper
|
||||
address: 172.16.100.22:2181
|
||||
address: zookeeper:2181
|
||||
protocols:
|
||||
triple:
|
||||
name: tri
|
||||
|
5
docs/env/test/conf.ini
vendored
5
docs/env/test/conf.ini
vendored
@ -1,3 +1,6 @@
|
||||
[system]
|
||||
mode = prod #正式prod #测试dev
|
||||
|
||||
[mysql]
|
||||
Db = mysql
|
||||
DbHost = mysql
|
||||
@ -10,4 +13,4 @@ DbName = fontree-approval
|
||||
RedisDB =
|
||||
RedisAddr = redis:6379
|
||||
RedisPW =
|
||||
RedisDBNAme =
|
||||
RedisDBNAme =
|
||||
|
2
docs/env/test/dubbogo.yaml
vendored
2
docs/env/test/dubbogo.yaml
vendored
@ -2,7 +2,7 @@ dubbo:
|
||||
registries:
|
||||
demoZK:
|
||||
protocol: zookeeper
|
||||
address: zookeeper:2181
|
||||
address: 121.229.45.214:9004
|
||||
protocols:
|
||||
triple:
|
||||
name: tri
|
||||
|
@ -48,6 +48,24 @@ func IntersectArrayInt(a []int, b []int) []int {
|
||||
return inter
|
||||
}
|
||||
|
||||
func IntersectArrayString(a []string, b []string) []string {
|
||||
var inter []string
|
||||
mp := make(map[string]bool)
|
||||
|
||||
for _, s := range a {
|
||||
if _, ok := mp[s]; !ok {
|
||||
mp[s] = true
|
||||
}
|
||||
}
|
||||
for _, s := range b {
|
||||
if _, ok := mp[s]; ok {
|
||||
inter = append(inter, s)
|
||||
}
|
||||
}
|
||||
|
||||
return inter
|
||||
}
|
||||
|
||||
func IntersectArrayUint64(a []uint64, b []uint64) []uint64 {
|
||||
var inter []uint64
|
||||
mp := make(map[uint64]bool)
|
||||
@ -124,6 +142,26 @@ func DiffArrayUint(a []uint, b []uint) []uint {
|
||||
return diffArray
|
||||
}
|
||||
|
||||
//a中删除在b中的
|
||||
func DiffArrayString(a []string, b []string) []string {
|
||||
var diffArray []string
|
||||
temp := map[string]struct{}{}
|
||||
|
||||
for _, val := range b {
|
||||
if _, ok := temp[val]; !ok {
|
||||
temp[val] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
for _, val := range a {
|
||||
if _, ok := temp[val]; !ok {
|
||||
diffArray = append(diffArray, val)
|
||||
}
|
||||
}
|
||||
|
||||
return diffArray
|
||||
}
|
||||
|
||||
func DiffArrayUint64(a []uint64, b []uint64) []uint64 {
|
||||
var diffArray []uint64
|
||||
temp := map[uint64]struct{}{}
|
||||
|
43
pkg/common/collection/slicefuc_test.go
Normal file
43
pkg/common/collection/slicefuc_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package collection
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCodetInfo(t *testing.T) {
|
||||
var first = []string{"a", "b", "c"}
|
||||
var second = []string{"a", "b", "c"}
|
||||
|
||||
result := DiffArrayString(first, second)
|
||||
result2 := IntersectArrayString(first, second)
|
||||
fmt.Println(result, result2)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("验证错误 ")
|
||||
}
|
||||
|
||||
second = []string{}
|
||||
result = DiffArrayString(first, second)
|
||||
result2 = IntersectArrayString(first, second)
|
||||
fmt.Println(result, result2)
|
||||
if len(result) != 3 {
|
||||
t.Errorf("验证错误 ")
|
||||
}
|
||||
|
||||
second = []string{"a"}
|
||||
result = DiffArrayString(first, second)
|
||||
result2 = IntersectArrayString(first, second)
|
||||
fmt.Println(result, result2)
|
||||
if len(result) != 2 {
|
||||
t.Errorf("验证错误 ")
|
||||
}
|
||||
|
||||
first = []string{}
|
||||
result = DiffArrayString(first, second)
|
||||
result2 = IntersectArrayString(first, second)
|
||||
fmt.Println(result, result2)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("验证错误 ")
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,11 @@ var (
|
||||
JWTSecret = []byte("asdfqwer1234")
|
||||
)
|
||||
|
||||
const (
|
||||
Is_IsCustom_Yes = 1
|
||||
Is_IsCustom_No = 2
|
||||
)
|
||||
|
||||
const (
|
||||
Success = 200
|
||||
Error = 500
|
||||
|
@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
@ -11,6 +13,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type KeyInfo struct {
|
||||
ApprovalKey string
|
||||
ApprovalName string
|
||||
ApprovalType string
|
||||
ApprovalValue string
|
||||
}
|
||||
type KeyInfos []KeyInfo
|
||||
|
||||
// Approval 审批
|
||||
type Approval struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"`
|
||||
@ -28,6 +38,7 @@ type Approval struct {
|
||||
NowUserId uint64 `gorm:"column:now_user_id" json:"nowUserId"`
|
||||
NowUserName string `gorm:"column:now_user_name" json:"nowUserName"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
ValueJson KeyInfos `gorm:"type:json;column:value_json;default:null;comment:自定义信息" json:"valueJson"`
|
||||
Reply string `gorm:"column:reply" json:"reply"`
|
||||
Domain *string `gorm:"column:domain" json:"domain"`
|
||||
Show *Show `gorm:"foreignKey:ApprovalID" json:"Show"`
|
||||
@ -37,6 +48,17 @@ type Approval struct {
|
||||
ApprovalWorkFlows []*ApprovalWorkFlow `gorm:"foreignKey:ApprovalID" json:"ApprovalWorkFlows"`
|
||||
}
|
||||
|
||||
func (j *KeyInfos) Scan(src interface{}) error {
|
||||
return json.Unmarshal(src.([]byte), j)
|
||||
}
|
||||
|
||||
func (j KeyInfos) Value() (driver.Value, error) {
|
||||
|
||||
v, err := json.Marshal(j)
|
||||
|
||||
return string(v), err
|
||||
}
|
||||
|
||||
const (
|
||||
TypeContent = "content"
|
||||
TypeWork = "work"
|
||||
@ -142,10 +164,13 @@ func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
|
||||
|
||||
err := DB.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
fmt.Println(0)
|
||||
setting, terr := GetApprovalSettingFromKeyWord(in.Domain, in.Type)
|
||||
|
||||
if terr != nil {
|
||||
return errors.New("抄送人没有配置")
|
||||
}
|
||||
fmt.Println(1)
|
||||
|
||||
// 保存基本信息
|
||||
entity = &Approval{
|
||||
@ -156,6 +181,7 @@ func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
|
||||
ApprovalUsers: setting.ApprovalUsers,
|
||||
Type: in.Type,
|
||||
Content: in.Content,
|
||||
ValueJson: ToKeyInfos(in.CustomizeInfo),
|
||||
Status: StatusDoing,
|
||||
Level: uint8(len(setting.ApprovalUsers)),
|
||||
NowLevel: 1,
|
||||
@ -163,19 +189,27 @@ func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
|
||||
NowUserName: setting.ApprovalUsers[0].Name,
|
||||
}
|
||||
|
||||
fmt.Println(3)
|
||||
if err := DB.Create(&entity).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 不同类型保存不同的结构体
|
||||
|
||||
fmt.Println(41, entity)
|
||||
err := entity.SaveContent(in)
|
||||
|
||||
fmt.Println(4)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(5)
|
||||
return BatchSave(setting.ApprovalUsers, entity.ID)
|
||||
})
|
||||
fmt.Println("nil", entity)
|
||||
fmt.Println("nil", entity.ID)
|
||||
|
||||
return entity, err
|
||||
|
||||
@ -239,6 +273,10 @@ func UpdateApproval(in *approval.CreateRequest) (*Approval, error) {
|
||||
Content: in.Content,
|
||||
}
|
||||
|
||||
if entity.Status == StatusFail {
|
||||
upEntity.Status = StatusDoing
|
||||
}
|
||||
|
||||
if err := DB.Where(&Approval{ID: in.ID}).Updates(&upEntity).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,45 +7,21 @@ import (
|
||||
|
||||
// ApprovalExhibition 绑定的画展包
|
||||
type ApprovalExhibition struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
ApprovalID uint64 `gorm:"column:approval_id" json:"approvalId"` // 申请的id
|
||||
ExhibitionID uint64 `gorm:"column:exhibition_id" json:"exhibitionId"` // 画展包的id
|
||||
PackageName string `gorm:"column:package_name" json:"PackageName"` // 作品名称
|
||||
PackageID uint64 `gorm:"column:package_id" json:"packageID"` // 作品类型id
|
||||
PackageSize uint64 `gorm:"column:package_size" json:"PackageSize"` // 平尺数
|
||||
PackageNumber string `gorm:"column:package_number" json:"packageNumber"` // 序号
|
||||
Address string `gorm:"column:address" json:"Address"` // 地点
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
ApprovalID uint64 `gorm:"column:approval_id" json:"approvalId"` // 申请的id
|
||||
ExhibitionID uint64 `gorm:"column:exhibition_id" json:"exhibitionId"` // 画展包的id
|
||||
PackageName string `gorm:"column:package_name" json:"PackageName"` // 作品名称
|
||||
PackageID string `gorm:"size:64;column:package_id;default:''" json:"packageID"` // 作品类型id
|
||||
PackageSize uint64 `gorm:"column:package_size" json:"PackageSize"` // 平尺数
|
||||
PackageNumber string `gorm:"column:package_number" json:"packageNumber"` // 序号
|
||||
Address string `gorm:"column:address" json:"Address"` // 地点
|
||||
ShowDate string `gorm:"type:varchar(10);default:'';column:show_date" json:"ShowDate"` // 位置
|
||||
}
|
||||
|
||||
// TableName get sql table name.获取数据库表名
|
||||
func (m *ApprovalExhibition) TableName() string {
|
||||
return "approval_exhibition"
|
||||
}
|
||||
|
||||
// ApprovalExhibitionColumns get sql column name.获取数据库列名
|
||||
var ApprovalExhibitionColumns = struct {
|
||||
ID string
|
||||
DeletedAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
ApprovalID string
|
||||
ExhibitionID string
|
||||
ExhibitionName string
|
||||
ArtworkID string
|
||||
ExhibitionSize string
|
||||
ExhibitionNumber string
|
||||
}{
|
||||
ID: "id",
|
||||
DeletedAt: "deleted_at",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
ApprovalID: "approval_id",
|
||||
ExhibitionID: "exhibition_id",
|
||||
ExhibitionName: "exhibition_name",
|
||||
ArtworkID: "artwork_id",
|
||||
ExhibitionSize: "exhibition_size",
|
||||
ExhibitionNumber: "exhibition_number",
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ type ApprovalSetting struct {
|
||||
KeyWord string `gorm:"column:key_word" json:"keyWord"`
|
||||
ApprovalUsers ApprovalUsers `gorm:"column:approval_users" json:"approvalUsers"`
|
||||
CopyUsers CopyUsers `gorm:"column:copy_users" json:"copyUsers"`
|
||||
Domain string `gorm:"column:domain" json:"domain"`
|
||||
ApprovalType *ApprovalType `gorm:"foreignKey:key_word;references:key_word" json:"approvalType"`
|
||||
|
||||
Domain string `gorm:"column:domain" json:"domain"`
|
||||
}
|
||||
|
||||
// TableName get sql table name.获取数据库表名
|
||||
@ -66,7 +68,7 @@ func GetApprovalSettingFromKeyWord(Domain, keyWord string) (setting *ApprovalSet
|
||||
|
||||
err = DB.Model(&ApprovalSetting{}).Where(&ApprovalSetting{KeyWord: keyWord, Domain: Domain}).First(&setting).Error
|
||||
|
||||
return setting, nil
|
||||
return setting, err
|
||||
}
|
||||
|
||||
func FormatCopyUsers(copyUsers []*approval.CopyUser) CopyUsers {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
md52 "github.com/fonchain_enterprise/fonchain-approval/pkg/common/md5"
|
||||
"gorm.io/plugin/soft_delete"
|
||||
"math/rand"
|
||||
@ -10,14 +12,16 @@ import (
|
||||
|
||||
// ApprovalType 审批类型
|
||||
type ApprovalType struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
|
||||
Domain string `gorm:"column:domain" json:"domain"` // 回复内容
|
||||
Title string `gorm:"column:title" json:"title"` // 回复内容
|
||||
Remark string `gorm:"column:remark" json:"remark"` // 回复内容
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
|
||||
IsNormal uint64 `gorm:"type:tinyint;column:is_normal;default:1;comment:是否是自定义" json:"isNormal"` // 回复内容
|
||||
KeyJson KeyInfos `gorm:"type:json;column:key_json;default:null;comment:自定义字段" json:"keyJson"`
|
||||
Domain string `gorm:"column:domain" json:"domain"` // 回复内容
|
||||
Title string `gorm:"column:title" json:"title"` // 回复内容
|
||||
Remark string `gorm:"column:remark" json:"remark"` // 回复内容
|
||||
}
|
||||
|
||||
// TableName get sql table name.获取数据库表名
|
||||
@ -25,6 +29,14 @@ func (m *ApprovalType) TableName() string {
|
||||
return "approval_type"
|
||||
}
|
||||
|
||||
var TypeMap = map[string]string{
|
||||
"content": "",
|
||||
"work": "",
|
||||
"exhibition": "",
|
||||
"bundle": "",
|
||||
"show": "",
|
||||
}
|
||||
|
||||
var keyWordMap = map[string]string{
|
||||
"普通审批": "content",
|
||||
"画作申请审批": "work",
|
||||
@ -50,6 +62,28 @@ func DataExist(domain, keyWork, title string) bool {
|
||||
|
||||
}
|
||||
|
||||
func ToKeyInfos(infos []*approval.KeyInfo) KeyInfos {
|
||||
var info KeyInfos
|
||||
|
||||
for index, t := range infos {
|
||||
|
||||
temp := KeyInfo{
|
||||
ApprovalKey: t.ApprovalKey,
|
||||
ApprovalName: t.ApprovalName,
|
||||
ApprovalType: t.ApprovalType,
|
||||
ApprovalValue: t.ApprovalValue,
|
||||
}
|
||||
|
||||
if temp.ApprovalKey == "" {
|
||||
temp.ApprovalKey = "key_" + fmt.Sprintf("%d", index)
|
||||
}
|
||||
|
||||
info = append(info, temp)
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func KeyWordFromTitle(title string) string {
|
||||
keyWord := md52.Md5Part(title+strconv.Itoa(rand.Intn(100)), 8, 16)
|
||||
|
||||
@ -65,3 +99,8 @@ func IsSystemKeyWork(title string) bool {
|
||||
_, isOk := keyWordMap[title]
|
||||
return isOk
|
||||
}
|
||||
|
||||
func IsSystemType(title string) bool {
|
||||
_, isOk := TypeMap[title]
|
||||
return isOk
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ type Exhibition struct {
|
||||
ReceivedAt string `gorm:"column:received_at" json:"receivedAt"` // 领取时间
|
||||
Address string `gorm:"column:address" json:"Address"` // 地点
|
||||
ApprovalID uint64 `gorm:"column:approval_id" json:"approvalId"` // 关联申请的ID
|
||||
ApplyID uint64 `gorm:"column:apply_id" json:"applyID"` // 画展包的id
|
||||
ApplyID string `gorm:"size:64;column:apply_id;default:''" json:"applyID"` // 画展包的id
|
||||
Num uint64 `gorm:"column:num" json:"num"` // 关联申请的ID
|
||||
ApprovalExhibitions []*ApprovalExhibition `gorm:"foreignKey:ExhibitionID" json:"ApprovalExhibitions"` //关联包
|
||||
}
|
||||
@ -53,7 +53,8 @@ func (m *Exhibition) SaveApprovalContent(in *approval.CreateRequest, a *Approval
|
||||
PackageID: approvalExhibition.PackageID,
|
||||
//PackageSize: approvalExhibition.PackageSize,
|
||||
//PackageNumber: approvalExhibition.PackageNumber,
|
||||
Address: approvalExhibition.Address,
|
||||
Address: approvalExhibition.Address,
|
||||
ShowDate: approvalExhibition.ShowDate,
|
||||
}
|
||||
|
||||
approvalExhibitions = append(approvalExhibitions, temp)
|
||||
@ -92,10 +93,10 @@ func (m *Exhibition) UpdateApprovalContent(in *approval.CreateRequest, a *Approv
|
||||
func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) error {
|
||||
approvalExhibitions := in.Exhibition.ApprovalExhibitions
|
||||
var oldApprovalExhibitions []ApprovalExhibition
|
||||
var oldPackageID []uint64
|
||||
var inPackageID []uint64
|
||||
var oldPackageID []string
|
||||
var inPackageID []string
|
||||
var err error
|
||||
inApprovalExhibitionMap := make(map[uint64]*approval.ApprovalExhibition, len(approvalExhibitions))
|
||||
inApprovalExhibitionMap := make(map[string]*approval.ApprovalExhibition, len(approvalExhibitions))
|
||||
|
||||
DB.Where(&ApprovalExhibition{ExhibitionID: m.ID}).Find(&oldApprovalExhibitions)
|
||||
|
||||
@ -108,7 +109,7 @@ func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) erro
|
||||
inApprovalExhibitionMap[approvalWork.PackageID] = approvalWork
|
||||
}
|
||||
|
||||
needDel := collection.DiffArrayUint64(oldPackageID, inPackageID)
|
||||
needDel := collection.DiffArrayString(oldPackageID, inPackageID)
|
||||
fmt.Println(needDel)
|
||||
|
||||
if len(needDel) > 0 {
|
||||
@ -116,7 +117,7 @@ func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) erro
|
||||
Delete(&ApprovalExhibition{})
|
||||
}
|
||||
|
||||
needAdd := collection.DiffArrayUint64(inPackageID, oldPackageID)
|
||||
needAdd := collection.DiffArrayString(inPackageID, oldPackageID)
|
||||
fmt.Println(needAdd)
|
||||
|
||||
//传递的id去除表 新增
|
||||
@ -130,7 +131,8 @@ func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) erro
|
||||
PackageID: inApprovalExhibitionMap[tempId].PackageID,
|
||||
//PackageSize: inApprovalExhibitionMap[tempId].PackageSize,
|
||||
//PackageNumber: inApprovalExhibitionMap[tempId].PackageNumber,
|
||||
Address: inApprovalExhibitionMap[tempId].Address,
|
||||
Address: inApprovalExhibitionMap[tempId].Address,
|
||||
ShowDate: inApprovalExhibitionMap[tempId].ShowDate,
|
||||
}
|
||||
|
||||
approvalWorks = append(approvalWorks, temp)
|
||||
@ -144,7 +146,7 @@ func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) erro
|
||||
}
|
||||
|
||||
//更新 主要修改绑定的数据权限id
|
||||
changeIds := collection.IntersectArrayUint64(inPackageID, oldPackageID)
|
||||
changeIds := collection.IntersectArrayString(inPackageID, oldPackageID)
|
||||
if len(changeIds) > 0 {
|
||||
for _, tempId := range changeIds {
|
||||
|
||||
@ -159,7 +161,8 @@ func (m *Exhibition) UpdateContent(in *approval.CreateRequest, a *Approval) erro
|
||||
PackageID: inApprovalExhibitionMap[tempId].PackageID,
|
||||
// PackageSize: inApprovalExhibitionMap[tempId].PackageSize,
|
||||
// PackageNumber: inApprovalExhibitionMap[tempId].PackageNumber,
|
||||
Address: inApprovalExhibitionMap[tempId].Address,
|
||||
Address: inApprovalExhibitionMap[tempId].Address,
|
||||
ShowDate: inApprovalExhibitionMap[tempId].ShowDate,
|
||||
}
|
||||
|
||||
DB.Model(&ApprovalExhibition{}).
|
||||
@ -188,7 +191,8 @@ func (m *Exhibition) BuildResContent(a *Approval, request *approval.CreateReques
|
||||
PackageName: one.PackageName,
|
||||
//PackageSize: one.PackageSize,
|
||||
//PackageNumber: one.PackageNumber,
|
||||
Address: one.Address,
|
||||
Address: one.Address,
|
||||
ShowDate: one.ShowDate,
|
||||
}
|
||||
approvalExhibitions = append(approvalExhibitions, temp)
|
||||
|
||||
|
@ -77,4 +77,5 @@ func Database(conn string) {
|
||||
sqlDB.SetMaxOpenConns(100) //打开
|
||||
sqlDB.SetConnMaxLifetime(time.Second * 30)
|
||||
DB = db
|
||||
migration()
|
||||
}
|
||||
|
32
pkg/model/migration.go
Normal file
32
pkg/model/migration.go
Normal file
@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//类型迁移
|
||||
func migration() {
|
||||
//自动迁移模式
|
||||
//增加字段
|
||||
addColumn(&ApprovalType{}, "is_normal")
|
||||
addColumn(&ApprovalType{}, "key_json")
|
||||
|
||||
addColumn(&Exhibition{}, "apply_id")
|
||||
addColumn(&ApprovalExhibition{}, "package_id")
|
||||
addColumn(&ApprovalExhibition{}, "show_date")
|
||||
|
||||
addColumn(&Approval{}, "value_json")
|
||||
}
|
||||
|
||||
//数据迁移
|
||||
func addColumn(dst interface{}, column string) {
|
||||
exist := DB.Migrator().HasColumn(dst, column)
|
||||
if !exist {
|
||||
err := DB.Migrator().AddColumn(dst, column)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -25,6 +25,9 @@ func (m *Show) TableName() string {
|
||||
}
|
||||
|
||||
func (m *Show) SaveApprovalContent(in *approval.CreateRequest, a *Approval) error {
|
||||
if in.Show == nil {
|
||||
return nil
|
||||
}
|
||||
m.ArtistNum = in.Show.ArtistNum
|
||||
m.ApprovalID = a.ID
|
||||
m.ShowAt = in.Show.ShowAt
|
||||
|
@ -2,6 +2,7 @@ package serializer
|
||||
|
||||
import (
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/e"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
||||
)
|
||||
|
||||
@ -62,6 +63,7 @@ func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateReques
|
||||
SubmitterName: entity.SubmitterName,
|
||||
Content: entity.Content,
|
||||
CanView: canViewed,
|
||||
IsCustom: e.Is_IsCustom_Yes,
|
||||
CanApproval: canApproval,
|
||||
WorkFlows: workFlows,
|
||||
Reply: entity.Reply,
|
||||
@ -69,12 +71,17 @@ func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateReques
|
||||
Show: show,
|
||||
Exhibition: exhibition,
|
||||
Bundle: bundle,
|
||||
CustomizeInfo: BuildKeyInfo(entity.ValueJson),
|
||||
CreatedAt: entity.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
AllStatus: allStatus, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
NowUserId: entity.NowUserId, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
NowUserName: entity.NowUserName, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
Level: uint64(entity.Level), //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
NowLevel: uint64(entity.NowLevel), //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
AllStatus: allStatus, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
|
||||
NowUserId: entity.NowUserId,
|
||||
NowUserName: entity.NowUserName,
|
||||
Level: uint64(entity.Level),
|
||||
NowLevel: uint64(entity.NowLevel),
|
||||
}
|
||||
|
||||
if model.IsSystemType(entity.Type) == true {
|
||||
response.IsCustom = e.Is_IsCustom_No
|
||||
}
|
||||
|
||||
_ = entity.SetResContent(response)
|
||||
|
@ -2,6 +2,7 @@ package serializer
|
||||
|
||||
import (
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/e"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
||||
)
|
||||
|
||||
@ -9,16 +10,38 @@ import (
|
||||
func BuildType(entity *model.ApprovalType) *approval.CreateTypeRequest {
|
||||
|
||||
response := &approval.CreateTypeRequest{
|
||||
ID: entity.ID,
|
||||
Domain: entity.Domain,
|
||||
Remark: entity.Remark,
|
||||
Title: entity.Title,
|
||||
KeyWord: entity.KeyWord,
|
||||
ID: entity.ID,
|
||||
Domain: entity.Domain,
|
||||
Remark: entity.Remark,
|
||||
Title: entity.Title,
|
||||
KeyWord: entity.KeyWord,
|
||||
IsCustom: e.Is_IsCustom_Yes,
|
||||
KeyInfos: BuildKeyInfo(entity.KeyJson),
|
||||
}
|
||||
|
||||
if model.IsSystemType(entity.KeyWord) == true {
|
||||
response.IsCustom = e.Is_IsCustom_No
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
func BuildKeyInfo(infos model.KeyInfos) []*approval.KeyInfo {
|
||||
var keyInfos []*approval.KeyInfo
|
||||
|
||||
for _, t := range infos {
|
||||
temp := &approval.KeyInfo{
|
||||
ApprovalKey: t.ApprovalKey,
|
||||
ApprovalName: t.ApprovalName,
|
||||
ApprovalType: t.ApprovalType,
|
||||
ApprovalValue: t.ApprovalValue,
|
||||
}
|
||||
keyInfos = append(keyInfos, temp)
|
||||
}
|
||||
|
||||
return keyInfos
|
||||
}
|
||||
|
||||
func BuildTypes(entity []*model.ApprovalType) (details []*approval.CreateTypeRequest) {
|
||||
|
||||
for _, temp := range entity {
|
||||
|
@ -2,6 +2,7 @@ package serializer
|
||||
|
||||
import (
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/e"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
||||
)
|
||||
|
||||
@ -35,6 +36,13 @@ func BuildSetting(entity *model.ApprovalSetting) *approval.SettingRequest {
|
||||
CopyUsers: copyUsers,
|
||||
ApprovalUsers: approvalUser,
|
||||
}
|
||||
if entity.ApprovalType != nil {
|
||||
response.IsCustom = e.Is_IsCustom_Yes
|
||||
response.CustomizeInfo = BuildKeyInfo(entity.ApprovalType.KeyJson)
|
||||
if model.IsSystemType(entity.ApprovalType.KeyWord) == true {
|
||||
response.IsCustom = e.Is_IsCustom_No
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/common/page"
|
||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/m"
|
||||
@ -23,7 +24,9 @@ func (a *ApprovalProvider) Create(ctx context.Context, in *approval.CreateReques
|
||||
return response, err
|
||||
}
|
||||
|
||||
response.ID = entity.ID
|
||||
if entity != nil {
|
||||
response.ID = entity.ID
|
||||
}
|
||||
response.Success = true
|
||||
|
||||
return response, err
|
||||
@ -286,7 +289,7 @@ func (a *ApprovalProvider) DetailSetting(ctx context.Context, in *approval.Detai
|
||||
return response, nil
|
||||
}
|
||||
|
||||
if err := model.DB.Model(&model.ApprovalSetting{}).
|
||||
if err := model.DB.Model(&model.ApprovalSetting{}).Preload("ApprovalType").
|
||||
Where(&model.ApprovalSetting{Domain: in.Domain, KeyWord: in.KeyWord}).
|
||||
First(&setting).Error; err != nil {
|
||||
response.Domain = in.Domain
|
||||
@ -300,6 +303,7 @@ func (a *ApprovalProvider) DetailSetting(ctx context.Context, in *approval.Detai
|
||||
func (a *ApprovalProvider) CreateType(ctx context.Context, in *approval.CreateTypeRequest) (*approval.TypeResponse, error) {
|
||||
response := &approval.TypeResponse{}
|
||||
|
||||
fmt.Println("创建类型:", in.String())
|
||||
keyWord := model.KeyWordFromTitle(in.Title)
|
||||
|
||||
if model.DataExist(in.Domain, keyWord, in.Title) == true {
|
||||
@ -311,6 +315,7 @@ func (a *ApprovalProvider) CreateType(ctx context.Context, in *approval.CreateTy
|
||||
Title: in.Title,
|
||||
Domain: in.Domain,
|
||||
Remark: in.Remark,
|
||||
KeyJson: model.ToKeyInfos(in.KeyInfos),
|
||||
}
|
||||
|
||||
if err := model.DB.Create(&typeObj).Error; err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user