manager_center_api_controller.go 84KB

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