Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
3399dad45e

File diff suppressed because it is too large
+ 707 - 720
controllers/secondary_order_api_contorller.go


+ 1 - 84
models/secondary_models.go View File

@@ -1,23 +1,5 @@
1 1
 package models
2 2
 
3
-//二级仓库
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
-	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"`
15
-}
16
-
17
-func (Storehouse) TableName() string {
18
-	return "xt_storehouse"
19
-}
20
-
21 3
 //仓库配置
22 4
 type StorehouseConfig struct {
23 5
 	ID                 int64 `gorm:"column:id" json:"id" form:"id"`
@@ -136,6 +118,7 @@ type XtStorehouseConfig struct {
136 118
 func (XtStorehouseConfig) TableName() string {
137 119
 	return "xt_storehouse_config"
138 120
 }
121
+
139 122
 //二级仓库
140 123
 type Storehouse struct {
141 124
 	ID                int64  `gorm:"column:id" json:"id" form:"id"`
@@ -154,72 +137,6 @@ func (Storehouse) TableName() string {
154 137
 	return "xt_storehouse"
155 138
 }
156 139
 
157
-//仓库配置
158
-type StorehouseConfig struct {
159
-	ID                 int64 `gorm:"column:id" json:"id" form:"id"`
160
-	UserOrgId          int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`                         //机构id
161
-	StorehouseInfo     int64 `gorm:"column:storehouse_info" json:"storehouse_info" form:"storehouse_info"`             //耗材 自动入库 的仓库id
162
-	StorehouseOutInfo  int64 `gorm:"column:storehouse_out_info" json:"storehouse_out_info" form:"storehouse_out_info"` //耗材 自动出库 的仓库id
163
-	DrugStorehouseInfo int64 `gorm:"drug_storehouse_info" json:"drug_storehouse_info" form:"drug_storehouse_info"`     //药品 自动入库 的仓库id
164
-	DrugStorehouseOut  int64 `gorm:"drug_storehouse_out" json:"drug_storehouse_out" form:"drug_storehouse_out"`        //药品 自动出库 的仓库id
165
-	Status             int64 `gorm:"status" json:"status" form:"status"`
166
-	Ctime              int64 `gorm:"ctime" json:"ctime" form:"ctime"`
167
-	Mtime              int64 `gorm:"mtime" json:"mtime" form:"mtime"`
168
-}
169
-
170
-func (StorehouseConfig) TableName() string {
171
-	return "xt_storehouse_config"
172
-}
173
-
174
-type App_Role_byli struct {
175
-	Id          int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
176
-	OrgId       int64  `gorm:"column:org_id" json:"org_id"`
177
-	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
178
-	UserName    string `gorm:"column:user_name" json:"user_name"` // 用户名称
179
-}
180
-
181
-func (App_Role_byli) TableName() string {
182
-	return "sgj_users.sgj_user_admin_role"
183
-}
184
-
185
-type UserOrg struct {
186
-	Id      int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
187
-	Creator int64 `gorm:"column:creator" json:"creator"`
188
-}
189
-
190
-func (UserOrg) TableName() string {
191
-	return "sgj_users.sgj_user_org"
192
-}
193
-
194
-//分页
195
-type Storehouselist struct {
196
-	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
197
-	StorehouseCode      string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`                 //仓库编号
198
-	StorehouseName      string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`                 //仓库名称
199
-	StorehouseAddress   string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`        //仓库地址
200
-	StorehouseStatus    int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`           //仓库状态
201
-	Status              int64  `gorm:"column:status" json:"status" form:"status"`                                            //数据状态
202
-	StorehouseAdminId   int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"`     //仓库管理员id
203
-	StorehouseAdminName string `gorm:"column:storehouse_admin_name" json:"storehouse_admin_name" form:"storehouse_admin_id"` //仓库管理员名字
204
-	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
205
-	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
206
-	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
207
-}
208
-
209
-type RolePurviews struct {
210
-	Id         int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT"`
211
-	RoleId     int64
212
-	OrgId      int64
213
-	AppId      int64
214
-	PurviewIds string `gorm:"column:purview_ids"`
215
-	Status     int8   // 状态 0.无效 1.有效 2.禁用
216
-	CreateTime int64  `gorm:"column:ctime"` // 创建时间
217
-	ModifyTime int64  `gorm:"column:mtime"` // 修改时间
218
-	Role       Role   `gorm:"ForeignKey:RoleId;AssociationForeignKey:ID" json:"role_info"`
219
-}
220
-
221
-func (RolePurviews) TableName() string {
222
-	return "sgj_users.sgj_user_role_purview"
223 140
 type XtSecondWarehouse struct {
224 141
 	ID                int64  `gorm:"column:id" json:"id" form:"id"`
225 142
 	SecondOrderNumber string `gorm:"column:second_order_number" json:"second_order_number" form:"second_order_number"`

+ 1 - 2
models/stock_models.go View File

@@ -141,7 +141,6 @@ type WarehousingInfo struct {
141 141
 	SupplyWarehouseId         int64       `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
142 142
 	SupplyWarehouseDetailInfo int64       `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
143 143
 	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
144
-	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
145 144
 	SecondWarehouseInfoId     int64       `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
146 145
 }
147 146
 
@@ -257,7 +256,6 @@ type WarehouseOutInfo struct {
257 256
 	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
258 257
 	SecondWarehouseInfoId   int64        `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
259 258
 	AdminUserId             int64        `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
260
-	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
261 259
 }
262 260
 
263 261
 func (WarehouseOutInfo) TableName() string {
@@ -357,6 +355,7 @@ type CancelStock struct {
357 355
 	Manufacturer      int64                `gorm:"column:manufacturer" json:"manufacturer"`
358 356
 	Type              int64                `gorm:"column:type" json:"type"`
359 357
 	XtCancelStockInfo []*XtCancelStockInfo `gorm:"ForeignKey:CancelStockId;AssociationForeignKey:ID" json:"XtCancelStockInfo"`
358
+	StorehouseId      int64                `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
360 359
 }
361 360
 
362 361
 func (CancelStock) TableName() string {

+ 0 - 770
service/secondary_service.go View File

@@ -966,777 +966,7 @@ func GetStoreWarehouseOutById(id int64, orgid int64) (models.WarehouseOut, error
966 966
 	err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&out).Error
967 967
 	return out, err
968 968
 }
969
-import (
970
-	"XT_New/models"
971
-	"XT_New/utils"
972
-	"fmt"
973
-	"github.com/jinzhu/gorm"
974
-	"math/rand"
975
-	"strconv"
976
-	"time"
977
-)
978
-
979
-//生成编号,规则为:"SH-"+4位随机数
980
-func CreateCode() string {
981
-	s := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000))
982
-	code := "SH-" + s
983
-	return code
984
-}
985
-
986
-//查询编号是否重复
987
-func FindStorehouseCode(orgid int64, code string) bool {
988
-	var total int
989
-	XTReadDB().Model(&models.Storehouse{}).Where(" storehouse_code = ? and user_org_id = ? and status = 1", code, orgid).Count(&total)
990
-	if total > 0 {
991
-		return true
992
-	} else {
993
-		return false
994
-	}
995
-}
996
-
997
-//判断仓库的库存是否为零 true为零,false不为零
998
-func IsStorehouseNil(id, orgid int64) bool { //根据 id gro_id 查为零的库存
999
-	var h, y int
1000
-	//判断耗材是否为零
1001
-	XTReadDB().Model(&models.WarehousingInfo{}).Where("stock_count > 0 and status = 1 and org_id = ? and storehouse_id = ?", orgid, id).Count(&h)
1002
-	if h > 0 {
1003
-		return false
1004
-	}
1005
-	//判断药品是否为零
1006
-	XTReadDB().Model(&models.XtDrugWarehouseInfo{}).Where("stock_max_number > 0 or stock_min_number > 0 ").Where(" org_id = ? and storehouse_id = ?", orgid, id).Count(&y)
1007
-	if y > 0 {
1008
-		return false
1009
-	}
1010
-	return true
1011
-}
1012
-
1013
-//修改仓库状态
1014
-func UpdateStorehouseStatus(id int64) error {
1015
-	err := XTWriteDB().Exec("UPDATE xt_storehouse,(SELECT CASE storehouse_status WHEN 1 THEN 0 WHEN 0 THEN 1 END AS tt FROM xt_storehouse WHERE id=?)tmp SET storehouse_status = tmp.tt where id=?", id, id).Error
1016
-	return err
1017
-}
1018
-
1019
-//删除仓库
1020
-func DeleteStorehouse(id int64) error {
1021
-	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ?", id).Update("status", 0).Error
1022
-	return err
1023
-}
1024
-
1025
-//查询仓库名称是否重复
1026
-func IsStorehouseName(orgid int64, storehouse_name string) (bool, error) {
1027
-	var total int
1028
-	var tmp bool
1029
-	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1", storehouse_name, orgid).Count(&total).Error
1030
-	if total > 0 {
1031
-		tmp = true //有重复的
1032
-	} else {
1033
-		tmp = false
1034
-	}
1035
-	return tmp, err
1036
-}
1037
-
1038
-//查询仓库地址是否重复
1039
-func IsStorehouseAddress(orgid int64, storehouse_address string) (bool, error) {
1040
-	var total int
1041
-	var tmp bool
1042
-	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1", storehouse_address, orgid).Count(&total).Error
1043
-	if total > 0 {
1044
-		tmp = true //有重复的
1045
-	} else {
1046
-		tmp = false
1047
-	}
1048
-	return tmp, err
1049
-}
1050
-
1051
-//查询仓库名称是否重复(用于修改)
1052
-func IsStorehouseNameUp(orgid, id int64, storehouse_name string) (bool, error) {
1053
-	var total int
1054
-	var tmp bool
1055
-	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1 and id != ?", storehouse_name, orgid, id).Count(&total).Error
1056
-	if total > 0 {
1057
-		tmp = true //有重复的
1058
-	} else {
1059
-		tmp = false
1060
-	}
1061
-	return tmp, err
1062
-}
1063
-
1064
-//查询仓库地址是否重复(用于修改)
1065
-func IsStorehouseAddressUp(orgid, id int64, storehouse_address string) (bool, error) {
1066
-	var total int
1067
-	var tmp bool
1068
-	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1 and id != ?", storehouse_address, orgid, id).Count(&total).Error
1069
-	if total > 0 {
1070
-		tmp = true //有重复的
1071
-	} else {
1072
-		tmp = false
1073
-	}
1074
-	return tmp, err
1075
-}
1076
-
1077
-//新增仓库
1078
-func AddStroehouse(storehouse models.Storehouse) error {
1079
-	tx := XTWriteDB().Begin()
1080
-	defer func() {
1081
-		if err != nil {
1082
-			utils.ErrorLog("新增仓库_事务失败,原因为", err)
1083
-			tx.Rollback()
1084
-		} else {
1085
-			tx.Commit()
1086
-		}
1087
-	}()
1088
-	//创建仓库
1089
-	err := tx.Create(&storehouse).Error
1090
-	if err != nil {
1091
-		return err
1092
-	}
1093
-	var id models.Storehouse
1094
-	//获取创建仓库的id
1095
-	err = tx.Model(&models.Storehouse{}).Select("id").Where("status = 1 and user_org_id = ?", storehouse.UserOrgId).Order("id desc").First(&id).Error
1096
-	if err != nil {
1097
-		return err
1098
-	}
1099
-	//判断是否存在仓库配置
1100
-	boolean := IsStorehouseconfigXT(storehouse.UserOrgId, tx)
1101
-	if boolean == false {
1102
-		//创建仓库配置
1103
-		err = CreateStorehouseConfigXT(storehouse.UserOrgId, id.ID, tx)
1104
-	} else {
1105
-		utils.ErrorLog("仓库配置已存在")
1106
-	}
1107
-
1108
-	return err
1109
-}
1110
-
1111
-//修改仓库
1112
-func UpdateStroehouse(storehouse models.Storehouse) error {
1113
-	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ? and status = 1", storehouse.ID).Updates(
1114
-		map[string]interface{}{
1115
-			"storehouse_name":     storehouse.StorehouseName,
1116
-			"storehouse_address":  storehouse.StorehouseAddress,
1117
-			"storehouse_status":   storehouse.StorehouseStatus,
1118
-			"storehouse_admin_id": storehouse.StorehouseAdminId,
1119
-			"mtime":               storehouse.Mtime,
1120
-		}).Error
1121
-	return err
1122
-}
1123
-
1124
-//查询一条仓库的信息
1125
-func GetOneStorehouse(id, orgid int64) (storehouse models.Storehouse, err error) {
1126
-	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ? and user_org_id = ?", id, orgid).Find(&storehouse).Error
1127
-	return
1128
-}
1129
-
1130
-//分页
1131
-func StorehouseList(page, limit, orgid int64, keyword string, slicekey []int64) (storehouse []models.Storehouse, total int64, err error) {
1132
-	db := XTReadDB().Model(&storehouse).Where("status = 1 and user_org_id = ?", orgid)
1133
-	offset := (page - 1) * limit
1134
-	if len(keyword) > 0 {
1135
-		var adminid string = "storehouse_code like ? or storehouse_name like ? or storehouse_address like ? "
1136
-		if len(slicekey) > 0 {
1137
-			for i := 0; i < len(slicekey); i++ {
1138
-				adminid = adminid + " or storehouse_admin_id =" + strconv.FormatInt(slicekey[i], 10)
1139
-			}
1140
-		}
1141
-		keyword = "%" + keyword + "%"
1142
-		db = db.Where(adminid, keyword, keyword, keyword)
1143
-	}
1144
-	err = db.Count(&total).Offset(offset).Order("id").Limit(limit).Find(&storehouse).Error
1145
-	return storehouse, total, err
1146
-}
1147
-
1148
-//获取当前机构所有可用的仓库名字
1149
-func GetAllStorehouseName(orgid int64) (storehouse []models.Storehouse, err error) {
1150
-	err = XTReadDB().Model(&models.Storehouse{}).Where("storehouse_status = 1 and status = 1 and user_org_id = ?", orgid).Find(&storehouse).Error
1151
-	return
1152
-}
1153
-
1154
-//根据机构id,生成一个默认仓库
1155
-func GetDefaultStorehouse(orgid int64) error {
1156
-	var code string
1157
-	for a := true; a == true; {
1158
-		code = CreateCode()
1159
-		tmp := FindStorehouseCode(orgid, code)
1160
-		//如果没有重复的编码结束循环
1161
-		if tmp == false {
1162
-			a = false
1163
-		}
1164
-	}
1165
-	createid, err := Getcreateid(orgid)
1166
-	if err != nil {
1167
-		return err
1168
-	}
1169
-	storehouse := models.Storehouse{
1170
-		StorehouseCode:    code,
1171
-		StorehouseName:    "默认仓库",
1172
-		StorehouseAddress: "",
1173
-		StorehouseStatus:  1,
1174
-		UserOrgId:         orgid,
1175
-		StorehouseAdminId: createid.Creator,
1176
-		Status:            1,
1177
-		Ctime:             time.Now().Unix(),
1178
-	}
1179
-	err = AddStroehouse(storehouse)
1180
-	return err
1181
-}
1182
-
1183
-//查找该机构id是否有仓库存在,ture存在,false不存在
1184
-func IsStorehouse(orgid int64) bool {
1185
-	var total int
1186
-	XTReadDB().Model(&models.Storehouse{}).Where("user_org_id = ?", orgid).Count(&total)
1187
-	if total > 0 {
1188
-		return true
1189
-	} else {
1190
-		return false
1191
-	}
1192
-}
1193
-
1194
-//查找该机构id是否有仓库配置存在,ture存在,false不存在
1195
-func IsStorehouseconfigXT(orgid int64, tx *gorm.DB) bool {
1196
-	var total int
1197
-	tx.Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Count(&total)
1198
-	if total > 0 {
1199
-		return true
1200
-	} else {
1201
-		return false
1202
-	}
1203
-}
1204
-
1205
-//  根据机构id查询仓库配置
1206
-//storehouse_info:耗材 自动入库 的仓库id
1207
-//storehouse_out_info:耗材 自动出库 的仓库id
1208
-//drug_storehouse_info:药品 自动入库 的仓库id
1209
-//drug_storehouse_out:药品 自动出库 的仓库id
1210
-func FindStorehouseConfig(orgid int64) (storehouse_config models.StorehouseConfig, err error) {
1211
-	err = XTReadDB().Model(&models.StorehouseConfig{}).Where("status = 1 and user_org_id = ?", orgid).Find(&storehouse_config).Error
1212
-	return
1213
-}
1214
-
1215
-//根据机构id,仓库id新建一个仓库配置
1216
-func CreateStorehouseConfig(orgid, id int64) (err error) {
1217
-	storeconfig := models.StorehouseConfig{
1218
-		UserOrgId:          orgid,
1219
-		StorehouseInfo:     id,
1220
-		StorehouseOutInfo:  id,
1221
-		DrugStorehouseInfo: id,
1222
-		DrugStorehouseOut:  id,
1223
-		Status:             1,
1224
-		Ctime:              time.Now().Unix(),
1225
-	}
1226
-	err = XTWriteDB().Create(&storeconfig).Error
1227
-	return
1228
-}
1229
-
1230
-//根据机构id,仓库id新建一个仓库配置,带事务
1231
-func CreateStorehouseConfigXT(orgid, id int64, tx *gorm.DB) (err error) {
1232
-	storeconfig := models.StorehouseConfig{
1233
-		UserOrgId:          orgid,
1234
-		StorehouseInfo:     id,
1235
-		StorehouseOutInfo:  id,
1236
-		DrugStorehouseInfo: id,
1237
-		DrugStorehouseOut:  id,
1238
-		Status:             1,
1239
-		Ctime:              time.Now().Unix(),
1240
-	}
1241
-	err = tx.Create(&storeconfig).Error
1242
-	return
1243
-}
1244
-
1245
-//更改耗材自动入库仓库
1246
-func UpdateInfo(orgid, id int64) (err error) {
1247
-	mtime := time.Now().Unix()
1248
-	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_info": id, "mtime": mtime}).Error
1249
-	return
1250
-}
1251
-
1252
-//更改耗材自动出库仓库
1253
-func UpdateOutInfo(orgid, id int64) (err error) {
1254
-	mtime := time.Now().Unix()
1255
-	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_out_info": id, "mtime": mtime}).Error
1256
-	return
1257
-}
1258
-
1259
-//更改药品自动入库仓库
1260
-func UpdateDrugInfo2(orgid, id int64) (err error) {
1261
-	mtime := time.Now().Unix()
1262
-	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_info": id, "mtime": mtime}).Error
1263
-	return
1264
-}
1265
-
1266
-//更改药品自动出库仓库
1267
-func UpdateDrugOut(orgid, id int64) (err error) {
1268
-	mtime := time.Now().Unix()
1269
-	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_out": id, "mtime": mtime}).Error
1270
-	return
1271
-}
1272
-
1273
-//根据id查询仓库名称
1274
-func FindStorehouseName(id int64) (storehouse models.Storehouse, err error) {
1275
-	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ?", id).Find(&storehouse).Error
1276
-	return
1277
-}
1278
-
1279
-//判断该仓库是否在仓库配置表中
1280
-func IsInConfig(orgid, id int64) bool {
1281
-	var total int
1282
-	XTReadDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Where(
1283
-		"storehouse_info = ? or storehouse_out_info = ? or drug_storehouse_info = ? or drug_storehouse_out = ?", id, id, id, id).Count(&total)
1284
-	if total > 0 {
1285
-		return true //存在
1286
-	} else {
1287
-		return false
1288
-	}
1289
-}
1290
-
1291
-//兼容旧数据
1292
-func Byliinit() (err error) {
1293
-	tx := XTWriteDB().Begin()
1294
-	defer func() {
1295
-		if err != nil && err.Error() != "record not found" {
1296
-			tx.Rollback()
1297
-		} else {
1298
-			tx.Commit()
1299
-		}
1300
-	}()
1301
-	err = initsgj_user_admin(tx)
1302
-	if err != nil && err.Error() != "record not found" {
1303
-		return
1304
-	}
1305
-	err = StoreReduceOrg(tx)
1306
-	if err != nil && err.Error() != "record not found" {
1307
-		return
1308
-	}
1309
-	err = StoreReduceConfig(tx)
1310
-	if err != nil && err.Error() != "record not found" {
1311
-		return
1312
-	}
1313
-	err = initxt_storehouse(tx)
1314
-	if err != nil && err.Error() != "record not found" {
1315
-		return
1316
-	}
1317
-	err = initxt_stock_flow(tx)
1318
-	if err != nil && err.Error() != "record not found" {
1319
-		return
1320
-	}
1321
-	err = initxt_drug_flow(tx)
1322
-	if err != nil && err.Error() != "record not found" {
1323
-		return
1324
-	}
1325
-	err = initdialysis_before_prepare(tx)
1326
-	if err != nil && err.Error() != "record not found" {
1327
-		return
1328
-	}
1329
-	err = initxt_automatic_reduce_detail(tx)
1330
-	if err != nil && err.Error() != "record not found" {
1331
-		return
1332
-	}
1333
-	err = initxt_drug_automatic_reduce_detail(tx)
1334
-	if err != nil && err.Error() != "record not found" {
1335
-		return
1336
-	}
1337
-	err = initxt_warehouse(tx)
1338
-	if err != nil && err.Error() != "record not found" {
1339
-		return
1340
-	}
1341
-	err = initxt_warehouse_info(tx)
1342
-	if err != nil && err.Error() != "record not found" {
1343
-		return
1344
-	}
1345
-	err = initxt_warehouse_out(tx)
1346
-	if err != nil && err.Error() != "record not found" {
1347
-		return
1348
-	}
1349
-	err = initxt_warehouse_out_info(tx)
1350
-	if err != nil && err.Error() != "record not found" {
1351
-		return
1352
-	}
1353
-	err = initxt_drug_warehouse(tx)
1354
-	if err != nil && err.Error() != "record not found" {
1355
-		return
1356
-	}
1357
-	err = initxt_drug_warehouse_info(tx)
1358
-	if err != nil && err.Error() != "record not found" {
1359
-		return
1360
-	}
1361
-	err = initxt_drug_warehouse_out(tx)
1362
-	if err != nil && err.Error() != "record not found" {
1363
-		return
1364
-	}
1365
-	err = initxt_drug_warehouse_out_info(tx)
1366
-	if err != nil && err.Error() != "record not found" {
1367
-		return
1368
-	}
1369
-	err = initxt_cancel_stock(tx)
1370
-	if err != nil && err.Error() != "record not found" {
1371
-		return
1372
-	}
1373
-	err = initxt_cancel_stock_info(tx)
1374
-	if err != nil && err.Error() != "record not found" {
1375
-		return
1376
-	}
1377
-	err = initxt_drug_cancel_stock(tx)
1378
-	if err != nil && err.Error() != "record not found" {
1379
-		return
1380
-	}
1381
-	err = initxt_drug_cancel_stock_info(tx)
1382
-	if err != nil && err.Error() != "record not found" {
1383
-		return
1384
-	}
1385
-	err = initxt_supplier_warehouse_info(tx)
1386
-	if err != nil && err.Error() != "record not found" {
1387
-		return
1388
-	}
1389
-	err = initxt_supplier_warehousing_info_order(tx)
1390
-	if err != nil && err.Error() != "record not found" {
1391
-		return
1392
-	}
1393
-	err = initxt_supplier_warehouse_out(tx)
1394
-	if err != nil && err.Error() != "record not found" {
1395
-		return
1396
-	}
1397
-	err = initxt_supplier_warehousing_out_order(tx)
1398
-	if err != nil && err.Error() != "record not found" {
1399
-		return
1400
-	}
1401
-	err = initxt_supplier_warehouse_cancel(tx)
1402
-	if err != nil && err.Error() != "record not found" {
1403
-		return
1404
-	}
1405
-	err = initxt_supplier_warehousing_cancel_order(tx)
1406
-
1407
-	return
1408
-}
1409
-
1410
-//初始化管理员名字
1411
-func initsgj_user_admin(tx *gorm.DB) (err error) {
1412
-	err = tx.Exec("update sgj_users.sgj_user_admin set name = \"超级管理员\" where name is null or name = \"\"").Error
1413
-	return
1414
-}
1415
-
1416
-//根据xt_gobal_template 获取的机构id减去仓库表存在的机构id,把结果插入到仓库表
1417
-func StoreReduceOrg(tx *gorm.DB) (err error) {
1418
-	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
1419
-		"SELECT CONCAT(\"SH-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
1420
-		"FROM" +
1421
-		"(select t1.org_id as id FROM sgj_xt.xt_gobal_template as t1 LEFT JOIN " +
1422
-		"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
1423
-	//err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
1424
-	//	"SELECT CONCAT(\"sh-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
1425
-	//	"FROM" +
1426
-	//	"(select t1.id FROM sgj_users.sgj_user_org as t1 LEFT JOIN " +
1427
-	//	"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.id = t2.i WHERE t2.i is null and t1.status != 0 and t1.import = 0)tmp").Error
1428
-	return
1429
-}
1430
-
1431
-//查找仓库表的orgid 减去仓库配置表的orgid,把结果插入到仓库配置表
1432
-func StoreReduceConfig(tx *gorm.DB) (err error) {
1433
-	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse_config(user_org_id,storehouse_info,storehouse_out_info,drug_storehouse_info,drug_storehouse_out,ctime)" +
1434
-		"SELECT tmp.user_org_id,tmp.id,tmp.id,tmp.id,tmp.id,UNIX_TIMESTAMP()" +
1435
-		"FROM(select t1.id,t1.user_org_id FROM sgj_xt.xt_storehouse as t1 LEFT JOIN " +
1436
-		"(SELECT user_org_id as i FROM sgj_xt.xt_storehouse_config) as t2 on t1.user_org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
1437
-	return
1438
-}
1439
-
1440
-//初始化 xt_storehouse 管理员的名字
1441
-func initxt_storehouse(tx *gorm.DB) (err error) {
1442
-	err = tx.Exec("UPDATE sgj_xt.xt_storehouse as t," +
1443
-		"(SELECT o.id,o.creator from sgj_users.sgj_user_org as o," +
1444
-		"(SELECT DISTINCT org_id from sgj_xt.xt_gobal_template)as t " +
1445
-		"WHERE t.org_id = o.id )tmp " +
1446
-		"SET t.storehouse_admin_id = tmp.creator,t.mtime = UNIX_TIMESTAMP()" +
1447
-		"WHERE t.status = 1 and t.user_org_id = tmp.id").Error
1448
-	return
1449
-}
1450
-
1451
-//初始化 xt_stock_flow(完成)
1452
-func initxt_stock_flow(tx *gorm.DB) (err error) {
1453
-	err = tx.Exec("UPDATE sgj_xt.xt_stock_flow as t," +
1454
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1455
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_stock_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1456
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1457
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1458
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1459
-	return
1460
-}
1461
-
1462
-//初始化 xt_drug_flow(完成)
1463
-func initxt_drug_flow(tx *gorm.DB) (err error) {
1464
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_flow as t," +
1465
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1466
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_drug_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1467
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1468
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1469
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1470
-	return
1471
-}
1472
-
1473
-//初始化 dialysis_before_prepare(完成)
1474
-func initdialysis_before_prepare(tx *gorm.DB) (err error) {
1475
-	err = tx.Exec("UPDATE sgj_xt.dialysis_before_prepare as t," +
1476
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1477
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.dialysis_before_prepare  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1478
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1479
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1480
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1481
-	return
1482
-}
1483 969
 
1484
-//初始化 xt_automatic_reduce_detail(完成)
1485
-func initxt_automatic_reduce_detail(tx *gorm.DB) (err error) {
1486
-	err = tx.Exec("UPDATE sgj_xt.xt_automatic_reduce_detail as t," +
1487
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1488
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1489
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1490
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1491
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1492
-	return
1493
-}
1494
-
1495
-//初始化 xt_drug_automatic_reduce_detail(完成)
1496
-func initxt_drug_automatic_reduce_detail(tx *gorm.DB) (err error) {
1497
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_automatic_reduce_detail as t," +
1498
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1499
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1500
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1501
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1502
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1503
-	return
1504
-}
1505
-
1506
-//初始化 xt_warehouse(完成)
1507
-func initxt_warehouse(tx *gorm.DB) (err error) {
1508
-	err = tx.Exec("UPDATE sgj_xt.xt_warehouse as t," +
1509
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1510
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1511
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1512
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1513
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1514
-	return
1515
-}
1516
-
1517
-//初始化 xt_warehouse_info(完成)
1518
-func initxt_warehouse_info(tx *gorm.DB) (err error) {
1519
-	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_info as t," +
1520
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1521
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1522
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1523
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1524
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1525
-	return
1526
-}
1527
-
1528
-//初始化 xt_warehouse_out(完成)
1529
-func initxt_warehouse_out(tx *gorm.DB) (err error) {
1530
-	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out as t," +
1531
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1532
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1533
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1534
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1535
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1536
-	return
1537
-}
1538
-
1539
-//初始化 xt_warehouse_out_info(完成)
1540
-func initxt_warehouse_out_info(tx *gorm.DB) (err error) {
1541
-	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out_info as t," +
1542
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1543
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1544
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1545
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1546
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1547
-	return
1548
-}
1549
-
1550
-//初始化 xt_drug_warehouse(完成)
1551
-func initxt_drug_warehouse(tx *gorm.DB) (err error) {
1552
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse as t," +
1553
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1554
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1555
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1556
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1557
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1558
-	return
1559
-}
1560
-
1561
-//初始化 xt_drug_warehouse_info(完成)
1562
-func initxt_drug_warehouse_info(tx *gorm.DB) (err error) {
1563
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_info as t," +
1564
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1565
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1566
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1567
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1568
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1569
-	return
1570
-}
1571
-
1572
-//初始化 xt_drug_warehouse_out(完成)
1573
-func initxt_drug_warehouse_out(tx *gorm.DB) (err error) {
1574
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out as t," +
1575
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1576
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1577
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1578
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1579
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1580
-	return
1581
-}
1582
-
1583
-//初始化 xt_drug_warehouse_out_info(完成)
1584
-func initxt_drug_warehouse_out_info(tx *gorm.DB) (err error) {
1585
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out_info as t," +
1586
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1587
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1588
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1589
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1590
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1591
-	return
1592
-}
1593
-
1594
-//初始化 xt_cancel_stock(完成)
1595
-func initxt_cancel_stock(tx *gorm.DB) (err error) {
1596
-	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock as t," +
1597
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1598
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1599
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1600
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1601
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1602
-	return
1603
-}
1604
-
1605
-//初始化 xt_cancel_stock_info(完成)
1606
-func initxt_cancel_stock_info(tx *gorm.DB) (err error) {
1607
-	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock_info as t," +
1608
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1609
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1610
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1611
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1612
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1613
-	return
1614
-}
1615
-
1616
-//初始化 xt_drug_cancel_stock(完成)
1617
-func initxt_drug_cancel_stock(tx *gorm.DB) (err error) {
1618
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
1619
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1620
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1621
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1622
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1623
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1624
-	return
1625
-}
1626
-
1627
-//初始化 xt_drug_cancel_stock_info(完成)
1628
-func initxt_drug_cancel_stock_info(tx *gorm.DB) (err error) {
1629
-	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock_info as t," +
1630
-		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1631
-		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1632
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1633
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1634
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1635
-	return
1636
-}
1637
-
1638
-//初始化 xt_supplier_warehouse_info(完成)
1639
-func initxt_supplier_warehouse_info(tx *gorm.DB) (err error) {
1640
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_info as t," +
1641
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1642
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1643
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1644
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1645
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1646
-	return
1647
-}
1648
-
1649
-//初始化 xt_supplier_warehousing_info_order(完成)
1650
-func initxt_supplier_warehousing_info_order(tx *gorm.DB) (err error) {
1651
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_info_order as t," +
1652
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1653
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_info_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1654
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1655
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1656
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1657
-	return
1658
-}
1659
-
1660
-//初始化 xt_supplier_warehouse_out(完成)
1661
-func initxt_supplier_warehouse_out(tx *gorm.DB) (err error) {
1662
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_out as t," +
1663
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1664
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1665
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1666
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1667
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1668
-	return
1669
-}
1670
-
1671
-//初始化 xt_supplier_warehousing_out_order(完成)
1672
-func initxt_supplier_warehousing_out_order(tx *gorm.DB) (err error) {
1673
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_out_order as t," +
1674
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1675
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_out_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1676
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1677
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1678
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1679
-	return
1680
-}
1681
-
1682
-//初始化 xt_supplier_warehouse_cancel(完成)
1683
-func initxt_supplier_warehouse_cancel(tx *gorm.DB) (err error) {
1684
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_cancel as t," +
1685
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1686
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_cancel  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1687
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1688
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1689
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1690
-	return
1691
-}
1692
-
1693
-//初始化 xt_supplier_warehousing_cancel_order(完成)
1694
-func initxt_supplier_warehousing_cancel_order(tx *gorm.DB) (err error) {
1695
-	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_cancel_order as t," +
1696
-		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1697
-		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_cancel_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1698
-		"WHERE t1.user_org_id = t2.orgid)tmp " +
1699
-		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1700
-		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1701
-	return
1702
-}
1703
-
1704
-//查询机构创建者的id
1705
-func Getcreateid(orgid int64) (createid models.UserOrg, err error) {
1706
-	err = XTReadDB().Select("id,creator").Where("id = ? and status = 1", orgid).Find(&createid).Error
1707
-	return
1708
-}
1709
-
1710
-//根据机构id查询拥有仓库管理权限的角色
1711
-func FindRoles(orgid int64) map[string]int {
1712
-	role := []models.RolePurviews{}
1713
-	roles := make(map[string]int)
1714
-	XTReadDB().Select("role_id").Where("purview_ids like \"%299%\" and org_id = ? and status = 1", orgid).Find(&role)
1715
-	for i := 0; i < len(role); i++ {
1716
-		roles[strconv.FormatInt(role[i].RoleId, 10)] = i
1717
-	}
1718
-	return roles
1719
-}
1720
-
1721
-//判断两个切片中的元素是否有重复的,true有重复的元素,false无相同元素
1722
-func IsIdentical(str1 []string, str2 []string) (t bool) {
1723
-	t = false
1724
-	if len(str1) == 0 || len(str2) == 0 {
1725
-		return
1726
-	}
1727
-	map1, map2 := make(map[string]int), make(map[string]int)
1728
-	for i := 0; i < len(str1); i++ {
1729
-		map1[str1[i]] = i
1730
-	}
1731
-	for i := 0; i < len(str2); i++ {
1732
-		map2[str2[i]] = i
1733
-	}
1734
-	for k, _ := range map1 {
1735
-		if _, ok := map2[k]; ok {
1736
-			t = true
1737
-		}
1738
-	}
1739
-	return
1740 970
 func ModifyWarehouseOut(id int64, orgid int64, good_id int64) error {
1741 971
 	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
1742 972