123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- package controllers
-
- import (
- "fmt"
- "math"
- "strconv"
- "time"
-
- "XT_New/enums"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- )
-
- type NewStockApiController struct {
- BaseAuthAPIController
- }
-
- func NewStockApiRegistRouters() {
- beego.Router("/api/drug/stock", &NewStockApiController{}, "Get:GetDrugStock")
- beego.Router("/api/drug/change", &NewStockApiController{}, "Get:GetDrugChange")
- //beego.Router("/api/drug/query", &NewStockApiController{}, "Get:GetDrugQuery")
-
- beego.Router("/api/drug/gethisdrugcodequery", &NewStockApiController{}, "Get:GetHisDrugCodeQuery")
- beego.Router("/api/drug/createuploaddrugcode", &NewStockApiController{}, "Get:CrateUploadDrugCode")
- beego.Router("/api/drug/getpatientdrugcode", &NewStockApiController{}, "Get:GetPatientDrugCode")
-
- }
-
- func (c *NewStockApiController) GetDrugStock() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- admin := c.GetAdminUserInfo()
- is_pc, _ := c.GetInt64("is_pc", 0)
- is_bg, _ := c.GetInt64("is_bg", 0)
- //manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
- //dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
- fmt.Println(startTime)
- fmt.Println(endTime)
-
- warehousingInfo, err := service.FindAllDrugWarehousingInfo(admin.CurrentOrgId, is_pc, is_bg, startTime, endTime)
- //list, _ := service.GetAll/**/StoreHouseListThree(admin.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- //"manufacturerList": manufacturerList,
- //"dealerList": dealerList,
- //"list": list,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *NewStockApiController) GetDrugChange() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
-
- is_sale, _ := c.GetInt64("is_sale")
- is_bg, _ := c.GetInt64("is_bg")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- orgId := c.GetAdminUserInfo().CurrentOrgId
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- list, total, _ := service.GetNewDrugFlow(orgId, limit, page, startTime, endTime, is_sale, is_bg)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- //patientList, _ := service.GetAllPatientListSix(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "info": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "houseList": houseList,
- //"patientList": patientList,
- })
- }
- func (c *NewStockApiController) GetDrugQuery() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin := c.GetAdminUserInfo()
-
- warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- if warehousing.ID <= 0 {
- return
- }
-
- warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "list": list,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (this *NewStockApiController) GetHisDrugCodeQuery() {
-
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- is_sale, _ := this.GetInt64("is_sale")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetHisDrugCodeQuery(orgId, startTime, endTime, limit, page, is_sale)
-
- drug, _ := service.GetAllDrugList(orgId)
-
- codeConfig, _ := service.GetDrugCodeConfig(orgId)
-
- patients, _ := service.GetAllpatient(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "drug": drug,
- "patients": patients,
- "codeConfig": codeConfig,
- })
-
- return
- }
-
- func (this *NewStockApiController) CrateUploadDrugCode() {
-
- drug_id, _ := this.GetInt64("drug_id")
-
- patient_id, _ := this.GetInt64("patient_id")
-
- advice_date, _ := this.GetInt64("advice_date")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //查询该药品是否出库
- outinfo, _ := service.GetDrugWarehouseOutInfoByDrugCode(drug_id, patient_id, advice_date, orgId)
-
- if len(outinfo) == 0 {
- this.ServeDynamicFailJsonSend("该药品未出库,请先出库")
- return
- } else {
- this.ServeDynamicFailJsonSend("成功!")
- return
- }
-
- }
-
- func (this *NewStockApiController) GetPatientDrugCode() {
-
- drug_id, _ := this.GetInt64("drug_id")
-
- patient_id, _ := this.GetInt64("patient_id")
-
- advice_date, _ := this.GetInt64("advice_date")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- advicelist, _ := service.FindeHisAdviceDocAdviceOne(orgId, patient_id, drug_id, advice_date)
- if len(advicelist) > 0 {
- var total int64
- var prescribing_number_total int64
- for _, item := range advicelist {
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //如果是药房发药的方式
- if medical.IsPharmacy == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse != 1 {
- //如果出库数量大于库存数量
- if prescribing_number_total > total {
- err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- }
- }
- }
-
- }
- }
- creater := this.GetAdminUserInfo().AdminUser.Id
- service.DispensingMedicineTwo(orgId, patient_id, advice_date, drug_id, creater)
-
- this.ServeDynamicFailJsonSend("发药成功!")
- return
- }
|