123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package controller
- import (
- "strings"
- "time"
- v1 "demo/api/v1"
- "demo/internal/app"
- "demo/internal/model"
- "github.com/gogf/gf/v2/net/ghttp"
- "github.com/pkg/errors"
- "github.com/siddontang/go/log"
- "github.com/xuri/excelize/v2"
- )
- // AddManagement
- // @Summary 脖环管理导入
- // @Description add by json account
- // @Tags 脖环管理
- // @Accept json
- // @Produce json
- // @Router /management/add [post]
- func AddManagement(r *ghttp.Request) {
- appG := app.Ghttp{C: r}
- pastureidStr := r.FormValue("pastureid")
- file, _, err := r.FormFile("file")
- if err != nil {
- err = errors.Wrap(err, "AddManagement-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- xlsx1, err := excelize.OpenReader(file)
- rows, _ := xlsx1.GetRows("sheet")
- managementBhList := make([]*model.ManagementBh, 0)
- timeLayout := "2006-01-02"
- var genreStr string
- var genre int64
- for i, r := range rows {
- var exist bool
- if i > 0 {
- var arg model.ManagementBh
- if genreStr == "" {
- genreStr = r[2]
- } else if genreStr != r[2] {
- continue
- }
- arg.Code = r[0]
- if r[1] == "" {
- continue
- }
- date, _ := time.Parse(timeLayout, r[1])
- arg.Date = date
- for _, management := range managementBhList {
- if management.Code == arg.Code {
- exist = true
- continue
- }
- }
- if !exist {
- managementBhList = append(managementBhList, &arg)
- }
- }
- }
- //0 售卖,1 返厂 2 置换
- if strings.Index(genreStr, "售卖") >= 0 {
- genre = 0
- } else if strings.Index(genreStr, "返厂") >= 0 {
- genre = 1
- } else if strings.Index(genreStr, "置换") >= 0 {
- genre = 2
- }
- //pastureid, _ := strconv.ParseInt(pastureidStr, 10, 64)
- err = srv.AddManagement(model.Management{
- Pastureid: pastureidStr,
- ImportTime: time.Now(),
- Genre: genre,
- Count: int64(len(managementBhList)),
- }, managementBhList)
- if err != nil {
- err = errors.Wrap(err, "AddManagement-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- appG.Response(app.StatusOK, app.SUCCESS, true)
- }
- // GetManagement
- // @Summary 脖环管理查看
- // @Description add by json account
- // @Tags 脖环管理
- // @Accept json
- // @Produce json
- // @Param index path int true "int "
- // @Param pagesize path int true "int "
- // @Param code path string true "string 脖环编码"
- // @Param status path string true "string 脖环状态"
- // @Param pastureid path string true "string 牧场id"
- // @Param genre path int64 true "int64 0 售卖,1 返厂 2 置换 -1 全部"
- // @Param startdate path string true "string 导入开始时间"
- // @Param enddate path string true "string 导入结束时间"
- // @Success 200 {object} v1.GetManagementRes
- // @Router /management/list [get]
- func GetManagement(r *ghttp.Request) {
- var req *v1.GetManagementReq
- appG := app.Ghttp{C: r}
- err := appG.C.Parse(&req)
- if err != nil {
- err = errors.Wrap(err, "GetNeckRingListing-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- managementList, count, err := srv.GetManagement(req.Index, req.PageSize, req.PastureId, req.Genre, req.StartDate, req.EndDate)
- if err != nil {
- err = errors.Wrap(err, "GetNeckRingListing-error")
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- resp := v1.GetManagementRes{}
- dataList := make([]*v1.Management, 0)
- for _, item := range managementList {
- var data v1.Management
- data.Id = item.Id
- data.Pastureid = item.Pastureid
- data.Count = item.Count
- data.Genre = item.Genre
- data.Recall = item.Recall
- if !item.ImportTime.IsZero() {
- data.ImportTime = item.ImportTime.Format("2006-01-02 15:04:05")
- }
- data.PastureName = item.PastureName
- dataList = append(dataList, &data)
- }
- resp.Total = count
- resp.List = dataList
- appG.Response(app.StatusOK, app.SUCCESS, resp)
- }
- // GetManagementBh
- // @Summary 脖环管理明细查看
- // @Description add by json account
- // @Tags 脖环管理
- // @Accept json
- // @Produce json
- // @Param index path int true "int "
- // @Param pagesize path int true "int "
- // @Param managementid path int true "int "
- // @Success 200 {object} v1.GetManagementBhRes
- // @Router /managementbh/list [get]
- func GetManagementBh(r *ghttp.Request) {
- var req *v1.GetManagementBhReq
- appG := app.Ghttp{C: r}
- err := appG.C.Parse(&req)
- if err != nil {
- err = errors.Wrap(err, "GetNeckRingListing-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- managementList, count, err := srv.GetManagementBh(req.Index, req.PageSize, req.ManagementId)
- if err != nil {
- err = errors.Wrap(err, "GetNeckRingListing-error")
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- resp := v1.GetManagementBhRes{}
- dataList := make([]*v1.ManagementBh, 0)
- for _, item := range managementList {
- var data v1.ManagementBh
- data.ManagementID = item.ManagementID
- data.Code = item.Code
- if !item.Date.IsZero() {
- data.Date = item.Date.Format("2006-01-02 15:04:05")
- }
- dataList = append(dataList, &data)
- }
- resp.Total = count
- resp.List = dataList
- appG.Response(app.StatusOK, app.SUCCESS, resp)
- }
|