manager_center_api_controller.go 83KB

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