123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package controller
- import (
- v1 "demo/api/v1"
- "demo/internal/app"
- "demo/internal/model"
- "fmt"
- "github.com/gogf/gf/v2/net/ghttp"
- "github.com/pkg/errors"
- "github.com/siddontang/go/log"
- "github.com/xuri/excelize/v2"
- "strconv"
- "time"
- )
- // AddRecall
- // @Summary 脖环召回计划添加
- // @Description add by json account
- // @Tags 脖环召回计划
- // @Accept json
- // @Produce json
- // @Param account body v1.AddRecallReq true "Add account"
- // @Router /recall/add [post]
- func AddRecall(r *ghttp.Request) {
- var req *v1.AddRecallReq
- username := r.Context().Value("jwt_username")
- appG := app.Ghttp{C: r}
- err := appG.C.Parse(&req)
- if err != nil {
- err = errors.Wrap(err, "AddRecall-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- file, _, err := r.FormFile("file")
- if err != nil {
- err = errors.Wrap(err, "AddRecall-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- var REGISTNUM2 []string
- xlsx1, err := excelize.OpenReader(file)
- rows, _ := xlsx1.GetRows("sheet")
- for i, r := range rows {
- if i > 0 {
- REGISTNUM2 = append(REGISTNUM2, r[0])
- }
- }
- dataList, err := srv.GetFactoryidByREGISTNUM2(REGISTNUM2)
- if err != nil {
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- for _, data := range dataList {
- exist := false
- for _, factoryID := range req.FactoryID {
- if factoryID == data.FactoryId {
- exist = true
- break
- }
- }
- if !exist {
- appG.Response(app.StatusInternalServerError, app.ERROR, "牛号与批次不匹配!!!")
- return
- }
- }
- neckringList, err := srv.GetNeckRingListingIDByFactoryId(req.FactoryID)
- if err != nil {
- err = errors.Wrap(err, "AddRecall-error")
- log.Error(err)
- appG.Response(app.StatusInternalServerError, app.ERROR, err)
- return
- }
- var hasRecalled []string
- for _, REGISTNUM := range REGISTNUM2 {
- exist := false
- code, _ := strconv.ParseInt(REGISTNUM, 10, 64)
- for _, item := range neckringList {
- if item.Code == code {
- exist = true
- break
- }
- }
- if !exist {
- hasRecalled = append(hasRecalled, REGISTNUM)
- }
- }
- if len(hasRecalled) > 0 {
- dataList := make([]map[string]interface{}, 0)
- for _, REGISTNUM := range REGISTNUM2 {
- exist := false
- for _, code := range hasRecalled {
- if REGISTNUM == code {
- exist = true
- break
- }
- }
- data := make(map[string]interface{})
- data["a1"] = REGISTNUM
- data["a2"] = ""
- if exist {
- data["a2"] = fmt.Sprintf("%s已经被召回!!!", REGISTNUM)
- }
- dataList = append(dataList, data)
- }
- appG.Response(app.StatusOK, app.RECALL, dataList)
- return
- }
- err = srv.AddRecall(model.Factory{
- Pastureid: req.Pastureid,
- Count: req.Count,
- CreateName: username.(string),
- CreateTime: time.Now(),
- Genre: 2,
- }, req.FactoryID, REGISTNUM2)
- if err != nil {
- return
- }
- appG.Response(app.StatusOK, app.SUCCESS, true)
- }
- // GetRecall
- // @Summary 脖环召回查看
- // @Description add by json account
- // @Tags 脖环召回计划
- // @Accept json
- // @Produce json
- // @Param index path int true "int "
- // @Param pagesize path int true "int "
- // @Param batch path string true "string 批次"
- // @Param startcount path string true "string 数量"
- // @Param endcount path string true "string 数量"
- // @Param createname path string true "string 登记人"
- // @Param startdate path string true "string 登记时间"
- // @Param enddate path string true "string 登记时间"
- // @Param factoryid path int true "string 查看召回批次"
- // @Param replacement path int true "string 置换时查看传 1"
- // @Success 200 {object} v1.GetRecallRes
- // @Router /recall/list [get]
- func GetRecall(r *ghttp.Request) {
- var req *v1.GetRecallReq
- 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
- }
- respList, count, err := srv.GetRecall(req.Index, req.PageSize, req.Pastureid, req.Batch, req.StartCount, req.EndCount, req.CreateName, req.StartDate, req.EndDate, req.FactoryID, req.Replacement)
- if err != nil {
- return
- }
- resp := v1.GetRecallRes{}
- dataList := make([]*v1.Recall, 0)
- for _, item := range respList {
- var data v1.Recall
- data.Id = item.Id
- data.PastureId = item.Pastureid
- data.PastureName = item.PastureName
- data.Count = item.Count
- data.Batch = item.Batch
- data.Recall = item.Recall
- data.CreateName = item.CreateName
- if !item.CreateTime.IsZero() {
- data.CreateTime = item.CreateTime.Format("2006-01-02")
- }
- dataList = append(dataList, &data)
- }
- resp.List = dataList
- resp.Total = count
- appG.Response(app.StatusOK, app.SUCCESS, resp)
- }
|