mainqaq il y a 2 ans
Parent
révision
8b9d5ba4ce

+ 94 - 32
controllers/secondary_order_api_contorller.go Voir le fichier

@@ -9,6 +9,7 @@ import (
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11 11
 	"github.com/jinzhu/gorm"
12
+	"strings"
12 13
 	"time"
13 14
 )
14 15
 
@@ -34,9 +35,23 @@ func SecondaryOrderApiRegistRouters() {
34 35
 	beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut")               //更改药品自动出库仓库
35 36
 	beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName")                   //获取仓库管理员信息
36 37
 	beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit")                         //初始化旧数据
38
+	beego.Router("/api/secondary/ttttt", &SecondaryOrderApiController{}, "get:TTTTT")
37 39
 
38 40
 }
39 41
 
42
+//ceshi
43
+func (this *SecondaryOrderApiController) TTTTT() {
44
+	orgid := this.GetAdminUserInfo().CurrentOrgId
45
+	err := service.GetDefaultStorehouse(orgid)
46
+	if err != nil {
47
+		utils.ErrorLog("创建默认仓库失败,原因为:", err)
48
+	}
49
+	this.ServeSuccessJSON(map[string]interface{}{
50
+		"list": err,
51
+	})
52
+	return
53
+}
54
+
40 55
 //获取仓库编码
