123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "bytes"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "io/ioutil"
- "log"
- "os"
- "path"
- "reflect"
- "regexp"
- "runtime"
- "strconv"
- "strings"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- type GobalConfigApiController struct {
- BaseAuthAPIController
- }
-
- func GobalConfigRegistRouters() {
- beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
- beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
-
- beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
-
- beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
-
- beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
- beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
- beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
- beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
-
- beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
- beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
-
- beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
- beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
-
- beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
- beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
-
- beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
- beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
-
- beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
-
- beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
- beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
-
- beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
-
- }
-
- //provinces, _ := service.GetDistrictsByUpid(0)21
-
- func (c *GobalConfigApiController) PostStockConfig() {
- is_open, _ := c.GetInt64("is_open", 0)
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- config := models.GobalConfig{
- OrgId: org_id,
- IsOpen: is_open,
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- IsOpenRemind: 0,
- }
-
- errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
-
- if errs == gorm.ErrRecordNotFound {
- err := service.CreateAutomaticReduceRecord(&config)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- } else if errs == nil {
- modifyConfig := models.GobalConfig{
- ID: configs.ID,
- OrgId: org_id,
- IsOpen: is_open,
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- IsOpenRemind: configs.IsOpenRemind,
- }
-
- err := service.UpdateAutomaticReduceRecord(&modifyConfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "is_open": is_open,
- })
-
- return
- }
-
- func (c *GobalConfigApiController) GetConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- }
-
- func (c *GobalConfigApiController) PostPrintTemplate() {
- template_id, _ := c.GetInt64("template_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- template := models.GobalTemplate{
- OrgId: org_id,
- TemplateId: template_id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- errs, templates := service.FindPrintTemplateByOrgId(org_id)
-
- if errs == gorm.ErrRecordNotFound {
- err := service.CreatePrintTemplateRecord(&template)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- } else if errs == nil {
- templates := models.GobalTemplate{
- ID: templates.ID,
- OrgId: org_id,
- TemplateId: template_id,
- Status: 1,
- Ctime: templates.Ctime,
- Mtime: time.Now().Unix(),
- }
-
- err := service.UpdatePrintTemplate(&templates)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "template_id": template_id,
- })
- return
- }
-
- func (c *GobalConfigApiController) PostPrintTemplateTwo() {
- template_id, _ := c.GetInt64("template_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- template := models.GobalTemplate{
- OrgId: org_id,
- TemplateId: template_id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- errs, templates := service.FindPrintTemplateByOrgId(org_id)
-
- if errs == gorm.ErrRecordNotFound {
- err := service.CreatePrintTemplateRecord(&template)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- if err == nil { //处理模版切换,显示配置处理逻辑
- //service.FindAllConfig
- //先将所有数据设置为显示
- updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
- if updateErr == nil {
- //查出该模版对应显示配置字段中所有隐藏的字段
- _, config := service.FindAllHideFiledConfig(template_id)
-
- var fileds []string
- for _, item := range config {
- fileds = append(fileds, item.FiledName)
- }
- service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
- }
- }
- FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template_id": template_id,
- "fileds": FiledList,
- })
-
- } else if errs == nil {
- templates := models.GobalTemplate{
- ID: templates.ID,
- OrgId: org_id,
- TemplateId: template_id,
- Status: 1,
- Ctime: templates.Ctime,
- Mtime: time.Now().Unix(),
- }
-
- err := service.UpdatePrintTemplate(&templates)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- if err == nil { //处理模版切换,显示配置处理逻辑
- //service.FindAllConfig
- //先将所有数据设置为显示
- updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
- if updateErr == nil {
- //查出该模版对应显示配置字段中所有隐藏的字段
- _, config := service.FindAllHideFiledConfig(template_id)
- var fileds []string
- for _, item := range config {
- fileds = append(fileds, item.FiledName)
- }
- service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
-
- }
-
- }
- FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template_id": template_id,
- "fileds": FiledList,
- })
- return
- }
- }
-
- func (c *GobalConfigApiController) GetPrintTemplate() {
- adminUserInfo := c.GetAdminUserInfo()
- _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- }
-
- func (c *GobalConfigApiController) PostConfig() {
- gateway_address := c.GetString("gateway_address")
- app_id := c.GetString("app_id")
- key := c.GetString("key")
- config_type, _ := c.GetInt64("config_type")
- time_type, _ := c.GetInt64("time_type")
- province, _ := c.GetInt64("province")
- city, _ := c.GetInt64("city")
-
- if config_type > 1 {
- _, err := service.GetDockingStatus(config_type, province, city)
- if err == gorm.ErrRecordNotFound {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
- return
- }
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- config := &models.DataUploadConfig{
- OrgId: org_id,
- ProvinceId: province,
- CityId: city,
- GatewayAddress: gateway_address,
- AppId: app_id,
- Key: key,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- TimeQuantum: time_type,
- ConfigType: config_type,
- }
- err := service.CreateConfigData(config)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *GobalConfigApiController) GetDataUploadConfig() {
- config_type, _ := c.GetInt64("config_type")
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- config, err := service.GetConfigData(org_id, config_type)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *GobalConfigApiController) GetDataUploadIsDocking() {
- config_type, _ := c.GetInt64("config_type")
- province, _ := c.GetInt64("province")
- city, _ := c.GetInt64("city")
-
- config, err := service.GetDockingStatus(config_type, province, city)
- fmt.Println(config)
- fmt.Println(err)
- if err == gorm.ErrRecordNotFound {
- c.ServeSuccessJSON(map[string]interface{}{
- "is_docking": 2,
- })
-
- } else if err == nil {
- if config.ID > 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "is_docking": 1,
- })
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "is_docking": 2,
- })
-
- }
- }
- }
-
- func (c *GobalConfigApiController) ModifyConfig() {
- id, _ := c.GetInt64("id")
- gateway_address := c.GetString("gateway_address")
- app_id := c.GetString("app_id")
- key := c.GetString("key")
- config_type, _ := c.GetInt64("config_type")
- time_type, _ := c.GetInt64("time_type")
- province, _ := c.GetInt64("province")
- city, _ := c.GetInt64("city")
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
-
- if config_type > 1 {
- _, err := service.GetDockingStatus(config_type, province, city)
- if err == gorm.ErrRecordNotFound {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
- return
- }
- }
-
- tempConfig, _ := service.GetConfigDataById(id)
-
- config := &models.DataUploadConfig{
- ID: tempConfig.ID,
- OrgId: org_id,
- ProvinceId: province,
- CityId: city,
- GatewayAddress: gateway_address,
- AppId: app_id,
- Key: key,
- Status: 1,
- CreateTime: tempConfig.CreateTime,
- ModifyTime: time.Now().Unix(),
- TimeQuantum: time_type,
- ConfigType: config_type,
- }
- err := service.SaveConfigData(config)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
- is_open_remind, _ := c.GetInt64("is_open_remind", 0)
- adminUserInfo := c.GetAdminUserInfo()
- org_id := adminUserInfo.CurrentOrgId
- config := models.DoctorAdviceConfig{
- UserOrgId: org_id,
- IsOpenRemind: is_open_remind,
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
-
- errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
-
- if errs == gorm.ErrRecordNotFound {
- err := service.CreateDoctorAdviceRecord(&config)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- } else if errs == nil {
- modifyConfig := models.DoctorAdviceConfig{
- ID: configs.ID,
- UserOrgId: org_id,
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- IsOpenRemind: is_open_remind,
- }
-
- err := service.UpdateDoctorAdviceRecord(&modifyConfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "is_open_remind": is_open_remind,
- })
-
- return
- }
-
- func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- }
-
- //SF6090214798525
- func (c *GobalConfigApiController) Load(filename string, v interface{}) {
- //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
- data, err := ioutil.ReadFile(filename)
- if err != nil {
- return
- }
- //读取的数据为json格式,需要进行解码
- err = json.Unmarshal(data, v)
- if err != nil {
- return
- }
- }
-
- type Config struct {
- Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
- }
-
- func LoadConfig(dataFile string) *Config {
- var config Config
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func StripComments(data []byte) ([]byte, error) {
- data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
- lines := bytes.Split(data, []byte("\n")) //split to muli lines
- filtered := make([][]byte, 0)
-
- for _, line := range lines {
- match, err := regexp.Match(`^\s*#`, line)
- if err != nil {
- return nil, err
- }
- if !match {
- filtered = append(filtered, line)
- }
- }
-
- return bytes.Join(filtered, []byte("\n")), nil
- }
-
- func emit(msgfmt string, args ...interface{}) {
- log.Printf(msgfmt, args...)
- }
-
- func (c *GobalConfigApiController) GetAdviceInitConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "advice_init": advice_init,
- })
- }
-
- func (c *GobalConfigApiController) PostInitAdviceTemplate() {
- is_init, _ := c.GetInt64("is_init")
- adminUserInfo := c.GetAdminUserInfo()
- adviceInit := &models.AdviceInit{
- UserOrgId: adminUserInfo.CurrentOrgId,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- IsInit: is_init,
- }
-
- adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
- for _, item := range adviceParentTemplate {
- parentTemplate := &models.DoctorAdviceParentTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- Name: item.Name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- AdviceType: item.AdviceType,
- }
-
- createErr := service.CreateDoctorParentTemplate(parentTemplate)
- fmt.Println(parentTemplate.ID)
- if createErr == nil {
- for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
- adviceTeplate := &models.DoctorAdviceTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceName: adviceTemplateItem.AdviceName,
- AdviceDesc: adviceTemplateItem.AdviceDesc,
- SingleDose: adviceTemplateItem.SingleDose,
- SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
- PrescribingNumber: adviceTemplateItem.PrescribingNumber,
- PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
- DeliveryWay: adviceTemplateItem.DeliveryWay,
- ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
- AdviceDoctor: adviceTemplateItem.AdviceDoctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- TemplateId: parentTemplate.ID,
- DrugSpec: adviceTemplateItem.DrugSpec,
- DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
- ParentId: adviceTemplateItem.ParentId,
- AdviceType: adviceTemplateItem.AdviceType,
- DayCount: adviceTemplateItem.DayCount,
- WeekDays: adviceTemplateItem.WeekDays,
- FrequencyType: adviceTemplateItem.FrequencyType,
- }
- createErr := service.CreateDoctorTemplate(adviceTeplate)
-
- if createErr == nil {
- for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
- adviceTeplate := &models.DoctorAdviceTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceName: childItem.AdviceName,
- AdviceDesc: childItem.AdviceDesc,
- SingleDose: childItem.SingleDose,
- SingleDoseUnit: childItem.SingleDoseUnit,
- PrescribingNumber: childItem.PrescribingNumber,
- PrescribingNumberUnit: childItem.PrescribingNumberUnit,
- DeliveryWay: childItem.DeliveryWay,
- ExecutionFrequency: childItem.ExecutionFrequency,
- AdviceDoctor: childItem.AdviceDoctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- TemplateId: parentTemplate.ID,
- DrugSpec: childItem.DrugSpec,
- DrugSpecUnit: childItem.DrugSpecUnit,
- ParentId: adviceTeplate.ID,
- AdviceType: childItem.AdviceType,
- DayCount: childItem.DayCount,
- WeekDays: childItem.WeekDays,
- FrequencyType: childItem.FrequencyType,
- }
- service.CreateDoctorTemplate(adviceTeplate)
- }
- }
- }
- }
- }
- err := service.CreateAdviceInitConfig(adviceInit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "init_config": adviceInit,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *GobalConfigApiController) CreateSystemPrescription() {
- adminUserInfo := c.GetAdminUserInfo()
- var solution models.SystemPrescription
- code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.RegistrarsId = adminUserInfo.AdminUser.Id
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.Status = 1
- solution.CreatedTime = time.Now().Unix()
- solution.UserOrgId = adminUserInfo.CurrentOrgId
- solution.UpdatedTime = time.Now().Unix()
-
- err := service.CreateSystemDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
- return
- }
-
- prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": solution,
- "prescriptions": prescriptions,
- })
- return
- }
-
- func (c *GobalConfigApiController) UpdateSystemPrescription() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.RegistrarsId = adminUserInfo.AdminUser.Id
-
- err := service.UpdateSystemDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "prescription": solution,
- })
- return
- }
-
- func (c *GobalConfigApiController) GetAllSystemPrescription() {
- adminUserInfo := c.GetAdminUserInfo()
- prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- })
- }
-
- func (c *GobalConfigApiController) GetSystemPrescription() {
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
-
- }
-
- func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if method == "create" {
- if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
- utils.ErrorLog("mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- mode := int64(dataBody["mode"].(float64))
- if mode <= 0 {
- utils.ErrorLog("mode <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeId = mode
-
- }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
- targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
- solution.TargetUltrafiltration = targetUltrafiltration
- }
-
- if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
- dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
- solution.DialysateFormulation = dialysateFormulation
- }
-
- if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
- dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
- solution.DialysisDurationHour = int64(dialysisDurationHour)
- }
-
- if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
- dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
- solution.DialysisDurationMinute = int64(dialysisDurationMinute)
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
- if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
- dialyzer := int64(dataBody["dialyzer"].(float64))
- solution.Dialyzer = dialyzer
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
- dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
- solution.Dewater = dewater
- }
-
- if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
- displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
- solution.DisplaceLiqui = displaceLiqui
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
- glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
- solution.Glucose = glucose
- }
-
- // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- // solution.DryWeight = dryWeight
- // }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
- dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
- solution.DialysateTemperature = dialysateTemperature
- }
-
- if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
- conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
- solution.Conductivity = conductivity
- }
-
- if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
- replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
- solution.ReplacementTotal = replacementTotal
- }
-
- if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
- dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
- solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
- }
-
- if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
- body_fluid := int64(dataBody["body_fluid"].(float64))
- solution.BodyFluid = body_fluid
- }
-
- if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
- body_fluid_other := dataBody["body_fluid_other"].(string)
- solution.BodyFluidOther = body_fluid_other
- }
-
- if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
- special_medicine := int64(dataBody["special_medicine"].(float64))
- solution.SpecialMedicine = special_medicine
- }
-
- if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
- special_medicine_other := dataBody["special_medicine_other"].(string)
- solution.SpecialMedicineOther = special_medicine_other
- }
-
- if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
- displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
- solution.DisplaceLiquiPart = displace_liqui_part
- }
- if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
- displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
- solution.DisplaceLiquiValue = displace_liqui_value
- }
- if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
- blood_access := int64(dataBody["blood_access"].(float64))
- solution.BloodAccess = blood_access
- }
-
- if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
- ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
- solution.Ultrafiltration = ultrafiltration
- }
-
- if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
- target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
- solution.TargetKtv = target_ktv
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- solution.Remark = remark
- }
-
- return
- }
-
- func (c *GobalConfigApiController) GetPrintInfo() {
- adminUserInfo := c.GetAdminUserInfo()
- OrgID := adminUserInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- idsInters := dataBody["ids"].([]interface{})
- if len(idsInters) == 0 {
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
- return
- }
- }
- ids := make([]int64, 0)
- for _, idsInter := range idsInters {
- id := int64(idsInter.(float64))
- ids = append(ids, id)
- }
- getPrint, err := service.GetPrint(ids, OrgID)
- c.ServeSuccessJSON(map[string]interface{}{
- "doctoradvice": getPrint,
- })
- }
-
- func (c *GobalConfigApiController) GetOrgs() {
- adminUserInfo := c.GetAdminUserInfo()
- //获取当前人姓名
- var id = adminUserInfo.AdminUser.Id
- orgId := adminUserInfo.CurrentOrgId
- var orgs []*models.Org
- adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
- creator, err := service.GetCreator(id, orgId)
- admin, err := service.GetSuperAdmin(id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range adminUser.Org {
- orgs = append(orgs, item)
- }
- for _, item := range adminUser.VMApp_Role {
- for _, subItem := range item.Org {
- orgs = append(orgs, subItem)
- }
- }
- orgs = RemoveRepeatedOrgElement(orgs)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "orgs": orgs,
- "adminUser": adminUser,
- "creator": creator,
- "admin": admin,
- })
-
- }
-
- func (this *GobalConfigApiController) ChangeOrg() {
- org_id, _ := this.GetInt64("org_id")
- adminUserInfo := this.GetAdminUserInfo()
- tempOrg, err := service.GetOrgById(org_id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- if tempOrg == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
- return
- }
-
- mobile := adminUserInfo.AdminUser.Mobile
- // 只取最近被创建的 admin_role
- adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
- if getAdminErr != nil {
- utils.ErrorLog("获取管理员失败:%v", getAdminErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if adminUser == nil {
- utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
- this.ServeJSON()
- return
- } else {
-
- adminUserInfo.CurrentOrgId = tempOrg.Id
- orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
- subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
- adminUserInfo.CurrentAppId = orgApp.Id
- appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
- var FiledList []*models.FiledConfig
- FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
- if len(FiledList) == 0 {
- err := service.BatchInsertFiledConfig(tempOrg.Id)
- if err == nil {
- FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
-
- } else {
- utils.ErrorLog("字段批量插入失败:%v", err)
- }
- }
-
- var didRegistedForSCRM bool = false
- var didRegistedForCDM bool = false
- var didRegistedForMall bool = false
-
- var curAppUrlfors []string
- var pruviews []*models.Purview
-
- if len(curAppUrlfors) == 0 {
- if adminUser.Id == tempOrg.Creator {
- urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
- urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
- urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
- urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
- curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
- curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
- curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
- curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
-
- didRegistedForSCRM = true
- didRegistedForCDM = true
- didRegistedForMall = true
-
- } else {
- appRole, _ := service.FindAdminUserIDA(appRole.Id)
- if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
- role_arr := strings.Split(appRole.RoleIds, ",")
- var ids string
- for _, role_id := range role_arr {
- id, _ := strconv.ParseInt(role_id, 10, 64)
- purview_ids, _ := service.GetRolePurviewIds(id)
- if len(ids) == 0 {
- ids = purview_ids
- } else {
- ids = ids + "," + purview_ids
- }
- }
- if len(ids) != 0 {
- pruviews, _ = service.GetPurviewById(ids)
- for _, item := range pruviews {
- if item.Module == 3 && item.Parentid > 0 {
- fmt.Println(item.Urlfor)
- curAppUrlfors = append(curAppUrlfors, item.Urlfor)
- }
- }
- } else {
-
- curAppUrlfors = append(curAppUrlfors, "")
- }
- } else {
- curAppUrlfors = append(curAppUrlfors, "")
-
- }
- for _, item := range pruviews {
- if item.Module == 6 {
- didRegistedForSCRM = true
- }
- if item.Module == 4 {
- didRegistedForCDM = true
- }
- if item.Module == 7 {
- didRegistedForMall = true
- }
- }
- }
- }
-
- userInfo := map[string]interface{}{
- "id": adminUser.Id,
- "mobile": adminUser.Mobile,
- "user_name": appRole.UserName,
- "avatar": appRole.Avatar,
- "intro": appRole.Intro,
- "user_type": appRole.UserType,
- "user_title": appRole.UserTitle,
- }
- org := map[string]interface{}{
- "id": tempOrg.Id,
- "org_name": tempOrg.OrgName,
- "org_short_name": tempOrg.OrgShortName,
- "org_intro": tempOrg.OrgIntroduction,
- "org_logo": tempOrg.OrgLogo,
- "province": tempOrg.Province,
- "city": tempOrg.City,
- "district": tempOrg.District,
- "address": tempOrg.Address,
- }
-
- tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
- template_info := map[string]interface{}{
- "id": tempInfo.ID,
- "org_id": tempInfo.OrgId,
- "template_id": tempInfo.TemplateId,
- }
-
- if tempOrg != nil && appRole != nil {
- // 插入一条登录记录
- ip := this.GetString("ip")
- loginLog := &models.AdminUserLoginLog{
- AdminUserId: adminUser.Id,
- OrgId: tempOrg.Id,
- AppId: appRole.AppId,
- IP: ip,
- OperateType: 3,
- AppType: 3,
- CreateTime: time.Now().Unix(),
- }
- if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
- utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
- }
- }
-
- this.SetSession("admin_user_info", adminUserInfo)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "user": userInfo,
- "org": org,
- "urlfors": curAppUrlfors,
- "current_org_id": adminUserInfo.CurrentOrgId,
- "current_app_id": adminUserInfo.CurrentAppId,
- "subscibe": subscibe,
- "template_info": template_info,
- "fileds": FiledList,
- "scrm_role_exist": didRegistedForSCRM,
- "cdm_role_exist": didRegistedForCDM,
- "mall_role_exist": didRegistedForMall,
- })
-
- }
-
- }
-
- func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
- newOrgs = make([]*models.Org, 0)
- for i := 0; i < len(orgs); i++ {
- repeat := false
- for j := i + 1; j < len(orgs); j++ {
- if orgs[i].Id == orgs[j].Id {
- repeat = true
- break
- }
- }
- if !repeat {
- newOrgs = append(newOrgs, orgs[i])
- }
- }
- return
- }
-
- func (this *GobalConfigApiController) GenerateLog() {
- log_type, _ := this.GetInt64("log_type", 0)
- logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "logs": logs,
- })
-
- }
|