auto_create_week_schedules_service.go 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. var NewDrugWarehouseOutTwo []*models.NewDrugWarehouseOutInfo
  64. //var XtDrugInventorys2 []*models.XtDrugInventory
  65. //readDb.Model(&models.XtDrugInventory{}).Where("user_org_id = ? and status = 1 and is_upload <> 1 AND stock_max_number > 0", org_id).Preload("BaseDrugLib", "status = 1").Find(&XtDrugInventorys)
  66. //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)
  67. //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)
  68. //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)
  69. ////大丰
  70. //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)
  71. //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)
  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. //响水
  74. //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)
  75. //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)
  76. //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)
  77. //3502
  78. //readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload = 1 ", 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)
  79. //3502
  80. readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload = 1 ", 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(&NewDrugWarehouseOutTwo)
  81. for _, item := range XtDrugInventorys {
  82. res := Post3501ForDrug(org_id, item)
  83. if res.Infcode == 0 {
  84. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  85. "is_upload": 1,
  86. })
  87. } else {
  88. continue
  89. }
  90. }
  91. for _, item := range NewDrugWarehouseOutTwo {
  92. res := Post3502ForDrug(org_id, item)
  93. if res.Infcode == 0 {
  94. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  95. "is_upload": 1,
  96. })
  97. } else {
  98. continue
  99. }
  100. }
  101. for _, item := range NewWarehousing {
  102. res := Post3503ForGoodInfo(org_id, item)
  103. if res.Infcode == 0 {
  104. writeDb.Model(&models.NewWarehousingInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  105. "is_upload": 1,
  106. })
  107. } else {
  108. continue
  109. }
  110. }
  111. for _, item := range NewWarehouseOut {
  112. res := Post3505ForGoodInfo(org_id, item)
  113. if res.Infcode == 0 {
  114. writeDb.Model(&models.NewWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  115. "is_upload": 1,
  116. })
  117. } else {
  118. continue
  119. }
  120. }
  121. for _, item := range NewCancelStock {
  122. res := Post3506ForGoodInfo(org_id, item)
  123. if res.Infcode == 0 {
  124. writeDb.Model(&models.NewCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  125. "is_upload": 1,
  126. })
  127. } else {
  128. continue
  129. }
  130. }
  131. for _, item := range NewDrugWarehouse {
  132. res := Post3503ForDrug(org_id, item)
  133. if res.Infcode == 0 {
  134. writeDb.Model(&models.NewDrugWarehouseInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  135. "is_upload": 1,
  136. })
  137. } else {
  138. continue
  139. }
  140. }
  141. for _, item := range NewDrugWarehouseOut {
  142. res := Post3505ForDrug(org_id, item)
  143. if res.Infcode == 0 {
  144. writeDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  145. "is_upload": 1,
  146. })
  147. }
  148. }
  149. for _, item := range NewDrugCancelStock {
  150. res := Post3506ForDrug(org_id, item)
  151. if res.Infcode == 0 {
  152. writeDb.Model(&models.NewDrugCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  153. "is_upload": 1,
  154. })
  155. } else {
  156. continue
  157. }
  158. }
  159. }
  160. func AutoGdybCreateStock() {
  161. org_id, _ := beego.AppConfig.Int64("org_id")
  162. var NewWarehousing []*models.NewWarehousingInfo
  163. var NewWarehouseOut []*models.NewWarehouseOutInfo
  164. var NewCancelStock []*models.NewCancelStockInfo
  165. var NewDrugWarehouse []*models.NewDrugWarehouseInfo
  166. var NewDrugWarehouseOut []*models.NewDrugWarehouseOutInfo
  167. var NewDrugCancelStock []*models.NewDrugCancelStockInfo
  168. var XtDrugInventorys []*models.XtDrugInventory
  169. var XtStockInventorys []*models.XtStockInventoryTwo
  170. var NewDrugWarehouseOutTwo []*models.NewDrugWarehouseOutInfo
  171. 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)
  172. readDb.Model(&models.NewCancelStockInfo{}).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).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&NewCancelStock)
  173. //3501,药品和耗材
  174. readDb.Model(&models.XtDrugInventory{}).Where("user_org_id = ? and status = 1 and is_upload <> 1 AND stock_max_number > 0", org_id).Preload("BaseDrugLib", "status = 1").Find(&XtDrugInventorys)
  175. readDb.Model(&models.XtStockInventoryTwo{}).Where("user_org_id = ? and status = 1 and is_upload <> 1 ", org_id).Preload("GoodInfo", "status = 1").Find(&XtStockInventorys)
  176. for _, item := range XtDrugInventorys {
  177. res := Post3501ForDrug(org_id, item)
  178. if res.Infcode == 0 {
  179. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  180. "is_upload": 1,
  181. })
  182. } else {
  183. continue
  184. }
  185. }
  186. for _, item := range XtStockInventorys {
  187. res := Post3501ForGoodInfo(org_id, item)
  188. if res.Infcode == 0 {
  189. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  190. "is_upload": 1,
  191. })
  192. } else {
  193. continue
  194. }
  195. }
  196. //3502
  197. readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload = 1 ", 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(&NewDrugWarehouseOutTwo)
  198. //readDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("org_id = ? and status = 1 and is_upload = 1 ", 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(&NewDrugWarehouseOutTwo)
  199. 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)
  200. for _, item := range NewDrugWarehouseOutTwo {
  201. res := Post3502ForDrug(org_id, item)
  202. if res.Infcode == 0 {
  203. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  204. "is_upload": 1,
  205. })
  206. } else {
  207. continue
  208. }
  209. }
  210. for _, item := range NewWarehouseOut {
  211. res := Post3502ForGoodInfo(org_id, item)
  212. if res.Infcode == 0 {
  213. writeDb.Model(&models.XtDrugInventory{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  214. "is_upload": 1,
  215. })
  216. } else {
  217. continue
  218. }
  219. }
  220. //3503
  221. for _, item := range NewWarehousing {
  222. res := Post3503ForGoodInfo(org_id, item)
  223. if res.Infcode == 0 {
  224. writeDb.Model(&models.NewWarehousingInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  225. "is_upload": 1,
  226. })
  227. } else {
  228. continue
  229. }
  230. }
  231. for _, item := range NewDrugWarehouse {
  232. res := Post3503ForDrug(org_id, item)
  233. if res.Infcode == 0 {
  234. writeDb.Model(&models.NewDrugWarehouseInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  235. "is_upload": 1,
  236. })
  237. } else {
  238. continue
  239. }
  240. }
  241. //3505
  242. for _, item := range NewWarehouseOut {
  243. res := Post3505ForGoodInfo(org_id, item)
  244. if res.Infcode == 0 {
  245. writeDb.Model(&models.NewWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  246. "is_upload": 1,
  247. })
  248. } else {
  249. continue
  250. }
  251. }
  252. for _, item := range NewDrugWarehouseOut {
  253. res := Post3505ForDrug(org_id, item)
  254. if res.Infcode == 0 {
  255. writeDb.Model(&models.NewDrugWarehouseOutInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  256. "is_upload": 1,
  257. })
  258. }
  259. }
  260. //3506
  261. for _, item := range NewCancelStock {
  262. res := Post3506ForGoodInfo(org_id, item)
  263. if res.Infcode == 0 {
  264. writeDb.Model(&models.NewCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  265. "is_upload": 1,
  266. })
  267. } else {
  268. continue
  269. }
  270. }
  271. for _, item := range NewDrugCancelStock {
  272. res := Post3506ForDrug(org_id, item)
  273. if res.Infcode == 0 {
  274. writeDb.Model(&models.NewDrugCancelStockInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{
  275. "is_upload": 1,
  276. })
  277. } else {
  278. continue
  279. }
  280. }
  281. }
  282. //耗材库盘上传
  283. func Post3501ForGoodInfo(org_id int64, infos *models.XtStockInventoryTwo) ResultSix {
  284. var res ResultSix
  285. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  286. data := make(map[string]interface{})
  287. var struct3501s []models.Struct3501
  288. var struct3501 models.Struct3501
  289. struct3501.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  290. struct3501.FixmedinsHilistId = miConfig.Code
  291. struct3501.FixmedinsHilistName = miConfig.OrgName
  292. struct3501.FixmedinsBchno = infos.Number
  293. struct3501.RxFlag = "0"
  294. struct3501.Invdate = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  295. struct3501.OrgName = miConfig.OrgName
  296. struct3501.AccessKey = miConfig.AccessKey
  297. struct3501.RequestUrl = miConfig.Url
  298. struct3501.SecretKey = miConfig.SecretKey
  299. struct3501.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  300. struct3501.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  301. struct3501.InvCnt = strconv.FormatInt(infos.Count, 10)
  302. struct3501.ManuDate = time.Unix(infos.WarehousingInfo.ProductDate, 0).Format("2006-01-02 15:04:05")
  303. struct3501.ExpyEnd = time.Unix(infos.WarehousingInfo.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  304. struct3501s = append(struct3501s, struct3501)
  305. data["struct_3501s"] = struct3501s[0]
  306. client := &http.Client{}
  307. bytesData, _ := json.Marshal(data)
  308. var req *http.Request
  309. if miConfig.UserOrgId == 10215 {
  310. result := Gdyb3501(struct3501, miConfig.SecretKey)
  311. var dat map[string]interface{}
  312. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  313. fmt.Println(dat)
  314. } else {
  315. fmt.Println(err)
  316. }
  317. userJSONBytes, _ := json.Marshal(dat)
  318. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  319. utils.ErrorLog("解析失败:%v", err)
  320. res.Infcode = -1
  321. return res
  322. }
  323. return res
  324. } else {
  325. if miConfig.MdtrtareaAdmvs == "320921" {
  326. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  327. } else {
  328. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  329. }
  330. resp, _ := client.Do(req)
  331. defer resp.Body.Close()
  332. body, ioErr := ioutil.ReadAll(resp.Body)
  333. if ioErr != nil {
  334. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  335. res.Infcode = -1
  336. return res
  337. }
  338. var respJSON map[string]interface{}
  339. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  340. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  341. res.Infcode = -1
  342. return res
  343. }
  344. var resSix10265 ResultSix10265 //1101结果
  345. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  346. result, _ := json.Marshal(respJSON)
  347. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  348. utils.ErrorLog("解析失败:%v", err)
  349. res.Infcode = -1
  350. return res
  351. }
  352. res.InfRefmsgid = resSix10265.InfRefmsgid
  353. res.Output = resSix10265.Output
  354. res.ErrMsg = resSix10265.ErrMsg
  355. res.Cainfo = resSix10265.Cainfo
  356. res.WarnMsg = resSix10265.WarnMsg
  357. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  358. res.Infcode = infocode
  359. return res
  360. }
  361. }
  362. //药品库盘上传
  363. func Post3501ForDrug(org_id int64, infos *models.XtDrugInventory) ResultSix {
  364. var res ResultSix
  365. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  366. data := make(map[string]interface{})
  367. var struct3501s []models.Struct3501
  368. var struct3501 models.Struct3501
  369. struct3501.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  370. struct3501.FixmedinsHilistId = miConfig.Code
  371. struct3501.FixmedinsHilistName = miConfig.OrgName
  372. struct3501.FixmedinsBchno = infos.BatchNumber
  373. struct3501.FixmedinsCode = miConfig.Code
  374. struct3501.RxFlag = "0"
  375. struct3501.Invdate = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  376. struct3501.OrgName = miConfig.OrgName
  377. struct3501.AccessKey = miConfig.AccessKey
  378. struct3501.RequestUrl = miConfig.Url
  379. struct3501.SecretKey = miConfig.SecretKey
  380. struct3501.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  381. struct3501.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  382. struct3501.InvCnt = strconv.FormatInt(infos.StockMaxNumber, 10)
  383. struct3501.ManuDate = time.Unix(infos.DrugWarehouseInfo.ProductDate, 0).Format("2006-01-02 15:04:05")
  384. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  385. struct3501s = append(struct3501s, struct3501)
  386. data["struct_3501s"] = struct3501s[0]
  387. client := &http.Client{}
  388. bytesData, _ := json.Marshal(data)
  389. var req *http.Request
  390. if miConfig.UserOrgId == 10215 {
  391. result := Gdyb3501(struct3501, miConfig.SecretKey)
  392. var dat map[string]interface{}
  393. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  394. fmt.Println(dat)
  395. } else {
  396. fmt.Println(err)
  397. }
  398. userJSONBytes, _ := json.Marshal(dat)
  399. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  400. utils.ErrorLog("解析失败:%v", err)
  401. res.Infcode = -1
  402. return res
  403. }
  404. return res
  405. } else {
  406. if miConfig.MdtrtareaAdmvs == "320921" {
  407. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  408. } else {
  409. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  410. }
  411. resp, _ := client.Do(req)
  412. defer resp.Body.Close()
  413. body, ioErr := ioutil.ReadAll(resp.Body)
  414. if ioErr != nil {
  415. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  416. res.Infcode = -1
  417. return res
  418. }
  419. var respJSON map[string]interface{}
  420. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  421. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  422. res.Infcode = -1
  423. return res
  424. }
  425. var resSix10265 ResultSix10265 //1101结果
  426. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  427. result, _ := json.Marshal(respJSON)
  428. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  429. utils.ErrorLog("解析失败:%v", err)
  430. res.Infcode = -1
  431. return res
  432. }
  433. res.InfRefmsgid = resSix10265.InfRefmsgid
  434. res.Output = resSix10265.Output
  435. res.ErrMsg = resSix10265.ErrMsg
  436. res.Cainfo = resSix10265.Cainfo
  437. res.WarnMsg = resSix10265.WarnMsg
  438. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  439. res.Infcode = infocode
  440. return res
  441. }
  442. }
  443. //商品库存变更
  444. func Post3502ForDrug(org_id int64, infos *models.NewDrugWarehouseOutInfo) ResultSix {
  445. var res ResultSix
  446. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  447. data := make(map[string]interface{})
  448. //var struct3502s []models.Struct3502
  449. var struct3502 models.Struct3502
  450. struct3502.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  451. struct3502.FixmedinsHilistId = miConfig.Code
  452. struct3502.FixmedinsHilistName = miConfig.OrgName
  453. struct3502.FixmedinsBchno = infos.NewDrugWarehouseInfo.BatchNumber
  454. struct3502.FixmedinsCode = miConfig.Code
  455. struct3502.RxFlag = "0"
  456. struct3502.InvChgTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  457. struct3502.OrgName = miConfig.OrgName
  458. struct3502.AccessKey = miConfig.AccessKey
  459. struct3502.RequestUrl = miConfig.Url
  460. struct3502.SecretKey = miConfig.SecretKey
  461. struct3502.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  462. struct3502.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  463. struct3502.InvChgType = "102"
  464. struct3502.Cnt = strconv.FormatInt(infos.Count, 10)
  465. struct3502.Pric = fmt.Sprintf("%.2f", infos.BaseDrugLib.RetailPrice)
  466. data["struct_3502s"] = struct3502
  467. client := &http.Client{}
  468. bytesData, _ := json.Marshal(data)
  469. var req *http.Request
  470. if miConfig.UserOrgId == 10215 {
  471. result := Gdyb3502(struct3502, miConfig.SecretKey)
  472. var dat map[string]interface{}
  473. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  474. fmt.Println(dat)
  475. } else {
  476. fmt.Println(err)
  477. }
  478. userJSONBytes, _ := json.Marshal(dat)
  479. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  480. utils.ErrorLog("解析失败:%v", err)
  481. res.Infcode = -1
  482. return res
  483. }
  484. return res
  485. } else {
  486. if miConfig.MdtrtareaAdmvs == "320921" {
  487. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3502", bytes.NewReader(bytesData))
  488. } else {
  489. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3502", bytes.NewReader(bytesData))
  490. }
  491. resp, _ := client.Do(req)
  492. defer resp.Body.Close()
  493. body, ioErr := ioutil.ReadAll(resp.Body)
  494. if ioErr != nil {
  495. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  496. res.Infcode = -1
  497. return res
  498. }
  499. var respJSON map[string]interface{}
  500. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  501. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  502. res.Infcode = -1
  503. return res
  504. }
  505. var resSix10265 ResultSix10265 //1101结果
  506. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  507. result, _ := json.Marshal(respJSON)
  508. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  509. utils.ErrorLog("解析失败:%v", err)
  510. res.Infcode = -1
  511. return res
  512. }
  513. res.InfRefmsgid = resSix10265.InfRefmsgid
  514. res.Output = resSix10265.Output
  515. res.ErrMsg = resSix10265.ErrMsg
  516. res.Cainfo = resSix10265.Cainfo
  517. res.WarnMsg = resSix10265.WarnMsg
  518. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  519. res.Infcode = infocode
  520. return res
  521. }
  522. }
  523. func Post3502ForGoodInfo(org_id int64, infos *models.NewWarehouseOutInfo) ResultSix {
  524. var res ResultSix
  525. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  526. data := make(map[string]interface{})
  527. //var struct3502s []models.Struct3502
  528. var struct3502 models.Struct3502
  529. struct3502.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  530. struct3502.FixmedinsHilistId = miConfig.Code
  531. struct3502.FixmedinsHilistName = miConfig.OrgName
  532. struct3502.FixmedinsBchno = infos.WarehousingInfo.Number
  533. struct3502.FixmedinsCode = miConfig.Code
  534. struct3502.RxFlag = "0"
  535. struct3502.InvChgTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  536. struct3502.OrgName = miConfig.OrgName
  537. struct3502.AccessKey = miConfig.AccessKey
  538. struct3502.RequestUrl = miConfig.Url
  539. struct3502.SecretKey = miConfig.SecretKey
  540. struct3502.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  541. struct3502.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  542. struct3502.InvChgType = "102"
  543. struct3502.Cnt = strconv.FormatInt(infos.Count, 10)
  544. struct3502.Pric = fmt.Sprintf("%.2f", infos.GoodInfo.RetailPrice)
  545. data["struct_3502s"] = struct3502
  546. client := &http.Client{}
  547. bytesData, _ := json.Marshal(data)
  548. var req *http.Request
  549. if miConfig.UserOrgId == 10215 {
  550. result := Gdyb3502(struct3502, miConfig.SecretKey)
  551. var dat map[string]interface{}
  552. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  553. fmt.Println(dat)
  554. } else {
  555. fmt.Println(err)
  556. }
  557. userJSONBytes, _ := json.Marshal(dat)
  558. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  559. utils.ErrorLog("解析失败:%v", err)
  560. res.Infcode = -1
  561. return res
  562. }
  563. return res
  564. } else {
  565. if miConfig.MdtrtareaAdmvs == "320921" {
  566. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3502", bytes.NewReader(bytesData))
  567. } else {
  568. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3502", bytes.NewReader(bytesData))
  569. }
  570. resp, _ := client.Do(req)
  571. defer resp.Body.Close()
  572. body, ioErr := ioutil.ReadAll(resp.Body)
  573. if ioErr != nil {
  574. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  575. res.Infcode = -1
  576. return res
  577. }
  578. var respJSON map[string]interface{}
  579. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  580. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  581. res.Infcode = -1
  582. return res
  583. }
  584. var resSix10265 ResultSix10265 //1101结果
  585. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  586. result, _ := json.Marshal(respJSON)
  587. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  588. utils.ErrorLog("解析失败:%v", err)
  589. res.Infcode = -1
  590. return res
  591. }
  592. res.InfRefmsgid = resSix10265.InfRefmsgid
  593. res.Output = resSix10265.Output
  594. res.ErrMsg = resSix10265.ErrMsg
  595. res.Cainfo = resSix10265.Cainfo
  596. res.WarnMsg = resSix10265.WarnMsg
  597. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  598. res.Infcode = infocode
  599. return res
  600. }
  601. }
  602. //采购
  603. func Post3503ForGoodInfo(org_id int64, infos *models.NewWarehousingInfo) ResultSix {
  604. fmt.Println(&infos)
  605. var res ResultSix
  606. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  607. data := make(map[string]interface{})
  608. var struct3503s []models.Struct3503
  609. var struct3503 models.Struct3503
  610. struct3503.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  611. struct3503.FixmedinsHilistId = miConfig.Code
  612. struct3503.FixmedinsCode = miConfig.Code
  613. struct3503.FixmedinsHilistName = miConfig.OrgName
  614. struct3503.FixmedinsBchno = infos.Number
  615. var d models.Dealers
  616. readDb.Model(&models.Dealers{}).Where("id = ?", infos.Dealer).First(&d)
  617. if d.ID == 0 {
  618. struct3503.SplerName = infos.Manufacturers.ManufacturerName
  619. } else {
  620. struct3503.SplerName = d.DealerName
  621. }
  622. struct3503.ManuLotnum = infos.Number
  623. struct3503.ProdentpName = infos.Manufacturers.ManufacturerName
  624. struct3503.Aprvno = infos.GoodInfo.Number
  625. struct3503.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02")
  626. struct3503.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02")
  627. struct3503.PurcRetnCnt = strconv.FormatInt(infos.TotalCount, 10)
  628. struct3503.RxFlag = "0"
  629. struct3503.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02")
  630. if org_id == 10217 {
  631. struct3503.PurcRetnOpterName = "施实芹"
  632. } else {
  633. struct3503.PurcRetnOpterName = ""
  634. }
  635. struct3503.OrgName = miConfig.OrgName
  636. struct3503.AccessKey = miConfig.AccessKey
  637. struct3503.RequestUrl = miConfig.Url
  638. struct3503.SecretKey = miConfig.SecretKey
  639. struct3503.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  640. struct3503.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  641. struct3503.Memo = ""
  642. struct3503s = append(struct3503s, struct3503)
  643. data["struct_3503s"] = struct3503s[0]
  644. client := &http.Client{}
  645. bytesData, _ := json.Marshal(data)
  646. fmt.Println(string(bytesData))
  647. var req *http.Request
  648. if miConfig.UserOrgId == 10215 {
  649. result := Gdyb3503(struct3503, miConfig.SecretKey)
  650. var dat map[string]interface{}
  651. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  652. fmt.Println(dat)
  653. } else {
  654. fmt.Println(err)
  655. }
  656. userJSONBytes, _ := json.Marshal(dat)
  657. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  658. utils.ErrorLog("解析失败:%v", err)
  659. res.Infcode = -1
  660. return res
  661. }
  662. return res
  663. } else {
  664. if miConfig.MdtrtareaAdmvs == "320921" {
  665. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  666. } else {
  667. fmt.Println("111111")
  668. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  669. }
  670. resp, _ := client.Do(req)
  671. defer resp.Body.Close()
  672. body, ioErr := ioutil.ReadAll(resp.Body)
  673. if ioErr != nil {
  674. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  675. res.Infcode = -1
  676. return res
  677. }
  678. var respJSON map[string]interface{}
  679. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  680. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  681. res.Infcode = -1
  682. return res
  683. }
  684. var resSix10265 ResultSix10265 //1101结果
  685. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  686. result, _ := json.Marshal(respJSON)
  687. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  688. utils.ErrorLog("解析失败:%v", err)
  689. res.Infcode = -1
  690. return res
  691. }
  692. res.InfRefmsgid = resSix10265.InfRefmsgid
  693. res.Output = resSix10265.Output
  694. res.ErrMsg = resSix10265.ErrMsg
  695. res.Cainfo = resSix10265.Cainfo
  696. res.WarnMsg = resSix10265.WarnMsg
  697. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  698. res.Infcode = infocode
  699. return res
  700. }
  701. }
  702. func Post3503ForDrug(org_id int64, infos *models.NewDrugWarehouseInfo) ResultSix {
  703. var res ResultSix
  704. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  705. data := make(map[string]interface{})
  706. var struct3503s []models.Struct3503
  707. var struct3503 models.Struct3503
  708. struct3503.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  709. struct3503.FixmedinsHilistId = miConfig.Code
  710. struct3503.FixmedinsHilistName = miConfig.OrgName
  711. struct3503.FixmedinsBchno = infos.BatchNumber
  712. var d models.Dealers
  713. readDb.Model(&models.Dealers{}).Where("id = ?", infos.Dealer).First(&d)
  714. struct3503.SplerName = d.DealerName
  715. struct3503.ManuLotnum = infos.BatchNumber
  716. struct3503.ProdentpName = infos.Manufacturers.ManufacturerName
  717. struct3503.Aprvno = infos.BaseDrugLib.Number
  718. struct3503.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  719. struct3503.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  720. struct3503.PurcRetnCnt = strconv.FormatInt(infos.WarehousingCount, 10)
  721. struct3503.RxFlag = "0"
  722. struct3503.PurcRetnStoinTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  723. if org_id == 10217 {
  724. struct3503.PurcRetnOpterName = "施实芹"
  725. } else {
  726. struct3503.PurcRetnOpterName = "顾林玲"
  727. }
  728. struct3503.OrgName = miConfig.OrgName
  729. struct3503.AccessKey = miConfig.AccessKey
  730. struct3503.RequestUrl = miConfig.Url
  731. struct3503.SecretKey = miConfig.SecretKey
  732. struct3503.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  733. struct3503.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  734. struct3503.Memo = ""
  735. struct3503s = append(struct3503s, struct3503)
  736. data["struct_3503s"] = struct3503s[0]
  737. client := &http.Client{}
  738. bytesData, _ := json.Marshal(data)
  739. var req *http.Request
  740. if miConfig.UserOrgId == 10215 {
  741. result := Gdyb3503(struct3503, miConfig.SecretKey)
  742. var dat map[string]interface{}
  743. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  744. fmt.Println(dat)
  745. } else {
  746. fmt.Println(err)
  747. }
  748. userJSONBytes, _ := json.Marshal(dat)
  749. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  750. utils.ErrorLog("解析失败:%v", err)
  751. res.Infcode = -1
  752. return res
  753. }
  754. return res
  755. } else {
  756. if miConfig.MdtrtareaAdmvs == "320921" {
  757. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  758. } else {
  759. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3503", bytes.NewReader(bytesData))
  760. }
  761. resp, _ := client.Do(req)
  762. defer resp.Body.Close()
  763. body, ioErr := ioutil.ReadAll(resp.Body)
  764. if ioErr != nil {
  765. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  766. res.Infcode = -1
  767. return res
  768. }
  769. var respJSON map[string]interface{}
  770. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  771. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  772. res.Infcode = -1
  773. return res
  774. }
  775. var resSix10265 ResultSix10265 //1101结果
  776. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  777. result, _ := json.Marshal(respJSON)
  778. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  779. utils.ErrorLog("解析失败:%v", err)
  780. res.Infcode = -1
  781. return res
  782. }
  783. res.InfRefmsgid = resSix10265.InfRefmsgid
  784. res.Output = resSix10265.Output
  785. res.ErrMsg = resSix10265.ErrMsg
  786. res.Cainfo = resSix10265.Cainfo
  787. res.WarnMsg = resSix10265.WarnMsg
  788. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  789. res.Infcode = infocode
  790. return res
  791. }
  792. }
  793. //销售
  794. func Post3505ForGoodInfo(org_id int64, infos *models.NewWarehouseOutInfo) ResultSix {
  795. var res ResultSix
  796. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  797. data := make(map[string]interface{})
  798. var struct3501s []models.Struct3505
  799. var struct3501 models.Struct3505
  800. struct3501.OrgName = miConfig.OrgName
  801. struct3501.AccessKey = miConfig.AccessKey
  802. struct3501.RequestUrl = miConfig.Url
  803. struct3501.SecretKey = miConfig.SecretKey
  804. struct3501.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  805. struct3501.FixmedinsHilistId = miConfig.Code
  806. struct3501.FixmedinsHilistName = miConfig.OrgName
  807. struct3501.FixmedinsBchno = infos.Number
  808. if org_id == 10188 {
  809. struct3501.PrscDrName = "王曙光"
  810. struct3501.PharName = "王曙光"
  811. struct3501.PharPracCertNo = ""
  812. } else if org_id == 10217 {
  813. struct3501.PrscDrName = "王云刚"
  814. struct3501.PharName = "王云刚"
  815. struct3501.PharPracCertNo = ""
  816. }
  817. timestamp := time.Now().Unix()
  818. tempTime := time.Unix(timestamp, 0)
  819. timeFormat := tempTime.Format("20060102150405")
  820. chrgBchno := rand.Intn(100000) + 10000
  821. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  822. struct3501.MdtrtSn = ipt_otp_no
  823. struct3501.ManuLotnum = infos.Number
  824. struct3501.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  825. struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  826. struct3501.RxFlag = "0"
  827. struct3501.TrdnFlag = "1"
  828. struct3501.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  829. struct3501.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  830. struct3501.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  831. struct3501.SelRetnOpterName = "仓管员"
  832. struct3501s = append(struct3501s, struct3501)
  833. data["struct_3501s"] = struct3501s
  834. client := &http.Client{}
  835. bytesData, _ := json.Marshal(data)
  836. var req *http.Request
  837. if miConfig.UserOrgId == 10215 {
  838. result := Gdyb3505(struct3501, miConfig.SecretKey)
  839. var dat map[string]interface{}
  840. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  841. fmt.Println(dat)
  842. } else {
  843. fmt.Println(err)
  844. }
  845. userJSONBytes, _ := json.Marshal(dat)
  846. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  847. utils.ErrorLog("解析失败:%v", err)
  848. res.Infcode = -1
  849. return res
  850. }
  851. return res
  852. } else {
  853. if miConfig.MdtrtareaAdmvs == "320921" {
  854. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  855. } else {
  856. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3501", bytes.NewReader(bytesData))
  857. }
  858. resp, _ := client.Do(req)
  859. defer resp.Body.Close()
  860. body, ioErr := ioutil.ReadAll(resp.Body)
  861. if ioErr != nil {
  862. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  863. res.Infcode = -1
  864. return res
  865. }
  866. var respJSON map[string]interface{}
  867. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  868. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  869. res.Infcode = -1
  870. return res
  871. }
  872. var resSix10265 ResultSix10265 //1101结果
  873. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  874. result, _ := json.Marshal(respJSON)
  875. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  876. utils.ErrorLog("解析失败:%v", err)
  877. res.Infcode = -1
  878. return res
  879. }
  880. res.InfRefmsgid = resSix10265.InfRefmsgid
  881. res.Output = resSix10265.Output
  882. res.ErrMsg = resSix10265.ErrMsg
  883. res.Cainfo = resSix10265.Cainfo
  884. res.WarnMsg = resSix10265.WarnMsg
  885. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  886. res.Infcode = infocode
  887. return res
  888. }
  889. }
  890. func Post3505ForDrug(org_id int64, infos *models.NewDrugWarehouseOutInfo) ResultSix {
  891. var res ResultSix
  892. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  893. data := make(map[string]interface{})
  894. var struct3505s []models.Struct3505
  895. var struct3505 models.Struct3505
  896. struct3505.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  897. struct3505.FixmedinsHilistId = miConfig.Code
  898. struct3505.FixmedinsHilistName = miConfig.OrgName
  899. struct3505.FixmedinsBchno = infos.NewDrugWarehouseInfo.BatchNumber
  900. struct3505.FixmedinsCode = miConfig.Code
  901. struct3505.OrgName = miConfig.OrgName
  902. struct3505.AccessKey = miConfig.AccessKey
  903. struct3505.RequestUrl = miConfig.Url
  904. struct3505.SecretKey = miConfig.SecretKey
  905. struct3505.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  906. struct3505.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  907. struct3505.FixmedinsBchno = infos.NewDrugWarehouseInfo.BatchNumber
  908. if org_id == 10188 {
  909. struct3505.PrscDrName = "王曙光"
  910. struct3505.PharName = "顾林玲"
  911. struct3505.PharPracCertNo = "K0404020449"
  912. } else if org_id == 10217 {
  913. struct3505.PrscDrName = "王云刚"
  914. struct3505.PharName = "施实芹"
  915. struct3505.PharPracCertNo = "1532050832051512010002"
  916. }
  917. timestamp := time.Now().Unix()
  918. tempTime := time.Unix(timestamp, 0)
  919. timeFormat := tempTime.Format("20060102150405")
  920. chrgBchno := rand.Intn(100000) + 10000
  921. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  922. struct3505.MdtrtSn = ipt_otp_no
  923. struct3505.ManuLotnum = infos.NewDrugWarehouseInfo.BatchNumber
  924. struct3505.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  925. //struct3505.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  926. struct3505.RxFlag = "0"
  927. struct3505.TrdnFlag = "1"
  928. struct3505.RtalDocno = strconv.FormatInt(int64(infos.ID), 10)
  929. struct3505.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  930. struct3505.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  931. if org_id == 10188 {
  932. struct3505.SelRetnOpterName = "孙欣欣"
  933. } else if org_id == 10217 {
  934. struct3505.SelRetnOpterName = "晁海燕"
  935. }
  936. struct3505s = append(struct3505s, struct3505)
  937. data["struct_3505s"] = struct3505s[0]
  938. client := &http.Client{}
  939. bytesData, _ := json.Marshal(data)
  940. var req *http.Request
  941. if miConfig.UserOrgId == 10215 {
  942. result := Gdyb3505(struct3505, miConfig.SecretKey)
  943. var dat map[string]interface{}
  944. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  945. fmt.Println(dat)
  946. } else {
  947. fmt.Println(err)
  948. }
  949. userJSONBytes, _ := json.Marshal(dat)
  950. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  951. utils.ErrorLog("解析失败:%v", err)
  952. res.Infcode = -1
  953. return res
  954. }
  955. return res
  956. } else {
  957. if miConfig.MdtrtareaAdmvs == "320921" {
  958. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  959. } else {
  960. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3505", bytes.NewReader(bytesData))
  961. }
  962. resp, _ := client.Do(req)
  963. defer resp.Body.Close()
  964. body, ioErr := ioutil.ReadAll(resp.Body)
  965. if ioErr != nil {
  966. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  967. res.Infcode = -1
  968. return res
  969. }
  970. var respJSON map[string]interface{}
  971. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  972. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  973. res.Infcode = -1
  974. return res
  975. }
  976. var resSix10265 ResultSix10265 //1101结果
  977. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  978. result, _ := json.Marshal(respJSON)
  979. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  980. utils.ErrorLog("解析失败:%v", err)
  981. res.Infcode = -1
  982. return res
  983. }
  984. res.InfRefmsgid = resSix10265.InfRefmsgid
  985. res.Output = resSix10265.Output
  986. res.ErrMsg = resSix10265.ErrMsg
  987. res.Cainfo = resSix10265.Cainfo
  988. res.WarnMsg = resSix10265.WarnMsg
  989. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  990. res.Infcode = infocode
  991. return res
  992. }
  993. }
  994. //销售退货
  995. func Post3506ForGoodInfo(org_id int64, infos *models.NewCancelStockInfo) ResultSix {
  996. var res ResultSix
  997. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  998. data := make(map[string]interface{})
  999. var struct3506s []models.Struct3506
  1000. var struct3506 models.Struct3506
  1001. struct3506.OrgName = miConfig.OrgName
  1002. struct3506.AccessKey = miConfig.AccessKey
  1003. struct3506.RequestUrl = miConfig.Url
  1004. struct3506.SecretKey = miConfig.SecretKey
  1005. struct3506.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  1006. struct3506.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  1007. struct3506.MedListCodg = infos.GoodInfo.MedicalInsuranceNumber
  1008. struct3506.FixmedinsHilistId = miConfig.Code
  1009. struct3506.FixmedinsHilistName = miConfig.OrgName
  1010. struct3506.FixmedinsBchno = infos.Number
  1011. struct3506.ManuLotnum = infos.Number
  1012. struct3506.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  1013. //struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  1014. struct3506.RxFlag = "0"
  1015. struct3506.TrdnFlag = "1"
  1016. struct3506.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  1017. struct3506.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  1018. //struct3506.SelRetnOpterName = "仓管员"
  1019. if org_id == 10188 {
  1020. struct3506.SelRetnOpterName = "孙欣欣"
  1021. } else if org_id == 10217 {
  1022. struct3506.SelRetnOpterName = "晁海燕"
  1023. }
  1024. struct3506.Memo = ""
  1025. struct3506s = append(struct3506s, struct3506)
  1026. data["struct_3506s"] = struct3506s
  1027. client := &http.Client{}
  1028. bytesData, _ := json.Marshal(data)
  1029. var req *http.Request
  1030. if miConfig.UserOrgId == 10215 {
  1031. result := Gdyb3506(struct3506, miConfig.SecretKey)
  1032. var dat map[string]interface{}
  1033. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1034. fmt.Println(dat)
  1035. } else {
  1036. fmt.Println(err)
  1037. }
  1038. userJSONBytes, _ := json.Marshal(dat)
  1039. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1040. utils.ErrorLog("解析失败:%v", err)
  1041. res.Infcode = -1
  1042. return res
  1043. }
  1044. return res
  1045. } else {
  1046. if miConfig.MdtrtareaAdmvs == "320921" {
  1047. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  1048. } else {
  1049. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  1050. }
  1051. resp, _ := client.Do(req)
  1052. defer resp.Body.Close()
  1053. body, ioErr := ioutil.ReadAll(resp.Body)
  1054. if ioErr != nil {
  1055. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1056. res.Infcode = -1
  1057. return res
  1058. }
  1059. var respJSON map[string]interface{}
  1060. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1061. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1062. res.Infcode = -1
  1063. return res
  1064. }
  1065. var resSix10265 ResultSix10265 //1101结果
  1066. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  1067. result, _ := json.Marshal(respJSON)
  1068. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  1069. utils.ErrorLog("解析失败:%v", err)
  1070. res.Infcode = -1
  1071. return res
  1072. }
  1073. res.InfRefmsgid = resSix10265.InfRefmsgid
  1074. res.Output = resSix10265.Output
  1075. res.ErrMsg = resSix10265.ErrMsg
  1076. res.Cainfo = resSix10265.Cainfo
  1077. res.WarnMsg = resSix10265.WarnMsg
  1078. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  1079. res.Infcode = infocode
  1080. return res
  1081. }
  1082. }
  1083. func Post3506ForDrug(org_id int64, infos *models.NewDrugCancelStockInfo) ResultSix {
  1084. var res ResultSix
  1085. miConfig, _ := FindMedicalInsuranceInfo(org_id)
  1086. data := make(map[string]interface{})
  1087. var struct3506s []models.Struct3506
  1088. var struct3506 models.Struct3506
  1089. struct3506.FixmedinsCode = miConfig.Code
  1090. struct3506.OrgName = miConfig.OrgName
  1091. struct3506.AccessKey = miConfig.AccessKey
  1092. struct3506.RequestUrl = miConfig.Url
  1093. struct3506.SecretKey = miConfig.SecretKey
  1094. struct3506.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  1095. struct3506.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  1096. struct3506.MedListCodg = infos.BaseDrugLib.MedicalInsuranceNumber
  1097. struct3506.FixmedinsHilistId = miConfig.Code
  1098. struct3506.FixmedinsHilistName = miConfig.OrgName
  1099. struct3506.FixmedinsBchno = infos.BatchNumber
  1100. struct3506.ManuLotnum = infos.BatchNumber
  1101. struct3506.ManuDate = time.Unix(infos.ProductDate, 0).Format("2006-01-02 15:04:05")
  1102. //struct3501.ExpyEnd = time.Unix(infos.ExpiryDate, 0).Format("2006-01-02 15:04:05")
  1103. struct3506.RxFlag = "0"
  1104. struct3506.TrdnFlag = "1"
  1105. struct3506.SelRetnCnt = strconv.FormatInt(int64(infos.Count), 10)
  1106. struct3506.SelRetnTime = time.Unix(infos.Ctime, 0).Format("2006-01-02 15:04:05")
  1107. //struct3506.SelRetnOpterName = "仓管员"
  1108. if org_id == 10188 {
  1109. struct3506.SelRetnOpterName = "孙欣欣"
  1110. } else if org_id == 10217 {
  1111. struct3506.SelRetnOpterName = "晁海燕"
  1112. }
  1113. struct3506.Memo = ""
  1114. struct3506s = append(struct3506s, struct3506)
  1115. data["struct_3506s"] = struct3506s[0]
  1116. client := &http.Client{}
  1117. bytesData, _ := json.Marshal(data)
  1118. var req *http.Request
  1119. if miConfig.UserOrgId == 10215 {
  1120. result := Gdyb3506(struct3506, miConfig.SecretKey)
  1121. var dat map[string]interface{}
  1122. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1123. fmt.Println(dat)
  1124. } else {
  1125. fmt.Println(err)
  1126. }
  1127. userJSONBytes, _ := json.Marshal(dat)
  1128. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1129. utils.ErrorLog("解析失败:%v", err)
  1130. res.Infcode = -1
  1131. return res
  1132. }
  1133. return res
  1134. } else {
  1135. if miConfig.MdtrtareaAdmvs == "320921" {
  1136. req, _ = http.NewRequest("POST", "http://192.168.2.110:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  1137. } else {
  1138. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3506", bytes.NewReader(bytesData))
  1139. }
  1140. resp, _ := client.Do(req)
  1141. defer resp.Body.Close()
  1142. body, ioErr := ioutil.ReadAll(resp.Body)
  1143. if ioErr != nil {
  1144. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1145. res.Infcode = -1
  1146. return res
  1147. }
  1148. var respJSON map[string]interface{}
  1149. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1150. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1151. res.Infcode = -1
  1152. return res
  1153. }
  1154. var resSix10265 ResultSix10265 //1101结果
  1155. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  1156. result, _ := json.Marshal(respJSON)
  1157. if err := json.Unmarshal([]byte(result), &resSix10265); err != nil {
  1158. utils.ErrorLog("解析失败:%v", err)
  1159. res.Infcode = -1
  1160. return res
  1161. }
  1162. res.InfRefmsgid = resSix10265.InfRefmsgid
  1163. res.Output = resSix10265.Output
  1164. res.ErrMsg = resSix10265.ErrMsg
  1165. res.Cainfo = resSix10265.Cainfo
  1166. res.WarnMsg = resSix10265.WarnMsg
  1167. infocode, _ := strconv.ParseInt(resSix10265.Infcode, 10, 64)
  1168. res.Infcode = infocode
  1169. return res
  1170. }
  1171. }