123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- 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"})
- }
- func PostPushContractDataToSAP(c *gin.Context) {
- req := new(http.PostPushContractDataToSAPReq)
- hrp := new(http.Response)
- if err := c.ShouldBind(&req); err != nil {
- hrp.Code = 200
- hrp.Message = err.Error()
- hrp.Msg = "fail"
- hrp.Data = err.Error()
- c.JSON(200, hrp)
- return
- }
- err := svc.PostPushContractDataToSAP(req.PastureId, req.ProviderId, req.ContractIdList)
- if err != nil {
- hrp.Code = 200
- hrp.Message = err.Error()
- hrp.Msg = "fail"
- hrp.Data = err.Error()
- c.JSON(200, hrp)
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
- }
|