Ver código fonte

Merge branch 'master' of http://git.shengws.com/csx/gdyb

test_user 1 mês atrás
pai
commit
d5d9725a4d

+ 172 - 1
controllers/sg/his_api_controller.go Ver arquivo

@@ -3176,6 +3176,175 @@ func GetNowTime() (int64, int64) {
3176 3176
 //		})
3177 3177
 //	}
3178 3178
 //}
3179
+func (c *HisApiController) ChangeDrugfour() {
3180
+	patient_id, _ := c.GetInt64("patient_id")
3181
+	admin_user_id, _ := c.GetInt64("admin_user_id")
3182
+	//id_arr := strings.Split(ids, ",")
3183
+	times := c.GetString("time", "")
3184
+	timeLayout := "2006-01-02"
3185
+	loc, _ := time.LoadLocation("Local")
3186
+	var stime, etime int64
3187
+	if times == "" {
3188
+		stime, etime = GetNowTime()
3189
+	} else {
3190
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
3191
+		stime = stmp.Unix()
3192
+		etime = stime + 86399
3193
+	}
3194
+	advicelist, _ := service.FindeHisAdviceDocAdvice(c.GetAdminUserInfo().CurrentOrgId, patient_id, stime, etime)
3195
+	var flows []*models.DrugFlow
3196
+	for _, item := range advicelist {
3197
+		flow, _ := service.GetNewDrugFlowInfoByPatient(patient_id, item.DrugId, times, c.GetAdminUserInfo().CurrentOrgId)
3198
+		flows = append(flows, flow...)
3199
+	}
3200
+	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
3201
+	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
3202
+	var err []string
3203
+
3204
+	for _, item := range flows {
3205
+		var res3 ResultSix
3206
+		if item.ConsumableType == 3 { //3为自动出库 7为自动退库
3207
+			prescription := service.GetHisPrescriptionByID(item.HisDoctorAdviceInfo.PrescriptionId)
3208
+			if prescription.OrderStatus == 2 {
3209
+				//已经结算
3210
+				//判断是否已经销售
3211
+				if item.IsSale == 1 { //是否已经销售,1是   0否
3212
+					//是否已经变更 1是  0否
3213
+					if item.IsChange == 0 { //没变更,进行变更操作
3214
+						bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
3215
+
3216
+						result, result2 := ChangeStock(item.Count, item, miConfig, "102", roles, bg_number)
3217
+						saveLog(result, result2, "3502", "自动出库,已经销售,未变更3502")
3218
+						var respJSON3 map[string]interface{}
3219
+						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
3220
+							utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
3221
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3222
+							return
3223
+						}
3224
+						userJSONBytes3, _ := json.Marshal(respJSON3)
3225
+						if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
3226
+							utils.ErrorLog("解析失败:%v", err)
3227
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3228
+							return
3229
+						}
3230
+						if res3.Infcode == 0 {
3231
+							item.IsChange = 1
3232
+							item.BgBchno = bg_number
3233
+							service.SaveDF2(item)
3234
+						} else {
3235
+
3236
+							err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
3237
+						}
3238
+					}
3239
+				} else { //没销售,
3240
+					var res FJ3507Result
3241
+					var res3507for10188 FJ3507ResultFor10188
3242
+					number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3505"
3243
+
3244
+					//进行商品销售接口
3245
+					result3, result4 := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles, number)
3246
+					saveLog(result3, result4, "3505", "自动出库,未销售进行销售行为,3505")
3247
+					var respJSON3 map[string]interface{}
3248
+					if err := json.Unmarshal([]byte(string(result3)), &respJSON3); err != nil {
3249
+						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
3250
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3251
+						return
3252
+					}
3253
+					userJSONBytes3, _ := json.Marshal(respJSON3)
3254
+					if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
3255
+						if err := json.Unmarshal(userJSONBytes3, &res3507for10188); err != nil {
3256
+							utils.ErrorLog("解析失败:%v", err)
3257
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3258
+							return
3259
+						}
3260
+						//if res3507for10188.Infcode
3261
+						res.InfRefmsgid = res3507for10188.InfRefmsgid
3262
+						//res.Output = resSix10265.Output
3263
+						res.ErrMsg = res3507for10188.ErrMsg
3264
+						res.Cainfo = res3507for10188.Cainfo
3265
+						res.WarnMsg = res3507for10188.WarnMsg
3266
+						infocode, _ := strconv.ParseInt(res3507for10188.Infcode, 10, 64)
3267
+						res.Infcode = infocode
3268
+					} else {
3269
+						if err := json.Unmarshal(userJSONBytes3, &res); err != nil {
3270
+							utils.ErrorLog("解析失败:%v", err)
3271
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3272
+							return
3273
+						}
3274
+
3275
+					}
3276
+					if res.Infcode == 0 {
3277
+						item.IsSale = 1
3278
+						item.Bchno = number
3279
+						item.SaleDate = time.Now().Format("2006-01-02")
3280
+
3281
+						err5 := service.SaveDF(item)
3282
+						if err5 == nil {
3283
+							if item.IsChange == 0 { //没变更,进行变更操作
3284
+								bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
3285
+
3286
+								result, result2 := ChangeStock(item.Count, item, miConfig, "102", roles, bg_number)
3287
+								saveLog(result, result2, "3502", "自动出库,没销售,未变更3502")
3288
+
3289
+								var respJSON3 map[string]interface{}
3290
+								if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
3291
+									utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
3292
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3293
+									return
3294
+								}
3295
+								if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
3296
+									if err := json.Unmarshal(userJSONBytes3, &res3507for10188); err != nil {
3297
+										utils.ErrorLog("解析失败:%v", err)
3298
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3299
+										return
3300
+									}
3301
+									//if res3507for10188.Infcode
3302
+									res3.InfRefmsgid = res3507for10188.InfRefmsgid
3303
+									//res.Output = resSix10265.Output
3304
+									res3.ErrMsg = res3507for10188.ErrMsg
3305
+									res3.Cainfo = res3507for10188.Cainfo
3306
+									res3.WarnMsg = res3507for10188.WarnMsg
3307
+									infocode, _ := strconv.ParseInt(res3507for10188.Infcode, 10, 64)
3308
+									res3.Infcode = infocode
3309
+								} else {
3310
+									if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
3311
+										utils.ErrorLog("解析失败:%v", err)
3312
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3313
+										return
3314
+									}
3315
+								}
3316
+								if res3.Infcode == 0 {
3317
+									item.IsChange = 1
3318
+									item.BgBchno = bg_number
3319
+									service.SaveDF2(item)
3320
+								} else {
3321
+
3322
+									err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
3323
+								}
3324
+							}
3325
+						}
3326
+					} else {
3327
+
3328
+						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售失败:"+res.ErrMsg)
3329
+					}
3330
+				}
3331
+
3332
+			} else { //还没结,提示用户去结算,并药品追溯上传
3333
+				err = append(err, item.HisDoctorAdviceInfo.AdviceName+"还没结算,请结算后,在药品追溯页面上传")
3334
+			}
3335
+		}
3336
+	}
3337
+	if len(err) == 0 {
3338
+		c.ServeSuccessJSON(map[string]interface{}{
3339
+			"msg": "销售变更成功",
3340
+		})
3341
+	} else {
3342
+		c.ServeSuccessJSON(map[string]interface{}{
3343
+			"failed_code": -10,
3344
+			"msg":         err,
3345
+		})
3346
+	}
3347
+}
3179 3348
 
