正在显示
9 个修改的文件
包含
255 行增加
和
194 行删除
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "crypto/sha1" | ||
5 | + "fmt" | ||
6 | + | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
11 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao" | ||
8 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | 12 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" |
9 | ) | 13 | ) |
10 | 14 | ||
@@ -23,12 +27,12 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd | @@ -23,12 +27,12 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd | ||
23 | if err != nil { | 27 | if err != nil { |
24 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 28 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
25 | } | 29 | } |
26 | - if err := transactionContext.StartTransaction(); err != nil { | ||
27 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
28 | - } | ||
29 | - defer func() { | ||
30 | - transactionContext.RollbackTransaction() | ||
31 | - }() | 30 | + // if err := transactionContext.StartTransaction(); err != nil { |
31 | + // return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
32 | + // } | ||
33 | + // defer func() { | ||
34 | + // transactionContext.RollbackTransaction() | ||
35 | + // }() | ||
32 | var ( | 36 | var ( |
33 | adminuserRepository domain.AdminUserRepository | 37 | adminuserRepository domain.AdminUserRepository |
34 | adminuser *domain.AdminUser | 38 | adminuser *domain.AdminUser |
@@ -114,10 +118,11 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -114,10 +118,11 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
114 | adminuser.Permission = permissionBases | 118 | adminuser.Permission = permissionBases |
115 | 119 | ||
116 | } else { | 120 | } else { |
121 | + defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456"))) | ||
117 | adminuser = &domain.AdminUser{ | 122 | adminuser = &domain.AdminUser{ |
118 | Id: saveUserCmd.Id, | 123 | Id: saveUserCmd.Id, |
119 | Account: saveUserCmd.Account, | 124 | Account: saveUserCmd.Account, |
120 | - Password: saveUserCmd.Password, | 125 | + Password: defaultPwd, |
121 | AdminName: saveUserCmd.Name, | 126 | AdminName: saveUserCmd.Name, |
122 | IsUsable: saveUserCmd.IsUsable, | 127 | IsUsable: saveUserCmd.IsUsable, |
123 | Permission: permissionBases, | 128 | Permission: permissionBases, |
@@ -127,6 +132,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -127,6 +132,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
127 | if err != nil { | 132 | if err != nil { |
128 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 133 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
129 | } | 134 | } |
135 | + transactionContext.CommitTransaction() | ||
130 | return adminuser, nil | 136 | return adminuser, nil |
131 | } | 137 | } |
132 | 138 | ||
@@ -135,12 +141,12 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | @@ -135,12 +141,12 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | ||
135 | if err != nil { | 141 | if err != nil { |
136 | return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 142 | return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
137 | } | 143 | } |
138 | - if err := transactionContext.StartTransaction(); err != nil { | ||
139 | - return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
140 | - } | ||
141 | - defer func() { | ||
142 | - transactionContext.RollbackTransaction() | ||
143 | - }() | 144 | + // if err := transactionContext.StartTransaction(); err != nil { |
145 | + // return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
146 | + // } | ||
147 | + // defer func() { | ||
148 | + // transactionContext.RollbackTransaction() | ||
149 | + // }() | ||
144 | var ( | 150 | var ( |
145 | adminuserRepository domain.AdminUserRepository | 151 | adminuserRepository domain.AdminUserRepository |
146 | adminusers []domain.AdminUser | 152 | adminusers []domain.AdminUser |
@@ -167,5 +173,65 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | @@ -167,5 +173,65 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | ||
167 | if err != nil { | 173 | if err != nil { |
168 | return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 174 | return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
169 | } | 175 | } |
176 | + transactionContext.CommitTransaction() | ||
170 | return adminusers, cnt, nil | 177 | return adminusers, cnt, nil |
171 | } | 178 | } |
179 | + | ||
180 | +func (adminUserSrv AdminUserService) UpdateAdminPassword(updatecmd command.UpdateAdminUserPwdCommand) error { | ||
181 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
182 | + if err != nil { | ||
183 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
184 | + } | ||
185 | + if err := transactionContext.StartTransaction(); err != nil { | ||
186 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
187 | + } | ||
188 | + defer func() { | ||
189 | + transactionContext.RollbackTransaction() | ||
190 | + }() | ||
191 | + | ||
192 | + var ( | ||
193 | + adminuserDao *dao.AdminUserDao | ||
194 | + ) | ||
195 | + if v, err := factory.CreateAdminUserkDao(map[string]interface{}{ | ||
196 | + "transactionContext": transactionContext, | ||
197 | + }); err != nil { | ||
198 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
199 | + } else { | ||
200 | + adminuserDao = v | ||
201 | + } | ||
202 | + err = adminuserDao.UpdatePassword(updatecmd.Id, updatecmd.Password) | ||
203 | + if err != nil { | ||
204 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
205 | + } | ||
206 | + transactionContext.CommitTransaction() | ||
207 | + return nil | ||
208 | +} | ||
209 | + | ||
210 | +func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable bool) error { | ||
211 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
212 | + if err != nil { | ||
213 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
214 | + } | ||
215 | + if err := transactionContext.StartTransaction(); err != nil { | ||
216 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
217 | + } | ||
218 | + defer func() { | ||
219 | + transactionContext.RollbackTransaction() | ||
220 | + }() | ||
221 | + var ( | ||
222 | + adminuserDao *dao.AdminUserDao | ||
223 | + ) | ||
224 | + if v, err := factory.CreateAdminUserkDao(map[string]interface{}{ | ||
225 | + "transactionContext": transactionContext, | ||
226 | + }); err != nil { | ||
227 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
228 | + } else { | ||
229 | + adminuserDao = v | ||
230 | + } | ||
231 | + err = adminuserDao.UpdateIsUsable(uid, isUsable) | ||
232 | + if err != nil { | ||
233 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
234 | + } | ||
235 | + transactionContext.CommitTransaction() | ||
236 | + return nil | ||
237 | +} |
1 | package factory | 1 | package factory |
2 | 2 | ||
3 | -//func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | ||
4 | -// var transactionContext *pg.TransactionContext | ||
5 | -// if value, ok := options["transactionContext"]; ok { | ||
6 | -// transactionContext = value.(*pg.TransactionContext) | ||
7 | -// } | ||
8 | -// return dao.NewTaskDao(transactionContext) | ||
9 | -//} | 3 | +import ( |
4 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +func CreateAdminUserkDao(options map[string]interface{}) (*dao.AdminUserDao, error) { | ||
9 | + var transactionContext *transaction.TransactionContext | ||
10 | + if value, ok := options["transactionContext"]; ok { | ||
11 | + transactionContext = value.(*transaction.TransactionContext) | ||
12 | + } | ||
13 | + return dao.NewAdminUserDao(transactionContext) | ||
14 | +} |
pkg/infrastructure/dao/pg_admin_user_dao.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +type AdminUserDao struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func NewAdminUserDao(transactionContext *transaction.TransactionContext) (*AdminUserDao, error) { | ||
15 | + if transactionContext == nil { | ||
16 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
17 | + } else { | ||
18 | + return &AdminUserDao{ | ||
19 | + transactionContext: transactionContext, | ||
20 | + }, nil | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +//UpdatePassword .... | ||
25 | +func (dao *AdminUserDao) UpdatePassword(id int64, pwd string) error { | ||
26 | + tx := dao.transactionContext.PgDd | ||
27 | + m := &models.AdminUser{} | ||
28 | + err := tx.Model(m).Where("id=?", id).First() | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + _, err = tx.Model(m).Where("id=?", id). | ||
33 | + Set("password=?", pwd). | ||
34 | + Update() | ||
35 | + return err | ||
36 | +} | ||
37 | + | ||
38 | +//UpdatePassword .... | ||
39 | +func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error { | ||
40 | + tx := dao.transactionContext.PgDd | ||
41 | + m := &models.AdminUser{} | ||
42 | + err := tx.Model(m).Where("id=?", id).First() | ||
43 | + if err != nil { | ||
44 | + return err | ||
45 | + } | ||
46 | + _, err = tx.Model(m).Where("id=?", id). | ||
47 | + Set("is-usable=?", isUsable). | ||
48 | + Update() | ||
49 | + return err | ||
50 | +} | ||
51 | + | ||
52 | +//AdminUserAccountExist ... | ||
53 | +func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) { | ||
54 | + tx := dao.transactionContext.PgDd | ||
55 | + m := &models.AdminUser{} | ||
56 | + ok, err := tx.Model(m). | ||
57 | + Where("account=?", account). | ||
58 | + Exists() | ||
59 | + | ||
60 | + return ok, err | ||
61 | +} |
1 | -package dao | ||
2 | - | ||
3 | -//import ( | ||
4 | -// "fmt" | ||
5 | -// "github.com/go-pg/pg/v10" | ||
6 | -// pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | -// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
8 | -// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" | ||
9 | -// "time" | ||
10 | -//) | ||
11 | -// | ||
12 | -//type EmployeeDao struct { | ||
13 | -// transactionContext *pgTransaction.TransactionContext | ||
14 | -//} | ||
15 | -// | ||
16 | -//func (dao *EmployeeDao) BatchRemove(uids []int64) error { | ||
17 | -// tx := dao.transactionContext.PgTx | ||
18 | -// _, err := tx.QueryOne( | ||
19 | -// pg.Scan(), | ||
20 | -// "DELETE FROM employees WHERE uid IN (?)", | ||
21 | -// pg.In(uids)) | ||
22 | -// return err | ||
23 | -//} | ||
24 | -// | ||
25 | -//func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error { | ||
26 | -// tx := dao.transactionContext.PgTx | ||
27 | -// _, err := tx.QueryOne( | ||
28 | -// pg.Scan(), | ||
29 | -// "UPDATE employees SET status=? WHERE uid IN (?)", | ||
30 | -// status, pg.In(uids)) | ||
31 | -// return err | ||
32 | -//} | ||
33 | -// | ||
34 | -//func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error { | ||
35 | -// tx := dao.transactionContext.PgTx | ||
36 | -// if _, err := tx.Query( | ||
37 | -// pg.Scan(), | ||
38 | -// "UPDATE employees SET is_principal=? WHERE company_id=?", | ||
39 | -// false, companyId); err != nil { | ||
40 | -// return err | ||
41 | -// } | ||
42 | -// if _, err := tx.QueryOne( | ||
43 | -// pg.Scan(), | ||
44 | -// "UPDATE employees SET is_principal=? WHERE company_id=? AND employee_account=?", | ||
45 | -// true, companyId, employeeAccount); err != nil { | ||
46 | -// return err | ||
47 | -// } | ||
48 | -// return nil | ||
49 | -//} | ||
50 | -// | ||
51 | -//func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { | ||
52 | -// tx := dao.transactionContext.PgTx | ||
53 | -// _, err := tx.QueryOne( | ||
54 | -// pg.Scan(), | ||
55 | -// "UPDATE employees SET su_money=su_money+? WHERE uid=?", | ||
56 | -// suMoney, uid) | ||
57 | -// return err | ||
58 | -//} | ||
59 | -// | ||
60 | -//func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) { | ||
61 | -// var unReadSystemNotification int | ||
62 | -// var unReadInteractionNotification int | ||
63 | -// tx := dao.transactionContext.PgTx | ||
64 | -// sentNotificationModel := new(models.SentNotification) | ||
65 | -// if count, err := tx.Model(sentNotificationModel).Relation("Notification"). | ||
66 | -// Where(`sent_notification.receiver @> '{"uid":?}'`, uid). | ||
67 | -// Where("notification.notification_type = ?", domain.NOTIFICATION_TYPE_SYSTEM). | ||
68 | -// Where("sent_notification.is_read = ?", false). | ||
69 | -// Count(); err != nil { | ||
70 | -// return nil, err | ||
71 | -// } else { | ||
72 | -// unReadSystemNotification = count | ||
73 | -// } | ||
74 | -// if count, err := tx.Model(sentNotificationModel).Relation("Notification"). | ||
75 | -// Where(`sent_notification.receiver @> '{"uid":?}'`, uid). | ||
76 | -// Where("notification.notification_type = ?", domain.NOTIFICATION_TYPE_INTERACTION). | ||
77 | -// Where("sent_notification.is_read = ?", false). | ||
78 | -// Count(); err != nil { | ||
79 | -// return nil, err | ||
80 | -// } else { | ||
81 | -// unReadInteractionNotification = count | ||
82 | -// } | ||
83 | -// return map[string]int{ | ||
84 | -// "unReadSystemNotification": unReadSystemNotification, | ||
85 | -// "unReadInteractionNotification": unReadInteractionNotification, | ||
86 | -// }, nil | ||
87 | -//} | ||
88 | -// | ||
89 | -//func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { | ||
90 | -// var incomeSuMoney float64 | ||
91 | -// var incomeSuMoneyOfYesterday float64 | ||
92 | -// tx := dao.transactionContext.PgTx | ||
93 | -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | ||
94 | -// yesterday := time.Now().AddDate(0, 0, -1) | ||
95 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
96 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
97 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
98 | -// Where(`su_money_transaction_record.record_type = ?`, 2). | ||
99 | -// Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). | ||
100 | -// Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). | ||
101 | -// Select(&incomeSuMoneyOfYesterday); err != nil { | ||
102 | -// return nil, err | ||
103 | -// } | ||
104 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
105 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
106 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
107 | -// Where(`su_money_transaction_record.record_type = ?`, 2). | ||
108 | -// Select(&incomeSuMoney); err != nil { | ||
109 | -// return nil, err | ||
110 | -// } | ||
111 | -// return map[string]interface{}{ | ||
112 | -// "incomeSuMoney": incomeSuMoney, | ||
113 | -// "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday, | ||
114 | -// }, nil | ||
115 | -//} | ||
116 | -// | ||
117 | -//func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { | ||
118 | -// var incomeSuMoney float64 | ||
119 | -// var expendSuMoney float64 | ||
120 | -// tx := dao.transactionContext.PgTx | ||
121 | -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | ||
122 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
123 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
124 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
125 | -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). | ||
126 | -// Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). | ||
127 | -// Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). | ||
128 | -// Select(&incomeSuMoney); err != nil { | ||
129 | -// return nil, err | ||
130 | -// } | ||
131 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
132 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). | ||
133 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
134 | -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})). | ||
135 | -// Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). | ||
136 | -// Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). | ||
137 | -// Select(&expendSuMoney); err != nil { | ||
138 | -// return nil, err | ||
139 | -// } | ||
140 | -// return map[string]interface{}{ | ||
141 | -// "incomeSuMoney": incomeSuMoney, | ||
142 | -// "expendSuMoney": expendSuMoney, | ||
143 | -// }, nil | ||
144 | -//} | ||
145 | -// | ||
146 | -//func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) { | ||
147 | -// if transactionContext == nil { | ||
148 | -// return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
149 | -// } else { | ||
150 | -// return &EmployeeDao{ | ||
151 | -// transactionContext: transactionContext, | ||
152 | -// }, nil | ||
153 | -// } | ||
154 | -//} |
@@ -5,9 +5,7 @@ import ( | @@ -5,9 +5,7 @@ import ( | ||
5 | "fmt" | 5 | "fmt" |
6 | 6 | ||
7 | "github.com/go-pg/pg/v10" | 7 | "github.com/go-pg/pg/v10" |
8 | - "github.com/go-pg/pg/v10/orm" | ||
9 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" |
10 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
11 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log" |
12 | ) | 10 | ) |
13 | 11 | ||
@@ -23,21 +21,21 @@ func init() { | @@ -23,21 +21,21 @@ func init() { | ||
23 | if !constant.DISABLE_SQL_GENERATE_PRINT { | 21 | if !constant.DISABLE_SQL_GENERATE_PRINT { |
24 | DB.AddQueryHook(SqlGeneratePrintHook{}) | 22 | DB.AddQueryHook(SqlGeneratePrintHook{}) |
25 | } | 23 | } |
26 | - if !constant.DISABLE_CREATE_TABLE { | ||
27 | - for _, model := range []interface{}{ | ||
28 | - //(*models.Employee)(nil), | ||
29 | - (*models.PartnerInfo)(nil), | ||
30 | - } { | ||
31 | - err := DB.CreateTable(model, &orm.CreateTableOptions{ | ||
32 | - Temp: false, | ||
33 | - IfNotExists: true, | ||
34 | - FKConstraints: true, | ||
35 | - }) | ||
36 | - if err != nil { | ||
37 | - panic(err) | ||
38 | - } | ||
39 | - } | ||
40 | - } | 24 | + // if !constant.DISABLE_CREATE_TABLE { |
25 | + // for _, model := range []interface{}{ | ||
26 | + // //(*models.Employee)(nil), | ||
27 | + // (*models.PartnerInfo)(nil), | ||
28 | + // } { | ||
29 | + // err := DB.CreateTable(model, &orm.CreateTableOptions{ | ||
30 | + // Temp: false, | ||
31 | + // IfNotExists: true, | ||
32 | + // FKConstraints: true, | ||
33 | + // }) | ||
34 | + // if err != nil { | ||
35 | + // panic(err) | ||
36 | + // } | ||
37 | + // } | ||
38 | + // } | ||
41 | } | 39 | } |
42 | 40 | ||
43 | type SqlGeneratePrintHook struct{} | 41 | type SqlGeneratePrintHook struct{} |
@@ -12,6 +12,7 @@ import ( | @@ -12,6 +12,7 @@ import ( | ||
12 | "github.com/astaxie/beego/logs" | 12 | "github.com/astaxie/beego/logs" |
13 | adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query" | 13 | adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query" |
14 | adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service" | 14 | adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service" |
15 | + adminuserCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command" | ||
15 | adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query" | 16 | adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query" |
16 | adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" | 17 | adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" |
17 | ) | 18 | ) |
@@ -165,3 +166,32 @@ func (c *AdminLoginController) AdminpPofile() { | @@ -165,3 +166,32 @@ func (c *AdminLoginController) AdminpPofile() { | ||
165 | } | 166 | } |
166 | c.ResponseData(respData) | 167 | c.ResponseData(respData) |
167 | } | 168 | } |
169 | + | ||
170 | +func (c *AdminLoginController) PwdUpdate() { | ||
171 | + //用与适配前端定义的数据结构 | ||
172 | + type Paramater struct { | ||
173 | + Pwd string `json:"pwd"` | ||
174 | + } | ||
175 | + var ( | ||
176 | + param Paramater | ||
177 | + err error | ||
178 | + ) | ||
179 | + if err = c.BindJsonData(¶m); err != nil { | ||
180 | + logs.Error(err) | ||
181 | + c.ResponseError(errors.New("json数据解析失败")) | ||
182 | + return | ||
183 | + } | ||
184 | + uid := c.GetUserId() | ||
185 | + newAdminUserService := adminuserservice.NewAdminUserService(nil) | ||
186 | + cmd := adminuserCmd.UpdateAdminUserPwdCommand{ | ||
187 | + Id: uid, | ||
188 | + Password: param.Pwd, | ||
189 | + } | ||
190 | + err = newAdminUserService.UpdateAdminPassword(cmd) | ||
191 | + if err != nil { | ||
192 | + c.ResponseError(err) | ||
193 | + return | ||
194 | + } | ||
195 | + c.ResponseData(nil) | ||
196 | + return | ||
197 | +} |
@@ -31,7 +31,6 @@ type adminDetailParam struct { | @@ -31,7 +31,6 @@ type adminDetailParam struct { | ||
31 | Id int64 `json:"id"` | 31 | Id int64 `json:"id"` |
32 | PermissionType []int `json:"permissionType"` | 32 | PermissionType []int `json:"permissionType"` |
33 | Status int `json:"status"` | 33 | Status int `json:"status"` |
34 | - Pwd string `json:"pwd"` | ||
35 | Account string `json:"account"` | 34 | Account string `json:"account"` |
36 | } | 35 | } |
37 | 36 | ||
@@ -51,7 +50,6 @@ func (c *AdminUserController) SaveAdminUser() { | @@ -51,7 +50,6 @@ func (c *AdminUserController) SaveAdminUser() { | ||
51 | Id: param.Id, | 50 | Id: param.Id, |
52 | Name: param.Account, | 51 | Name: param.Account, |
53 | Account: param.Account, | 52 | Account: param.Account, |
54 | - Password: param.Pwd, | ||
55 | PermissionId: param.PermissionType, | 53 | PermissionId: param.PermissionType, |
56 | IsUsable: false, | 54 | IsUsable: false, |
57 | } | 55 | } |
@@ -169,3 +167,50 @@ func (c *AdminUserController) ListAdminUser() { | @@ -169,3 +167,50 @@ func (c *AdminUserController) ListAdminUser() { | ||
169 | c.ResponsePageList(listData, cnt, param.PageNumber) | 167 | c.ResponsePageList(listData, cnt, param.PageNumber) |
170 | return | 168 | return |
171 | } | 169 | } |
170 | + | ||
171 | +func (c *AdminUserController) ForbiddenAdminUser() { | ||
172 | + //用与适配前端定义的数据结构 | ||
173 | + type Paramter struct { | ||
174 | + Id int64 `json:"id"` | ||
175 | + } | ||
176 | + var ( | ||
177 | + param Paramter | ||
178 | + err error | ||
179 | + ) | ||
180 | + if err = c.BindJsonData(¶m); err != nil { | ||
181 | + logs.Error(err) | ||
182 | + c.ResponseError(errors.New("json数据解析失败")) | ||
183 | + return | ||
184 | + } | ||
185 | + newAdminUserService := adminuserservice.NewAdminUserService(nil) | ||
186 | + err = newAdminUserService.UpdateAdminIsUsable(param.Id, false) | ||
187 | + if err != nil { | ||
188 | + c.ResponseError(err) | ||
189 | + return | ||
190 | + } | ||
191 | + c.ResponseData(nil) | ||
192 | + return | ||
193 | +} | ||
194 | + | ||
195 | +//BeforeEditAdminUser 编辑管理员操作的前置接口 | ||
196 | +func (c *AdminUserController) BeforeEditAdminUser() { | ||
197 | + newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil) | ||
198 | + allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{ | ||
199 | + ParentId: 0, | ||
200 | + }) | ||
201 | + if err != nil { | ||
202 | + logs.Error("获取权限数据失败:%s", err) | ||
203 | + c.ResponseError(errors.New("服务异常")) | ||
204 | + return | ||
205 | + } | ||
206 | + var rspData []map[string]interface{} | ||
207 | + for i := range allPermission { | ||
208 | + m := map[string]interface{}{ | ||
209 | + "id": allPermission[i].Id, | ||
210 | + "permissionName": allPermission[i].Name, | ||
211 | + } | ||
212 | + rspData = append(rspData, m) | ||
213 | + } | ||
214 | + c.ResponseData(rspData) | ||
215 | + return | ||
216 | +} |
@@ -11,12 +11,14 @@ func init() { | @@ -11,12 +11,14 @@ func init() { | ||
11 | beego.NSRouter("/login", &controllers.AdminLoginController{}, "POST:Login"), | 11 | beego.NSRouter("/login", &controllers.AdminLoginController{}, "POST:Login"), |
12 | beego.NSRouter("/captcha-init", &controllers.AdminLoginController{}, "POST:CaptchaInit"), | 12 | beego.NSRouter("/captcha-init", &controllers.AdminLoginController{}, "POST:CaptchaInit"), |
13 | beego.NSRouter("/profile", &controllers.AdminLoginController{}, "POST:AdminpPofile"), | 13 | beego.NSRouter("/profile", &controllers.AdminLoginController{}, "POST:AdminpPofile"), |
14 | + beego.NSRouter("/pwd-update", &controllers.AdminLoginController{}, "POST:PwdUpdate"), | ||
14 | ), | 15 | ), |
15 | - | ||
16 | beego.NSNamespace("/admin", | 16 | beego.NSNamespace("/admin", |
17 | beego.NSRouter("/update", &controllers.AdminUserController{}, "POST:SaveAdminUser"), | 17 | beego.NSRouter("/update", &controllers.AdminUserController{}, "POST:SaveAdminUser"), |
18 | beego.NSRouter("/detail", &controllers.AdminUserController{}, "POST:GetAdminUser"), | 18 | beego.NSRouter("/detail", &controllers.AdminUserController{}, "POST:GetAdminUser"), |
19 | beego.NSRouter("/list", &controllers.AdminUserController{}, "POST:ListAdminUser"), | 19 | beego.NSRouter("/list", &controllers.AdminUserController{}, "POST:ListAdminUser"), |
20 | + beego.NSRouter("/forbidden", &controllers.AdminUserController{}, "POST:ForbiddenAdminUser"), | ||
21 | + beego.NSRouter("/permission", &controllers.AdminUserController{}, "POST:BeforeEditAdminUser"), | ||
20 | ), | 22 | ), |
21 | ) | 23 | ) |
22 | beego.AddNamespace(adminRouter) | 24 | beego.AddNamespace(adminRouter) |
-
请 注册 或 登录 后发表评论