41 56
 func (this *SecondaryOrderApiController) GetStoreCode() {
42 57
 	orgId := this.GetAdminUserInfo().CurrentOrgId
@@ -58,7 +73,7 @@ func (this *SecondaryOrderApiController) GetStoreCode() {
58 73
 //修改仓库状态
59 74
 func (this *SecondaryOrderApiController) UpdateStatus() {
60 75
 	orgId := this.GetAdminUserInfo().CurrentOrgId
61
-	orgId = 9675
76
+	//orgId = 9675
62 77
 	check := map[string][]string{
63 78
 		"id": {"must", "int", "id"},
64 79
 	}
@@ -179,6 +194,7 @@ func (this *SecondaryOrderApiController) IsStorehouseAddress() {
179 194
 
180 195
 //分页
181 196
 func (this *SecondaryOrderApiController) StorehouseList() {
197
+	adminUserInfo := this.GetAdminUserInfo()
182 198
 	page, _ := this.GetInt64("page")   //页码
183 199
 	limit, _ := this.GetInt64("limit") //每一页查出来的条数
184 200
 	check := map[string][]string{
@@ -191,10 +207,61 @@ func (this *SecondaryOrderApiController) StorehouseList() {
191 207
 	if err != nil {
192 208
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
193 209
 	}
210
+	namemap := make(map[int64]string)
211
+	//根据管理员id获取管理员
212
+	viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
213
+	for _, v := range viewModels {
214
+		namemap[int64(v.AdminUserId)] = v.UserName
215
+	}
216
+	slicekey := make([]int64, 0)
217
+	if len(keyword) > 0 {
218
+		for k, v := range namemap {
219
+			res := strings.Contains(v, keyword)
220
+			if res == true {
221
+				slicekey = append(slicekey, k)
222
+			}
223
+		}
224
+	}
194 225
 	//获取分页的数据
195
-	list, total, err := service.StorehouseList(page, limit, orgId, keyword)
226
+	list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
227
+
228
+	//分页
229
+	type Storehouselist struct {
230
+		ID                  int64
231
+		StorehouseCode      string //仓库编号
232
+		StorehouseName      string //仓库名称
233
+		StorehouseAddress   string //仓库地址
234
+		StorehouseStatus    int64  //仓库状态
235
+		Status              int64  //数据状态
236
+		StorehouseAdminId   int64  //仓库管理员id
237
+		StorehouseAdminName string //仓库管理员名字
238
+		UserOrgId           int64
239
+	}
240
+	//初始化该结构体
241
+	tmplist := []*Storehouselist{}
242
+	for i := 0; i < len(list); i++ {
243
+		tlist := &Storehouselist{
244
+			list[i].ID,
245
+			list[i].StorehouseCode,
246
+			list[i].StorehouseName,
247
+			list[i].StorehouseAddress,
248
+			list[i].StorehouseStatus,
249
+			list[i].Status,
250
+			list[i].StorehouseAdminId,
251
+			"",
252
+			list[i].UserOrgId,
253
+		}
254
+		tmplist = append(tmplist, tlist)
255
+	}
256
+	for _, v := range tmplist {
257
+		if k, ok := namemap[v.StorehouseAdminId]; ok {
258
+			v.StorehouseAdminName = k
259
+		} else {
260
+			v.StorehouseAdminName = "超级管理员"
261
+		}
262
+	}
196 263
 	this.ServeSuccessJSON(map[string]interface{}{
197
-		"list":  list,
264
+		"list":  tmplist,
198 265
 		"total": total,
199 266
 	})
200 267
 }
@@ -210,26 +277,19 @@ func (this *SecondaryOrderApiController) AddStorehouse() {
210 277
 		return
211 278
 	}
212 279
 	var storehouse_status, admin_id int64
213
-	var admin_name string
214 280
 	tmpstatus := dataBody["storehouse_status"]
215
-	tmpid := dataBody["storehouse_admin_id"]
216
-	tmpname := dataBody["storehouse_admin_name"]
281
+	tmpid := dataBody["storehouse_admin_id"] //管理员id
217 282
 	if tmpstatus == nil {
218 283
 		storehouse_status = 1
219 284
 	} else {
220 285
 		storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
221 286
 	}
222 287
 	if tmpid == nil {
223
-		admin_id = 0
288
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
289
+		return
224 290
 	} else {
225 291
 		admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
226 292
 	}
227
-	if tmpname == nil {
228
-		admin_name = "admin"
229
-	} else {
230
-		admin_name = dataBody["storehouse_admin_name"].(string) //管理员名称
231
-	}
232
-
233 293
 	switch {
234 294
 	case dataBody["storehouse_code"] == nil:
235 295
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
@@ -267,17 +327,15 @@ func (this *SecondaryOrderApiController) AddStorehouse() {
267 327
 		return
268 328
 	}
269 329
 
270
-	//storehouse_admin := int64(dataBody["storehouse_admin"].(float64))//仓库管理员,暂时不用管
271 330
 	storehouse := models.Storehouse{
272
-		StorehouseCode:      code,
273
-		StorehouseName:      name,
274
-		StorehouseAddress:   address,
275
-		StorehouseStatus:    storehouse_status,
276
-		UserOrgId:           orgId,
277
-		Status:              1,
278
-		StorehouseAdminId:   admin_id,
279
-		StorehouseAdminName: admin_name,
280
-		Ctime:               time.Now().Unix(),
331
+		StorehouseCode:    code,
332
+		StorehouseName:    name,
333
+		StorehouseAddress: address,
334
+		StorehouseStatus:  storehouse_status,
335
+		UserOrgId:         orgId,
336
+		Status:            1,
337
+		StorehouseAdminId: admin_id,
338
+		Ctime:             time.Now().Unix(),
281 339
 	}
282 340
 	err = service.AddStroehouse(storehouse)
283 341
 	if err != nil {
@@ -293,19 +351,27 @@ func (this *SecondaryOrderApiController) AddStorehouse() {
293 351
 //修改仓库
294 352
 func (this *SecondaryOrderApiController) UpdateStorehouse() {
295 353
 	dataBody := make(map[string]interface{}, 0)
354
+	//orgId := this.GetAdminUserInfo().CurrentOrgId
296 355
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
297 356
 	if err != nil {
298 357
 		utils.ErrorLog(err.Error())
299 358
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
300 359
 		return
301 360
 	}
302
-	var storehouse_status int64
361
+	var storehouse_status, admin_id int64
303 362
 	tmpstatus := dataBody["storehouse_status"]
363
+	tmpid := dataBody["storehouse_admin_id"]
304 364
 	if tmpstatus == nil {
305 365
 		storehouse_status = 1
306 366
 	} else {
307 367
 		storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
308 368
 	}
369
+	if tmpid == nil {
370
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
371
+		return
372
+	} else {
373
+		admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
374
+	}
309 375
 
310 376
 	switch {
311 377
 	case dataBody["id"] == nil:
@@ -322,12 +388,12 @@ func (this *SecondaryOrderApiController) UpdateStorehouse() {
322 388
 	name := dataBody["storehouse_name"].(string)       //仓库名称
323 389
 	address := dataBody["storehouse_address"].(string) //地址
324 390
 
325
-	//storehouse_admin := int64(dataBody["storehouse_admin"].(float64))//仓库管理员,暂时不用管
326 391
 	storehouse := models.Storehouse{
327 392
 		ID:                id,
328 393
 		StorehouseName:    name,
329 394
 		StorehouseAddress: address,
330 395
 		StorehouseStatus:  storehouse_status,
396
+		StorehouseAdminId: admin_id,
331 397
 		Mtime:             time.Now().Unix(),
332 398
 	}
333 399
 	err = service.UpdateStroehouse(storehouse)
@@ -555,14 +621,10 @@ func (this *SecondaryOrderApiController) Byliinit() {
555 621
 
556 622
 //查询机构所属管理员
557 623
 func (this *SecondaryOrderApiController) GetuserName() {
558
-	orgId := this.GetAdminUserInfo().CurrentOrgId
559
-	username, err := service.GetuserName(orgId)
560
-	if err != nil {
561
-		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
562
-		return
563
-	}
624
+	adminUserInfo := this.GetAdminUserInfo()
625
+	viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
564 626
 	this.ServeSuccessJSON(map[string]interface{}{
565
-		"list": username,
627
+		"list": viewModels,
566 628
 	})
567 629
 
568 630
 }

+ 38 - 14
models/secondary_models.go Voir le fichier

@@ -2,17 +2,16 @@ package models
2 2
 
3 3
 //二级仓库
4 4
 type Storehouse struct {
5
-	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
6
-	StorehouseCode      string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`                 //仓库编号
7
-	StorehouseName      string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`                 //仓库名称
8
-	StorehouseAddress   string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`        //仓库地址
9
-	StorehouseStatus    int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`           //仓库状态
10
-	Status              int64  `gorm:"column:status" json:"status" form:"status"`                                            //数据状态
11
-	StorehouseAdminId   int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"`     //仓库管理员id
12
-	StorehouseAdminName string `gorm:"column:storehouse_admin_name" json:"storehouse_admin_name" form:"storehouse_admin_id"` //仓库管理员名字
13
-	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
14
-	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
15
-	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
5
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
6
+	StorehouseCode    string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`             //仓库编号
7
+	StorehouseName    string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`             //仓库名称
8
+	StorehouseAddress string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`    //仓库地址
9
+	StorehouseStatus  int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`       //仓库状态
10
+	Status            int64  `gorm:"column:status" json:"status" form:"status"`                                        //数据状态
11
+	StorehouseAdminId int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"` //仓库管理员id
12
+	UserOrgId         int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
13
+	Ctime             int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
14
+	Mtime             int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
16 15
 }
17 16
 
18 17
 func (Storehouse) TableName() string {
@@ -37,11 +36,36 @@ func (StorehouseConfig) TableName() string {
37 36
 }
38 37
 
39 38
 type App_Role_byli struct {
40
-	Id       int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
41
-	OrgId    int64  `gorm:"column:org_id" json:"org_id"`
42
-	UserName string `gorm:"column:user_name" json:"user_name"` // 用户名称
39
+	Id          int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
40
+	OrgId       int64  `gorm:"column:org_id" json:"org_id"`
41
+	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
42
+	UserName    string `gorm:"column:user_name" json:"user_name"` // 用户名称
43 43
 }
44 44
 
45 45
 func (App_Role_byli) TableName() string {
46 46
 	return "sgj_users.sgj_user_admin_role"
47 47
 }
48
+
49
+type UserOrg struct {
50
+	Id      int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
51
+	Creator int64 `gorm:"column:creator" json:"creator"`
52
+}
53
+
54
+func (UserOrg) TableName() string {
55
+	return "sgj_users.sgj_user_org"
56
+}
57
+
58
+//分页
59
+type Storehouselist struct {
60
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
61
+	StorehouseCode      string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`                 //仓库编号
62
+	StorehouseName      string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`                 //仓库名称
63
+	StorehouseAddress   string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`        //仓库地址
64
+	StorehouseStatus    int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`           //仓库状态
65
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`                                            //数据状态
66
+	StorehouseAdminId   int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"`     //仓库管理员id
67
+	StorehouseAdminName string `gorm:"column:storehouse_admin_name" json:"storehouse_admin_name" form:"storehouse_admin_id"` //仓库管理员名字
68
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
69
+	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
70
+	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
71
+}

+ 45 - 23
service/secondary_service.go Voir le fichier

@@ -6,6 +6,7 @@ import (
6 6
 	"fmt"
7 7
 	"github.com/jinzhu/gorm"
8 8
 	"math/rand"
9
+	"strconv"
9 10
 	"time"
10 11
 )
11 12
 
@@ -118,10 +119,11 @@ func AddStroehouse(storehouse models.Storehouse) error {
118 119
 func UpdateStroehouse(storehouse models.Storehouse) error {
119 120
 	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ? and status = 1", storehouse.ID).Updates(
120 121
 		map[string]interface{}{
121
-			"storehouse_name":    storehouse.StorehouseName,
122
-			"storehouse_address": storehouse.StorehouseAddress,
123
-			"storehouse_status":  storehouse.StorehouseStatus,
124
-			"mtime":              storehouse.Mtime,
122
+			"storehouse_name":     storehouse.StorehouseName,
123
+			"storehouse_address":  storehouse.StorehouseAddress,
124
+			"storehouse_status":   storehouse.StorehouseStatus,
125
+			"storehouse_admin_id": storehouse.StorehouseAdminId,
126
+			"mtime":               storehouse.Mtime,
125 127
 		}).Error
126 128
 	return err
127 129
 }
@@ -133,12 +135,18 @@ func GetOneStorehouse(id, orgid int64) (storehouse models.Storehouse, err error)
133 135
 }
134 136
 
135 137
 //分页
136
-func StorehouseList(page, limit, orgid int64, keyword string) (storehouse []models.Storehouse, total int64, err error) {
138
+func StorehouseList(page, limit, orgid int64, keyword string, slicekey []int64) (storehouse []models.Storehouse, total int64, err error) {
137 139
 	db := XTReadDB().Model(&storehouse).Where("status = 1 and user_org_id = ?", orgid)
138 140
 	offset := (page - 1) * limit
139 141
 	if len(keyword) > 0 {
142
+		var adminid string = "storehouse_code like ? or storehouse_name like ? or storehouse_address like ? "
143
+		if len(slicekey) > 0 {
144
+			for i := 0; i < len(slicekey); i++ {
145
+				adminid = adminid + " or storehouse_admin_id =" + strconv.FormatInt(slicekey[i], 10)
146
+			}
147
+		}
140 148
 		keyword = "%" + keyword + "%"
141
-		db = db.Where("storehouse_code like ? or storehouse_name like ? or storehouse_address like ? or storehouse_admin_name like ?", keyword, keyword, keyword, keyword)
149
+		db = db.Where(adminid, keyword, keyword, keyword)
142 150
 	}
143 151
 	err = db.Count(&total).Offset(offset).Order("id").Limit(limit).Find(&storehouse).Error
144 152
 	return storehouse, total, err
@@ -161,17 +169,21 @@ func GetDefaultStorehouse(orgid int64) error {
161 169
 			a = false
162 170
 		}
163 171
 	}
172
+	createid, err := Getcreateid(orgid)
173
+	if err != nil {
174
+		return err
175
+	}
164 176
 	storehouse := models.Storehouse{
165
-		StorehouseCode:      code,
166
-		StorehouseName:      "默认仓库",
167
-		StorehouseAddress:   "",
168
-		StorehouseStatus:    1,
169
-		UserOrgId:           orgid,
170
-		StorehouseAdminName: "admin",
171
-		Status:              1,
172
-		Ctime:               time.Now().Unix(),
173
-	}
174
-	err := AddStroehouse(storehouse)
177
+		StorehouseCode:    code,
178
+		StorehouseName:    "默认仓库",
179
+		StorehouseAddress: "",
180
+		StorehouseStatus:  1,
181
+		UserOrgId:         orgid,
182
+		StorehouseAdminId: createid.Creator,
183
+		Status:            1,
184
+		Ctime:             time.Now().Unix(),
185
+	}
186
+	err = AddStroehouse(storehouse)
175 187
 	return err
176 188
 }
177 189
 
@@ -293,6 +305,10 @@ func Byliinit() (err error) {
293 305
 			tx.Commit()
294 306
 		}
295 307
 	}()
308
+	err = initsgj_user_admin(tx)
309
+	if err != nil && err.Error() != "record not found" {
310
+		return
311
+	}
296 312
 	err = StoreReduceOrg(tx)
297 313
 	if err != nil && err.Error() != "record not found" {
298 314
 		return
@@ -398,6 +414,12 @@ func Byliinit() (err error) {
398 414
 	return
399 415
 }
400 416
 
417
+//初始化管理员名字
418
+func initsgj_user_admin(tx *gorm.DB) (err error) {
419
+	err = tx.Exec("update sgj_users.sgj_user_admin set name = \"超级管理员\" where name is null or name = \"\"").Error
420
+	return
421
+}
422
+
401 423
 //根据xt_gobal_template 获取的机构id减去仓库表存在的机构id,把结果插入到仓库表
402 424
 func StoreReduceOrg(tx *gorm.DB) (err error) {
403 425
 	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
@@ -422,13 +444,13 @@ func StoreReduceConfig(tx *gorm.DB) (err error) {
422 444
 	return
423 445
 }
424 446
 
425
-//初始化 xt_storehouse()把插入管理员的名字
447
+//初始化 xt_storehouse 管理员的名字
426 448
 func initxt_storehouse(tx *gorm.DB) (err error) {
427 449
 	err = tx.Exec("UPDATE sgj_xt.xt_storehouse as t," +
428
-		"(SELECT o.id,o.creator,u.name from sgj_users.sgj_user_org as o,sgj_users.sgj_user_admin as u," +
450
+		"(SELECT o.id,o.creator from sgj_users.sgj_user_org as o," +
429 451
 		"(SELECT DISTINCT org_id from sgj_xt.xt_gobal_template)as t " +
430
-		"WHERE o.creator = u.id AND t.org_id = o.id )tmp " +
431
-		"SET t.storehouse_admin_id = tmp.creator,t.storehouse_admin_name = tmp.name,t.mtime = UNIX_TIMESTAMP()" +
452
+		"WHERE t.org_id = o.id )tmp " +
453
+		"SET t.storehouse_admin_id = tmp.creator,t.mtime = UNIX_TIMESTAMP()" +
432 454
 		"WHERE t.status = 1 and t.user_org_id = tmp.id").Error
433 455
 	return
434 456
 }
@@ -686,8 +708,8 @@ func initxt_supplier_warehousing_cancel_order(tx *gorm.DB) (err error) {
686 708
 	return
687 709
 }
688 710
 
689
-//查询机构下的所有用户名
690
-func GetuserName(orgid int64) (username []models.App_Role_byli, err error) {
691
-	err = XTReadDB().Select("id,org_id,user_name").Where("org_id = ?", orgid).Find(&username).Error
711
+//查询机构创建者的id
712
+func Getcreateid(orgid int64) (createid models.UserOrg, err error) {
713
+	err = XTReadDB().Select("id,creator").Where("id = ? and status = 1", orgid).Find(&createid).Error
692 714
 	return
693 715
 }