3180 3349
 func (c *HisApiController) ChangeDrug() {
3181 3350
 	ids := c.GetString("ids")
@@ -4445,7 +4614,9 @@ func (c *HisApiController) ChangeDrugTen() {
4445 4614
 
4446 4615
 	//ids := c.GetString("ids")
4447 4616
 	//id_arr := strings.Split(ids, ",")
4448
-	flows, _ := service.GetNewDrugFlowInforTen()
4617
+	now := time.Now()
4618
+	timestamp := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
4619
+	flows, _ := service.GetNewDrugFlowInforTen(timestamp)
4449 4620
 	admin_user_id, _ := c.GetInt64("admin_user_id")
4450 4621
 	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
4451 4622
 	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)

+ 7 - 10
models/new_stock_models.go Ver arquivo

@@ -261,13 +261,12 @@ type NewDrugWarehouseInfo struct {
261 261
 	SecondWarehouseInfoId     int64  `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
262 262
 	IsCheck                   int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
263 263
 
264
-	IsPc    int64  `gorm:"column:is_pc" json:"is_pc" form:"is_pc"`
265
-	IsBg    int64  `gorm:"column:is_bg" json:"is_bg" form:"is_bg"`
266
-	Bchno   string `gorm:"column:bchno" json:"bchno" form:"bchno"`
267
-	PcDate  int64 `gorm:"column:pc_date" json:"pc_date" form:"pc_date"`
268
-	BgBchno string `gorm:"column:bg_bchno" json:"bg_bchno" form:"bg_bchno"`
264
+	IsPc     int64  `gorm:"column:is_pc" json:"is_pc" form:"is_pc"`
265
+	IsBg     int64  `gorm:"column:is_bg" json:"is_bg" form:"is_bg"`
266
+	Bchno    string `gorm:"column:bchno" json:"bchno" form:"bchno"`
267
+	PcDate   int64  `gorm:"column:pc_date" json:"pc_date" form:"pc_date"`
268
+	BgBchno  string `gorm:"column:bg_bchno" json:"bg_bchno" form:"bg_bchno"`
269 269
 	DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
270
-
271 270
 }
272 271
 
273 272
 func (NewDrugWarehouseInfo) TableName() string {
@@ -424,7 +423,7 @@ type DrugFlow struct {
424 423
 	LastStockMaxNumber        int64                `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
425 424
 	LastStockMinNumber        int64                `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
426 425
 	AdviceId                  int64                `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
427
-	HisDoctorAdviceInfo       HisDoctorAdviceInfo  `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
426
+	HisDoctorAdviceInfo       HisDoctorAdviceInfo  `gorm:"ForeignKey:PatientID,RecordDate;AssociationForeignKey,DrugId:PatientID,SystemTime,DrugId" json:"advice"`
428 427
 	SupplyWarehouseId         int64                `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
429 428
 	SupplyCancelOutId         int64                `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
430 429
 	SupplyWarehouseDetailInfo int64                `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
@@ -445,9 +444,7 @@ type DrugFlow struct {
445 444
 	Bchno                     string               `gorm:"column:bchno" json:"bchno" form:"bchno"`
446 445
 	SaleDate                  string               `gorm:"column:sale_date" json:"sale_date" form:"sale_date"`
447 446
 	BgBchno                   string               `gorm:"column:bg_bchno" json:"bg_bchno" form:"bg_bchno"`
448
-	DrugCode 	string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
449
-
450
-
447
+	DrugCode                  string               `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
451 448
 }
452 449
 
453 450
 func (DrugFlow) TableName() string {

+ 4 - 4
service/his_service.go Ver arquivo

@@ -1739,8 +1739,8 @@ func GetNewDrugFlowInfo(org_id int64, id_arr []string) (flows []*models.DrugFlow
1739 1739
 	return
1740 1740
 }
1741 1741
 
1742
-func GetNewDrugFlowInfoByPatient(patient_id int64, advice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
1743
-	err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and advice_id = ? and system_time = ?", org_id, patient_id, advice_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1742
+func GetNewDrugFlowInfoByPatient(patient_id int64, advdrug_idice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
1743
+	err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and drug_id = ? and system_time = ?", org_id, patient_id, drug_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1744 1744
 		return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
1745 1745
 	}).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
1746 1746
 	return
@@ -1767,8 +1767,8 @@ func GetNewDrugFlowInfothree() (flows []*models.DrugFlow, err error) {
1767 1767
 	return
1768 1768
 }
1769 1769
 
1770
-func GetNewDrugFlowInforTen() (flows []*models.DrugFlow, err error) {
1771
-	err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10318 and status = 1 and drug_code != '' and consumable_type = 3 and is_sale = 0").Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1770
+func GetNewDrugFlowInforTen(system_time int64) (flows []*models.DrugFlow, err error) {
1771
+	err = readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info info on info.patient_id = xt_drug_flow.patient_id and info.drug_id = xt_drug_flow.drug_id and info.record_date = xt_drug_flow.system_time").Where("user_org_id = 10318 and status = 1 and consumable_type = 3 and is_sale = 0 and system_time = ?", system_time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1772 1772
 		return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
1773 1773
 	}).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
1774 1774
 	return