auto_create_week_schedules_service.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package service
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "gdyb/models"
  6. "gdyb/utils"
  7. "github.com/astaxie/beego"
  8. "github.com/robfig/cron"
  9. "io/ioutil"
  10. "math/rand"
  11. "net/http"
  12. "strconv"
  13. "time"
  14. )
  15. type ResultSix struct {
  16. Cainfo interface{} `json:"cainfo"`
  17. ErrMsg string `json:"err_msg"`
  18. InfRefmsgid string `json:"inf_refmsgid"`
  19. Infcode int64 `json:"infcode"`
  20. Output struct {
  21. } `json:"output"`
  22. RefmsgTime string `json:"refmsg_time"`
  23. RespondTime string `json:"respond_time"`
  24. Signtype interface{} `json:"signtype"`
  25. WarnMsg interface{} `json:"warn_msg"`
  26. }
  27. type ResultSix10265 struct {
  28. Cainfo interface{} `json:"cainfo"`
  29. ErrMsg string `json:"err_msg"`
  30. InfRefmsgid string `json:"inf_refmsgid"`
  31. Infcode string `json:"infcode"`
  32. Output struct {
  33. } `json:"output"`
  34. RefmsgTime string `json:"refmsg_time"`
  35. RespondTime string `json:"respond_time"`
  36. Signtype interface{} `json:"signtype"`
  37. WarnMsg interface{} `json:"warn_msg"`
  38. }
  39. // cron表达式 https://www.cnblogs.com/zuxingyu/p/6023919.html
  40. var createWeekSchedulesCronJob *cron.Cron
  41. func init() {
  42. utils.InfoLog("开启自动排班定时任务")
  43. createWeekSchedulesCronJob = cron.New()
  44. spec := "0 0 18 * * ?" // 每天6点上传当天数据
  45. //spec := "0 */1 * * * ?"
  46. createWeekSchedulesCronJob.AddFunc(spec, func() {
  47. AutoCreateStock()
  48. })
  49. }
  50. func BeginAutoCreateWeekSchedulesJob() {
  51. createWeekSchedulesCronJob.Start()
  52. }
  53. func AutoCreateStock() {
  54. org_id, _ := beego.AppConfig.Int64("org_id")
  55. var NewWarehousing []*models.NewWarehousingInfo
  56. var NewWarehouseOut []*models.NewWarehouseOutInfo
  57. var NewCancelStock []*models.NewCancelStockInfo
  58. var NewDrugWarehouse []*models.NewDrugWarehouseInfo
  59. var NewDrugWarehouseOut []*models.NewDrugWarehouseOutInfo
  60. var NewDrugCancelStock []*models.NewDrugCancelStockInfo
  61. readDb.Model(&models.NewWarehousingInfo{}).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(&NewWarehousing)
  62. 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)
  63. 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)
  64. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("user_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(&NewDrugWarehouse)
  65. readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("user_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(&NewDrugWarehouseOut)
  66. readDb.Model(&models.NewDrugCancelStockInfo{}).Where("user_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)
  67. for _, item := range NewWarehousing {
  68. res := Post3503ForGoodInfo(org_id, item)
  69. if res.Infcode == 0 {
  70. writeDb.Model(&models.NewWarehousingInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  71. "is_upload": 1,
  72. })
  73. } else {
  74. continue
  75. }
  76. }
  77. for _, item := range NewWarehouseOut {
  78. res := Post3505ForGoodInfo(org_id, item)
  79. if res.Infcode == 0 {
  80. writeDb.Model(&models.NewWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  81. "is_upload": 1,
  82. })
  83. } else {
  84. continue
  85. }
  86. }
  87. for _, item := range NewCancelStock {
  88. res := Post3506ForGoodInfo(org_id, item)
  89. if res.Infcode == 0 {
  90. writeDb.Model(&models.NewCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  91. "is_upload": 1,
  92. })
  93. } else {
  94. continue
  95. }
  96. }
  97. for _, item := range NewDrugWarehouse {
  98. res := Post3503ForDrug(org_id, item)
  99. if res.Infcode == 0 {
  100. writeDb.Model(&models.NewDrugWarehouseInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  101. "is_upload": 1,
  102. })
  103. } else {
  104. continue
  105. }
  106. }
  107. for _, item := range NewDrugWarehouseOut {
  108. res := Post3505ForDrug(org_id, item)
  109. if res.Infcode == 0 {
  110. writeDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  111. "is_upload": 1,
  112. })
  113. }
  114. }
  115. for _, item := range NewDrugCancelStock {
  116. res := Post3506ForDrug(org_id, item)
  117. if res.Infcode == 0 {
  118. writeDb.Model(&models.NewDrugCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  119. "is_upload": 1,
  120. })
  121. } else {
  122. continue
  123. }
  124. }
  125. }
  126. //采购
  127. func Post3503ForGoodInfo(org_id int64, infos *models.NewWarehousingInfo) ResultSix {
  128. var res ResultSix
  129. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  130. data := make(map[string]interface{})
  131. var struct3503s []models.Struct3503
  132. var struct3503 models.Struct3503
  133. struct3503.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  134. struct3503.FixmedinsHilistId = miConfig.Code
  135. struct3503.FixmedinsHilistName = miConfig.OrgName
  136. struct3503.FixmedinsBchno = infos.Number
  137. struct3503.SplerName = infos.Dealers.DealerName
  138. struct3503.ManuLotnum = infos.Number
  139. struct3503.ProdentpName = infos.Manufacturers.ManufacturerName
  140. struct3503.Aprvno = infos.LicenseNumber
  141. struct3503.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  142. struct3503.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  143. struct3503.PurcRetnCnt = strconv.FormatInt(infos.TotalCount, 10)
  144. struct3503.RxFlag = "0"
  145. struct3503.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  146. struct3503.PurcRetnOpterName = "仓管员"
  147. struct3503.OrgName = miConfig.OrgName
  148. struct3503.AccessKey = miConfig.AccessKey
  149. struct3503.RequestUrl = miConfig.Url
  150. struct3503.SecretKey = miConfig.SecretKey
  151. struct3503.Memo = ""
  152. struct3503s = append(struct3503s, struct3503)
  153. data["struct_3501s"] = struct3503s
  154. client := &http.Client{}
  155. bytesData, _ := json.Marshal(data)
  156. var req *http.Request
  157. if miConfig.MdtrtareaAdmvs == "320921" {
  158. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  159. } else {
  160. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  161. }
  162. resp, _ := client.Do(req)
  163. defer resp.Body.Close()
  164. body, ioErr := ioutil.ReadAll(resp.Body)
  165. if ioErr != nil {
  166. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  167. res.Infcode = -1
  168. return res
  169. }
  170. var respJSON map[string]interface{}
  171. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  172. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  173. res.Infcode = -1
  174. return res
  175. }
  176. var resSix10265 ResultSix10265 //1101结果
  177. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  178. result, _ := json.Marshal(respJSON)
  179. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  180. utils.ErrorLog("解析失败:%v", err)
  181. res.Infcode = -1
  182. return res
  183. }
  184. res.InfRefmsgid = resSix10265.InfRefmsgid
  185. res.Output = resSix10265.Output
  186. res.ErrMsg = resSix10265.ErrMsg
  187. res.Cainfo = resSix10265.Cainfo
  188. res.WarnMsg = resSix10265.WarnMsg
  189. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  190. res.Infcode = infocode
  191. return res
  192. }
  193. func Post3503ForDrug(org_id int64, infos *models.NewDrugWarehouseInfo) ResultSix {
  194. var res ResultSix
  195. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  196. data := make(map[string]interface{})
  197. var struct3501s []models.Struct3503
  198. var struct3501 models.Struct3503
  199. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  200. struct3501.FixmedinsHilistId = miConfig.Code
  201. struct3501.FixmedinsHilistName = miConfig.OrgName
  202. struct3501.FixmedinsBchno = infos.BatchNumber
  203. struct3501.SplerName = infos.Dealers.DealerName
  204. struct3501.ManuLotnum = infos.BatchNumber
  205. struct3501.ProdentpName = infos.Manufacturers.ManufacturerName
  206. struct3501.Aprvno = infos.BaseDrugLib.Number
  207. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  208. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  209. struct3501.PurcRetnCnt = strconv.FormatInt(infos.WarehousingCount, 10)
  210. struct3501.RxFlag = "0"
  211. struct3501.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  212. struct3501.PurcRetnOpterName = "仓管员"
  213. struct3501.OrgName = miConfig.OrgName
  214. struct3501.AccessKey = miConfig.AccessKey
  215. struct3501.RequestUrl = miConfig.Url
  216. struct3501.SecretKey = miConfig.SecretKey
  217. struct3501.Memo = ""
  218. struct3501s = append(struct3501s, struct3501)
  219. data["struct_3501s"] = struct3501s
  220. client := &http.Client{}
  221. bytesData, _ := json.Marshal(data)
  222. var req *http.Request
  223. if miConfig.MdtrtareaAdmvs == "320921" {
  224. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  225. } else {
  226. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  227. }
  228. resp, _ := client.Do(req)
  229. defer resp.Body.Close()
  230. body, ioErr := ioutil.ReadAll(resp.Body)
  231. if ioErr != nil {
  232. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  233. res.Infcode = -1
  234. return res
  235. }
  236. var respJSON map[string]interface{}
  237. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  238. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  239. res.Infcode = -1
  240. return res
  241. }
  242. var resSix10265 ResultSix10265 //1101结果
  243. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  244. result, _ := json.Marshal(respJSON)
  245. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  246. utils.ErrorLog("解析失败:%v", err)
  247. res.Infcode = -1
  248. return res
  249. }
  250. res.InfRefmsgid = resSix10265.InfRefmsgid
  251. res.Output = resSix10265.Output
  252. res.ErrMsg = resSix10265.ErrMsg
  253. res.Cainfo = resSix10265.Cainfo
  254. res.WarnMsg = resSix10265.WarnMsg
  255. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  256. res.Infcode = infocode
  257. return res
  258. }
  259. //销售
  260. func Post3505ForGoodInfo(org_id int64, infos *models.NewWarehouseOutInfo) ResultSix {
  261. var res ResultSix
  262. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  263. data := make(map[string]interface{})
  264. var struct3501s []models.Struct3505
  265. var struct3501 models.Struct3505
  266. struct3501.OrgName = miConfig.OrgName
  267. struct3501.AccessKey = miConfig.AccessKey
  268. struct3501.RequestUrl = miConfig.Url
  269. struct3501.SecretKey = miConfig.SecretKey
  270. struct3501.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  271. struct3501.FixmedinsHilistId = miConfig.Code
  272. struct3501.FixmedinsHilistName = miConfig.OrgName
  273. struct3501.FixmedinsBchno = infos.Number
  274. if org_id == 10188 {
  275. struct3501.PrscDrName = "王曙光"
  276. struct3501.PharName = "王曙光"
  277. struct3501.PharPracCertNo = ""
  278. } else if org_id == 10217 {
  279. struct3501.PrscDrName = "王云刚"
  280. struct3501.PharName = "王云刚"
  281. struct3501.PharPracCertNo = ""
  282. }
  283. timestamp := time.Now().Unix()
  284. tempTime := time.Unix(timestamp, 0)
  285. timeFormat := tempTime.Format("20060102150405")
  286. chrgBchno := rand.Intn(100000) + 10000
  287. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  288. struct3501.MdtrtSn = ipt_otp_no
  289. struct3501.ManuLotnum = infos.Number
  290. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  291. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  292. struct3501.RxFlag = "0"
  293. struct3501.TrdnFlag = "1"
  294. struct3501.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  295. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  296. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  297. struct3501.SelRetnOpterName = "仓管员"
  298. struct3501s = append(struct3501s, struct3501)
  299. data["struct_3501s"] = struct3501s
  300. client := &http.Client{}
  301. bytesData, _ := json.Marshal(data)
  302. var req *http.Request
  303. if miConfig.MdtrtareaAdmvs == "320921" {
  304. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  305. } else {
  306. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  307. }
  308. resp, _ := client.Do(req)
  309. defer resp.Body.Close()
  310. body, ioErr := ioutil.ReadAll(resp.Body)
  311. if ioErr != nil {
  312. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  313. res.Infcode = -1
  314. return res
  315. }
  316. var respJSON map[string]interface{}
  317. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  318. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  319. res.Infcode = -1
  320. return res
  321. }
  322. var resSix10265 ResultSix10265 //1101结果
  323. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  324. result, _ := json.Marshal(respJSON)
  325. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  326. utils.ErrorLog("解析失败:%v", err)
  327. res.Infcode = -1
  328. return res
  329. }
  330. res.InfRefmsgid = resSix10265.InfRefmsgid
  331. res.Output = resSix10265.Output
  332. res.ErrMsg = resSix10265.ErrMsg
  333. res.Cainfo = resSix10265.Cainfo
  334. res.WarnMsg = resSix10265.WarnMsg
  335. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  336. res.Infcode = infocode
  337. return res
  338. }
  339. func Post3505ForDrug(org_id int64, infos *models.NewDrugWarehouseOutInfo) ResultSix {
  340. var res ResultSix
  341. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  342. data := make(map[string]interface{})
  343. var struct3501s []models.Struct3505
  344. var struct3501 models.Struct3505
  345. struct3501.OrgName = miConfig.OrgName
  346. struct3501.AccessKey = miConfig.AccessKey
  347. struct3501.RequestUrl = miConfig.Url
  348. struct3501.SecretKey = miConfig.SecretKey
  349. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  350. struct3501.FixmedinsHilistId = miConfig.Code
  351. struct3501.FixmedinsHilistName = miConfig.OrgName
  352. struct3501.FixmedinsBchno = infos.BatchNumber
  353. if org_id == 10188 {
  354. struct3501.PrscDrName = "王曙光"
  355. struct3501.PharName = "王曙光"
  356. struct3501.PharPracCertNo = ""
  357. } else if org_id == 10217 {
  358. struct3501.PrscDrName = "王云刚"
  359. struct3501.PharName = "王云刚"
  360. struct3501.PharPracCertNo = ""
  361. }
  362. timestamp := time.Now().Unix()
  363. tempTime := time.Unix(timestamp, 0)
  364. timeFormat := tempTime.Format("20060102150405")
  365. chrgBchno := rand.Intn(100000) + 10000
  366. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  367. struct3501.MdtrtSn = ipt_otp_no
  368. struct3501.ManuLotnum = infos.BatchNumber
  369. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  370. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  371. struct3501.RxFlag = "0"
  372. struct3501.TrdnFlag = "1"
  373. struct3501.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  374. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  375. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  376. struct3501.SelRetnOpterName = "仓管员"
  377. struct3501s = append(struct3501s, struct3501)
  378. data["struct_3501s"] = struct3501s
  379. client := &http.Client{}
  380. bytesData, _ := json.Marshal(data)
  381. var req *http.Request
  382. if miConfig.MdtrtareaAdmvs == "320921" {
  383. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  384. } else {
  385. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  386. }
  387. resp, _ := client.Do(req)
  388. defer resp.Body.Close()
  389. body, ioErr := ioutil.ReadAll(resp.Body)
  390. if ioErr != nil {
  391. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  392. res.Infcode = -1
  393. return res
  394. }
  395. var respJSON map[string]interface{}
  396. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  397. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  398. res.Infcode = -1
  399. return res
  400. }
  401. var resSix10265 ResultSix10265 //1101结果
  402. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  403. result, _ := json.Marshal(respJSON)
  404. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  405. utils.ErrorLog("解析失败:%v", err)
  406. res.Infcode = -1
  407. return res
  408. }
  409. res.InfRefmsgid = resSix10265.InfRefmsgid
  410. res.Output = resSix10265.Output
  411. res.ErrMsg = resSix10265.ErrMsg
  412. res.Cainfo = resSix10265.Cainfo
  413. res.WarnMsg = resSix10265.WarnMsg
  414. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  415. res.Infcode = infocode
  416. return res
  417. }
  418. //销售退货
  419. func Post3506ForGoodInfo(org_id int64, infos *models.NewCancelStockInfo) ResultSix {
  420. var res ResultSix
  421. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  422. data := make(map[string]interface{})
  423. var struct3501s []models.Struct3506
  424. var struct3501 models.Struct3506
  425. struct3501.OrgName = miConfig.OrgName
  426. struct3501.AccessKey = miConfig.AccessKey
  427. struct3501.RequestUrl = miConfig.Url
  428. struct3501.SecretKey = miConfig.SecretKey
  429. struct3501.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  430. struct3501.FixmedinsHilistId = miConfig.Code
  431. struct3501.FixmedinsHilistName = miConfig.OrgName
  432. struct3501.FixmedinsBchno = infos.Number
  433. struct3501.ManuLotnum = infos.Number
  434. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  435. //struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  436. struct3501.RxFlag = "0"
  437. struct3501.TrdnFlag = "1"
  438. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  439. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  440. struct3501.SelRetnOpterName = "仓管员"
  441. struct3501.Memo = ""
  442. struct3501s = append(struct3501s, struct3501)
  443. data["struct_3501s"] = struct3501s
  444. client := &http.Client{}
  445. bytesData, _ := json.Marshal(data)
  446. var req *http.Request
  447. if miConfig.MdtrtareaAdmvs == "320921" {
  448. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  449. } else {
  450. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  451. }
  452. resp, _ := client.Do(req)
  453. defer resp.Body.Close()
  454. body, ioErr := ioutil.ReadAll(resp.Body)
  455. if ioErr != nil {
  456. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  457. res.Infcode = -1
  458. return res
  459. }
  460. var respJSON map[string]interface{}
  461. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  462. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  463. res.Infcode = -1
  464. return res
  465. }
  466. var resSix10265 ResultSix10265 //1101结果
  467. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  468. result, _ := json.Marshal(respJSON)
  469. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  470. utils.ErrorLog("解析失败:%v", err)
  471. res.Infcode = -1
  472. return res
  473. }
  474. res.InfRefmsgid = resSix10265.InfRefmsgid
  475. res.Output = resSix10265.Output
  476. res.ErrMsg = resSix10265.ErrMsg
  477. res.Cainfo = resSix10265.Cainfo
  478. res.WarnMsg = resSix10265.WarnMsg
  479. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  480. res.Infcode = infocode
  481. return res
  482. }
  483. func Post3506ForDrug(org_id int64, infos *models.NewDrugCancelStockInfo) ResultSix {
  484. var res ResultSix
  485. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  486. data := make(map[string]interface{})
  487. var struct3501s []models.Struct3506
  488. var struct3501 models.Struct3506
  489. struct3501.OrgName = miConfig.OrgName
  490. struct3501.AccessKey = miConfig.AccessKey
  491. struct3501.RequestUrl = miConfig.Url
  492. struct3501.SecretKey = miConfig.SecretKey
  493. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  494. struct3501.FixmedinsHilistId = miConfig.Code
  495. struct3501.FixmedinsHilistName = miConfig.OrgName
  496. struct3501.FixmedinsBchno = infos.BatchNumber
  497. struct3501.ManuLotnum = infos.BatchNumber
  498. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  499. struct3501.RxFlag = "0"
  500. struct3501.TrdnFlag = "1"
  501. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  502. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  503. struct3501.SelRetnOpterName = "仓管员"
  504. struct3501.Memo = ""
  505. struct3501s = append(struct3501s, struct3501)
  506. data["struct_3501s"] = struct3501s
  507. client := &http.Client{}
  508. bytesData, _ := json.Marshal(data)
  509. var req *http.Request
  510. if miConfig.MdtrtareaAdmvs == "320921" {
  511. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  512. } else {
  513. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  514. }
  515. resp, _ := client.Do(req)
  516. defer resp.Body.Close()
  517. body, ioErr := ioutil.ReadAll(resp.Body)
  518. if ioErr != nil {
  519. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  520. res.Infcode = -1
  521. return res
  522. }
  523. var respJSON map[string]interface{}
  524. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  525. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  526. res.Infcode = -1
  527. return res
  528. }
  529. var resSix10265 ResultSix10265 //1101结果
  530. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  531. result, _ := json.Marshal(respJSON)
  532. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  533. utils.ErrorLog("解析失败:%v", err)
  534. res.Infcode = -1
  535. return res
  536. }
  537. res.InfRefmsgid = resSix10265.InfRefmsgid
  538. res.Output = resSix10265.Output
  539. res.ErrMsg = resSix10265.ErrMsg
  540. res.Cainfo = resSix10265.Cainfo
  541. res.WarnMsg = resSix10265.WarnMsg
  542. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  543. res.Infcode = infocode
  544. return res
  545. }