auto_create_week_schedules_service.go 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. package service
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/models"
  7. "gdyb/utils"
  8. "github.com/astaxie/beego"
  9. "github.com/robfig/cron"
  10. "io/ioutil"
  11. "math/rand"
  12. "net/http"
  13. "strconv"
  14. "time"
  15. )
  16. type ResultSix struct {
  17. Cainfo interface{} `json:"cainfo"`
  18. ErrMsg string `json:"err_msg"`
  19. InfRefmsgid string `json:"inf_refmsgid"`
  20. Infcode int64 `json:"infcode"`
  21. Output struct {
  22. } `json:"output"`
  23. RefmsgTime string `json:"refmsg_time"`
  24. RespondTime string `json:"respond_time"`
  25. Signtype interface{} `json:"signtype"`
  26. WarnMsg interface{} `json:"warn_msg"`
  27. }
  28. type ResultSix10265 struct {
  29. Cainfo interface{} `json:"cainfo"`
  30. ErrMsg string `json:"err_msg"`
  31. InfRefmsgid string `json:"inf_refmsgid"`
  32. Infcode string `json:"infcode"`
  33. Output struct {
  34. } `json:"output"`
  35. RefmsgTime string `json:"refmsg_time"`
  36. RespondTime string `json:"respond_time"`
  37. Signtype interface{} `json:"signtype"`
  38. WarnMsg interface{} `json:"warn_msg"`
  39. }
  40. // cron表达式 https://www.cnblogs.com/zuxingyu/p/6023919.html
  41. var createWeekSchedulesCronJob *cron.Cron
  42. func init() {
  43. utils.InfoLog("开启自动排班定时任务")
  44. createWeekSchedulesCronJob = cron.New()
  45. spec := "0 0 18 * * ?" // 每天6点上传当天数据
  46. //spec := "0 */1 * * * ?"
  47. createWeekSchedulesCronJob.AddFunc(spec, func() {
  48. AutoCreateStock()
  49. })
  50. }
  51. func BeginAutoCreateWeekSchedulesJob() {
  52. createWeekSchedulesCronJob.Start()
  53. }
  54. func AutoCreateStock() {
  55. org_id, _ := beego.AppConfig.Int64("org_id")
  56. var NewWarehousing []*models.NewWarehousingInfo
  57. var NewWarehouseOut []*models.NewWarehouseOutInfo
  58. var NewCancelStock []*models.NewCancelStockInfo
  59. var NewDrugWarehouse []*models.NewDrugWarehouseInfo
  60. var NewDrugWarehouseOut []*models.NewDrugWarehouseOutInfo
  61. var NewDrugCancelStock []*models.NewDrugCancelStockInfo
  62. var XtDrugInventorys []*models.XtDrugInventory
  63. readDb.Model(&models.XtDrugInventory{}).Where("user_org_id = ? and status = 1 and is_upload <> 1", org_id).Preload("BaseDrugLib", "status = 1").Find(&XtDrugInventorys)
  64. //readDb.Model(&models.NewWarehousingInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1", org_id).Preload("GoodInfo", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).First(&NewWarehousing)
  65. //readDb.Model(&models.NewWarehouseOutInfo{}).Where("user_org_id = ? and status = 1 and is_upload <> 1", org_id).Preload("GoodInfo", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewWarehouseOut)
  66. //readDb.Model(&models.NewCancelStockInfo{}).Where("user_org_id = ? and status = 1 and is_upload <> 1", org_id).Preload("GoodInfo", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewCancelStock)
  67. //readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1 AND id >= 4778", org_id).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugWarehouse)
  68. //readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1 AND id >= 360136", org_id).Preload("NewDrugWarehouseInfo","status = 1").Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugWarehouseOut)
  69. //readDb.Model(&models.NewDrugCancelStockInfo{}).Where("user_org_id = ? and status = 1 and is_upload <> 1 AND id >= 4778", org_id).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugCancelStock)
  70. //readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1 AND id >= 5720", org_id).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugWarehouse)
  71. //readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1 AND id >= 366003", org_id).Preload("NewDrugWarehouseInfo","status = 1").Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugWarehouseOut)
  72. //readDb.Model(&models.NewDrugCancelStockInfo{}).Where("org_id = ? and status = 1 and is_upload <> 1 ", org_id).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewDrugCancelStock)
  73. for _, item := range XtDrugInventorys {
  74. res := Post3501ForDrug(org_id, item)
  75. if res.Infcode == 0 {
  76. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  77. "is_upload": 1,
  78. })
  79. } else {
  80. continue
  81. }
  82. }
  83. for _, item := range NewWarehousing {
  84. res := Post3503ForGoodInfo(org_id, item)
  85. if res.Infcode == 0 {
  86. writeDb.Model(&models.NewWarehousingInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  87. "is_upload": 1,
  88. })
  89. } else {
  90. continue
  91. }
  92. }
  93. for _, item := range NewWarehouseOut {
  94. res := Post3505ForGoodInfo(org_id, item)
  95. if res.Infcode == 0 {
  96. writeDb.Model(&models.NewWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  97. "is_upload": 1,
  98. })
  99. } else {
  100. continue
  101. }
  102. }
  103. for _, item := range NewCancelStock {
  104. res := Post3506ForGoodInfo(org_id, item)
  105. if res.Infcode == 0 {
  106. writeDb.Model(&models.NewCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  107. "is_upload": 1,
  108. })
  109. } else {
  110. continue
  111. }
  112. }
  113. for _, item := range NewDrugWarehouse {
  114. res := Post3503ForDrug(org_id, item)
  115. if res.Infcode == 0 {
  116. writeDb.Model(&models.NewDrugWarehouseInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  117. "is_upload": 1,
  118. })
  119. } else {
  120. continue
  121. }
  122. }
  123. for _, item := range NewDrugWarehouseOut {
  124. res := Post3505ForDrug(org_id, item)
  125. if res.Infcode == 0 {
  126. writeDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  127. "is_upload": 1,
  128. })
  129. }
  130. }
  131. for _, item := range NewDrugCancelStock {
  132. res := Post3506ForDrug(org_id, item)
  133. if res.Infcode == 0 {
  134. writeDb.Model(&models.NewDrugCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  135. "is_upload": 1,
  136. })
  137. } else {
  138. continue
  139. }
  140. }
  141. }
  142. func Post3501ForGoodInfo(org_id int64, infos *models.XtDrugInventory) ResultSix {
  143. var res ResultSix
  144. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  145. data := make(map[string]interface{})
  146. var struct3501s []models.Struct3501
  147. var struct3501 models.Struct3501
  148. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  149. struct3501.FixmedinsHilistId = miConfig.Code
  150. struct3501.FixmedinsHilistName = miConfig.OrgName
  151. struct3501.FixmedinsBchno = infos.BatchNumber
  152. struct3501.RxFlag = "0"
  153. struct3501.Invdate = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  154. struct3501.OrgName = miConfig.OrgName
  155. struct3501.AccessKey = miConfig.AccessKey
  156. struct3501.RequestUrl = miConfig.Url
  157. struct3501.SecretKey = miConfig.SecretKey
  158. struct3501.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  159. struct3501.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  160. struct3501.InvCnt = strconv.FormatInt(infos.Count, 10)
  161. struct3501.ManuDate = time.Unix(infos.DrugWarehouseInfo.ProductDate, 0).Format("2006-01-02 15:04:05")
  162. struct3501.ExpyEnd = time.Unix(infos.DrugWarehouseInfo.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  163. struct3501s = append(struct3501s, struct3501)
  164. data["struct_3501s"] = struct3501s[0]
  165. client := &http.Client{}
  166. bytesData, _ := json.Marshal(data)
  167. var req *http.Request
  168. if miConfig.MdtrtareaAdmvs == "320921" {
  169. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  170. } else {
  171. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  172. }
  173. resp, _ := client.Do(req)
  174. defer resp.Body.Close()
  175. body, ioErr := ioutil.ReadAll(resp.Body)
  176. if ioErr != nil {
  177. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  178. res.Infcode = -1
  179. return res
  180. }
  181. var respJSON map[string]interface{}
  182. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  183. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  184. res.Infcode = -1
  185. return res
  186. }
  187. var resSix10265 ResultSix10265 //1101结果
  188. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  189. result, _ := json.Marshal(respJSON)
  190. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  191. utils.ErrorLog("解析失败:%v", err)
  192. res.Infcode = -1
  193. return res
  194. }
  195. res.InfRefmsgid = resSix10265.InfRefmsgid
  196. res.Output = resSix10265.Output
  197. res.ErrMsg = resSix10265.ErrMsg
  198. res.Cainfo = resSix10265.Cainfo
  199. res.WarnMsg = resSix10265.WarnMsg
  200. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  201. res.Infcode = infocode
  202. return res
  203. }
  204. func Post3501ForDrug(org_id int64, infos *models.XtDrugInventory) ResultSix {
  205. var res ResultSix
  206. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  207. data := make(map[string]interface{})
  208. var struct3501s []models.Struct3501
  209. var struct3501 models.Struct3501
  210. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  211. struct3501.FixmedinsHilistId = miConfig.Code
  212. struct3501.FixmedinsHilistName = miConfig.OrgName
  213. struct3501.FixmedinsBchno = infos.BatchNumber
  214. struct3501.RxFlag = "0"
  215. struct3501.Invdate = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  216. struct3501.OrgName = miConfig.OrgName
  217. struct3501.AccessKey = miConfig.AccessKey
  218. struct3501.RequestUrl = miConfig.Url
  219. struct3501.SecretKey = miConfig.SecretKey
  220. struct3501.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  221. struct3501.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  222. struct3501.InvCnt = strconv.FormatInt(infos.Count, 10)
  223. struct3501.ManuDate = time.Unix(infos.DrugWarehouseInfo.ProductDate, 0).Format("2006-01-02 15:04:05")
  224. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  225. struct3501s = append(struct3501s, struct3501)
  226. data["struct_3501s"] = struct3501s[0]
  227. client := &http.Client{}
  228. bytesData, _ := json.Marshal(data)
  229. var req *http.Request
  230. if miConfig.MdtrtareaAdmvs == "320921" {
  231. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  232. } else {
  233. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  234. }
  235. resp, _ := client.Do(req)
  236. defer resp.Body.Close()
  237. body, ioErr := ioutil.ReadAll(resp.Body)
  238. if ioErr != nil {
  239. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  240. res.Infcode = -1
  241. return res
  242. }
  243. var respJSON map[string]interface{}
  244. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  245. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  246. res.Infcode = -1
  247. return res
  248. }
  249. var resSix10265 ResultSix10265 //1101结果
  250. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  251. result, _ := json.Marshal(respJSON)
  252. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  253. utils.ErrorLog("解析失败:%v", err)
  254. res.Infcode = -1
  255. return res
  256. }
  257. res.InfRefmsgid = resSix10265.InfRefmsgid
  258. res.Output = resSix10265.Output
  259. res.ErrMsg = resSix10265.ErrMsg
  260. res.Cainfo = resSix10265.Cainfo
  261. res.WarnMsg = resSix10265.WarnMsg
  262. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  263. res.Infcode = infocode
  264. return res
  265. }
  266. //采购
  267. func Post3503ForGoodInfo(org_id int64, infos *models.NewWarehousingInfo) ResultSix {
  268. fmt.Println(&infos)
  269. var res ResultSix
  270. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  271. data := make(map[string]interface{})
  272. var struct3503s []models.Struct3503
  273. var struct3503 models.Struct3503
  274. struct3503.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  275. struct3503.FixmedinsHilistId = miConfig.Code
  276. struct3503.FixmedinsCode = miConfig.Code
  277. struct3503.FixmedinsHilistName = miConfig.OrgName
  278. struct3503.FixmedinsBchno = infos.Number
  279. var d models.Dealers
  280. readDb.Model(&models.Dealers{}).Where("id = ?", infos.Dealer).First(&d)
  281. if d.ID == 0 {
  282. struct3503.SplerName = infos.Manufacturers.ManufacturerName
  283. } else {
  284. struct3503.SplerName = d.DealerName
  285. }
  286. struct3503.ManuLotnum = infos.Number
  287. struct3503.ProdentpName = infos.Manufacturers.ManufacturerName
  288. struct3503.Aprvno = infos.GoodInfo.Number
  289. struct3503.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02")
  290. struct3503.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02")
  291. struct3503.PurcRetnCnt = strconv.FormatInt(infos.TotalCount, 10)
  292. struct3503.RxFlag = "0"
  293. struct3503.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02")
  294. if org_id == 10217 {
  295. struct3503.PurcRetnOpterName = "施实芹"
  296. } else {
  297. struct3503.PurcRetnOpterName = ""
  298. }
  299. struct3503.OrgName = miConfig.OrgName
  300. struct3503.AccessKey = miConfig.AccessKey
  301. struct3503.RequestUrl = miConfig.Url
  302. struct3503.SecretKey = miConfig.SecretKey
  303. struct3503.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  304. struct3503.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  305. struct3503.Memo = ""
  306. struct3503s = append(struct3503s, struct3503)
  307. data["struct_3503s"] = struct3503s[0]
  308. client := &http.Client{}
  309. bytesData, _ := json.Marshal(data)
  310. fmt.Println(string(bytesData))
  311. var req *http.Request
  312. if miConfig.MdtrtareaAdmvs == "320921" {
  313. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  314. } else {
  315. fmt.Println("111111")
  316. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  317. }
  318. resp, _ := client.Do(req)
  319. defer resp.Body.Close()
  320. body, ioErr := ioutil.ReadAll(resp.Body)
  321. if ioErr != nil {
  322. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  323. res.Infcode = -1
  324. return res
  325. }
  326. var respJSON map[string]interface{}
  327. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  328. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  329. res.Infcode = -1
  330. return res
  331. }
  332. var resSix10265 ResultSix10265 //1101结果
  333. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  334. result, _ := json.Marshal(respJSON)
  335. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  336. utils.ErrorLog("解析失败:%v", err)
  337. res.Infcode = -1
  338. return res
  339. }
  340. res.InfRefmsgid = resSix10265.InfRefmsgid
  341. res.Output = resSix10265.Output
  342. res.ErrMsg = resSix10265.ErrMsg
  343. res.Cainfo = resSix10265.Cainfo
  344. res.WarnMsg = resSix10265.WarnMsg
  345. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  346. res.Infcode = infocode
  347. return res
  348. }
  349. func Post3503ForDrug(org_id int64, infos *models.NewDrugWarehouseInfo) ResultSix {
  350. var res ResultSix
  351. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  352. data := make(map[string]interface{})
  353. var struct3503s []models.Struct3503
  354. var struct3503 models.Struct3503
  355. struct3503.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  356. struct3503.FixmedinsHilistId = miConfig.Code
  357. struct3503.FixmedinsHilistName = miConfig.OrgName
  358. struct3503.FixmedinsBchno = infos.BatchNumber
  359. var d models.Dealers
  360. readDb.Model(&models.Dealers{}).Where("id = ?", infos.Dealer).First(&d)
  361. struct3503.SplerName = d.DealerName
  362. struct3503.ManuLotnum = infos.BatchNumber
  363. struct3503.ProdentpName = infos.Manufacturers.ManufacturerName
  364. struct3503.Aprvno = infos.BaseDrugLib.Number
  365. struct3503.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  366. struct3503.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  367. struct3503.PurcRetnCnt = strconv.FormatInt(infos.WarehousingCount, 10)
  368. struct3503.RxFlag = "0"
  369. struct3503.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  370. if org_id == 10217 {
  371. struct3503.PurcRetnOpterName = "施实芹"
  372. } else {
  373. struct3503.PurcRetnOpterName = "顾林玲"
  374. }
  375. struct3503.OrgName = miConfig.OrgName
  376. struct3503.AccessKey = miConfig.AccessKey
  377. struct3503.RequestUrl = miConfig.Url
  378. struct3503.SecretKey = miConfig.SecretKey
  379. struct3503.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  380. struct3503.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  381. struct3503.Memo = ""
  382. struct3503s = append(struct3503s, struct3503)
  383. data["struct_3503s"] = struct3503s[0]
  384. client := &http.Client{}
  385. bytesData, _ := json.Marshal(data)
  386. var req *http.Request
  387. if miConfig.MdtrtareaAdmvs == "320921" {
  388. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  389. } else {
  390. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  391. }
  392. resp, _ := client.Do(req)
  393. defer resp.Body.Close()
  394. body, ioErr := ioutil.ReadAll(resp.Body)
  395. if ioErr != nil {
  396. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  397. res.Infcode = -1
  398. return res
  399. }
  400. var respJSON map[string]interface{}
  401. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  402. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  403. res.Infcode = -1
  404. return res
  405. }
  406. var resSix10265 ResultSix10265 //1101结果
  407. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  408. result, _ := json.Marshal(respJSON)
  409. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  410. utils.ErrorLog("解析失败:%v", err)
  411. res.Infcode = -1
  412. return res
  413. }
  414. res.InfRefmsgid = resSix10265.InfRefmsgid
  415. res.Output = resSix10265.Output
  416. res.ErrMsg = resSix10265.ErrMsg
  417. res.Cainfo = resSix10265.Cainfo
  418. res.WarnMsg = resSix10265.WarnMsg
  419. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  420. res.Infcode = infocode
  421. return res
  422. }
  423. //销售
  424. func Post3505ForGoodInfo(org_id int64, infos *models.NewWarehouseOutInfo) ResultSix {
  425. var res ResultSix
  426. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  427. data := make(map[string]interface{})
  428. var struct3501s []models.Struct3505
  429. var struct3501 models.Struct3505
  430. struct3501.OrgName = miConfig.OrgName
  431. struct3501.AccessKey = miConfig.AccessKey
  432. struct3501.RequestUrl = miConfig.Url
  433. struct3501.SecretKey = miConfig.SecretKey
  434. struct3501.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  435. struct3501.FixmedinsHilistId = miConfig.Code
  436. struct3501.FixmedinsHilistName = miConfig.OrgName
  437. struct3501.FixmedinsBchno = infos.Number
  438. if org_id == 10188 {
  439. struct3501.PrscDrName = "王曙光"
  440. struct3501.PharName = "王曙光"
  441. struct3501.PharPracCertNo = ""
  442. } else if org_id == 10217 {
  443. struct3501.PrscDrName = "王云刚"
  444. struct3501.PharName = "王云刚"
  445. struct3501.PharPracCertNo = ""
  446. }
  447. timestamp := time.Now().Unix()
  448. tempTime := time.Unix(timestamp, 0)
  449. timeFormat := tempTime.Format("20060102150405")
  450. chrgBchno := rand.Intn(100000) + 10000
  451. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  452. struct3501.MdtrtSn = ipt_otp_no
  453. struct3501.ManuLotnum = infos.Number
  454. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  455. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  456. struct3501.RxFlag = "0"
  457. struct3501.TrdnFlag = "1"
  458. struct3501.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  459. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  460. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  461. struct3501.SelRetnOpterName = "仓管员"
  462. struct3501s = append(struct3501s, struct3501)
  463. data["struct_3501s"] = struct3501s
  464. client := &http.Client{}
  465. bytesData, _ := json.Marshal(data)
  466. var req *http.Request
  467. if miConfig.MdtrtareaAdmvs == "320921" {
  468. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  469. } else {
  470. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  471. }
  472. resp, _ := client.Do(req)
  473. defer resp.Body.Close()
  474. body, ioErr := ioutil.ReadAll(resp.Body)
  475. if ioErr != nil {
  476. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  477. res.Infcode = -1
  478. return res
  479. }
  480. var respJSON map[string]interface{}
  481. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  482. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  483. res.Infcode = -1
  484. return res
  485. }
  486. var resSix10265 ResultSix10265 //1101结果
  487. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  488. result, _ := json.Marshal(respJSON)
  489. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  490. utils.ErrorLog("解析失败:%v", err)
  491. res.Infcode = -1
  492. return res
  493. }
  494. res.InfRefmsgid = resSix10265.InfRefmsgid
  495. res.Output = resSix10265.Output
  496. res.ErrMsg = resSix10265.ErrMsg
  497. res.Cainfo = resSix10265.Cainfo
  498. res.WarnMsg = resSix10265.WarnMsg
  499. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  500. res.Infcode = infocode
  501. return res
  502. }
  503. func Post3505ForDrug(org_id int64, infos *models.NewDrugWarehouseOutInfo) ResultSix {
  504. var res ResultSix
  505. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  506. data := make(map[string]interface{})
  507. var struct3505s []models.Struct3505
  508. var struct3505 models.Struct3505
  509. struct3505.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  510. struct3505.FixmedinsHilistId = miConfig.Code
  511. struct3505.FixmedinsHilistName = miConfig.OrgName
  512. struct3505.FixmedinsBchno = infos.NewDrugWarehouseInfo.BatchNumber
  513. struct3505.FixmedinsCode = miConfig.Code
  514. struct3505.OrgName = miConfig.OrgName
  515. struct3505.AccessKey = miConfig.AccessKey
  516. struct3505.RequestUrl = miConfig.Url
  517. struct3505.SecretKey = miConfig.SecretKey
  518. struct3505.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  519. struct3505.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  520. struct3505.FixmedinsBchno = infos.NewDrugWarehouseInfo.BatchNumber
  521. if org_id == 10188 {
  522. struct3505.PrscDrName = "王曙光"
  523. struct3505.PharName = "顾林玲"
  524. struct3505.PharPracCertNo = "K0404020449"
  525. } else if org_id == 10217 {
  526. struct3505.PrscDrName = "王云刚"
  527. struct3505.PharName = "施实芹"
  528. struct3505.PharPracCertNo = "1532050832051512010002"
  529. }
  530. timestamp := time.Now().Unix()
  531. tempTime := time.Unix(timestamp, 0)
  532. timeFormat := tempTime.Format("20060102150405")
  533. chrgBchno := rand.Intn(100000) + 10000
  534. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  535. struct3505.MdtrtSn = ipt_otp_no
  536. struct3505.ManuLotnum = infos.NewDrugWarehouseInfo.BatchNumber
  537. struct3505.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  538. //struct3505.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  539. struct3505.RxFlag = "0"
  540. struct3505.TrdnFlag = "1"
  541. struct3505.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  542. struct3505.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  543. struct3505.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  544. if org_id == 10188 {
  545. struct3505.SelRetnOpterName = "孙欣欣"
  546. } else if org_id == 10217 {
  547. struct3505.SelRetnOpterName = "晁海燕"
  548. }
  549. struct3505s = append(struct3505s, struct3505)
  550. data["struct_3505s"] = struct3505s[0]
  551. client := &http.Client{}
  552. bytesData, _ := json.Marshal(data)
  553. var req *http.Request
  554. if miConfig.MdtrtareaAdmvs == "320921" {
  555. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  556. } else {
  557. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  558. }
  559. resp, _ := client.Do(req)
  560. defer resp.Body.Close()
  561. body, ioErr := ioutil.ReadAll(resp.Body)
  562. if ioErr != nil {
  563. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  564. res.Infcode = -1
  565. return res
  566. }
  567. var respJSON map[string]interface{}
  568. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  569. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  570. res.Infcode = -1
  571. return res
  572. }
  573. var resSix10265 ResultSix10265 //1101结果
  574. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  575. result, _ := json.Marshal(respJSON)
  576. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  577. utils.ErrorLog("解析失败:%v", err)
  578. res.Infcode = -1
  579. return res
  580. }
  581. res.InfRefmsgid = resSix10265.InfRefmsgid
  582. res.Output = resSix10265.Output
  583. res.ErrMsg = resSix10265.ErrMsg
  584. res.Cainfo = resSix10265.Cainfo
  585. res.WarnMsg = resSix10265.WarnMsg
  586. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  587. res.Infcode = infocode
  588. return res
  589. }
  590. //销售退货
  591. func Post3506ForGoodInfo(org_id int64, infos *models.NewCancelStockInfo) ResultSix {
  592. var res ResultSix
  593. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  594. data := make(map[string]interface{})
  595. var struct3506s []models.Struct3506
  596. var struct3506 models.Struct3506
  597. struct3506.OrgName = miConfig.OrgName
  598. struct3506.AccessKey = miConfig.AccessKey
  599. struct3506.RequestUrl = miConfig.Url
  600. struct3506.SecretKey = miConfig.SecretKey
  601. struct3506.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  602. struct3506.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  603. struct3506.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  604. struct3506.FixmedinsHilistId = miConfig.Code
  605. struct3506.FixmedinsHilistName = miConfig.OrgName
  606. struct3506.FixmedinsBchno = infos.Number
  607. struct3506.ManuLotnum = infos.Number
  608. struct3506.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  609. //struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  610. struct3506.RxFlag = "0"
  611. struct3506.TrdnFlag = "1"
  612. struct3506.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  613. struct3506.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  614. //struct3506.SelRetnOpterName = "仓管员"
  615. if org_id == 10188 {
  616. struct3506.SelRetnOpterName = "孙欣欣"
  617. } else if org_id == 10217 {
  618. struct3506.SelRetnOpterName = "晁海燕"
  619. }
  620. struct3506.Memo = ""
  621. struct3506s = append(struct3506s, struct3506)
  622. data["struct_3506s"] = struct3506s
  623. client := &http.Client{}
  624. bytesData, _ := json.Marshal(data)
  625. var req *http.Request
  626. if miConfig.MdtrtareaAdmvs == "320921" {
  627. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  628. } else {
  629. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  630. }
  631. resp, _ := client.Do(req)
  632. defer resp.Body.Close()
  633. body, ioErr := ioutil.ReadAll(resp.Body)
  634. if ioErr != nil {
  635. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  636. res.Infcode = -1
  637. return res
  638. }
  639. var respJSON map[string]interface{}
  640. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  641. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  642. res.Infcode = -1
  643. return res
  644. }
  645. var resSix10265 ResultSix10265 //1101结果
  646. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  647. result, _ := json.Marshal(respJSON)
  648. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  649. utils.ErrorLog("解析失败:%v", err)
  650. res.Infcode = -1
  651. return res
  652. }
  653. res.InfRefmsgid = resSix10265.InfRefmsgid
  654. res.Output = resSix10265.Output
  655. res.ErrMsg = resSix10265.ErrMsg
  656. res.Cainfo = resSix10265.Cainfo
  657. res.WarnMsg = resSix10265.WarnMsg
  658. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  659. res.Infcode = infocode
  660. return res
  661. }
  662. func Post3506ForDrug(org_id int64, infos *models.NewDrugCancelStockInfo) ResultSix {
  663. var res ResultSix
  664. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  665. data := make(map[string]interface{})
  666. var struct3506s []models.Struct3506
  667. var struct3506 models.Struct3506
  668. struct3506.FixmedinsCode = miConfig.Code
  669. struct3506.OrgName = miConfig.OrgName
  670. struct3506.AccessKey = miConfig.AccessKey
  671. struct3506.RequestUrl = miConfig.Url
  672. struct3506.SecretKey = miConfig.SecretKey
  673. struct3506.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  674. struct3506.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  675. struct3506.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  676. struct3506.FixmedinsHilistId = miConfig.Code
  677. struct3506.FixmedinsHilistName = miConfig.OrgName
  678. struct3506.FixmedinsBchno = infos.BatchNumber
  679. struct3506.ManuLotnum = infos.BatchNumber
  680. struct3506.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  681. //struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  682. struct3506.RxFlag = "0"
  683. struct3506.TrdnFlag = "1"
  684. struct3506.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  685. struct3506.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  686. //struct3506.SelRetnOpterName = "仓管员"
  687. if org_id == 10188 {
  688. struct3506.SelRetnOpterName = "孙欣欣"
  689. } else if org_id == 10217 {
  690. struct3506.SelRetnOpterName = "晁海燕"
  691. }
  692. struct3506.Memo = ""
  693. struct3506s = append(struct3506s, struct3506)
  694. data["struct_3506s"] = struct3506s[0]
  695. client := &http.Client{}
  696. bytesData, _ := json.Marshal(data)
  697. var req *http.Request
  698. if miConfig.MdtrtareaAdmvs == "320921" {
  699. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  700. } else {
  701. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  702. }
  703. resp, _ := client.Do(req)
  704. defer resp.Body.Close()
  705. body, ioErr := ioutil.ReadAll(resp.Body)
  706. if ioErr != nil {
  707. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  708. res.Infcode = -1
  709. return res
  710. }
  711. var respJSON map[string]interface{}
  712. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  713. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  714. res.Infcode = -1
  715. return res
  716. }
  717. var resSix10265 ResultSix10265 //1101结果
  718. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  719. result, _ := json.Marshal(respJSON)
  720. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  721. utils.ErrorLog("解析失败:%v", err)
  722. res.Infcode = -1
  723. return res
  724. }
  725. res.InfRefmsgid = resSix10265.InfRefmsgid
  726. res.Output = resSix10265.Output
  727. res.ErrMsg = resSix10265.ErrMsg
  728. res.Cainfo = resSix10265.Cainfo
  729. res.WarnMsg = resSix10265.WarnMsg
  730. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  731. res.Infcode = infocode
  732. return res
  733. }