package purchase import ( "context" "github.com/gin-gonic/gin" "go.uber.org/zap" "srm/global" "srm/model/common/request" "srm/model/common/response" "srm/model/purchase" purchaseRes "srm/model/purchase/response" "srm/proto/qualityinspect" service "srm/service/purchase" "srm/utils" ) type QualityInspectApi struct{} // GetQualityInspectList // @Tags QualityInspect // @Summary 分页获取质检单列表 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data query request.PageInfo true "页码, 每页大小" // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取质检单列表,返回包括列表,总数,页码,每页数量" // @Router /purchase/qualityInspectList [get] func (e *QualityInspectApi) GetQualityInspectList(c *gin.Context) { var pageInfo request.PageInfo err := c.ShouldBindQuery(&pageInfo) if err != nil { response.FailWithMessage(err.Error(), c) return } err = utils.Verify(pageInfo, utils.PageInfoVerify) if err != nil { response.FailWithMessage(err.Error(), c) return } list, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) purchaseList := list.([]*purchase.Purchase) purchaseNumbers := make([]string, 0, len(purchaseList)) for _, item := range purchaseList { purchaseNumbers = append(purchaseNumbers, item.Number) } resultList := make([]*purchaseRes.QualityInspectList, 0, len(purchaseList)) if len(purchaseList) != 0 { err = utils.AssignTo(purchaseList, &resultList) if err != nil { global.GVA_LOG.Error("mapStructure decode", zap.Error(err)) response.FailWithMessage("内部错误", c) return } client := qualityinspect.NewQualityInspectServiceClient(qualityinspect.Conn) inspectList, err := client.GetInspectList(context.Background(), &qualityinspect.GetInspectListRequest{ PurchaseOrderId: purchaseNumbers, }) if err != nil { global.GVA_LOG.Error("GetInspectList", zap.Error(err)) response.FailWithMessage("内部错误", c) return } inspectUnFinishedMap := make(map[string]bool, len(purchaseNumbers)) //默认完成 for _, inspectItem := range inspectList.List { if inspectItem.Status != qualityinspect.InspectStatus_InspectStatusInspectFinish { inspectUnFinishedMap[inspectItem.PurchaseOrderId] = true } } for _, result := range resultList { if inspectUnFinishedMap[result.Number] { result.InspectStatus = "待质检" } else { result.InspectStatus = "已完成" } } } response.OkWithDetailed(response.PageResult{ List: resultList, Total: total, Page: pageInfo.Page, PageSize: pageInfo.PageSize, }, "获取成功", c) } // //// QualityTest //// @Tags QualityInspect //// @Summary QualityTest //// @Security ApiKeyAuth //// @accept application/json //// @Produce application/json //// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取质检单列表,返回包括列表,总数,页码,每页数量" //// @Router /purchase/qualityTest [get] //func (e *QualityInspectApi) QualityTest(c *gin.Context) { // client := quality.NewQualityServiceClient(qualityinspect.Conn) // list, err := client.GetQualityStatusList(context.Background(), &quality.QualityStatusRequest{WorkOrderId: []string{"GD-0116", "GD-0117", "GD-0156"}}) // if err != nil { // fmt.Println(err) // response.FailWithMessage("内部错误", c) // return // } // for _, status := range list.List { // fmt.Println(status) // } // response.Ok(c) //} // //// GetQualityInspect //// @Tags QualityInspect //// @Summary 获取单一质检单信息 //// @Security ApiKeyAuth //// @accept application/json //// @Produce application/json //// @Param id path int true "质检单ID" true "质检单ID" //// @Success 200 {object} response.Response{data=QualityInspectRes.QualityInspectResponse,msg=string} "获取单一质检单信息,返回包括质检单详情" //// @Router /purchase/qualityInspect/{id} [get] //func (e *QualityInspectApi) GetQualityInspect(c *gin.Context) { // id, _ := strconv.Atoi(c.Param("id")) // if id == 0 { // response.FailWithMessage("参数缺失", c) // return // } // data, err := service.NewPurchaseService().GetPurchase(uint(id)) // if err != nil { // global.GVA_LOG.Error("获取失败!", zap.Error(err)) // response.FailWithMessage("获取失败", c) // return // } // productList, err := service.NewPurchaseService().GetPurchaseProductList(uint(id)) // if err != nil { // global.GVA_LOG.Error("获取失败!", zap.Error(err)) // response.FailWithMessage("获取失败", c) // return // } // respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) // err = mapstructure.Decode(productList, &respProductList) // if err != nil { // global.GVA_LOG.Error("获取失败!", zap.Error(err)) // response.FailWithMessage("获取失败", c) // return // } // for k, item := range productList { // respProductList[k].Amount = item.Amount // respProductList[k].Price = item.Price // respProductList[k].Total = item.Total // err = mapstructure.Decode(item.Product, &respProductList[k]) // if err != nil { // global.GVA_LOG.Error("获取失败!", zap.Error(err)) // response.FailWithMessage("获取失败", c) // return // } // } // // response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: respProductList}, "获取成功", c) //}