package routers import ( "github.com/360EntSecGroup-Skylar/excelize" "github.com/Anderson-Lu/gofasion/gofasion" "github.com/gin-gonic/gin" "github.com/pkg/errors" "io/ioutil" "kpt.xdmy/apiserver/model" "kpt.xdmy/apiserver/model/http" "kpt.xdmy/apiserver/routers/restful" "kpt.xdmy/apiserver/service" "kpt.xdmy/pkg/logging" "strconv" ) func ProofList(c *gin.Context) { p := new(model.ProofReq) //if !Bind(c, p) { // return //} dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) p.OrderNumber = fsion.Get("OrderNumber").ValueStr() p.NumberType = fsion.Get("NumberType").ValueInt() rp := service.ProofList(p) c.JSON(200, &rp) } func ProofOff(c *gin.Context) { p := new(model.ProofReq) if !Bind(c, p) { return } rp := svc.ProofOff(p) c.JSON(200, &rp) } func ProofOffList(c *gin.Context) { p := new(model.ProofReq) if !Bind(c, p) { return } rp := service.ProofList(p) c.JSON(rp.Code, &rp) } func ManualTransfer(c *gin.Context) { list := make([]*http.ManaulReq, 0) //p := new(http.ManaulReq) c.Bind(&list) tx, err := restful.Dbs.Beginx() defer func() { switch { case err != nil: logging.Error("tx.Begin 事务启动失败__error:", err) if tx != nil { tx.Rollback() } default: if tx != nil { err = tx.Commit() } } }() for _, item := range list { err := service.ManualTransfer(item.Id, tx) if err == nil { c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) return } else { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"}) return } } } func ManaulSapOrder(c *gin.Context) { ////dataByte, _ := ioutil.ReadAll(c.Request.Body) ////fsion := gofasion.NewFasion(string(dataByte)) ////for _, code := range fsion.Array() { //if e := service.ManaulSapOrderJob(""); e != nil { // c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"}) // return //} ////} dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) for _, code := range fsion.Array() { if e := service.ManaulSapOrderJob(code.Get("buyeCode").ValueStr()); e != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"}) return } } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) } func ManaulSrmOrderJob(c *gin.Context) { dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) //parammaps := fsion.Get("list").Array() for _, code := range fsion.Array() { service.ManaulSrmOrderJob(code.Get("buyeCode").ValueStr()) } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) } //手动入库 func LaidProof(c *gin.Context) { dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) //parammaps := fsion.Get("list").Array() var err []error tx, err1 := restful.Dbs.Beginx() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } for _, parammap := range fsion.Array() { p := new(http.ProofPartReq) p.LaidCode = parammap.Get("laidCode").ValueStr() p.StorageTime = parammap.Get("creatTime").ValueStr() err1 := svc.LaidProof(p, tx) err = append(err, err1) } err1 = tx.Commit() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) } //手动出库 func UseProof(c *gin.Context) { dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) //parammaps := fsion.Get("list").Array() tx, err1 := restful.Dbs.Beginx() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } for _, parammap := range fsion.Array() { p := new(http.ProofPartReq) p.UseForm = parammap.Get("useForm").ValueStr() p.ReceiveTime = parammap.Get("creatTime").ValueStr() svc.UseProof(p, tx) } err1 = tx.Commit() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) } //手动退货 func RefundProof(c *gin.Context) { //p := make([]*http.ProofPartReq, 0) //c.Bind(&p) //for _, item := range p { dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) //parammaps := fsion.Get("list").Array() tx, err1 := restful.Dbs.Beginx() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } for _, parammap := range fsion.Array() { p := new(http.ProofPartReq) p.ID = parammap.Get("id").ValueInt() svc.RefundProof(p, tx) } err1 = tx.Commit() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"}) } //手动退库 func QuitProof(c *gin.Context) { dataByte, _ := ioutil.ReadAll(c.Request.Body) fsion := gofasion.NewFasion(string(dataByte)) //parammaps := fsion.Get("list").Array() tx, err1 := restful.Dbs.Beginx() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } for _, parammap := range fsion.Array() { p := new(http.ProofPartReq) p.UseForm = parammap.Get("useForm").ValueStr() p.QuitDate = parammap.Get("quitDate").ValueStr() svc.QuitProof(p, tx) } err1 = tx.Commit() if err1 != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"}) } func Exec(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("人员花名册") service.Exec(rows) } func DepartmentExec(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("Sheet1") service.DepartmentExec(rows) } func ProviderExec(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("Sheet1") service.ProviderExec(rows) } func EquipmentExec(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } pastureIdstr := c.PostForm("pastureId") //dataByte, _ := ioutil.ReadAll(c.Request.Body) //fsion := gofasion.NewFasion(string(dataByte)) //pastureId := fsion.Get("pastureId").ValueInt() f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("设备基础信息") pastureId, err := strconv.Atoi(pastureIdstr) if err != nil { panic(err) } err = service.EquipmentExec(rows, pastureId) if err != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"}) } func EquipmentExecAdd(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("财务资产汇总") err = service.EquipmentExecAdd(rows) if err != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"}) return } c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"}) } func ContractExec(c *gin.Context) { file, err := c.FormFile("file") if err != nil { err = errors.Wrap(err, "AddManagement-error") return } f, _ := file.Open() xlsx1, err := excelize.OpenReader(f) rows := xlsx1.GetRows("三位小数清单") service.ContractExec(rows) c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"}) }