self_drug_api_congtroller.go 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
  69. beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
  70. beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
  71. beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
  72. beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
  73. beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Delete:DeleteDrugInventory")
  74. beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
  75. beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
  76. }
  77. func (this *SelfDrugApiController) GetCurrentPatient() {
  78. adminUserInfo := this.GetAdminUserInfo()
  79. orgId := adminUserInfo.CurrentOrgId
  80. patient, err := service.GetCurrentPatient(orgId)
  81. if err != nil {
  82. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  83. return
  84. }
  85. this.ServeSuccessJSON(map[string]interface{}{
  86. "patient": patient,
  87. })
  88. }
  89. func (this *SelfDrugApiController) GetAllDrugName() {
  90. adminUserInfo := this.GetAdminUserInfo()
  91. orgId := adminUserInfo.CurrentOrgId
  92. //查询药品库是否开启
  93. //configStock, _ := service.GetDrugStockConfig(orgId)
  94. //if configStock.IsOpen == 1 {
  95. //
  96. //}
  97. drugName, err := service.GetAllDrugName(orgId)
  98. if err != nil {
  99. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  100. return
  101. }
  102. this.ServeSuccessJSON(map[string]interface{}{
  103. "drugName": drugName,
  104. })
  105. }
  106. func (this *SelfDrugApiController) SaveDrugName() {
  107. adminUserInfo := this.GetAdminUserInfo()
  108. orgId := adminUserInfo.CurrentOrgId
  109. drug_name := this.GetString("drug_name")
  110. id, _ := this.GetInt64("id")
  111. //fmt.Println("drug_name", drug_name)
  112. drugName := models.XtDrugName{
  113. UserOrgId: orgId,
  114. DrugName: drug_name,
  115. Status: 1,
  116. CreatedTime: time.Now().Unix(),
  117. DrugId: id,
  118. }
  119. _, errcode := service.GetDrugName(drug_name, orgId)
  120. if errcode == gorm.ErrRecordNotFound {
  121. err := service.SaveDrugName(&drugName)
  122. if err != nil {
  123. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  124. return
  125. }
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "drugName": drugName,
  128. })
  129. } else {
  130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  131. return
  132. }
  133. }
  134. func (this *SelfDrugApiController) GetDrugNameList() {
  135. adminUserInfo := this.GetAdminUserInfo()
  136. orgId := adminUserInfo.CurrentOrgId
  137. list, err := service.GetDrugNameList(orgId)
  138. if err != nil {
  139. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  140. return
  141. }
  142. this.ServeSuccessJSON(map[string]interface{}{
  143. "list": list,
  144. })
  145. }
  146. func (this *SelfDrugApiController) GetRulleName() {
  147. adminUserInfo := this.GetAdminUserInfo()
  148. orgId := adminUserInfo.CurrentOrgId
  149. id, _ := this.GetInt64("id")
  150. drugId, _ := service.GetDrugId(id)
  151. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  152. if err != nil {
  153. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  154. return
  155. }
  156. this.ServeSuccessJSON(map[string]interface{}{
  157. "rullerList": rullerList,
  158. })
  159. }
  160. func (this *SelfDrugApiController) GetUnitByBaseId() {
  161. id, _ := this.GetInt64("id")
  162. baseList, err := service.GetUnitByBaseId(id)
  163. if err != nil {
  164. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  165. return
  166. }
  167. this.ServeSuccessJSON(map[string]interface{}{
  168. "baseList": baseList,
  169. })
  170. }
  171. func (this *SelfDrugApiController) SaveRulleName() {
  172. drug_name := this.GetString("drug_name")
  173. drug_spec := this.GetString("drug_spec")
  174. drug_stock_limit := this.GetString("drug_stock_limit")
  175. drug_name_id, _ := this.GetInt64("drug_name_id")
  176. drug_id, _ := this.GetInt64("drug_id")
  177. price, _ := this.GetInt64("price")
  178. prices := strconv.FormatInt(price, 10)
  179. durg_price, _ := strconv.ParseFloat(prices, 64)
  180. unit := this.GetString("unit")
  181. adminUserInfo := this.GetAdminUserInfo()
  182. orgId := adminUserInfo.CurrentOrgId
  183. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  184. drugSpecName := models.XtStandName{
  185. DrugName: drug_name,
  186. DrugSpec: drug_spec,
  187. DrugStockLimit: drug_stock_limit,
  188. DrugNameId: drug_name_id,
  189. Price: durg_price,
  190. MinUnit: unit,
  191. UserOrgId: orgId,
  192. Status: 1,
  193. CreatedTime: time.Now().Unix(),
  194. DrugId: drug_id,
  195. }
  196. //查询该机构下药品规格名称是否存在
  197. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  198. if errcode == gorm.ErrRecordNotFound {
  199. err := service.SaveRulleName(&drugSpecName)
  200. if err != nil {
  201. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  202. return
  203. }
  204. this.ServeSuccessJSON(map[string]interface{}{
  205. "RullerName": drugSpecName,
  206. })
  207. } else if errcode == nil {
  208. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  209. return
  210. }
  211. }
  212. func (this *SelfDrugApiController) EditRullerName() {
  213. id, _ := this.GetInt64("id")
  214. rullerDetail, err := service.GetRullerNameDetail(id)
  215. if err != nil {
  216. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  217. return
  218. }
  219. this.ServeSuccessJSON(map[string]interface{}{
  220. "rullerDetail": rullerDetail,
  221. })
  222. }
  223. func (this *SelfDrugApiController) UpdatedRullerName() {
  224. id, _ := this.GetInt64("id")
  225. drug_name := this.GetString("drug_name")
  226. drug_stock_limit := this.GetString("drug_stock_limit")
  227. price, _ := this.GetInt64("price")
  228. prices := strconv.FormatInt(price, 10)
  229. durg_price, _ := strconv.ParseFloat(prices, 64)
  230. drug_spec := this.GetString("drug_spec")
  231. unit := this.GetString("unit")
  232. drug_name_id, _ := this.GetInt64("drug_name_id")
  233. drug_id, _ := this.GetInt64("drug_id")
  234. RullerName := models.XtStandName{
  235. DrugName: drug_name,
  236. DrugStockLimit: drug_stock_limit,
  237. Price: durg_price,
  238. DrugSpec: drug_spec,
  239. MinUnit: unit,
  240. DrugNameId: drug_name_id,
  241. DrugId: drug_id,
  242. }
  243. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  244. if errcode == gorm.ErrRecordNotFound {
  245. err := service.UpdatedRullerName(id, &RullerName)
  246. if err != nil {
  247. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  248. return
  249. }
  250. this.ServeSuccessJSON(map[string]interface{}{
  251. "RullerName": RullerName,
  252. })
  253. } else if errcode == nil {
  254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  255. return
  256. }
  257. }
  258. func (this *SelfDrugApiController) GetAllDrugNameList() {
  259. adminUserInfo := this.GetAdminUserInfo()
  260. orgId := adminUserInfo.CurrentOrgId
  261. rullerName, err := service.GetAllDrugNameList(orgId)
  262. list, err := service.GetMedicalDrugNameList(orgId)
  263. if err != nil {
  264. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  265. return
  266. }
  267. this.ServeSuccessJSON(map[string]interface{}{
  268. "rullerName": rullerName,
  269. "list": list,
  270. })
  271. }
  272. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  273. id := this.GetString("id")
  274. adminUserInfo := this.GetAdminUserInfo()
  275. orgId := adminUserInfo.CurrentOrgId
  276. fmt.Println("orgid", orgId)
  277. drugName, err := service.GetRullerListByDrugName(id, orgId)
  278. if err != nil {
  279. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  280. return
  281. }
  282. this.ServeSuccessJSON(map[string]interface{}{
  283. "drugName": drugName,
  284. })
  285. }
  286. func (this *SelfDrugApiController) SaveSelfMedicines() {
  287. dataBody := make(map[string]interface{}, 0)
  288. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  289. fmt.Println(err)
  290. patient_id := int64(dataBody["patient_id"].(float64))
  291. medicineData, _ := dataBody["medicineData"].([]interface{})
  292. adminUserInfo := this.GetAdminUserInfo()
  293. orgId := adminUserInfo.CurrentOrgId
  294. for _, item := range medicineData {
  295. items := item.(map[string]interface{})
  296. drug_name := items["drug_name"].(string)
  297. drug_name_id := int64(items["drug_name_id"].(float64))
  298. drug_spec := items["drug_spec"].(string)
  299. min_unit := items["min_unit"].(string)
  300. drug_id := int64(items["drug_id"].(float64))
  301. //根据drug_id
  302. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  303. medical := models.XtSelfMedical{
  304. DrugName: drug_name,
  305. DrugNameId: drug_name_id,
  306. DrugSpec: drug_spec,
  307. CreatedTime: time.Now().Unix(),
  308. Status: 1,
  309. UserOrgId: orgId,
  310. PatientId: patient_id,
  311. MinUnit: min_unit,
  312. ExecutionFrequency: drugMedical.ExecutionFrequency,
  313. PrescribingNumber: drugMedical.PrescribingNumber,
  314. DeliveryWay: drugMedical.DeliveryWay,
  315. SingleDose: drugMedical.SingleDose,
  316. DrugId: drug_id,
  317. }
  318. //查询同个病人同个药品同个规格是否已存在
  319. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  320. if errcode == gorm.ErrRecordNotFound {
  321. err := service.CreateSelfMedical(&medical)
  322. fmt.Println(err)
  323. } else if errcode == nil {
  324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  325. return
  326. }
  327. }
  328. returnData := make(map[string]interface{}, 0)
  329. returnData["msg"] = "ok"
  330. this.ServeSuccessJSON(returnData)
  331. return
  332. }
  333. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  334. adminUserInfo := this.GetAdminUserInfo()
  335. orgid := adminUserInfo.CurrentOrgId
  336. //fmt.Println(orgid)
  337. appId := adminUserInfo.CurrentAppId
  338. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  339. if err != nil {
  340. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  341. return
  342. }
  343. this.ServeSuccessJSON(map[string]interface{}{
  344. "staff": staff,
  345. })
  346. }
  347. func (this *SelfDrugApiController) SaveStock() {
  348. timeLayout := "2006-01-02"
  349. loc, _ := time.LoadLocation("Local")
  350. start_time := this.GetString("start_time")
  351. fmt.Println("start_time", start_time)
  352. admin_user_id, _ := this.GetInt64("admin_user_id")
  353. fmt.Println("admin_user_id", admin_user_id)
  354. patient_id, _ := this.GetInt64("patient_id")
  355. dataBody := make(map[string]interface{}, 0)
  356. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  357. fmt.Println(err)
  358. stocks, _ := dataBody["stocks"].([]interface{})
  359. adminUserInfo := this.GetAdminUserInfo()
  360. orgId := adminUserInfo.CurrentOrgId
  361. for _, item := range stocks {
  362. items := item.(map[string]interface{})
  363. drug_name := items["drug_name"].(string)
  364. fmt.Println("drug_name", drug_name)
  365. drug_name_id := int64(items["drug_name_id"].(float64))
  366. fmt.Println("parient_id", drug_name_id)
  367. drug_spec := items["drug_spec"].(string)
  368. store_number := items["store_number"].(string)
  369. fmt.Println("store_number", store_number)
  370. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  371. remarks := items["remarks"].(string)
  372. min_unit := items["min_unit"].(string)
  373. medic_id := int64(items["id"].(float64))
  374. timeStr := time.Now().Format("2006-01-02")
  375. timeArr := strings.Split(timeStr, "-")
  376. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  377. total = total + 1
  378. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  379. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  380. number = number + total
  381. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  382. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  383. stock := models.XtSelfStock{
  384. DrugName: drug_name,
  385. DrugNameId: drug_name_id,
  386. DrugSpec: drug_spec,
  387. StoreNumber: storeNumber,
  388. Remarks: remarks,
  389. AdminUserId: admin_user_id,
  390. StorckTime: theTime.Unix(),
  391. CreatedTime: time.Now().Unix(),
  392. Status: 1,
  393. UserOrgId: orgId,
  394. StockInNumber: warehousing_in_order,
  395. PatientId: patient_id,
  396. MinUnit: min_unit,
  397. StorageMode: 1,
  398. MedicId: medic_id,
  399. }
  400. err := service.CreateStock(&stock)
  401. fmt.Println("err", err)
  402. }
  403. returnData := make(map[string]interface{}, 0)
  404. returnData["msg"] = "ok"
  405. this.ServeSuccessJSON(returnData)
  406. return
  407. }
  408. func (this *SelfDrugApiController) SaveOutStock() {
  409. timeLayout := "2006-01-02"
  410. loc, _ := time.LoadLocation("Local")
  411. start_time := this.GetString("start_time")
  412. admin_user_id, _ := this.GetInt64("admin_user_id")
  413. patient_id, _ := this.GetInt64("patient_id")
  414. dataBody := make(map[string]interface{}, 0)
  415. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  416. fmt.Println(err)
  417. outStocks, _ := dataBody["outStocks"].([]interface{})
  418. adminUserInfo := this.GetAdminUserInfo()
  419. orgId := adminUserInfo.CurrentOrgId
  420. for _, item := range outStocks {
  421. items := item.(map[string]interface{})
  422. drug_name := items["drug_name"].(string)
  423. drug_name_id := int64(items["drug_name_id"].(float64))
  424. drug_spec := items["drug_spec"].(string)
  425. outstore_number := items["outstore_number"].(string)
  426. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  427. remarks := items["remarks"].(string)
  428. medic_id := int64(items["id"].(float64))
  429. timeStr := time.Now().Format("2006-01-02")
  430. timeArr := strings.Split(timeStr, "-")
  431. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  432. total = total + 1
  433. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  434. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  435. number = number + total
  436. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  437. fmt.Println(remarks)
  438. fmt.Println(items)
  439. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  440. stock := models.XtSelfOutStock{
  441. DrugName: drug_name,
  442. DrugNameId: drug_name_id,
  443. DrugSpec: drug_spec,
  444. OutstoreNumber: outStoreNumber,
  445. Remarks: remarks,
  446. AdminUserId: admin_user_id,
  447. StorckTime: theTime.Unix(),
  448. CreatedTime: time.Now().Unix(),
  449. Status: 1,
  450. UserOrgId: orgId,
  451. StockOutNumber: warehousing_out_order,
  452. PatientId: patient_id,
  453. ExitMode: 1,
  454. MedicId: medic_id,
  455. }
  456. err := service.CreateOutStock(&stock)
  457. fmt.Println("err", err)
  458. }
  459. returnData := make(map[string]interface{}, 0)
  460. returnData["msg"] = "ok"
  461. this.ServeSuccessJSON(returnData)
  462. return
  463. }
  464. func (this *SelfDrugApiController) DeleteDrugById() {
  465. id, _ := this.GetInt64("id")
  466. drug_name := this.GetString("drug_name")
  467. adminUserInfo := this.GetAdminUserInfo()
  468. orgId := adminUserInfo.CurrentOrgId
  469. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  470. if errcode == gorm.ErrRecordNotFound {
  471. service.DeleteDrugName(id)
  472. returnData := make(map[string]interface{}, 0)
  473. returnData["msg"] = "ok"
  474. this.ServeSuccessJSON(returnData)
  475. } else if errcode == nil {
  476. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  477. return
  478. }
  479. }
  480. func (this *SelfDrugApiController) SaveRadio() {
  481. radio, _ := this.GetInt64("radio")
  482. adminUserInfo := this.GetAdminUserInfo()
  483. orgId := adminUserInfo.CurrentOrgId
  484. drugSet := models.XtDrugSet{
  485. DrugStart: radio,
  486. UserOrgId: orgId,
  487. Status: 1,
  488. CreatedTime: time.Now().Unix(),
  489. }
  490. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  491. if errcode == gorm.ErrRecordNotFound {
  492. err := service.SaveRadio(&drugSet)
  493. if err != nil {
  494. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  495. return
  496. }
  497. this.ServeSuccessJSON(map[string]interface{}{
  498. "drugSet": drugSet,
  499. })
  500. } else if errcode == nil {
  501. err := service.UpdateDrugSet(&drugSet, orgId)
  502. if err != nil {
  503. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  504. return
  505. }
  506. this.ServeSuccessJSON(map[string]interface{}{
  507. "drugSet": drugSet,
  508. })
  509. }
  510. }
  511. func (this *SelfDrugApiController) DeleteDrugStand() {
  512. id, _ := this.GetInt64("id")
  513. name := this.GetString("name")
  514. adminUserInfo := this.GetAdminUserInfo()
  515. orgId := adminUserInfo.CurrentOrgId
  516. _, errcode := service.GetMedicalsByName(orgId, name)
  517. if errcode == gorm.ErrRecordNotFound {
  518. err := service.DeleteDrugStand(id)
  519. fmt.Println(err)
  520. returnData := make(map[string]interface{}, 0)
  521. returnData["msg"] = "ok"
  522. this.ServeSuccessJSON(returnData)
  523. } else if errcode == nil {
  524. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  525. return
  526. }
  527. }
  528. func (this *SelfDrugApiController) GetStockList() {
  529. patientid, _ := this.GetInt64("id")
  530. start_time := this.GetString("start_time")
  531. fmt.Println("开始时间", start_time)
  532. timeLayout := "2006-01-02"
  533. loc, _ := time.LoadLocation("Local")
  534. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  535. startimeUnix := theTime.Unix()
  536. keyword := this.GetString("keyword")
  537. fmt.Println("keyword", keyword)
  538. adminUserInfo := this.GetAdminUserInfo()
  539. orgId := adminUserInfo.CurrentOrgId
  540. //获取
  541. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  542. //统计总数量
  543. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  544. //统计出库数量
  545. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  546. //统计该病人时间段内出库条数
  547. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  548. if err != nil {
  549. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  550. return
  551. }
  552. this.ServeSuccessJSON(map[string]interface{}{
  553. "medicalList": medicalList,
  554. "stocklist": stocklist,
  555. "outStocklist": outStocklist,
  556. "outList": outList,
  557. })
  558. }
  559. func (this *SelfDrugApiController) DeleteDrugName() {
  560. drug_name := this.GetString("drugname")
  561. patient_id, _ := this.GetInt64("patientid")
  562. //查询该药品是否出库
  563. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  564. if len(stocklist) == 0 {
  565. //删除该药品
  566. service.DeleteDrugStockNumber(drug_name, patient_id)
  567. returnData := make(map[string]interface{}, 0)
  568. returnData["msg"] = "ok"
  569. this.ServeSuccessJSON(returnData)
  570. } else {
  571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  572. return
  573. }
  574. }
  575. func (this *SelfDrugApiController) GetDrugDetail() {
  576. timeLayout := "2006-01-02"
  577. loc, _ := time.LoadLocation("Local")
  578. drug_name := this.GetString("drug_name")
  579. drug_spec := this.GetString("drug_spec")
  580. start_time := this.GetString("start_time")
  581. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  582. end_time := this.GetString("end_time")
  583. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  584. patient_id, _ := this.GetInt64("patient_id")
  585. adminUserInfo := this.GetAdminUserInfo()
  586. orgId := adminUserInfo.CurrentOrgId
  587. //查询入库明细
  588. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  589. //查询出库明细
  590. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  591. if err != nil {
  592. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  593. return
  594. }
  595. this.ServeSuccessJSON(map[string]interface{}{
  596. "stockDetail": stockDetail,
  597. "outStockDetail": outStockDetail,
  598. })
  599. }
  600. func (this *SelfDrugApiController) GetAllPatientStockList() {
  601. timeLayout := "2006-01-02"
  602. loc, _ := time.LoadLocation("Local")
  603. drug_name := this.GetString("drug_name")
  604. drug_spec := this.GetString("drug_spec")
  605. start_time := this.GetString("start_time")
  606. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  607. startUnix := theTime.Unix()
  608. end_time := this.GetString("end_time")
  609. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  610. endTimeUnix := endTimes.Unix()
  611. keywords := this.GetString("search_input")
  612. adminUserInfo := this.GetAdminUserInfo()
  613. orgId := adminUserInfo.CurrentOrgId
  614. //入库
  615. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  616. //出库
  617. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  618. if err != nil {
  619. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  620. return
  621. }
  622. this.ServeSuccessJSON(map[string]interface{}{
  623. "stocklist": stocklist,
  624. "outStockList": outStockList,
  625. })
  626. }
  627. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  628. patient_id, _ := this.GetInt64("patient_id")
  629. fmt.Println("patient_id", patient_id)
  630. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  631. if err != nil {
  632. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  633. return
  634. }
  635. this.ServeSuccessJSON(map[string]interface{}{
  636. "medicalList": medicalList,
  637. })
  638. }
  639. func (this *SelfDrugApiController) GetSelfMedicalList() {
  640. patient_id, _ := this.GetInt64("patient_id")
  641. adminUserInfo := this.GetAdminUserInfo()
  642. orgId := adminUserInfo.CurrentOrgId
  643. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  644. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  645. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  646. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  647. this.ServeSuccessJSON(map[string]interface{}{
  648. "base_drug_config": drugStockConfig,
  649. "private_drug_config": privateDrugConfig,
  650. "base_drug_list": drugList,
  651. "private_drug_list": privateDrugList,
  652. })
  653. ////查询是否开启药品库
  654. //config, _ := service.GetDruckStockConfig(orgId)
  655. //
  656. //fmt.Println("--------------------------",config.IsOpen)
  657. ////开启
  658. //if config.IsOpen == 1 {
  659. // //查询该机构下的药品库
  660. // drugName, _ := service.GetAllDrugName(orgId)
  661. //
  662. // //查询该机构是否开启自备药
  663. // medical, _ := service.GetSetSelfMedical(orgId)
  664. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  665. // //开启
  666. // if medical.DrugStart == 1 {
  667. // list, err := service.GetSelfMedicalList(patient_id)
  668. // if err != nil {
  669. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  670. // return
  671. // }
  672. // this.ServeSuccessJSON(map[string]interface{}{
  673. // "medicalList": list,
  674. // "drugName": drugName,
  675. // })
  676. // } else {
  677. // this.ServeSuccessJSON(map[string]interface{}{
  678. // "drugName": drugName,
  679. // })
  680. // }
  681. //}
  682. }
  683. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  684. drug_name := this.GetString("drug_name")
  685. patient_id, _ := this.GetInt64("patient_id")
  686. way, _ := this.GetInt64("way")
  687. adminUserInfo := this.GetAdminUserInfo()
  688. orgId := adminUserInfo.CurrentOrgId
  689. drug_id, _ := this.GetInt64("id")
  690. //从基础库查询
  691. if way == 1 {
  692. //查询基础库数据
  693. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  694. //统计入库数量
  695. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  696. //统计出库数量
  697. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  698. if err != nil {
  699. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  700. return
  701. }
  702. this.ServeSuccessJSON(map[string]interface{}{
  703. "drugspec": medcal,
  704. "countInfo": countInfo,
  705. "countout": countout,
  706. })
  707. }
  708. //从自备药库查询
  709. if way == 2 {
  710. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  711. if err != nil {
  712. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  713. return
  714. }
  715. this.ServeSuccessJSON(map[string]interface{}{
  716. "drugspec": drugspec,
  717. })
  718. }
  719. }
  720. func (this *SelfDrugApiController) GetDrugSet() {
  721. adminUserInfo := this.GetAdminUserInfo()
  722. orgId := adminUserInfo.CurrentOrgId
  723. drugSet, err := service.GetDrugSet(orgId)
  724. if err != nil {
  725. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  726. return
  727. }
  728. this.ServeSuccessJSON(map[string]interface{}{
  729. "drugSet": drugSet,
  730. })
  731. }
  732. func (this *SelfDrugApiController) GetAllMedicalList() {
  733. adminUserInfo := this.GetAdminUserInfo()
  734. orgId := adminUserInfo.CurrentOrgId
  735. list, err := service.GetAllMedicalList(orgId)
  736. if err != nil {
  737. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  738. return
  739. }
  740. this.ServeSuccessJSON(map[string]interface{}{
  741. "drugName": list,
  742. })
  743. }
  744. func (this *SelfDrugApiController) GetStandName() {
  745. name := this.GetString("name")
  746. adminUserInfo := this.GetAdminUserInfo()
  747. orgId := adminUserInfo.CurrentOrgId
  748. rullerlist, err := service.GetRulleName(orgId, name)
  749. if err != nil {
  750. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  751. return
  752. }
  753. this.ServeSuccessJSON(map[string]interface{}{
  754. "rullerlist": rullerlist,
  755. })
  756. }
  757. func (this *SelfDrugApiController) GetRullerList() {
  758. id, _ := this.GetInt64("id")
  759. adminUserInfo := this.GetAdminUserInfo()
  760. orgId := adminUserInfo.CurrentOrgId
  761. rullerList, err := service.GetRulleList(orgId, id)
  762. if err != nil {
  763. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  764. return
  765. }
  766. this.ServeSuccessJSON(map[string]interface{}{
  767. "rullerlist": rullerList,
  768. })
  769. }
  770. func (this *SelfDrugApiController) DeleteDrugNameById() {
  771. id, _ := this.GetInt64("id")
  772. drug_name := this.GetString("drug_name")
  773. adminUserInfo := this.GetAdminUserInfo()
  774. orgId := adminUserInfo.CurrentOrgId
  775. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  776. if errcode == gorm.ErrRecordNotFound {
  777. service.DeleteDrugNameById(id)
  778. returnData := make(map[string]interface{}, 0)
  779. returnData["msg"] = "ok"
  780. this.ServeSuccessJSON(returnData)
  781. } else if errcode == nil {
  782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  783. return
  784. }
  785. }
  786. func (this *SelfDrugApiController) GetPatientDetail() {
  787. id, _ := this.GetInt64("id")
  788. adminUserInfo := this.GetAdminUserInfo()
  789. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  790. if err != nil {
  791. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  792. return
  793. }
  794. this.ServeSuccessJSON(map[string]interface{}{
  795. "patientDetail": patientDetail,
  796. })
  797. }
  798. //func (this *SelfDrugApiController) ToPatientDetail() {
  799. //
  800. // keyword := this.GetString("keyword")
  801. // adminUser := this.GetAdminUserInfo()
  802. // orgId := adminUser.CurrentOrgId
  803. // patient, err := service.ToSeachPatient(keyword, orgId)
  804. // if err != nil {
  805. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  806. // return
  807. // }
  808. // this.ServeSuccessJSON(map[string]interface{}{
  809. // "patient": patient,
  810. // })
  811. //}
  812. func (this *SelfDrugApiController) GetSelfStockQuery() {
  813. adminUserInfo := this.GetAdminUserInfo()
  814. orgId := adminUserInfo.CurrentOrgId
  815. type_name, _ := this.GetInt64("type_name")
  816. keywords := this.GetString("keywords")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. start_time := this.GetString("start_time")
  820. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  821. startUnix := theTime.Unix()
  822. end_time := this.GetString("end_time")
  823. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  824. endTimeUnix := endTimes.Unix()
  825. page, _ := this.GetInt64("page")
  826. limit, _ := this.GetInt64("limit")
  827. //统计入库数量
  828. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  829. //统计出库数量
  830. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  831. if err != nil {
  832. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  833. return
  834. }
  835. this.ServeSuccessJSON(map[string]interface{}{
  836. "stockQuery": stockQuery,
  837. "total": total,
  838. "stockOutQuery": stockOutQuery,
  839. })
  840. }
  841. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  842. keyword := this.GetString("keyword")
  843. orgId := this.GetAdminUserInfo().CurrentOrgId
  844. list, err := service.PostSearchDrugWarehouseList(keyword, orgId)
  845. manufacturerList, err := service.GetAllManufacturerList(orgId)
  846. dealerList, err := service.GetAllDealerList(orgId)
  847. if err != nil {
  848. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  849. return
  850. }
  851. this.ServeSuccessJSON(map[string]interface{}{
  852. "list": list,
  853. "manufacturerList": manufacturerList,
  854. "dealerList": dealerList,
  855. })
  856. }
  857. func (this *SelfDrugApiController) SaveDrugPrice() {
  858. fmt.Println("999999999999999999999")
  859. timeLayout := "2006-01-02"
  860. loc, _ := time.LoadLocation("Local")
  861. dataBody := make(map[string]interface{}, 0)
  862. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  863. fmt.Println(err)
  864. tableData, _ := dataBody["tableData"].([]interface{})
  865. fmt.Println("999939433443", tableData)
  866. if len(tableData) > 0 {
  867. for _, item := range tableData {
  868. items := item.(map[string]interface{})
  869. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  870. utils.ErrorLog("drug_name")
  871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  872. return
  873. }
  874. drug_name := items["drug_name"].(string)
  875. fmt.Println("drug_aname23232323232", drug_name)
  876. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  877. utils.ErrorLog("drug_name")
  878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  879. return
  880. }
  881. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  882. utils.ErrorLog("retail_price")
  883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  887. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  888. utils.ErrorLog("warehousing_order")
  889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  890. return
  891. }
  892. warehousing_order := items["warehousing_order"].(string)
  893. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  894. utils.ErrorLog("number")
  895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  896. return
  897. }
  898. number := items["number"].(string)
  899. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  900. utils.ErrorLog("dealer")
  901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  902. return
  903. }
  904. dealer := items["dealer"].(string)
  905. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  906. utils.ErrorLog("manufacturer")
  907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  908. return
  909. }
  910. manufacturer := items["manufacturer"].(string)
  911. //if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  912. // utils.ErrorLog("specification_name")
  913. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  914. // return
  915. //}
  916. //specification_name := items["specification_name"].(string)
  917. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  918. utils.ErrorLog("remark")
  919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. remark := items["remark"].(string)
  923. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  924. utils.ErrorLog("warehousing_unit")
  925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  926. return
  927. }
  928. warehousing_unit := items["warehousing_unit"].(string)
  929. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  930. utils.ErrorLog("last_price")
  931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  932. return
  933. }
  934. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  935. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  936. utils.ErrorLog("count")
  937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. count := int64(items["count"].(float64))
  941. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  942. utils.ErrorLog("new_price")
  943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  944. return
  945. }
  946. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  947. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  948. utils.ErrorLog("drug_id")
  949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  950. return
  951. }
  952. drug_id := int64(items["drug_id"].(float64))
  953. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  954. utils.ErrorLog("start_time")
  955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. var startTime int64
  959. start_time := items["start_time"].(string)
  960. if len(start_time) > 0 {
  961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  962. if err != nil {
  963. fmt.Println(err)
  964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. startTime = theTime.Unix()
  968. }
  969. orgId := this.GetAdminUserInfo().CurrentOrgId
  970. Creater := this.GetAdminUserInfo().AdminUser.Id
  971. drugAdjust := models.XtDrugAdjustPrice{
  972. DrugName: drug_name,
  973. SpecificationName: "",
  974. WarehousingUnit: warehousing_unit,
  975. Count: count,
  976. LastPrice: last_price,
  977. RetailPrice: retail_price,
  978. NewPrice: new_price,
  979. Manufacturer: manufacturer,
  980. Dealer: dealer,
  981. Remark: remark,
  982. DrugId: drug_id,
  983. UserOrgId: orgId,
  984. Ctime: time.Now().Unix(),
  985. Mtime: 0,
  986. Status: 1,
  987. WarehousingOrder: warehousing_order,
  988. Number: number,
  989. StartTime: startTime,
  990. Creater: Creater,
  991. Checker: 0,
  992. CheckerStatus: 2,
  993. CheckerTime: 0,
  994. }
  995. err := service.CreateDrugPrice(drugAdjust)
  996. fmt.Println(err)
  997. }
  998. }
  999. returnData := make(map[string]interface{}, 0)
  1000. returnData["msg"] = "ok"
  1001. this.ServeSuccessJSON(returnData)
  1002. return
  1003. }
  1004. func (this *SelfDrugApiController) GetDrugPriceList() {
  1005. timeLayout := "2006-01-02"
  1006. loc, _ := time.LoadLocation("Local")
  1007. dataBody := make(map[string]interface{}, 0)
  1008. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1009. fmt.Println(err)
  1010. orgId := this.GetAdminUserInfo().CurrentOrgId
  1011. keyword := this.GetString("keyword")
  1012. start_time := this.GetString("start_time")
  1013. end_time := this.GetString("end_time")
  1014. var startTime int64
  1015. if len(start_time) > 0 {
  1016. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1017. if err != nil {
  1018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1019. return
  1020. }
  1021. startTime = theTime.Unix()
  1022. }
  1023. var endTime int64
  1024. if len(end_time) > 0 {
  1025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1026. if err != nil {
  1027. utils.ErrorLog(err.Error())
  1028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1029. return
  1030. }
  1031. endTime = theTime.Unix()
  1032. }
  1033. limit, _ := this.GetInt64("limit")
  1034. page, _ := this.GetInt64("page")
  1035. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1036. doctorList, err := service.GetAllDoctorThree(orgId)
  1037. if err != nil {
  1038. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1039. return
  1040. }
  1041. this.ServeSuccessJSON(map[string]interface{}{
  1042. "total": total,
  1043. "list": list,
  1044. "doctorList": doctorList,
  1045. })
  1046. }
  1047. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1048. timeLayout := "2006-01-02"
  1049. loc, _ := time.LoadLocation("Local")
  1050. dataBody := make(map[string]interface{}, 0)
  1051. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1052. fmt.Println(err)
  1053. idstr := this.GetString("ids")
  1054. ids := strings.Split(idstr, ",")
  1055. check_time := this.GetString("check_time")
  1056. var checkTime int64
  1057. if len(check_time) > 0 {
  1058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1059. if err != nil {
  1060. fmt.Println(err)
  1061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1062. return
  1063. }
  1064. checkTime = theTime.Unix()
  1065. }
  1066. checker, _ := this.GetInt64("checker")
  1067. adjustPrice := models.XtDrugAdjustPrice{
  1068. Checker: checker,
  1069. CheckerStatus: 1,
  1070. CheckerTime: checkTime,
  1071. }
  1072. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1073. fmt.Println("err", err)
  1074. this.ServeSuccessJSON(map[string]interface{}{
  1075. "adjustPrice": adjustPrice,
  1076. })
  1077. }
  1078. func (this *SelfDrugApiController) SaveDrugDamage() {
  1079. fmt.Println("999999999999999999999")
  1080. timeLayout := "2006-01-02"
  1081. loc, _ := time.LoadLocation("Local")
  1082. dataBody := make(map[string]interface{}, 0)
  1083. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1084. fmt.Println(err)
  1085. tableData, _ := dataBody["tableData"].([]interface{})
  1086. fmt.Println("999939433443", tableData)
  1087. if len(tableData) > 0 {
  1088. for _, item := range tableData {
  1089. items := item.(map[string]interface{})
  1090. drug_name := items["drug_name"].(string)
  1091. fmt.Println("durg_nae232333223332232323323223232323", drug_name)
  1092. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1093. utils.ErrorLog("drug_name")
  1094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1098. utils.ErrorLog("retail_price")
  1099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1100. return
  1101. }
  1102. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1103. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1104. utils.ErrorLog("warehousing_order")
  1105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. warehousing_order := items["warehousing_order"].(string)
  1109. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1110. utils.ErrorLog("number")
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1112. return
  1113. }
  1114. number := items["number"].(string)
  1115. //if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1116. // utils.ErrorLog("dealer")
  1117. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1118. // return
  1119. //}
  1120. //dealer := items["dealer"].(string)
  1121. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1122. utils.ErrorLog("manufacturer")
  1123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1124. return
  1125. }
  1126. manufacturer := items["manufacturer"].(string)
  1127. //if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1128. // utils.ErrorLog("specification_name")
  1129. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. // return
  1131. //}
  1132. //specification_name := items["specification_name"].(string)
  1133. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1134. utils.ErrorLog("remark")
  1135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1136. return
  1137. }
  1138. remark := items["remark"].(string)
  1139. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1140. utils.ErrorLog("warehousing_unit")
  1141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1142. return
  1143. }
  1144. warehousing_unit := items["warehousing_unit"].(string)
  1145. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1146. utils.ErrorLog("last_price")
  1147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1148. return
  1149. }
  1150. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1151. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1152. utils.ErrorLog("count")
  1153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1154. return
  1155. }
  1156. count := int64(items["count"].(float64))
  1157. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1158. utils.ErrorLog("new_price")
  1159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1163. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1164. utils.ErrorLog("drug_id")
  1165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1166. return
  1167. }
  1168. drug_id := int64(items["drug_id"].(float64))
  1169. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1170. utils.ErrorLog("start_time")
  1171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1172. return
  1173. }
  1174. var startTime int64
  1175. start_time := items["start_time"].(string)
  1176. if len(start_time) > 0 {
  1177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1178. if err != nil {
  1179. fmt.Println(err)
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. startTime = theTime.Unix()
  1184. }
  1185. orgId := this.GetAdminUserInfo().CurrentOrgId
  1186. Creater := this.GetAdminUserInfo().AdminUser.Id
  1187. drugDamage := models.XtDrugDamage{
  1188. DrugName: drug_name,
  1189. SpecificationName: "",
  1190. WarehousingUnit: warehousing_unit,
  1191. Count: count,
  1192. LastPrice: last_price,
  1193. RetailPrice: retail_price,
  1194. NewPrice: new_price,
  1195. Manufacturer: manufacturer,
  1196. Dealer: "",
  1197. Remark: remark,
  1198. DrugId: drug_id,
  1199. UserOrgId: orgId,
  1200. Ctime: time.Now().Unix(),
  1201. Mtime: 0,
  1202. Status: 1,
  1203. WarehousingOrder: warehousing_order,
  1204. Number: number,
  1205. StartTime: startTime,
  1206. Creater: Creater,
  1207. Checker: 0,
  1208. CheckerStatus: 2,
  1209. CheckerTime: 0,
  1210. }
  1211. err := service.CreateDrugDamage(drugDamage)
  1212. fmt.Println(err)
  1213. }
  1214. }
  1215. returnData := make(map[string]interface{}, 0)
  1216. returnData["msg"] = "ok"
  1217. this.ServeSuccessJSON(returnData)
  1218. }
  1219. func (this *SelfDrugApiController) GetDrugDamageList() {
  1220. timeLayout := "2006-01-02"
  1221. loc, _ := time.LoadLocation("Local")
  1222. dataBody := make(map[string]interface{}, 0)
  1223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1224. fmt.Println(err)
  1225. orgId := this.GetAdminUserInfo().CurrentOrgId
  1226. keyword := this.GetString("keyword")
  1227. fmt.Println("keywoer2r2r32rwrwr", keyword)
  1228. start_time := this.GetString("start_time")
  1229. end_time := this.GetString("end_time")
  1230. var startTime int64
  1231. if len(start_time) > 0 {
  1232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1233. if err != nil {
  1234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1235. return
  1236. }
  1237. startTime = theTime.Unix()
  1238. }
  1239. var endTime int64
  1240. if len(end_time) > 0 {
  1241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1242. if err != nil {
  1243. utils.ErrorLog(err.Error())
  1244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. }
  1247. endTime = theTime.Unix()
  1248. }
  1249. limit, _ := this.GetInt64("limit")
  1250. page, _ := this.GetInt64("page")
  1251. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page)
  1252. doctorList, err := service.GetAllDoctorThree(orgId)
  1253. if err != nil {
  1254. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1255. return
  1256. }
  1257. this.ServeSuccessJSON(map[string]interface{}{
  1258. "total": total,
  1259. "list": list,
  1260. "doctorList": doctorList,
  1261. })
  1262. }
  1263. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1264. timeLayout := "2006-01-02"
  1265. loc, _ := time.LoadLocation("Local")
  1266. dataBody := make(map[string]interface{}, 0)
  1267. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1268. fmt.Println(err)
  1269. idstr := this.GetString("ids")
  1270. ids := strings.Split(idstr, ",")
  1271. check_time := this.GetString("check_time")
  1272. var checkTime int64
  1273. if len(check_time) > 0 {
  1274. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1275. if err != nil {
  1276. fmt.Println(err)
  1277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1278. return
  1279. }
  1280. checkTime = theTime.Unix()
  1281. }
  1282. checker, _ := this.GetInt64("checker")
  1283. damage := models.XtDrugDamage{
  1284. Checker: checker,
  1285. CheckerStatus: 1,
  1286. CheckerTime: checkTime,
  1287. }
  1288. err = service.UpdateDrugDamage(ids, damage)
  1289. fmt.Println(err)
  1290. this.ServeSuccessJSON(map[string]interface{}{
  1291. "damage": damage,
  1292. })
  1293. }
  1294. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1295. id, _ := this.GetInt64("id")
  1296. detail, err := service.GetDrugModifyPrice(id)
  1297. fmt.Println(err)
  1298. this.ServeSuccessJSON(map[string]interface{}{
  1299. "detail": detail,
  1300. })
  1301. }
  1302. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1303. drug_name := this.GetString("drug_name")
  1304. retailPrice := this.GetString("retail_price")
  1305. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1306. newPrice := this.GetString("new_price")
  1307. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1308. count, _ := this.GetInt64("count")
  1309. remark := this.GetString("remark")
  1310. id, _ := this.GetInt64("id")
  1311. adjustPrice := models.XtDrugAdjustPrice{
  1312. DrugName: drug_name,
  1313. Count: count,
  1314. RetailPrice: retail_price,
  1315. NewPrice: new_price,
  1316. Remark: remark,
  1317. }
  1318. err := service.ModifyDrugPrice(id, adjustPrice)
  1319. fmt.Println(err)
  1320. this.ServeSuccessJSON(map[string]interface{}{
  1321. "adjustPrice": adjustPrice,
  1322. })
  1323. }
  1324. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1325. ids := this.GetString("ids")
  1326. idsSplit := strings.Split(ids, ",")
  1327. list, err := service.GetModifyPricePrint(idsSplit)
  1328. fmt.Println(err)
  1329. this.ServeSuccessJSON(map[string]interface{}{
  1330. "list": list,
  1331. })
  1332. }
  1333. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1334. id, _ := this.GetInt64("id")
  1335. detail, _ := service.GetDrugDamageDetail(id)
  1336. this.ServeSuccessJSON(map[string]interface{}{
  1337. "detail": detail,
  1338. })
  1339. }
  1340. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1341. id, _ := this.GetInt64("id")
  1342. drug_id, _ := this.GetInt64("drug_id")
  1343. drug_name := this.GetString("drug_name")
  1344. //drug_origin_place := this.GetString("drug_origin_place")
  1345. lastPrice := this.GetString("last_price")
  1346. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1347. newPrice := this.GetString("new_price")
  1348. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1349. manufacturer := this.GetString("manufacturer")
  1350. number := this.GetString("number")
  1351. retailPrice := this.GetString("retail_price")
  1352. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1353. remark := this.GetString("remark")
  1354. count, _ := this.GetInt64("count")
  1355. warehousing_unit := this.GetString("warehousing_unit")
  1356. damage := models.XtDrugDamage{
  1357. DrugName: drug_name,
  1358. SpecificationName: "",
  1359. WarehousingUnit: warehousing_unit,
  1360. Count: count,
  1361. LastPrice: last_price,
  1362. RetailPrice: retail_price,
  1363. NewPrice: new_price,
  1364. Manufacturer: manufacturer,
  1365. Dealer: "",
  1366. Remark: remark,
  1367. DrugId: drug_id,
  1368. Number: number,
  1369. }
  1370. err := service.ModifyDrugDamage(id, damage)
  1371. fmt.Println(err)
  1372. this.ServeSuccessJSON(map[string]interface{}{
  1373. "damage": damage,
  1374. })
  1375. }
  1376. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1377. id, _ := this.GetInt64("id")
  1378. err := service.DeleteDrugDamage(id)
  1379. fmt.Println(err)
  1380. returnData := make(map[string]interface{}, 0)
  1381. returnData["msg"] = "ok"
  1382. this.ServeSuccessJSON(returnData)
  1383. }
  1384. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1385. idsSplit := this.GetString("ids")
  1386. ids := strings.Split(idsSplit, ",")
  1387. list, _ := service.GetDrugDamagePrint(ids)
  1388. this.ServeSuccessJSON(map[string]interface{}{
  1389. "list": list,
  1390. })
  1391. }
  1392. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1393. id, _ := this.GetInt64("id")
  1394. list, _ := service.GetWarehoseInfoById(id)
  1395. this.ServeSuccessJSON(map[string]interface{}{
  1396. "list": list,
  1397. })
  1398. }
  1399. func (this *SelfDrugApiController) SaveDrugInventory() {
  1400. timeLayout := "2006-01-02"
  1401. loc, _ := time.LoadLocation("Local")
  1402. dataBody := make(map[string]interface{}, 0)
  1403. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1404. fmt.Println(err)
  1405. tableData, _ := dataBody["tableData"].([]interface{})
  1406. fmt.Println("999939433443", tableData)
  1407. if len(tableData) > 0 {
  1408. for _, item := range tableData {
  1409. items := item.(map[string]interface{})
  1410. drug_name := items["drug_name"].(string)
  1411. fmt.Println("durg_nae232333223332232323323223232323", drug_name)
  1412. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1413. utils.ErrorLog("drug_name")
  1414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1418. utils.ErrorLog("retail_price")
  1419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1423. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1424. utils.ErrorLog("warehousing_order")
  1425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. warehousing_order := items["warehousing_order"].(string)
  1429. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1430. utils.ErrorLog("dealer")
  1431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. dealer := items["dealer"].(string)
  1435. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1436. utils.ErrorLog("manufacturer")
  1437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. manufacturer := items["manufacturer"].(string)
  1441. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1442. utils.ErrorLog("specification_name")
  1443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. specification_name := items["specification_name"].(string)
  1447. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1448. utils.ErrorLog("remark")
  1449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1450. return
  1451. }
  1452. remark := items["remark"].(string)
  1453. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1454. utils.ErrorLog("warehousing_unit")
  1455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1456. return
  1457. }
  1458. warehousing_unit := items["warehousing_unit"].(string)
  1459. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1460. utils.ErrorLog("last_price")
  1461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1462. return
  1463. }
  1464. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1465. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1466. utils.ErrorLog("count")
  1467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1468. return
  1469. }
  1470. count := int64(items["count"].(float64))
  1471. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1472. utils.ErrorLog("new_price")
  1473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1474. return
  1475. }
  1476. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1477. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1478. utils.ErrorLog("drug_id")
  1479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1480. return
  1481. }
  1482. drug_id := int64(items["drug_id"].(float64))
  1483. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1484. utils.ErrorLog("start_time")
  1485. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1486. return
  1487. }
  1488. var startTime int64
  1489. start_time := items["start_time"].(string)
  1490. if len(start_time) > 0 {
  1491. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1492. if err != nil {
  1493. fmt.Println(err)
  1494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. startTime = theTime.Unix()
  1498. }
  1499. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1500. utils.ErrorLog("product_date")
  1501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1502. return
  1503. }
  1504. product_date := int64(items["product_date"].(float64))
  1505. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1506. utils.ErrorLog("expiry_date")
  1507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1508. return
  1509. }
  1510. expiry_date := int64(items["expiry_date"].(float64))
  1511. orgId := this.GetAdminUserInfo().CurrentOrgId
  1512. Creater := this.GetAdminUserInfo().AdminUser.Id
  1513. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1514. utils.ErrorLog("number")
  1515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1516. return
  1517. }
  1518. numbers := items["number"].(string)
  1519. if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
  1520. utils.ErrorLog("batch_number")
  1521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1522. return
  1523. }
  1524. batch_number := items["batch_number"].(string)
  1525. inventory := models.XtDrugInventory{
  1526. DrugName: drug_name,
  1527. SpecificationName: specification_name,
  1528. WarehousingUnit: warehousing_unit,
  1529. Count: count,
  1530. LastPrice: last_price,
  1531. RetailPrice: retail_price,
  1532. NewPrice: new_price,
  1533. Manufacturer: manufacturer,
  1534. Dealer: dealer,
  1535. Remark: remark,
  1536. DrugId: drug_id,
  1537. UserOrgId: orgId,
  1538. Ctime: time.Now().Unix(),
  1539. Mtime: 0,
  1540. Status: 1,
  1541. WarehousingOrder: warehousing_order,
  1542. LicenseNumber: "",
  1543. StartTime: startTime,
  1544. Creater: Creater,
  1545. Checker: 0,
  1546. CheckerStatus: 2,
  1547. CheckerTime: 0,
  1548. ExpiryDate: expiry_date,
  1549. ProductDate: product_date,
  1550. Number: numbers,
  1551. BatchNumber: batch_number,
  1552. }
  1553. err = service.CreateDrugInventory(inventory)
  1554. fmt.Println(err)
  1555. }
  1556. }
  1557. this.ServeSuccessJSON(map[string]interface{}{
  1558. "msg": "msg",
  1559. })
  1560. }
  1561. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1562. timeLayout := "2006-01-02"
  1563. loc, _ := time.LoadLocation("Local")
  1564. dataBody := make(map[string]interface{}, 0)
  1565. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1566. fmt.Println(err)
  1567. orgId := this.GetAdminUserInfo().CurrentOrgId
  1568. keyword := this.GetString("keyword")
  1569. fmt.Println("keywoer2r2r32rwrwr", keyword)
  1570. start_time := this.GetString("start_time")
  1571. end_time := this.GetString("end_time")
  1572. var startTime int64
  1573. if len(start_time) > 0 {
  1574. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1575. if err != nil {
  1576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1577. return
  1578. }
  1579. startTime = theTime.Unix()
  1580. }
  1581. var endTime int64
  1582. if len(end_time) > 0 {
  1583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1584. if err != nil {
  1585. utils.ErrorLog(err.Error())
  1586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. endTime = theTime.Unix()
  1590. }
  1591. limit, _ := this.GetInt64("limit")
  1592. page, _ := this.GetInt64("page")
  1593. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1594. fmt.Println("list23232323223", list)
  1595. doctorList, _ := service.GetAllDoctorThree(orgId)
  1596. if err != nil {
  1597. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1598. return
  1599. }
  1600. this.ServeSuccessJSON(map[string]interface{}{
  1601. "total": total,
  1602. "list": list,
  1603. "doctorList": doctorList,
  1604. })
  1605. }
  1606. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1607. timeLayout := "2006-01-02"
  1608. loc, _ := time.LoadLocation("Local")
  1609. dataBody := make(map[string]interface{}, 0)
  1610. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1611. fmt.Println(err)
  1612. idstr := this.GetString("ids")
  1613. ids := strings.Split(idstr, ",")
  1614. check_time := this.GetString("check_time")
  1615. var checkTime int64
  1616. if len(check_time) > 0 {
  1617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1618. if err != nil {
  1619. fmt.Println(err)
  1620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. checkTime = theTime.Unix()
  1624. }
  1625. checker, _ := this.GetInt64("checker")
  1626. inventory := models.XtDrugInventory{
  1627. Checker: checker,
  1628. CheckerStatus: 1,
  1629. CheckerTime: checkTime,
  1630. }
  1631. err = service.UpdateDrugInventory(ids, inventory)
  1632. fmt.Println(err)
  1633. returnData := make(map[string]interface{}, 0)
  1634. returnData["msg"] = "ok"
  1635. this.ServeSuccessJSON(returnData)
  1636. }
  1637. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  1638. id, _ := this.GetInt64("id")
  1639. detail, err := service.GetDrugInventoryDetail(id)
  1640. if err != nil {
  1641. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1642. return
  1643. }
  1644. this.ServeSuccessJSON(map[string]interface{}{
  1645. "detail": detail,
  1646. })
  1647. }
  1648. func (this *SelfDrugApiController) ModifyInventory() {
  1649. id, _ := this.GetInt64("id")
  1650. drug_id, _ := this.GetInt64("drug_id")
  1651. drug_name := this.GetString("drug_name")
  1652. specification_name := this.GetString("specification_name")
  1653. retailPrice := this.GetString("retail_price")
  1654. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1655. warehousing_order := this.GetString("warehousing_order")
  1656. number := this.GetString("number")
  1657. manufacturer := this.GetString("manufacturer")
  1658. remark := this.GetString("remark")
  1659. warehousing_unit := this.GetString("warehousing_unit")
  1660. total, _ := this.GetInt64("total")
  1661. lastPrice := this.GetString("last_price")
  1662. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1663. count, _ := this.GetInt64("count")
  1664. drug_origin_place := this.GetString("drug_origin_place")
  1665. inventory := models.XtDrugInventory{
  1666. DrugName: drug_name,
  1667. SpecificationName: specification_name,
  1668. WarehousingUnit: warehousing_unit,
  1669. Count: count,
  1670. LastPrice: last_price,
  1671. RetailPrice: retail_price,
  1672. Manufacturer: manufacturer,
  1673. Remark: remark,
  1674. DrugId: drug_id,
  1675. WarehousingOrder: warehousing_order,
  1676. Number: number,
  1677. Total: total,
  1678. DrugOriginPlace: drug_origin_place,
  1679. }
  1680. err := service.ModifyDrugInventory(id, inventory)
  1681. if err != nil {
  1682. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1683. return
  1684. }
  1685. this.ServeSuccessJSON(map[string]interface{}{
  1686. "inventory": inventory,
  1687. })
  1688. }
  1689. func (this *SelfDrugApiController) DeleteDrugInventory() {
  1690. id, _ := this.GetInt64("id")
  1691. err := service.DeleteDrugInventory(id)
  1692. fmt.Println(err)
  1693. returnData := make(map[string]interface{}, 0)
  1694. returnData["msg"] = "ok"
  1695. this.ServeSuccessJSON(returnData)
  1696. }
  1697. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  1698. ids := this.GetString("ids")
  1699. idssplit := strings.Split(ids, ",")
  1700. list, err := service.GetDrugInventoryPrintList(idssplit)
  1701. if err != nil {
  1702. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1703. return
  1704. }
  1705. this.ServeSuccessJSON(map[string]interface{}{
  1706. "list": list,
  1707. })
  1708. }
  1709. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  1710. keyword := this.GetString("keyword")
  1711. limit, _ := this.GetInt64("limit")
  1712. page, _ := this.GetInt64("page")
  1713. orgId := this.GetAdminUserInfo().CurrentOrgId
  1714. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId)
  1715. fmt.Println("list23232323223", list)
  1716. doctorList, _ := service.GetAllDoctorThree(orgId)
  1717. if err != nil {
  1718. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1719. return
  1720. }
  1721. this.ServeSuccessJSON(map[string]interface{}{
  1722. "total": total,
  1723. "list": list,
  1724. "doctorList": doctorList,
  1725. })
  1726. }