manager_center_api_controller.go 81KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/mozillazg/go-pinyin"
  15. )
  16. type ManagerCenterApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ManagerCenterRegistRouters() {
  20. //药品基础库
  21. beego.Router("/api/basedruglib/create", &ManagerCenterApiController{}, "post:CreateBaseDrugLib")
  22. beego.Router("/api/basedruglib/edit", &ManagerCenterApiController{}, "post:EditBaseDrugLib")
  23. beego.Router("/api/basedruglib/get", &ManagerCenterApiController{}, "get:GetBaseDrugLib")
  24. beego.Router("/api/basedruglib/list", &ManagerCenterApiController{}, "get:GetBaseDrugLibList")
  25. beego.Router("/api/medicineinsurancepercent/create", &ManagerCenterApiController{}, "post:CreateMedicineInsurancePercent")
  26. beego.Router("/api/drugunitsafeguard/create", &ManagerCenterApiController{}, "post:CreateDrugUnitSafeguard")
  27. beego.Router("/api/medicineinsurancepercent/get", &ManagerCenterApiController{}, "get:GetMedicineInsurancePercent")
  28. //beego.Router("/api/drugunitsafeguard/get", &ManagerCenterApiController{}, "get:GetDrugUnitSafeguard")
  29. beego.Router("/api/drug/basedruglib", &ManagerCenterApiController{}, "get:DeleteBaseDrugById")
  30. //专项字典
  31. beego.Router("/api/dictionary/getconfiglist", &ManagerCenterApiController{}, "get,post:GetConfigList")
  32. beego.Router("/api/dictionary/createconfig", &ManagerCenterApiController{}, "Post:CreateConfig")
  33. beego.Router("/api/dictionary/createchildconfig", &ManagerCenterApiController{}, "Post:CreateChildConfig")
  34. beego.Router("/api/dictionary/updatechildconfig", &ManagerCenterApiController{}, "Post:UpdateChildConfig")
  35. beego.Router("/api/dictionary/deletechildconfig", &ManagerCenterApiController{}, "Post:DeleteChildConfig")
  36. beego.Router("/api/dictionary/updatetemplate", &ManagerCenterApiController{}, "Post:UpdateTemplate")
  37. beego.Router("/api/dictionary/getmanageconfiglist", &ManagerCenterApiController{}, "get,post:GetManageConfigList")
  38. //经销商
  39. beego.Router("/api/stock/dealer/create", &ManagerCenterApiController{}, "post:CreateDealer")
  40. beego.Router("/api/stock/dealer/modify", &ManagerCenterApiController{}, "post:ModifyDealer")
  41. //经过测试这个接口完全不会执行,因为被另一个路由占用了
  42. beego.Router("/api/stock/dealer/list", &ManagerCenterApiController{}, "get:GetDealersList")
  43. beego.Router("/api/stock/dealer/delete", &ManagerCenterApiController{}, "post:DeleteDealer")
  44. beego.Router("/api/stock/dealer/get", &ManagerCenterApiController{}, "get:GetDealer")
  45. //厂商
  46. beego.Router("/api/stock/manufacturer/create", &ManagerCenterApiController{}, "post:CreateManufacturer")
  47. beego.Router("/api/stock/manufacturer/modify", &ManagerCenterApiController{}, "post:ModifyManufacturer")
  48. //经过测试这个接口也完全不会执行,因为被另一个路由占用了
  49. beego.Router("/api/stock/manufacturer/list", &ManagerCenterApiController{}, "get:GetManufacturerList")
  50. beego.Router("/api/stock/manufacturer/delete", &ManagerCenterApiController{}, "post:DeleteManufacturer")
  51. beego.Router("/api/stock/manufacturer/get", &ManagerCenterApiController{}, "get:GetManufacturer")
  52. beego.Router("/api/stock/good/info/create", &ManagerCenterApiController{}, "post:CreateGoodInfo")
  53. beego.Router("/api/stock/good/info/modify", &ManagerCenterApiController{}, "post:ModifyGoodInfo")
  54. beego.Router("/api/stock/good/info/list", &ManagerCenterApiController{}, "get:GetGoodInfoList")
  55. beego.Router("/api/info/delete", &ManagerCenterApiController{}, "post:DeleteGoodInfo")
  56. beego.Router("/api/stock/good/info/get", &ManagerCenterApiController{}, "get:GetGoodInfoByGoodId")
  57. beego.Router("/api/stock/good/info", &ManagerCenterApiController{}, "get:GetGoodInfoById")
  58. //门诊大病
  59. beego.Router("/api/mz/sick/create", &ManagerCenterApiController{}, "post:CreateMZSick")
  60. beego.Router("/api/mz/sick/modify", &ManagerCenterApiController{}, "post:ModifyMZSick")
  61. beego.Router("/api/mz/sick/list", &ManagerCenterApiController{}, "get:GetMZSickList")
  62. beego.Router("/api/mz/sick/delete", &ManagerCenterApiController{}, "post:DeleteMZSick")
  63. beego.Router("/api/mz/sick/get", &ManagerCenterApiController{}, "get:GetMZSick")
  64. beego.Router("/api/addition/create", &ManagerCenterApiController{}, "post:CreateAddition")
  65. beego.Router("/api/addition/modify", &ManagerCenterApiController{}, "post:ModifyAddition")
  66. beego.Router("/api/addition/list", &ManagerCenterApiController{}, "get:GetAdditionList")
  67. beego.Router("/api/addition/delete", &ManagerCenterApiController{}, "post:DeleteAddition")
  68. beego.Router("/api/addition/get", &ManagerCenterApiController{}, "get:GetAddition")
  69. //门诊诊断
  70. beego.Router("/api/diagnose/create", &ManagerCenterApiController{}, "post:CreateDiagnose")
  71. beego.Router("/api/diagnose/modify", &ManagerCenterApiController{}, "post:ModifyDiagnose")
  72. beego.Router("/api/diagnose/list", &ManagerCenterApiController{}, "get:GetDiagnoseList")
  73. beego.Router("/api/diagnose/delete", &ManagerCenterApiController{}, "post:DeleteDiagnose")
  74. beego.Router("/api/diagnose/get", &ManagerCenterApiController{}, "get:GetDiagnose")
  75. beego.Router("/api/drug/getalldruglist", &ManagerCenterApiController{}, "get:GetAllDrugList")
  76. beego.Router("/api/drug/postsearchdruglist", &ManagerCenterApiController{}, "get:GetSearchDrugList")
  77. beego.Router("/api/patient/addpatientdiagnose", &ManagerCenterApiController{}, "Post:AddPatientDiagnos")
  78. beego.Router("/api/patient/getpatientdiagnose", &ManagerCenterApiController{}, "Get:GetPatientDiagnose")
  79. beego.Router("/api/patient/getpatientdiagnosedetail", &ManagerCenterApiController{}, "Get:GetPatientDiagnoseDetail")
  80. beego.Router("/api/patient/updatepatientcase", &ManagerCenterApiController{}, "Post:UpdatePatientCase")
  81. beego.Router("/api/patient/deletepatientdiagnose", &ManagerCenterApiController{}, "Get:DeletePatientDiagnose")
  82. }
  83. func (c *ManagerCenterApiController) CreateBaseDrugLib() {
  84. drug_name := c.GetString("drug_name")
  85. wubi := c.GetString("wubi")
  86. drug_alias := c.GetString("drug_alias")
  87. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  88. drug_alias_wubi := c.GetString("drug_alias_wubi")
  89. drug_category, _ := c.GetInt64("drug_category")
  90. drug_spec := c.GetString("drug_spec")
  91. drug_type, _ := c.GetInt64("drug_type")
  92. drug_stock_limit := c.GetString("drug_stock_limit")
  93. drug_origin_place := c.GetString("drug_origin_place")
  94. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  95. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  96. max_unit := c.GetString("max_unit")
  97. min_unit := c.GetString("min_unit")
  98. unit_matrixing := c.GetString("unit_matrixing")
  99. retail_price, _ := c.GetFloat("retail_price")
  100. last_price, _ := c.GetFloat("last_price")
  101. drug_control, _ := c.GetInt64("drug_control")
  102. number := c.GetString("number")
  103. drug_classify := c.GetString("drug_classify")
  104. drug_dose, _ := c.GetFloat("drug_dose")
  105. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  106. medical_insurance_number := c.GetString("medical_insurance_number")
  107. provinces_code := c.GetString("provinces_code")
  108. manufacturer, _ := c.GetInt64("manufacturer")
  109. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  110. statistics_category, _ := c.GetInt64("statistics_category")
  111. code := c.GetString("code")
  112. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  113. is_record, _ := c.GetInt64("is_record")
  114. agent := c.GetString("agent")
  115. drug_status := c.GetString("drug_status")
  116. limit_remark := c.GetString("limit_remark")
  117. delivery_way := c.GetString("delivery_way")
  118. execution_frequency := c.GetString("execution_frequency")
  119. single_dose, _ := c.GetFloat("single_dose")
  120. fmt.Println(single_dose)
  121. prescribing_number, _ := c.GetFloat("prescribing_number")
  122. label, _ := c.GetInt64("label")
  123. sort, _ := c.GetInt64("sort")
  124. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  125. is_default, _ := c.GetInt64("is_default")
  126. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  127. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  128. is_charge_use, _ := c.GetInt64("is_charge_use")
  129. dealer, _ := c.GetInt64("dealer")
  130. prescription_mark, _ := c.GetInt64("prescription_mark")
  131. social_security_directory_code := c.GetString("social_security_directory_code")
  132. record_date := c.GetString("record_date")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  136. drug_remark := c.GetString("drug_remark")
  137. //dose, _ := c.GetFloat("dose")
  138. dose := c.GetString("dose")
  139. dose_unit := c.GetString("dose_unit")
  140. min_price, _ := c.GetFloat("min_price")
  141. min_number, _ := c.GetInt64("min_number")
  142. drug_day := c.GetString("drug_day")
  143. hosp_appr_flag, _ := c.GetInt64("hosp_appr_flag")
  144. lmt_used_flag, _ := c.GetInt64("lmt_used_flag")
  145. prescribing_number_unit := c.GetString("prescribing_number_unit")
  146. is_user, _ := c.GetInt64("is_user")
  147. is_pharmacy, _ := c.GetInt64("is_pharmacy")
  148. bbx01 := c.GetString("bbx01")
  149. bby01 := c.GetString("bby01")
  150. is_project, _ := c.GetInt64("is_project")
  151. is_show, _ := c.GetInt64("is_show")
  152. adminInfo := c.GetAdminUserInfo()
  153. is_self_drug, _ := c.GetInt64("is_self_drug")
  154. hans := drug_name // 要转换的汉字字符串
  155. // 创建一个拼音转换器
  156. p := pinyin.NewArgs()
  157. // 将汉字转为拼音
  158. pinyinSlice := pinyin.Pinyin(hans, p)
  159. // 输出拼音
  160. fmt.Println("Pinyin:", pinyinSlice)
  161. // 获取首字母
  162. firstLetter := ""
  163. for _, py := range pinyinSlice {
  164. if len(py) > 0 {
  165. firstLetter += string(py[0][0])
  166. }
  167. }
  168. drugLib := &models.BaseDrugLib{
  169. DrugName: drug_name,
  170. Wubi: wubi,
  171. DrugAlias: drug_alias,
  172. DrugAliasPinyin: drug_alias_pinyin,
  173. DrugAliasWubi: drug_alias_wubi,
  174. DrugCategory: drug_category,
  175. DrugSpec: drug_spec,
  176. DrugType: drug_type,
  177. DrugStockLimit: drug_stock_limit,
  178. DrugOriginPlace: drug_origin_place,
  179. MedicalInsuranceLevel: medical_insurance_level,
  180. DrugDosageForm: drug_dosage_form,
  181. MaxUnit: max_unit,
  182. MinUnit: min_unit,
  183. UnitMatrixing: unit_matrixing,
  184. RetailPrice: retail_price,
  185. LastPrice: last_price,
  186. DrugControl: drug_control,
  187. Number: number,
  188. DrugClassify: drug_classify,
  189. DrugDose: drug_dose,
  190. DrugDoseUnit: drug_dose_unit,
  191. MedicalInsuranceNumber: medical_insurance_number,
  192. ProvincesCode: provinces_code,
  193. Manufacturer: manufacturer,
  194. PharmacologyCategory: pharmacology_category,
  195. StatisticsCategory: statistics_category,
  196. Code: code,
  197. IsSpecialDiseases: is_special_diseases,
  198. IsRecord: is_record,
  199. Agent: agent,
  200. DrugStatus: drug_status,
  201. LimitRemark: limit_remark,
  202. DeliveryWay: delivery_way,
  203. ExecutionFrequency: execution_frequency,
  204. SingleDose: drug_dose,
  205. PrescribingNumber: prescribing_number,
  206. Label: label,
  207. Sort: sort,
  208. IsUseDoctorAdvice: is_use_doctor_advice,
  209. IsDefault: is_default,
  210. IsChargePredict: is_charge_predict,
  211. IsStatisticsWork: is_statistics_work,
  212. IsChargeUse: is_charge_use,
  213. OrgId: adminInfo.CurrentOrgId,
  214. Status: 1,
  215. Ctime: time.Now().Unix(),
  216. Mtime: time.Now().Unix(),
  217. Dealer: dealer,
  218. PrescriptionMark: prescription_mark,
  219. SocialSecurityDirectoryCode: social_security_directory_code,
  220. RecordDate: theTime.Unix(),
  221. DrugRemark: drug_remark,
  222. DrugDay: drug_day,
  223. MinNumber: min_number,
  224. Dose: dose,
  225. MinPrice: min_price,
  226. DoseUnit: dose_unit,
  227. HospApprFlag: hosp_appr_flag,
  228. LmtUsedFlag: lmt_used_flag,
  229. PrescribingNumberUnit: prescribing_number_unit,
  230. IsUse: is_user,
  231. IsPharmacy: is_pharmacy,
  232. Bby01: bby01,
  233. ZuobiaoId: bbx01,
  234. Bbx01: bbx01,
  235. Bck01b: "10",
  236. IsProject: is_project,
  237. IsShow: is_show,
  238. IsSelfDrug: is_self_drug,
  239. }
  240. drugLib.FirstLetter = firstLetter
  241. drugLib.Pinyin = firstLetter
  242. total := service.FindAllDrugLibRecordTotal(adminInfo.CurrentOrgId)
  243. drug_code := strconv.FormatInt(total+1, 10)
  244. drug_code = "54000000" + drug_code
  245. drugLib.DrugCode = drug_code
  246. count := service.FindBaseDrugLibRecordCountOne(drugLib)
  247. if count == 0 {
  248. if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
  249. drugLib.DrugSpec = drugLib.Dose + drugLib.DoseUnit + "*" + string(drugLib.MinNumber) + drugLib.MinUnit + "/" + drugLib.MaxUnit
  250. }
  251. err := service.CreateBaseDrugLib(drugLib)
  252. if err == nil {
  253. c.ServeSuccessJSON(map[string]interface{}{
  254. "msg": "创建成功",
  255. })
  256. } else {
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  258. return
  259. }
  260. return
  261. } else {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDrugRepeatDataException)
  263. return
  264. }
  265. }
  266. func (c *ManagerCenterApiController) EditBaseDrugLib() {
  267. id, _ := c.GetInt64("id")
  268. drug_name := c.GetString("drug_name")
  269. wubi := c.GetString("wubi")
  270. drug_alias := c.GetString("drug_alias")
  271. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  272. drug_alias_wubi := c.GetString("drug_alias_wubi")
  273. drug_category, _ := c.GetInt64("drug_category")
  274. drug_spec := c.GetString("drug_spec")
  275. drug_type, _ := c.GetInt64("drug_type")
  276. drug_stock_limit := c.GetString("drug_stock_limit")
  277. drug_origin_place := c.GetString("drug_origin_place")
  278. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  279. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  280. max_unit := c.GetString("max_unit")
  281. min_unit := c.GetString("min_unit")
  282. unit_matrixing := c.GetString("unit_matrixing")
  283. retail_price, _ := c.GetFloat("retail_price")
  284. last_price, _ := c.GetFloat("last_price")
  285. drug_control, _ := c.GetInt64("drug_control")
  286. number := c.GetString("number")
  287. drug_classify := c.GetString("drug_classify")
  288. drug_dose, _ := c.GetFloat("drug_dose")
  289. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  290. medical_insurance_number := c.GetString("medical_insurance_number")
  291. provinces_code := c.GetString("provinces_code")
  292. manufacturer, _ := c.GetInt64("manufacturer")
  293. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  294. statistics_category, _ := c.GetInt64("statistics_category")
  295. code := c.GetString("code")
  296. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  297. is_record, _ := c.GetInt64("is_record")
  298. agent := c.GetString("agent")
  299. drug_status := c.GetString("drug_status")
  300. limit_remark := c.GetString("limit_remark")
  301. delivery_way := c.GetString("delivery_way")
  302. execution_frequency := c.GetString("execution_frequency")
  303. single_dose, _ := c.GetFloat("single_dose")
  304. fmt.Println("sigle_dose", single_dose)
  305. prescribing_number, _ := c.GetFloat("prescribing_number")
  306. label, _ := c.GetInt64("label")
  307. sort, _ := c.GetInt64("sort")
  308. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  309. is_default, _ := c.GetInt64("is_default")
  310. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  311. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  312. is_charge_use, _ := c.GetInt64("is_charge_use")
  313. drug_code := c.GetString("drug_code")
  314. //unit := c.GetString("unit")
  315. dealer, _ := c.GetInt64("dealer")
  316. prescription_mark, _ := c.GetInt64("prescription_mark")
  317. social_security_directory_code := c.GetString("social_security_directory_code")
  318. record_date := c.GetString("record_date")
  319. timeLayout := "2006-01-02"
  320. loc, _ := time.LoadLocation("Local")
  321. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  322. drug_remark := c.GetString("drug_remark")
  323. min_number, _ := c.GetInt64("min_number")
  324. drug_day := c.GetString("drug_day")
  325. //dose, _ := c.GetFloat("dose")
  326. dose := c.GetString("dose")
  327. dose_unit := c.GetString("dose_unit")
  328. total, _ := c.GetFloat("total")
  329. min_price, _ := c.GetFloat("min_price")
  330. hosp_appr_flag, _ := c.GetInt64("hosp_appr_flag")
  331. lmt_used_flag, _ := c.GetInt64("lmt_used_flag")
  332. prescribing_number_unit := c.GetString("prescribing_number_unit")
  333. is_user, _ := c.GetInt64("is_user")
  334. sum_count, _ := c.GetInt64("sum_count")
  335. sum_in_count, _ := c.GetInt64("sum_in_count")
  336. is_pharmacy, _ := c.GetInt64("is_pharmacy")
  337. bbx01 := c.GetString("bbx01")
  338. bby01 := c.GetString("bby01")
  339. is_project, _ := c.GetInt64("is_project")
  340. is_show, _ := c.GetInt64("is_show")
  341. is_self_drug, _ := c.GetInt64("is_self_drug")
  342. adminInfo := c.GetAdminUserInfo()
  343. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  344. hans := drug_name // 要转换的汉字字符串
  345. // 创建一个拼音转换器
  346. p := pinyin.NewArgs()
  347. // 将汉字转为拼音
  348. pinyinSlice := pinyin.Pinyin(hans, p)
  349. // 获取首字母
  350. firstLetter := ""
  351. for _, py := range pinyinSlice {
  352. if len(py) > 0 {
  353. firstLetter += string(py[0][0])
  354. }
  355. }
  356. drugLib := &models.BaseDrugLib{
  357. ID: id,
  358. DrugName: drug_name,
  359. Pinyin: firstLetter,
  360. Wubi: wubi,
  361. DrugAlias: drug_alias,
  362. DrugAliasPinyin: drug_alias_pinyin,
  363. DrugAliasWubi: drug_alias_wubi,
  364. DrugCategory: drug_category,
  365. DrugSpec: drug_spec,
  366. DrugType: drug_type,
  367. DrugStockLimit: drug_stock_limit,
  368. DrugOriginPlace: drug_origin_place,
  369. MedicalInsuranceLevel: medical_insurance_level,
  370. DrugDosageForm: drug_dosage_form,
  371. MaxUnit: max_unit,
  372. MinUnit: min_unit,
  373. UnitMatrixing: unit_matrixing,
  374. RetailPrice: retail_price,
  375. LastPrice: last_price,
  376. DrugControl: drug_control,
  377. Number: number,
  378. DrugClassify: drug_classify,
  379. DrugDose: drug_dose,
  380. DrugDoseUnit: drug_dose_unit,
  381. MedicalInsuranceNumber: medical_insurance_number,
  382. Manufacturer: manufacturer,
  383. PharmacologyCategory: pharmacology_category,
  384. StatisticsCategory: statistics_category,
  385. Code: code,
  386. IsSpecialDiseases: is_special_diseases,
  387. IsRecord: is_record,
  388. Agent: agent,
  389. DrugStatus: drug_status,
  390. LimitRemark: limit_remark,
  391. DeliveryWay: delivery_way,
  392. ExecutionFrequency: execution_frequency,
  393. PrescribingNumber: prescribing_number,
  394. Label: label,
  395. Sort: sort,
  396. IsUseDoctorAdvice: is_use_doctor_advice,
  397. IsDefault: is_default,
  398. IsChargePredict: is_charge_predict,
  399. IsStatisticsWork: is_statistics_work,
  400. IsChargeUse: is_charge_use,
  401. OrgId: adminInfo.CurrentOrgId,
  402. Status: 1,
  403. Ctime: drug.Ctime,
  404. Mtime: time.Now().Unix(),
  405. DrugCode: drug_code,
  406. Dealer: dealer,
  407. PrescriptionMark: prescription_mark,
  408. SocialSecurityDirectoryCode: social_security_directory_code,
  409. RecordDate: theTime.Unix(),
  410. DrugRemark: drug_remark,
  411. DrugDay: drug_day,
  412. HospApprFlag: hosp_appr_flag,
  413. LmtUsedFlag: lmt_used_flag,
  414. MinNumber: min_number,
  415. Dose: dose,
  416. MinPrice: min_price,
  417. DoseUnit: dose_unit,
  418. PrescribingNumberUnit: prescribing_number_unit,
  419. Total: total,
  420. SingleDose: drug_dose,
  421. ProvincesCode: provinces_code,
  422. IsUse: is_user,
  423. SumCount: sum_count,
  424. SumInCount: sum_in_count,
  425. IsPharmacy: is_pharmacy,
  426. ZuobiaoId: bbx01,
  427. Bby01: bby01,
  428. Bbx01: bbx01,
  429. Bck01b: "10",
  430. IsProject: is_project,
  431. FirstLetter: firstLetter,
  432. IsShow: is_show,
  433. IsSelfDrug: is_self_drug,
  434. }
  435. if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
  436. drugLib.DrugSpec = drugLib.Dose + drugLib.DoseUnit + "*" + string(drugLib.MinNumber) + drugLib.MinUnit + "/" + drugLib.MaxUnit
  437. }
  438. err := service.UpdateBaseDrugLib(drugLib)
  439. //查下医嘱模板
  440. adviceList, _ := service.GetHisAdvicelistTemplate(id, adminInfo.CurrentOrgId)
  441. if len(adviceList) > 0 {
  442. for _, item := range adviceList {
  443. service.UpdateHisAdviceListTemplate(item.ID, retail_price)
  444. }
  445. }
  446. //查询是否存在
  447. _, errOne := service.GetDrugNameIsExist(id, adminInfo.CurrentOrgId)
  448. if errOne == gorm.ErrRecordNotFound {
  449. c.ServeSuccessJSON(map[string]interface{}{
  450. "msg": "修改成功",
  451. })
  452. return
  453. } else if errOne == nil {
  454. //修改xt_drug_name 表
  455. drugName := models.XtDrugName{
  456. DrugName: drug_name,
  457. }
  458. service.UpdatedDrugName(id, adminInfo.CurrentOrgId, &drugName)
  459. }
  460. //查询是否存在
  461. _, errTwo := service.GetStandNameIsExist(id, adminInfo.CurrentOrgId)
  462. if errTwo == gorm.ErrRecordNotFound {
  463. c.ServeSuccessJSON(map[string]interface{}{
  464. "msg": "修改成功",
  465. })
  466. return
  467. } else if errTwo == nil {
  468. //修改规格xt_stand_name表
  469. standName := models.XtStandName{
  470. DrugName: drug_name,
  471. DrugSpec: drug_spec,
  472. DrugStockLimit: drug_stock_limit,
  473. MinUnit: min_unit,
  474. }
  475. service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
  476. }
  477. _, errThree := service.GetSelfMedicalIsExist(id, adminInfo.CurrentOrgId)
  478. if errThree == gorm.ErrRecordNotFound {
  479. c.ServeSuccessJSON(map[string]interface{}{
  480. "msg": "修改成功",
  481. })
  482. return
  483. } else if errThree == nil {
  484. //修改药品表
  485. medical := models.XtSelfMedical{
  486. DrugName: drug_name,
  487. DrugSpec: drug_spec,
  488. ExecutionFrequency: execution_frequency,
  489. PrescribingNumber: prescribing_number,
  490. DeliveryWay: delivery_way,
  491. SingleDose: single_dose,
  492. MinUnit: min_unit,
  493. }
  494. service.UpdateSelfMedical(id, adminInfo.CurrentOrgId, &medical)
  495. }
  496. _, errFour := service.GetSelfStosckIsExist(id, adminInfo.CurrentOrgId)
  497. if errFour == gorm.ErrRecordNotFound {
  498. c.ServeSuccessJSON(map[string]interface{}{
  499. "msg": "修改成功",
  500. })
  501. return
  502. } else if errFour == nil {
  503. stock := models.XtSelfStock{
  504. DrugSpec: drug_spec,
  505. DrugName: drug_name,
  506. MinUnit: min_unit,
  507. }
  508. service.UpdatedSelfStock(&stock, id, adminInfo.CurrentOrgId)
  509. }
  510. _, errFive := service.GetOutSelfOutStockIsExist(id, adminInfo.CurrentOrgId)
  511. if errFive == gorm.ErrRecordNotFound {
  512. c.ServeSuccessJSON(map[string]interface{}{
  513. "msg": "修改成功",
  514. })
  515. return
  516. } else if errFive == nil {
  517. outStock := models.XtSelfOutStock{
  518. DrugName: drug_name,
  519. DrugSpec: drug_spec,
  520. }
  521. //修改出库表
  522. service.UpdatedOutSelfStock(&outStock, id, adminInfo.CurrentOrgId)
  523. }
  524. _, errSix := service.GetDoctorAdviceIsExist(id, adminInfo.CurrentOrgId)
  525. if errSix == gorm.ErrRecordNotFound {
  526. fmt.Println("进来了吗5")
  527. c.ServeSuccessJSON(map[string]interface{}{
  528. "msg": "修改成功",
  529. })
  530. return
  531. } else if errSix == nil {
  532. //查询未执行的医嘱
  533. advice := models.DoctorAdvice{
  534. AdviceName: drug_name,
  535. AdviceDesc: drug_spec,
  536. DeliveryWay: delivery_way,
  537. ExecutionFrequency: execution_frequency,
  538. SingleDose: single_dose,
  539. SingleDoseUnit: min_unit,
  540. }
  541. service.UpdateNoExcuteDoctorAdvice(id, adminInfo.CurrentOrgId, &advice)
  542. }
  543. _, errSeven := service.GetDoctorAdviceTemplateIsExist(id, adminInfo.CurrentOrgId)
  544. if errSeven == gorm.ErrRecordNotFound {
  545. fmt.Println("进来了吗6")
  546. c.ServeSuccessJSON(map[string]interface{}{
  547. "msg": "修改成功",
  548. })
  549. return
  550. } else if errSeven == nil {
  551. //修改医嘱模板
  552. template := models.DoctorAdviceTemplate{
  553. AdviceName: drug_name,
  554. AdviceDesc: drug_spec,
  555. DeliveryWay: delivery_way,
  556. ExecutionFrequency: execution_frequency,
  557. SingleDose: single_dose,
  558. SingleDoseUnit: min_unit,
  559. }
  560. service.UpdatedDoctorAdviceTemplate(id, adminInfo.CurrentOrgId, &template)
  561. }
  562. if err == nil {
  563. c.ServeSuccessJSON(map[string]interface{}{
  564. "msg": "修改成功",
  565. })
  566. return
  567. } else {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  569. return
  570. }
  571. }
  572. func (c *ManagerCenterApiController) GetBaseDrugLib() {
  573. id, _ := c.GetInt64("id")
  574. adminInfo := c.GetAdminUserInfo()
  575. drug, err := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  576. if err == nil {
  577. c.ServeSuccessJSON(map[string]interface{}{
  578. "drug": drug,
  579. })
  580. return
  581. } else {
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  583. return
  584. }
  585. }
  586. func (c *ManagerCenterApiController) GetBaseDrugLibList() {
  587. page, _ := c.GetInt64("page", 1)
  588. limit, _ := c.GetInt64("limit", 10)
  589. is_use, _ := c.GetInt64("is_use", 0)
  590. is_charge, _ := c.GetInt64("is_charge", 0)
  591. is_inject, _ := c.GetInt64("is_inject", 0)
  592. manufacturer, _ := c.GetInt64("manufacturer")
  593. is_record, _ := c.GetInt64("is_record")
  594. keyword := c.GetString("keyword")
  595. adminInfo := c.GetAdminUserInfo()
  596. if page <= 0 {
  597. page = 1
  598. }
  599. if limit <= 0 {
  600. limit = 10
  601. }
  602. list, total, _ := service.GetBaseDrugLibList(adminInfo.CurrentOrgId, keyword, page, limit, is_use, is_charge, is_inject, manufacturer, is_record)
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "list": list,
  605. "total": total,
  606. })
  607. return
  608. }
  609. func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
  610. module, _ := c.GetInt64("module", 0)
  611. adminInfo := c.GetAdminUserInfo()
  612. dataBody := make(map[string]interface{}, 0)
  613. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  614. if err != nil {
  615. utils.ErrorLog(err.Error())
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. var mips []*models.MedicineInsurancePercentage
  620. var errs error
  621. record_time := time.Now().Unix()
  622. if dataBody["mip"] != nil && reflect.TypeOf(dataBody["mip"]).String() == "[]interface {}" {
  623. mip_map, _ := dataBody["mip"].([]interface{})
  624. if len(mip_map) > 0 {
  625. for _, item := range mip_map {
  626. items := item.(map[string]interface{})
  627. if items["type_id"] == nil || reflect.TypeOf(items["type_id"]).String() != "float64" {
  628. utils.ErrorLog("type_id")
  629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. type_id := int64(items["type_id"].(float64))
  633. if items["medicine_insurance_type"] == nil || reflect.TypeOf(items["medicine_insurance_type"]).String() != "float64" {
  634. utils.ErrorLog("medicine_insurance_type")
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. types := int64(items["medicine_insurance_type"].(float64))
  639. if items["percent"] == nil || reflect.TypeOf(items["percent"]).String() != "string" {
  640. utils.ErrorLog("percent")
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  642. return
  643. }
  644. percent, _ := strconv.ParseFloat(items["percent"].(string), 64)
  645. //percent := items["percent"].(float64)
  646. mip_temp := &models.MedicineInsurancePercentage{
  647. TypeId: type_id,
  648. Status: 1,
  649. Ctime: time.Now().Unix(),
  650. Mtime: time.Now().Unix(),
  651. RecordTime: record_time,
  652. MedicineInsuranceType: types,
  653. UserOrgId: adminInfo.CurrentOrgId,
  654. Percent: percent,
  655. Module: module,
  656. GoodId: 0,
  657. }
  658. mips = append(mips, mip_temp)
  659. }
  660. }
  661. for _, item := range mips {
  662. errs = service.CreateMedicineInsurancePercentage(item)
  663. }
  664. }
  665. if errs == nil {
  666. c.ServeSuccessJSON(map[string]interface{}{
  667. "msg": "添加成功",
  668. })
  669. return
  670. } else {
  671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  672. return
  673. }
  674. }
  675. func (c *ManagerCenterApiController) CreateDrugUnitSafeguard() {
  676. }
  677. // GetPatientsList 取配置信息列表
  678. func (c *ManagerCenterApiController) GetConfigList() {
  679. adminUserInfo := c.GetAdminUserInfo()
  680. configList, _ := service.GetDictionaryConfigList(adminUserInfo.CurrentOrgId)
  681. c.ServeSuccessJSON(map[string]interface{}{
  682. "configlist": configList,
  683. })
  684. return
  685. }
  686. func (c *ManagerCenterApiController) GetManageConfigList() {
  687. adminUserInfo := c.GetAdminUserInfo()
  688. configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "configlist": configList,
  691. })
  692. return
  693. }
  694. // CreateConfig 创建配置信息
  695. func (c *ManagerCenterApiController) CreateConfig() {
  696. adminUserInfo := c.GetAdminUserInfo()
  697. var dataconfig models.DictionaryDataconfig
  698. var resultConfig models.DictionaryConfigViewModel
  699. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  700. if code > 0 {
  701. c.ServeFailJSONWithSGJErrorCode(code)
  702. return
  703. }
  704. // 验证关键字段的值是否重复
  705. thisConfig, _ := service.FindDictionaryConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  706. if thisConfig.ID > 0 {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  708. return
  709. }
  710. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  711. dataconfig.Value = fieldValue + 1
  712. dataBody := make(map[string]interface{}, 0)
  713. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  714. if err != nil {
  715. utils.ErrorLog(err.Error())
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  720. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  721. dataconfig.Status = 1
  722. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  723. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  724. dataconfig.Remark = string(dataBody["remark"].(string))
  725. if dataBody["order"] != nil {
  726. dataconfig.Order = int64(dataBody["order"].(float64))
  727. } else {
  728. dataconfig.Order = 0
  729. }
  730. err = service.CreateDictionaryConfig(&dataconfig)
  731. if err != nil {
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  733. return
  734. } else {
  735. resultConfig.ID = dataconfig.ID
  736. resultConfig.Module = dataconfig.Module
  737. resultConfig.Name = dataconfig.Name
  738. resultConfig.OrgId = dataconfig.OrgId
  739. resultConfig.ParentId = dataconfig.ParentId
  740. resultConfig.FieldName = dataconfig.FieldName
  741. resultConfig.CreateUserId = dataconfig.CreateUserId
  742. resultConfig.Title = dataconfig.Title
  743. resultConfig.Content = dataconfig.Content
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "dataconfig": resultConfig,
  747. "msg": "ok",
  748. })
  749. return
  750. }
  751. func (c *ManagerCenterApiController) UpdateTemplate() {
  752. adminUserInfo := c.GetAdminUserInfo()
  753. var dataconfig models.DictionaryDataconfig
  754. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  755. if code > 0 {
  756. c.ServeFailJSONWithSGJErrorCode(code)
  757. return
  758. }
  759. dataBody := make(map[string]interface{}, 0)
  760. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  761. if err != nil {
  762. utils.ErrorLog(err.Error())
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  764. return
  765. }
  766. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  767. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  768. dataconfig.Status = 1
  769. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  770. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  771. dataconfig.Remark = string(dataBody["remark"].(string))
  772. if dataBody["order"] != nil {
  773. dataconfig.Order = int64(dataBody["order"].(float64))
  774. } else {
  775. dataconfig.Order = 0
  776. }
  777. // 验证关键字段的值是否重复
  778. // cur_id := int64(dataBody["id"].(float64))
  779. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  780. // if thisConfig.ID >0 {
  781. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  782. // return
  783. // }
  784. configOrgId := int64(dataBody["org_id"].(float64))
  785. if configOrgId == 0 {
  786. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  787. err := service.CreateDictionaryConfig(&dataconfig)
  788. if err != nil {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  790. return
  791. }
  792. } else {
  793. dataconfig.ID = int64(dataBody["id"].(float64))
  794. err = service.UpdateDictionaryTemplate(&dataconfig)
  795. if err != nil {
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  797. return
  798. }
  799. }
  800. c.ServeSuccessJSON(map[string]interface{}{
  801. "dataconfig": dataconfig,
  802. "msg": "ok",
  803. })
  804. return
  805. }
  806. func (c *ManagerCenterApiController) UpdateChildConfig() {
  807. adminUserInfo := c.GetAdminUserInfo()
  808. var dataconfig models.DictionaryDataconfig
  809. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  810. if code > 0 {
  811. c.ServeFailJSONWithSGJErrorCode(code)
  812. return
  813. }
  814. dataBody := make(map[string]interface{}, 0)
  815. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  816. if err != nil {
  817. utils.ErrorLog(err.Error())
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  819. return
  820. }
  821. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  822. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  823. dataconfig.Status = 1
  824. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  825. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  826. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  827. dataconfig.Remark = string(dataBody["remark"].(string))
  828. dataconfig.Order = int64(dataBody["orders"].(float64))
  829. dataconfig.Code = string(dataBody["code"].(string))
  830. //if dataBody["orders"] != nil {
  831. // dataconfig.Order = int64(dataBody["orders"].(float64))
  832. // fmt.Println("dataconfig",dataconfig.Order)
  833. //} else {
  834. // dataconfig.Order = 0
  835. //}
  836. configOrgId := int64(dataBody["org_id"].(float64))
  837. // 验证关键字段的值是否重复
  838. // configId := int64(dataBody["id"].(float64))
  839. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  840. // if thisConfig.ID >0 {
  841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  842. // return
  843. // }
  844. if configOrgId == 0 {
  845. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  846. err := service.CreateDictionaryConfig(&dataconfig)
  847. if err != nil {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  849. return
  850. }
  851. } else {
  852. dataconfig.ID = int64(dataBody["id"].(float64))
  853. err = service.UpdateDictionaryChildConfig(&dataconfig)
  854. if err != nil {
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  856. return
  857. }
  858. }
  859. c.ServeSuccessJSON(map[string]interface{}{
  860. "dataconfig": dataconfig,
  861. "msg": "ok",
  862. })
  863. return
  864. }
  865. func (c *ManagerCenterApiController) DeleteChildConfig() {
  866. adminUserInfo := c.GetAdminUserInfo()
  867. var dataconfig models.DictionaryDataconfig
  868. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  869. if code > 0 {
  870. c.ServeFailJSONWithSGJErrorCode(code)
  871. return
  872. }
  873. dataBody := make(map[string]interface{}, 0)
  874. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  875. if err != nil {
  876. utils.ErrorLog(err.Error())
  877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  878. return
  879. }
  880. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  881. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  882. dataconfig.Status = 0
  883. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  884. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  885. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  886. dataconfig.Remark = string(dataBody["remark"].(string))
  887. if dataBody["order"] != nil {
  888. dataconfig.Order = int64(dataBody["order"].(float64))
  889. } else {
  890. dataconfig.Order = 0
  891. }
  892. configOrgId := int64(dataBody["org_id"].(float64))
  893. if configOrgId == 0 {
  894. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  895. err := service.CreateDictionaryConfig(&dataconfig)
  896. if err != nil {
  897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  898. return
  899. }
  900. } else {
  901. dataconfig.ID = int64(dataBody["id"].(float64))
  902. err := service.DeleteDictionaryChildConfig(&dataconfig)
  903. if err != nil {
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  905. return
  906. }
  907. }
  908. c.ServeSuccessJSON(map[string]interface{}{
  909. "dataconfig": dataconfig,
  910. "msg": "ok",
  911. })
  912. return
  913. }
  914. // CreateChildConfig 创建子配置信息
  915. func (c *ManagerCenterApiController) CreateChildConfig() {
  916. adminUserInfo := c.GetAdminUserInfo()
  917. var dataconfig models.DictionaryDataconfig
  918. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  919. if code > 0 {
  920. c.ServeFailJSONWithSGJErrorCode(code)
  921. return
  922. }
  923. dataBody := make(map[string]interface{}, 0)
  924. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  925. if err != nil {
  926. utils.ErrorLog(err.Error())
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  928. return
  929. }
  930. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  931. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  932. dataconfig.Status = 1
  933. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  934. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  935. dataconfig.Remark = string(dataBody["remark"].(string))
  936. dataconfig.Code = string(dataBody["code"].(string))
  937. fmt.Println("3444444444", dataconfig.Code)
  938. if dataBody["order"] != nil {
  939. dataconfig.Order = int64(dataBody["order"].(float64))
  940. } else {
  941. dataconfig.Order = 0
  942. }
  943. // 验证关键字段的值是否重复
  944. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  945. // if thisConfig.ID >0 {
  946. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  947. // return
  948. // }
  949. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  950. dataconfig.Value = fieldValue + 1
  951. err = service.CreateDictionaryConfig(&dataconfig)
  952. if err != nil {
  953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  954. return
  955. }
  956. c.ServeSuccessJSON(map[string]interface{}{
  957. "dataconfig": dataconfig,
  958. "msg": "ok",
  959. })
  960. return
  961. }
  962. func dictionaryConfigFormData(dataconfig *models.DictionaryDataconfig, data []byte) (code int) {
  963. configBody := make(map[string]interface{}, 0)
  964. err := json.Unmarshal(data, &configBody)
  965. utils.InfoLog(string(data))
  966. if err != nil {
  967. utils.ErrorLog(err.Error())
  968. code = enums.ErrorCodeParamWrong
  969. return
  970. }
  971. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  972. utils.ErrorLog("module")
  973. code = enums.ErrorCodeParamWrong
  974. return
  975. }
  976. module, _ := configBody["module"].(string)
  977. if len(module) == 0 {
  978. utils.ErrorLog("len(module) == 0")
  979. code = enums.ErrorCodeParamWrong
  980. return
  981. }
  982. dataconfig.Module = module
  983. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" {
  984. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  985. utils.ErrorLog("title")
  986. code = enums.ErrorCodeParamWrong
  987. return
  988. }
  989. title, _ := configBody["title"].(string)
  990. if len(title) == 0 {
  991. utils.ErrorLog("len(title) == 0")
  992. code = enums.ErrorCodeParamWrong
  993. return
  994. }
  995. dataconfig.Title = title
  996. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  997. utils.ErrorLog("content")
  998. code = enums.ErrorCodeParamWrong
  999. return
  1000. }
  1001. content, _ := configBody["content"].(string)
  1002. if len(content) == 0 {
  1003. utils.ErrorLog("len(content) == 0")
  1004. code = enums.ErrorCodeParamWrong
  1005. return
  1006. }
  1007. dataconfig.Content = content
  1008. } else {
  1009. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  1010. utils.ErrorLog("name")
  1011. code = enums.ErrorCodeParamWrong
  1012. return
  1013. }
  1014. name, _ := configBody["name"].(string)
  1015. if len(name) == 0 {
  1016. utils.ErrorLog("len(name) == 0")
  1017. code = enums.ErrorCodeParamWrong
  1018. return
  1019. }
  1020. dataconfig.Name = name
  1021. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  1022. utils.ErrorLog("field_name")
  1023. code = enums.ErrorCodeParamWrong
  1024. return
  1025. }
  1026. field_name, _ := configBody["field_name"].(string)
  1027. if len(field_name) == 0 {
  1028. utils.ErrorLog("len(field_name) == 0")
  1029. code = enums.ErrorCodeParamWrong
  1030. return
  1031. }
  1032. dataconfig.FieldName = field_name
  1033. }
  1034. return
  1035. }
  1036. func dictionaryConfigChildFormData(dataconfig *models.DictionaryDataconfig, data []byte) (code int) {
  1037. configBody := make(map[string]interface{}, 0)
  1038. err := json.Unmarshal(data, &configBody)
  1039. utils.InfoLog(string(data))
  1040. if err != nil {
  1041. utils.ErrorLog(err.Error())
  1042. code = enums.ErrorCodeParamWrong
  1043. return
  1044. }
  1045. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  1046. utils.ErrorLog("module")
  1047. code = enums.ErrorCodeParamWrong
  1048. return
  1049. }
  1050. module, _ := configBody["module"].(string)
  1051. if len(module) == 0 {
  1052. utils.ErrorLog("len(module) == 0")
  1053. code = enums.ErrorCodeParamWrong
  1054. return
  1055. }
  1056. dataconfig.Module = module
  1057. if module == "education" || module == "summary" {
  1058. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  1059. utils.ErrorLog("title")
  1060. code = enums.ErrorCodeParamWrong
  1061. return
  1062. }
  1063. title, _ := configBody["title"].(string)
  1064. if len(title) == 0 {
  1065. utils.ErrorLog("len(title) == 0")
  1066. code = enums.ErrorCodeParamWrong
  1067. return
  1068. }
  1069. dataconfig.Title = title
  1070. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  1071. utils.ErrorLog("content")
  1072. code = enums.ErrorCodeParamWrong
  1073. return
  1074. }
  1075. content, _ := configBody["content"].(string)
  1076. if len(content) == 0 {
  1077. utils.ErrorLog("len(content) == 0")
  1078. code = enums.ErrorCodeParamWrong
  1079. return
  1080. }
  1081. dataconfig.Content = content
  1082. } else {
  1083. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  1084. utils.ErrorLog("module")
  1085. code = enums.ErrorCodeParamWrong
  1086. return
  1087. }
  1088. parent_id := int64(configBody["parent_id"].(float64))
  1089. if parent_id <= 0 {
  1090. utils.ErrorLog("parent_id <= 0")
  1091. code = enums.ErrorCodeParamWrong
  1092. return
  1093. }
  1094. dataconfig.ParentId = parent_id
  1095. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  1096. utils.ErrorLog("name")
  1097. code = enums.ErrorCodeParamWrong
  1098. return
  1099. }
  1100. name, _ := configBody["name"].(string)
  1101. if len(name) == 0 {
  1102. utils.ErrorLog("len(name) == 0")
  1103. code = enums.ErrorCodeParamWrong
  1104. return
  1105. }
  1106. dataconfig.Name = name
  1107. }
  1108. return
  1109. }
  1110. func (c *ManagerCenterApiController) CreateDealer() {
  1111. dealer_name := c.GetString("dealer_name")
  1112. contact := c.GetString("contact")
  1113. contact_phone := c.GetString("contact_phone")
  1114. platform_number := c.GetString("platform_number")
  1115. email := c.GetString("email")
  1116. contact_address := c.GetString("contact_address")
  1117. remark := c.GetString("remark")
  1118. pinyin := c.GetString("pinyin")
  1119. wubi := c.GetString("wubi")
  1120. if len(dealer_name) <= 0 {
  1121. utils.ErrorLog("len(dealer_name) == 0")
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. adminUserInfo := c.GetAdminUserInfo()
  1126. total := service.FindAllDealerTotal(adminUserInfo.CurrentOrgId)
  1127. totalStr := strconv.FormatInt(total+1, 10)
  1128. code := "1000" + totalStr
  1129. dealer := models.Dealer{
  1130. DealerName: dealer_name,
  1131. Contact: contact,
  1132. ContactPhone: contact_phone,
  1133. ContactAddress: contact_address,
  1134. DealerCode: code,
  1135. Ctime: time.Now().Unix(),
  1136. Mtime: time.Now().Unix(),
  1137. Remark: remark,
  1138. Creater: adminUserInfo.AdminUser.Id,
  1139. Email: email,
  1140. PlatformNumber: platform_number,
  1141. OrgId: adminUserInfo.CurrentOrgId,
  1142. Status: 1,
  1143. PinYin: pinyin,
  1144. WuBi: wubi,
  1145. }
  1146. err, dealers := service.AddSigleDealer(&dealer)
  1147. if err == nil {
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "dealer": dealers,
  1150. })
  1151. } else {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1153. }
  1154. }
  1155. func (c *ManagerCenterApiController) ModifyDealer() {
  1156. id, _ := c.GetInt64("id", 0)
  1157. dealer_name := c.GetString("dealer_name")
  1158. contact := c.GetString("contact")
  1159. contact_phone := c.GetString("contact_phone")
  1160. platform_number := c.GetString("platform_number")
  1161. dealer_code := c.GetString("dealer_code")
  1162. email := c.GetString("email")
  1163. contact_address := c.GetString("contact_address")
  1164. remark := c.GetString("remark")
  1165. pinyin := c.GetString("pinyin")
  1166. wubi := c.GetString("wubi")
  1167. if id <= 0 {
  1168. utils.ErrorLog("id == 0")
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. if len(dealer_name) <= 0 {
  1173. utils.ErrorLog("len(dealer_name) == 0")
  1174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1175. return
  1176. }
  1177. adminUserInfo := c.GetAdminUserInfo()
  1178. dealer := models.Dealer{
  1179. ID: id,
  1180. DealerName: dealer_name,
  1181. Contact: contact,
  1182. ContactPhone: contact_phone,
  1183. ContactAddress: contact_address,
  1184. Mtime: time.Now().Unix(),
  1185. DealerCode: dealer_code,
  1186. Remark: remark,
  1187. Creater: adminUserInfo.AdminUser.Id,
  1188. Email: email,
  1189. PlatformNumber: platform_number,
  1190. Modifier: adminUserInfo.AdminUser.Id,
  1191. OrgId: adminUserInfo.CurrentOrgId,
  1192. Status: 1,
  1193. PinYin: pinyin,
  1194. WuBi: wubi,
  1195. }
  1196. err := service.ModifyDealer(&dealer)
  1197. if err == nil {
  1198. c.ServeSuccessJSON(map[string]interface{}{
  1199. "dealer": dealer,
  1200. })
  1201. } else {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1203. }
  1204. }
  1205. func (c *ManagerCenterApiController) GetDealersList() {
  1206. page, _ := c.GetInt64("page", 1)
  1207. limit, _ := c.GetInt64("limit", 7)
  1208. key, _ := c.GetInt64("key", 0)
  1209. adminUserInfo := c.GetAdminUserInfo()
  1210. deales, total, err := service.FindAllDealerList(adminUserInfo.CurrentOrgId, page, limit, key)
  1211. if err == nil {
  1212. c.ServeSuccessJSON(map[string]interface{}{
  1213. "dealer": deales,
  1214. "total": total,
  1215. })
  1216. } else {
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1218. }
  1219. }
  1220. func (c *ManagerCenterApiController) DeleteDealer() {
  1221. id, _ := c.GetInt64("id", 0)
  1222. total, _ := service.FindStockInByDealerId(id)
  1223. if total > 0 {
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteDealerWrong)
  1225. return
  1226. }
  1227. err := service.DeleteDealerById(id)
  1228. if err == nil {
  1229. c.ServeSuccessJSON(map[string]interface{}{
  1230. "msg": "删除成功",
  1231. })
  1232. } else {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1234. }
  1235. }
  1236. func (c *ManagerCenterApiController) GetDealer() {
  1237. id, _ := c.GetInt64("id", 0)
  1238. dealer, err := service.FindDealerById(id)
  1239. if err == nil {
  1240. c.ServeSuccessJSON(map[string]interface{}{
  1241. "dealer": dealer,
  1242. })
  1243. } else {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1245. }
  1246. }
  1247. func (c *ManagerCenterApiController) CreateManufacturer() {
  1248. manufacturer_name := c.GetString("manufacturer_name")
  1249. contact := c.GetString("contact")
  1250. contact_phone := c.GetString("contact_phone")
  1251. platform_number := c.GetString("platform_number")
  1252. email := c.GetString("email")
  1253. contact_address := c.GetString("contact_address")
  1254. remark := c.GetString("remark")
  1255. pinyin := c.GetString("pinyin")
  1256. wubi := c.GetString("wubi")
  1257. if len(manufacturer_name) <= 0 {
  1258. utils.ErrorLog("len(manufacturer_name) == 0")
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. adminUserInfo := c.GetAdminUserInfo()
  1263. total := service.FindManufacturerTotal(adminUserInfo.CurrentOrgId)
  1264. totalStr := strconv.FormatInt(total+1, 10)
  1265. code := "2000" + totalStr
  1266. manufacturer := models.Manufacturer{
  1267. ManufacturerName: manufacturer_name,
  1268. Contact: contact,
  1269. ContactPhone: contact_phone,
  1270. ContactAddress: contact_address,
  1271. Ctime: time.Now().Unix(),
  1272. Mtime: time.Now().Unix(),
  1273. Remark: remark,
  1274. Creater: adminUserInfo.AdminUser.Id,
  1275. Email: email,
  1276. PlatformNumber: platform_number,
  1277. OrgId: adminUserInfo.CurrentOrgId,
  1278. Status: 1,
  1279. ManufacturerCode: code,
  1280. PinYin: pinyin,
  1281. WuBi: wubi,
  1282. }
  1283. err, manufacturers := service.AddSigleManufacturer(&manufacturer)
  1284. if err == nil {
  1285. c.ServeSuccessJSON(map[string]interface{}{
  1286. "manufacturer": manufacturers,
  1287. })
  1288. } else {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1290. }
  1291. }
  1292. func (c *ManagerCenterApiController) ModifyManufacturer() {
  1293. id, _ := c.GetInt64("id", 0)
  1294. manufacturer_name := c.GetString("manufacturer_name")
  1295. contact := c.GetString("contact")
  1296. contact_phone := c.GetString("contact_phone")
  1297. platform_number := c.GetString("platform_number")
  1298. email := c.GetString("email")
  1299. contact_address := c.GetString("contact_address")
  1300. remark := c.GetString("remark")
  1301. manufacturer_code := c.GetString("manufacturer_code")
  1302. pinyin := c.GetString("pinyin")
  1303. wubi := c.GetString("wubi")
  1304. if id <= 0 {
  1305. utils.ErrorLog("id == 0")
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. if len(manufacturer_name) <= 0 {
  1310. utils.ErrorLog("len(manufacturer_name) == 0")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. adminUserInfo := c.GetAdminUserInfo()
  1315. manufacturer := models.Manufacturer{
  1316. ID: id,
  1317. ManufacturerName: manufacturer_name,
  1318. Contact: contact,
  1319. ContactPhone: contact_phone,
  1320. ContactAddress: contact_address,
  1321. Mtime: time.Now().Unix(),
  1322. Remark: remark,
  1323. Creater: adminUserInfo.AdminUser.Id,
  1324. Email: email,
  1325. PlatformNumber: platform_number,
  1326. Modifier: adminUserInfo.AdminUser.Id,
  1327. OrgId: adminUserInfo.CurrentOrgId,
  1328. ManufacturerCode: manufacturer_code,
  1329. Status: 1,
  1330. PinYin: pinyin,
  1331. WuBi: wubi,
  1332. }
  1333. err := service.ModifyManufacturer(&manufacturer)
  1334. if err == nil {
  1335. c.ServeSuccessJSON(map[string]interface{}{
  1336. "manufacturer": manufacturer,
  1337. })
  1338. } else {
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1340. }
  1341. }
  1342. func (c *ManagerCenterApiController) GetManufacturerList() {
  1343. page, _ := c.GetInt64("page", 1)
  1344. limit, _ := c.GetInt64("limit", 10)
  1345. key, _ := c.GetInt64("key", 0)
  1346. adminUserInfo := c.GetAdminUserInfo()
  1347. manufacturer, total, err := service.FindAllManufacturerList(adminUserInfo.CurrentOrgId, page, limit, key)
  1348. if err == nil {
  1349. c.ServeSuccessJSON(map[string]interface{}{
  1350. "manufacturer": manufacturer,
  1351. "total": total,
  1352. })
  1353. } else {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1355. }
  1356. }
  1357. func (c *ManagerCenterApiController) DeleteManufacturer() {
  1358. id, _ := c.GetInt64("id", 0)
  1359. total, _ := service.FindStockInByManufacturerId(id)
  1360. if total > 0 {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteManufacturerWrong)
  1362. return
  1363. }
  1364. err := service.DeleteManufacturerById(id)
  1365. if err == nil {
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "msg": "删除成功",
  1368. })
  1369. } else {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1371. }
  1372. }
  1373. func (c *ManagerCenterApiController) GetManufacturer() {
  1374. id, _ := c.GetInt64("id", 0)
  1375. manufacturer, err := service.FindManufacturerById(id)
  1376. if err == nil {
  1377. c.ServeSuccessJSON(map[string]interface{}{
  1378. "manufacturer": manufacturer,
  1379. })
  1380. } else {
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1382. }
  1383. }
  1384. func (c *ManagerCenterApiController) GetAllDealer() {
  1385. adminUserInfo := c.GetAdminUserInfo()
  1386. dealer, err := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1387. if err == nil {
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "dealer": dealer,
  1390. })
  1391. } else {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1393. }
  1394. }
  1395. func (c *ManagerCenterApiController) GetAllManufacturer() {
  1396. adminUserInfo := c.GetAdminUserInfo()
  1397. manufacturer, err := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1398. if err == nil {
  1399. c.ServeSuccessJSON(map[string]interface{}{
  1400. "manufacturer": manufacturer,
  1401. })
  1402. } else {
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1404. }
  1405. }
  1406. func (c *ManagerCenterApiController) CreateGoodInfo() {
  1407. good_id, _ := c.GetInt64("good_id", 0)
  1408. specification_name := c.GetString("specification_name")
  1409. register_number := c.GetString("register_number")
  1410. good_unit, _ := c.GetInt64("good_unit", -1)
  1411. buy_price, _ := c.GetFloat("buy_price", 0)
  1412. sell_price, _ := c.GetFloat("sell_price", 0)
  1413. remark := c.GetString("remark")
  1414. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1415. dealer, _ := c.GetInt64("dealer", 0)
  1416. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1417. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1418. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1419. good_name := c.GetString("good_name")
  1420. wubi := c.GetString("wubi")
  1421. good_kind, _ := c.GetInt64("good_kind", 0)
  1422. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1423. retail_price, _ := c.GetFloat("retail_price", 0)
  1424. fmt.Println(retail_price)
  1425. medical_insurance_number := c.GetString("medical_insurance_number")
  1426. provinces_code := c.GetString("provinces_code")
  1427. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1428. is_record, _ := c.GetInt64("is_record")
  1429. statistics_category, _ := c.GetInt64("statistics_category")
  1430. good_status := c.GetString("good_status")
  1431. default_count, _ := c.GetInt64("default_count")
  1432. sign, _ := c.GetInt64("sign")
  1433. is_default, _ := c.GetInt64("is_default")
  1434. is_charge_use, _ := c.GetInt64("is_charge_use")
  1435. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1436. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1437. sort, _ := c.GetInt64("sort")
  1438. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1439. agent := c.GetString("agent")
  1440. good_number := c.GetString("good_number")
  1441. social_security_directory_code := c.GetString("social_security_directory_code")
  1442. production_type := c.GetString("production_type")
  1443. special_medical := c.GetString("special_medical")
  1444. min_number, _ := c.GetInt64("min_number")
  1445. packing_unit := c.GetString("packing_unit")
  1446. packing_price, _ := c.GetFloat("packing_price")
  1447. min_unit := c.GetString("min_unit")
  1448. default_count_unit := c.GetString("default_count_unit")
  1449. is_user, _ := c.GetInt64("is_user")
  1450. number := c.GetString("number")
  1451. is_warehouse, _ := c.GetInt64("is_warehouse")
  1452. bbx01 := c.GetString("bbx01")
  1453. bby01 := c.GetString("bby01")
  1454. is_show, _ := c.GetInt64("is_show")
  1455. adminUserInfo := c.GetAdminUserInfo()
  1456. totals := service.FindGoodInfoByNameTwo(specification_name, adminUserInfo.CurrentOrgId, good_id, good_name)
  1457. if totals > 0 {
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  1459. return
  1460. }
  1461. total := service.FindAllGoodInfoTotal(adminUserInfo.CurrentOrgId)
  1462. code := strconv.FormatInt(total+1, 10)
  1463. code = "24000000" + code
  1464. // 创建一个拼音转换器
  1465. p := pinyin.NewArgs()
  1466. // 将汉字转为拼音
  1467. pinyinSlice := pinyin.Pinyin(good_name, p)
  1468. // 获取首字母
  1469. firstLetter := ""
  1470. for _, py := range pinyinSlice {
  1471. if len(py) > 0 {
  1472. firstLetter += string(py[0][0])
  1473. }
  1474. }
  1475. goodInfo := models.GoodInfo{
  1476. GoodCode: code,
  1477. SpecificationName: specification_name,
  1478. GoodTypeId: good_id,
  1479. GoodUnit: good_unit,
  1480. BuyPrice: buy_price,
  1481. SellPrice: sell_price,
  1482. Remark: remark,
  1483. Ctime: time.Now().Unix(),
  1484. Manufacturer: manufacturer,
  1485. Dealer: dealer,
  1486. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1487. StockWarnCount: stock_warn_count,
  1488. IsReuse: is_reuse,
  1489. Status: 1,
  1490. OrgId: adminUserInfo.CurrentOrgId,
  1491. Creater: adminUserInfo.AdminUser.Id,
  1492. GoodName: good_name,
  1493. Pinyin: firstLetter,
  1494. FirstLetter: firstLetter,
  1495. Wubi: wubi,
  1496. GoodKind: good_kind,
  1497. MedicalInsuranceNumber: medical_insurance_number,
  1498. IsSpecialDiseases: is_special_diseases,
  1499. IsRecord: is_record,
  1500. StatisticsCategory: statistics_category,
  1501. GoodStatus: good_status,
  1502. DefaultCount: default_count,
  1503. Sign: sign,
  1504. IsDefault: is_default,
  1505. IsChargeUse: is_charge_use,
  1506. IsChargePredict: is_charge_predict,
  1507. IsStatisticsWork: is_statistics_work,
  1508. Sort: sort,
  1509. IsDoctorUse: is_doctor_use,
  1510. Agent: agent,
  1511. GoodNumber: good_number,
  1512. MedicalInsuranceLevel: medical_insurance_level,
  1513. RetailPrice: packing_price,
  1514. SocialSecurityDirectoryCode: social_security_directory_code,
  1515. ProductionType: production_type,
  1516. SpecialMedical: special_medical,
  1517. MinNumber: min_number,
  1518. PackingUnit: packing_unit,
  1519. PackingPrice: packing_price,
  1520. DefaultCountUnit: default_count_unit,
  1521. MinUnit: min_unit,
  1522. RegisterNumber: register_number,
  1523. ProvincesCode: provinces_code,
  1524. IsUser: is_user,
  1525. Number: number,
  1526. IsWarehouse: is_warehouse,
  1527. Bbx01: bbx01,
  1528. Bby01: bby01,
  1529. ZuobiaoId: bbx01,
  1530. Bck01b: "55",
  1531. IsShow: is_show,
  1532. }
  1533. err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
  1534. if err == nil {
  1535. c.ServeSuccessJSON(map[string]interface{}{
  1536. "goodInfo": goodInfos,
  1537. })
  1538. } else {
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1540. }
  1541. }
  1542. func (c *ManagerCenterApiController) ModifyGoodInfo() {
  1543. id, _ := c.GetInt64("id", 0)
  1544. good_id, _ := c.GetInt64("good_id", 0)
  1545. specification_name := c.GetString("specification_name")
  1546. good_unit, _ := c.GetInt64("good_unit", -1)
  1547. buy_price, _ := c.GetFloat("buy_price", 0)
  1548. sell_price, _ := c.GetFloat("sell_price", 0)
  1549. remark := c.GetString("remark")
  1550. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1551. dealer, _ := c.GetInt64("dealer", 0)
  1552. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1553. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1554. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1555. code := c.GetString("good_code")
  1556. provinces_code := c.GetString("provinces_code")
  1557. good_name := c.GetString("good_name")
  1558. wubi := c.GetString("wubi")
  1559. good_kind, _ := c.GetInt64("good_kind", 0)
  1560. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1561. retail_price, _ := c.GetFloat("retail_price", 0)
  1562. fmt.Println(retail_price)
  1563. medical_insurance_number := c.GetString("medical_insurance_number")
  1564. //provinces_code := c.GetString("provinces_code")
  1565. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1566. is_record, _ := c.GetInt64("is_record")
  1567. statistics_category, _ := c.GetInt64("statistics_category")
  1568. good_status := c.GetString("good_status")
  1569. default_count, _ := c.GetInt64("default_count")
  1570. sign, _ := c.GetInt64("sign")
  1571. is_default, _ := c.GetInt64("is_default")
  1572. is_charge_use, _ := c.GetInt64("is_charge_use")
  1573. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1574. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1575. sort, _ := c.GetInt64("sort")
  1576. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1577. agent := c.GetString("agent")
  1578. good_number := c.GetString("good_number")
  1579. social_security_directory_code := c.GetString("social_security_directory_code")
  1580. production_type := c.GetString("production_type")
  1581. special_medical := c.GetString("special_medical")
  1582. min_number, _ := c.GetInt64("min_number")
  1583. packing_unit := c.GetString("packing_unit")
  1584. packing_price, _ := c.GetFloat("packing_price")
  1585. default_count_unit := c.GetString("default_count_unit")
  1586. min_unit := c.GetString("min_unit")
  1587. total, _ := c.GetFloat("total")
  1588. register_number := c.GetString("register_number")
  1589. is_user, _ := c.GetInt64("is_user")
  1590. number := c.GetString("number")
  1591. is_warehouse, _ := c.GetInt64("is_warehouse")
  1592. bbx01 := c.GetString("bbx01")
  1593. bby01 := c.GetString("bby01")
  1594. is_show, _ := c.GetInt64("is_show")
  1595. // 创建一个拼音转换器
  1596. p := pinyin.NewArgs()
  1597. // 将汉字转为拼音
  1598. pinyinSlice := pinyin.Pinyin(good_name, p)
  1599. // 获取首字母
  1600. firstLetter := ""
  1601. for _, py := range pinyinSlice {
  1602. if len(py) > 0 {
  1603. firstLetter += string(py[0][0])
  1604. }
  1605. }
  1606. adminUserInfo := c.GetAdminUserInfo()
  1607. goodInfo := models.GoodInfo{
  1608. ID: id,
  1609. GoodCode: code,
  1610. SpecificationName: specification_name,
  1611. GoodTypeId: good_id,
  1612. GoodUnit: good_unit,
  1613. BuyPrice: buy_price,
  1614. SellPrice: sell_price,
  1615. Remark: remark,
  1616. Mtime: time.Now().Unix(),
  1617. Manufacturer: manufacturer,
  1618. Dealer: dealer,
  1619. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1620. StockWarnCount: stock_warn_count,
  1621. IsReuse: is_reuse,
  1622. Status: 1,
  1623. OrgId: adminUserInfo.CurrentOrgId,
  1624. Modifier: adminUserInfo.AdminUser.Id,
  1625. GoodName: good_name,
  1626. Pinyin: firstLetter,
  1627. FirstLetter: firstLetter,
  1628. Wubi: wubi,
  1629. GoodKind: good_kind,
  1630. MedicalInsuranceNumber: medical_insurance_number,
  1631. ProvincesCode: provinces_code,
  1632. IsSpecialDiseases: is_special_diseases,
  1633. IsRecord: is_record,
  1634. StatisticsCategory: statistics_category,
  1635. GoodStatus: good_status,
  1636. DefaultCount: default_count,
  1637. Sign: sign,
  1638. IsDefault: is_default,
  1639. IsChargeUse: is_charge_use,
  1640. IsChargePredict: is_charge_predict,
  1641. IsStatisticsWork: is_statistics_work,
  1642. Sort: sort,
  1643. IsDoctorUse: is_doctor_use,
  1644. Agent: agent,
  1645. GoodNumber: good_number,
  1646. MedicalInsuranceLevel: medical_insurance_level,
  1647. RetailPrice: packing_price,
  1648. SpecialMedical: special_medical,
  1649. SocialSecurityDirectoryCode: social_security_directory_code,
  1650. ProductionType: production_type,
  1651. MinNumber: min_number,
  1652. PackingUnit: packing_unit,
  1653. PackingPrice: packing_price,
  1654. DefaultCountUnit: default_count_unit,
  1655. MinUnit: min_unit,
  1656. Total: total,
  1657. RegisterNumber: register_number,
  1658. IsUser: is_user,
  1659. Number: number,
  1660. IsWarehouse: is_warehouse,
  1661. Bbx01: bbx01,
  1662. Bby01: bby01,
  1663. ZuobiaoId: bbx01,
  1664. Bck01b: "55",
  1665. IsShow: is_show,
  1666. }
  1667. totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)
  1668. if totals > 0 {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  1670. return
  1671. }
  1672. err, goodInfos := service.ModifyGoodInfo(&goodInfo)
  1673. if adminUserInfo.CurrentOrgId != 10653 && adminUserInfo.CurrentOrgId != 10644 {
  1674. list, _ := service.GetHisPrescripionProjectList(good_id, adminUserInfo.CurrentOrgId)
  1675. if len(list) > 0 {
  1676. for _, item := range list {
  1677. service.UpdateHisPrescriptionProjectList(item.ID, sell_price)
  1678. }
  1679. }
  1680. }
  1681. if err == nil {
  1682. c.ServeSuccessJSON(map[string]interface{}{
  1683. "goodInfo": goodInfos,
  1684. })
  1685. } else {
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1687. }
  1688. }
  1689. func (c *ManagerCenterApiController) GetGoodInfoList() {
  1690. page, _ := c.GetInt64("page", 1)
  1691. limit, _ := c.GetInt64("limit", 7)
  1692. keyword := c.GetString("keyword")
  1693. is_use, _ := c.GetInt64("is_use")
  1694. is_charge, _ := c.GetInt64("is_charge")
  1695. good_kind, _ := c.GetInt64("good_kind")
  1696. is_mark, _ := c.GetInt64("is_mark")
  1697. manufacturer, _ := c.GetInt64("manufacturer")
  1698. is_type, _ := c.GetInt64("is_type")
  1699. adminUserInfo := c.GetAdminUserInfo()
  1700. goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword, is_use, is_charge, good_kind, is_mark, manufacturer, is_type)
  1701. if err == nil {
  1702. c.ServeSuccessJSON(map[string]interface{}{
  1703. "list": goodInfos,
  1704. "total": total,
  1705. })
  1706. } else {
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1708. }
  1709. }
  1710. func (c *ManagerCenterApiController) DeleteGoodInfo() {
  1711. id, _ := c.GetInt64("id", 0)
  1712. adminUserInfo := c.GetAdminUserInfo()
  1713. total, _ := service.FindWarehouseInfoTotalByGoodId(id)
  1714. total2, _ := service.FindWarehouseOutInfoTotalByGoodId(id)
  1715. if total > 0 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1717. return
  1718. }
  1719. if total2 > 0 {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1721. return
  1722. }
  1723. err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
  1724. if err == nil {
  1725. c.ServeSuccessJSON(map[string]interface{}{
  1726. "msg": "删除成功",
  1727. })
  1728. } else {
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1730. }
  1731. }
  1732. func (c *ManagerCenterApiController) GetGoodInfoByGoodId() {
  1733. id, _ := c.GetInt64("id", 0)
  1734. goodInfo, err := service.FindGoodInfoByGoodId(id)
  1735. if err == nil {
  1736. c.ServeSuccessJSON(map[string]interface{}{
  1737. "list": goodInfo,
  1738. })
  1739. } else {
  1740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1741. }
  1742. }
  1743. func (c *ManagerCenterApiController) GetGoodInfoById() {
  1744. id, _ := c.GetInt64("id", 0)
  1745. goodInfo, err := service.FindGoodInfoById(id)
  1746. if err == nil {
  1747. c.ServeSuccessJSON(map[string]interface{}{
  1748. "goodInfo": goodInfo,
  1749. })
  1750. } else {
  1751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1752. }
  1753. }
  1754. func (c *ManagerCenterApiController) GetMedicineInsurancePercent() {
  1755. adminUser := c.GetAdminUserInfo()
  1756. type_id, _ := c.GetInt64("type_id", 0)
  1757. module, _ := c.GetInt64("module", 0)
  1758. mip, err := service.GetLastMedicineInsurance(adminUser.CurrentOrgId, type_id, module)
  1759. if err == nil {
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "mip": mip,
  1762. })
  1763. } else {
  1764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1765. }
  1766. }
  1767. func (c *ManagerCenterApiController) CreateMZSick() {
  1768. class_name := c.GetString("class_name")
  1769. content_code := c.GetString("content_code")
  1770. country_code := c.GetString("country_code")
  1771. country_content_name := c.GetString("country_content_name")
  1772. remark := c.GetString("remark")
  1773. pinyin := c.GetString("pinyin")
  1774. wubi := c.GetString("wubi")
  1775. if len(class_name) <= 0 {
  1776. utils.ErrorLog("len(class_name) == 0")
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1778. return
  1779. }
  1780. if len(content_code) <= 0 {
  1781. utils.ErrorLog("len(content_code) == 0")
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. adminUserInfo := c.GetAdminUserInfo()
  1786. dealer := models.OutpatientServiceSick{
  1787. ClassName: class_name,
  1788. ContentCode: content_code,
  1789. CountryCode: country_code,
  1790. CountryContentName: country_content_name,
  1791. Ctime: time.Now().Unix(),
  1792. Mtime: time.Now().Unix(),
  1793. Remark: remark,
  1794. UserOrgId: adminUserInfo.CurrentOrgId,
  1795. Status: 1,
  1796. Pinyin: pinyin,
  1797. Wubi: wubi,
  1798. }
  1799. err, dealers := service.AddSigleMZSick(&dealer)
  1800. if err == nil {
  1801. redis := service.RedisClient()
  1802. defer redis.Close()
  1803. sick_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_sick"
  1804. redis.Set(sick_keys, "", time.Second*60*60*18)
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "sick": dealers,
  1807. })
  1808. } else {
  1809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1810. }
  1811. }
  1812. func (c *ManagerCenterApiController) ModifyMZSick() {
  1813. id, _ := c.GetInt64("id", 0)
  1814. class_name := c.GetString("class_name")
  1815. content_code := c.GetString("content_code")
  1816. country_code := c.GetString("country_code")
  1817. country_content_name := c.GetString("country_content_name")
  1818. remark := c.GetString("remark")
  1819. pinyin := c.GetString("pinyin")
  1820. wubi := c.GetString("wubi")
  1821. if id <= 0 {
  1822. utils.ErrorLog("id == 0")
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1824. return
  1825. }
  1826. if len(class_name) <= 0 {
  1827. utils.ErrorLog("len(class_name) == 0")
  1828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1829. return
  1830. }
  1831. if len(content_code) <= 0 {
  1832. utils.ErrorLog("len(content_code) == 0")
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. adminUserInfo := c.GetAdminUserInfo()
  1837. dealer := models.OutpatientServiceSick{
  1838. ID: id,
  1839. ClassName: class_name,
  1840. ContentCode: content_code,
  1841. CountryCode: country_code,
  1842. CountryContentName: country_content_name,
  1843. Ctime: time.Now().Unix(),
  1844. Mtime: time.Now().Unix(),
  1845. Remark: remark,
  1846. UserOrgId: adminUserInfo.CurrentOrgId,
  1847. Pinyin: pinyin,
  1848. Wubi: wubi,
  1849. Status: 1,
  1850. }
  1851. err := service.ModifyMZSick(&dealer)
  1852. if err == nil {
  1853. redis := service.RedisClient()
  1854. defer redis.Close()
  1855. sick_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_sick"
  1856. redis.Set(sick_keys, "", time.Second*60*60*18)
  1857. c.ServeSuccessJSON(map[string]interface{}{
  1858. "sick": dealer,
  1859. })
  1860. } else {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1862. }
  1863. }
  1864. func (c *ManagerCenterApiController) GetMZSickList() {
  1865. page, _ := c.GetInt64("page", 1)
  1866. limit, _ := c.GetInt64("limit", 7)
  1867. adminUserInfo := c.GetAdminUserInfo()
  1868. mzSick, total, err := service.FindAllMZSickList(adminUserInfo.CurrentOrgId, page, limit)
  1869. if err == nil {
  1870. c.ServeSuccessJSON(map[string]interface{}{
  1871. "sick": mzSick,
  1872. "total": total,
  1873. })
  1874. } else {
  1875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1876. }
  1877. }
  1878. func (c *ManagerCenterApiController) DeleteMZSick() {
  1879. id, _ := c.GetInt64("id", 0)
  1880. err := service.DeleteMZSickById(id)
  1881. if err == nil {
  1882. redis := service.RedisClient()
  1883. defer redis.Close()
  1884. sick_keys := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + "_sick"
  1885. redis.Set(sick_keys, "", time.Second*60*60*18)
  1886. c.ServeSuccessJSON(map[string]interface{}{
  1887. "msg": "删除成功",
  1888. })
  1889. } else {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1891. }
  1892. }
  1893. func (c *ManagerCenterApiController) GetMZSick() {
  1894. id, _ := c.GetInt64("id", 0)
  1895. mzSick, err := service.FindMZSickById(id)
  1896. if err == nil {
  1897. c.ServeSuccessJSON(map[string]interface{}{
  1898. "sick": mzSick,
  1899. })
  1900. } else {
  1901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1902. }
  1903. }
  1904. func (c *ManagerCenterApiController) DeleteBaseDrugById() {
  1905. id, _ := c.GetInt64("id")
  1906. //查询入库单
  1907. _, errcode := service.GetDrugWareoutInfo(id)
  1908. if errcode == gorm.ErrRecordNotFound {
  1909. //查询出库单
  1910. _, errcodes := service.GetDrugWareOutById(id)
  1911. if errcodes == gorm.ErrRecordNotFound {
  1912. //删除
  1913. service.DeleteBaseDrugById(id)
  1914. returnData := make(map[string]interface{}, 0)
  1915. returnData["msg"] = "ok"
  1916. c.ServeSuccessJSON(returnData)
  1917. return
  1918. } else if errcodes == nil {
  1919. c.ServeFailJsonSend(enums.ErrorCodeDataException, "已出库")
  1920. return
  1921. }
  1922. } else if errcode == nil {
  1923. c.ServeFailJsonSend(enums.ErrorCodeDataException, "已入库")
  1924. return
  1925. }
  1926. }
  1927. func (c *ManagerCenterApiController) CreateAddition() {
  1928. name := c.GetString("name")
  1929. code := c.GetString("code")
  1930. //price, _ := c.GetFloat("price")
  1931. price := c.GetString("price")
  1932. price_float, _ := strconv.ParseFloat(price, 64)
  1933. if len(name) <= 0 {
  1934. utils.ErrorLog("len(name) == 0")
  1935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1936. return
  1937. }
  1938. //if len(code) <= 0 {
  1939. // utils.ErrorLog("len(code) == 0")
  1940. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1941. // return
  1942. //}
  1943. adminUserInfo := c.GetAdminUserInfo()
  1944. addition := models.XtHisAddtionConfig{
  1945. Name: name,
  1946. Code: code,
  1947. Status: 1,
  1948. Price: price_float,
  1949. Ctime: time.Now().Unix(),
  1950. Mtime: time.Now().Unix(),
  1951. UserOrgId: adminUserInfo.CurrentOrgId,
  1952. }
  1953. err, additions := service.AddSigleAddition(&addition)
  1954. if err == nil {
  1955. c.ServeSuccessJSON(map[string]interface{}{
  1956. "addition": additions,
  1957. })
  1958. } else {
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1960. }
  1961. }
  1962. func (c *ManagerCenterApiController) ModifyAddition() {
  1963. id, _ := c.GetInt64("id", 0)
  1964. name := c.GetString("name")
  1965. code := c.GetString("code")
  1966. price, _ := c.GetFloat("price")
  1967. if id <= 0 {
  1968. utils.ErrorLog("id == 0")
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. if len(name) <= 0 {
  1973. utils.ErrorLog("len(class_name) == 0")
  1974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1975. return
  1976. }
  1977. //if len(code) <= 0 {
  1978. // utils.ErrorLog("len(content_code) == 0")
  1979. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1980. // return
  1981. //}
  1982. adminUserInfo := c.GetAdminUserInfo()
  1983. addition := models.XtHisAddtionConfig{
  1984. ID: id,
  1985. Name: name,
  1986. Code: code,
  1987. Ctime: time.Now().Unix(),
  1988. Mtime: time.Now().Unix(),
  1989. UserOrgId: adminUserInfo.CurrentOrgId,
  1990. Price: price,
  1991. Status: 1,
  1992. }
  1993. err := service.ModifyAddition(&addition)
  1994. if err == nil {
  1995. c.ServeSuccessJSON(map[string]interface{}{
  1996. "addition": addition,
  1997. })
  1998. } else {
  1999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2000. }
  2001. }
  2002. func (c *ManagerCenterApiController) GetAdditionList() {
  2003. page, _ := c.GetInt64("page", 1)
  2004. limit, _ := c.GetInt64("limit", 7)
  2005. adminUserInfo := c.GetAdminUserInfo()
  2006. addition, total, err := service.FindAllAdditionList(adminUserInfo.CurrentOrgId, page, limit)
  2007. if err == nil {
  2008. c.ServeSuccessJSON(map[string]interface{}{
  2009. "addition": addition,
  2010. "total": total,
  2011. })
  2012. } else {
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2014. }
  2015. }
  2016. func (c *ManagerCenterApiController) DeleteAddition() {
  2017. id, _ := c.GetInt64("id", 0)
  2018. err := service.DeleteAdditionById(id)
  2019. if err == nil {
  2020. c.ServeSuccessJSON(map[string]interface{}{
  2021. "msg": "删除成功",
  2022. })
  2023. } else {
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2025. }
  2026. }
  2027. func (c *ManagerCenterApiController) GetAddition() {
  2028. id, _ := c.GetInt64("id", 0)
  2029. addition, err := service.FindAdditionById(id)
  2030. if err == nil {
  2031. c.ServeSuccessJSON(map[string]interface{}{
  2032. "addition": addition,
  2033. })
  2034. } else {
  2035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2036. }
  2037. }
  2038. func (c *ManagerCenterApiController) CreateDiagnose() {
  2039. class_name := c.GetString("class_name")
  2040. content_code := c.GetString("content_code")
  2041. country_code := c.GetString("country_code")
  2042. country_content_name := c.GetString("country_content_name")
  2043. remark := c.GetString("remark")
  2044. pinyin := c.GetString("pinyin")
  2045. wubi := c.GetString("wubi")
  2046. sort, _ := c.GetInt64("sort")
  2047. fmt.Println("sort-------------------", sort)
  2048. if len(class_name) <= 0 {
  2049. utils.ErrorLog("len(class_name) == 0")
  2050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2051. return
  2052. }
  2053. if len(content_code) <= 0 {
  2054. utils.ErrorLog("len(content_code) == 0")
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. adminUserInfo := c.GetAdminUserInfo()
  2059. dealer := models.HisXtDiagnoseConfig{
  2060. ClassName: class_name,
  2061. ContentCode: content_code,
  2062. CountryCode: country_code,
  2063. CountryContentName: country_content_name,
  2064. Ctime: time.Now().Unix(),
  2065. Mtime: time.Now().Unix(),
  2066. Remark: remark,
  2067. UserOrgId: adminUserInfo.CurrentOrgId,
  2068. Status: 1,
  2069. Pinyin: pinyin,
  2070. Wubi: wubi,
  2071. Sort: sort,
  2072. }
  2073. err, dealers := service.AddSigleDiagnose(&dealer)
  2074. if err == nil {
  2075. redis := service.RedisClient()
  2076. defer redis.Close()
  2077. diagnose_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_diagnose"
  2078. redis.Set(diagnose_keys, "", time.Second*60*60*18)
  2079. c.ServeSuccessJSON(map[string]interface{}{
  2080. "sick": dealers,
  2081. })
  2082. } else {
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2084. }
  2085. }
  2086. func (c *ManagerCenterApiController) ModifyDiagnose() {
  2087. id, _ := c.GetInt64("id", 0)
  2088. class_name := c.GetString("class_name")
  2089. content_code := c.GetString("content_code")
  2090. country_code := c.GetString("country_code")
  2091. country_content_name := c.GetString("country_content_name")
  2092. remark := c.GetString("remark")
  2093. pinyin := c.GetString("pinyin")
  2094. wubi := c.GetString("wubi")
  2095. sort, _ := c.GetInt64("sort")
  2096. if id <= 0 {
  2097. utils.ErrorLog("id == 0")
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2099. return
  2100. }
  2101. if len(class_name) <= 0 {
  2102. utils.ErrorLog("len(class_name) == 0")
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2104. return
  2105. }
  2106. if len(content_code) <= 0 {
  2107. utils.ErrorLog("len(content_code) == 0")
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2109. return
  2110. }
  2111. adminUserInfo := c.GetAdminUserInfo()
  2112. dealer := models.HisXtDiagnoseConfig{
  2113. ID: id,
  2114. ClassName: class_name,
  2115. ContentCode: content_code,
  2116. CountryCode: country_code,
  2117. CountryContentName: country_content_name,
  2118. Ctime: time.Now().Unix(),
  2119. Mtime: time.Now().Unix(),
  2120. Remark: remark,
  2121. UserOrgId: adminUserInfo.CurrentOrgId,
  2122. Pinyin: pinyin,
  2123. Wubi: wubi,
  2124. Status: 1,
  2125. Sort: sort,
  2126. }
  2127. err := service.ModifyDiagnose(&dealer)
  2128. if err == nil {
  2129. redis := service.RedisClient()
  2130. defer redis.Close()
  2131. diagnose_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_diagnose"
  2132. redis.Set(diagnose_keys, "", time.Second*60*60*18)
  2133. c.ServeSuccessJSON(map[string]interface{}{
  2134. "sick": dealer,
  2135. })
  2136. } else {
  2137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2138. }
  2139. }
  2140. func (c *ManagerCenterApiController) GetDiagnoseList() {
  2141. page, _ := c.GetInt64("page", 1)
  2142. limit, _ := c.GetInt64("limit", 7)
  2143. adminUserInfo := c.GetAdminUserInfo()
  2144. mzSick, total, err := service.FindAllDiagnoseList(adminUserInfo.CurrentOrgId, page, limit)
  2145. if err == nil {
  2146. c.ServeSuccessJSON(map[string]interface{}{
  2147. "sick": mzSick,
  2148. "total": total,
  2149. })
  2150. } else {
  2151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2152. }
  2153. }
  2154. func (c *ManagerCenterApiController) DeleteDiagnose() {
  2155. id, _ := c.GetInt64("id", 0)
  2156. err := service.DeleteDiagnoseById(id)
  2157. if err == nil {
  2158. redis := service.RedisClient()
  2159. defer redis.Close()
  2160. diagnose_keys := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + "_diagnose"
  2161. redis.Set(diagnose_keys, "", time.Second*60*60*18)
  2162. c.ServeSuccessJSON(map[string]interface{}{
  2163. "msg": "删除成功",
  2164. })
  2165. } else {
  2166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2167. }
  2168. }
  2169. func (c *ManagerCenterApiController) GetDiagnose() {
  2170. id, _ := c.GetInt64("id", 0)
  2171. mzSick, err := service.FindDiagnoseById(id)
  2172. if err == nil {
  2173. c.ServeSuccessJSON(map[string]interface{}{
  2174. "sick": mzSick,
  2175. })
  2176. } else {
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2178. }
  2179. }
  2180. func (c *ManagerCenterApiController) GetAllDrugList() {
  2181. orgId := c.GetAdminUserInfo().CurrentOrgId
  2182. list, err := service.GetAllDrugList(orgId)
  2183. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2184. dealerList, _ := service.GetAllDealerList(orgId)
  2185. if err == nil {
  2186. c.ServeSuccessJSON(map[string]interface{}{
  2187. "list": list,
  2188. "manufacturerList": manufacturerList,
  2189. "dealerList": dealerList,
  2190. })
  2191. } else {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2193. }
  2194. }
  2195. func (c *ManagerCenterApiController) GetSearchDrugList() {
  2196. keyword := c.GetString("keyword")
  2197. orgId := c.GetAdminUserInfo().CurrentOrgId
  2198. storehouse_id, _ := c.GetInt64("storehouse_id")
  2199. list, err := service.GetSearchDrugListSix(keyword, orgId, storehouse_id)
  2200. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2201. dealerList, _ := service.GetAllDealerList(orgId)
  2202. if err == nil {
  2203. c.ServeSuccessJSON(map[string]interface{}{
  2204. "list": list,
  2205. "manufacturerList": manufacturerList,
  2206. "dealerList": dealerList,
  2207. })
  2208. } else {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2210. }
  2211. }
  2212. func (c *ManagerCenterApiController) AddPatientDiagnos() {
  2213. dataBody := make(map[string]interface{}, 0)
  2214. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2215. class_name := dataBody["class_name"].(string)
  2216. sort := int64(dataBody["sort"].(float64))
  2217. orgId := c.GetAdminUserInfo().CurrentOrgId
  2218. diagnose := models.XtPatientDiagnose{
  2219. ClassName: class_name,
  2220. Sort: sort,
  2221. UserOrgId: orgId,
  2222. Status: 1,
  2223. Ctime: time.Now().Unix(),
  2224. Mtime: 0,
  2225. }
  2226. err = service.CreatePatientDiagnose(diagnose)
  2227. if err == nil {
  2228. c.ServeSuccessJSON(map[string]interface{}{
  2229. "diagnose": diagnose,
  2230. })
  2231. } else {
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2233. }
  2234. }
  2235. func (c *ManagerCenterApiController) GetPatientDiagnose() {
  2236. limit, _ := c.GetInt64("limit")
  2237. page, _ := c.GetInt64("page")
  2238. orgId := c.GetAdminUserInfo().CurrentOrgId
  2239. list, total, err := service.GetPatientDiagnose(limit, page, orgId)
  2240. if err == nil {
  2241. c.ServeSuccessJSON(map[string]interface{}{
  2242. "list": list,
  2243. "total": total,
  2244. })
  2245. } else {
  2246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2247. }
  2248. }
  2249. func (c *ManagerCenterApiController) GetPatientDiagnoseDetail() {
  2250. id, _ := c.GetInt64("id")
  2251. detail, err := service.GetPatientDiagnoseDetail(id)
  2252. if err == nil {
  2253. c.ServeSuccessJSON(map[string]interface{}{
  2254. "detail": detail,
  2255. })
  2256. } else {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2258. }
  2259. }
  2260. func (c *ManagerCenterApiController) UpdatePatientCase() {
  2261. dataBody := make(map[string]interface{}, 0)
  2262. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2263. class_name := dataBody["class_name"].(string)
  2264. sort := int64(dataBody["sort"].(float64))
  2265. id := int64(dataBody["id"].(float64))
  2266. err = service.UpdatePatientCase(class_name, sort, id)
  2267. if err == nil {
  2268. c.ServeSuccessJSON(map[string]interface{}{
  2269. "msg": "msg",
  2270. })
  2271. } else {
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2273. }
  2274. }
  2275. func (c *ManagerCenterApiController) DeletePatientDiagnose() {
  2276. id, _ := c.GetInt64("id")
  2277. service.DeletePatientDiagnose(id)
  2278. returnData := make(map[string]interface{}, 0)
  2279. returnData["msg"] = "ok"
  2280. c.ServeSuccessJSON(returnData)
  2281. return
  2282. }