| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "net/url" |
| | |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/request" |
| | | "wms/response" |
| | | "wms/service" |
| | | "wms/task" |
| | | ) |
| | |
| | | |
| | | // GetHistory |
| | | // @Tags 报表 |
| | | // @Summary 获取历史信息 |
| | | // @Summary 获取出入库明细 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body request.GetInventoryHistory true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]response.InventoryHistory} "成功" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.MoveHistory} "成功" |
| | | // @Router /api-wms/v1/forms/getHistory [post] |
| | | func (slf ReportFormsController) GetHistory(c *gin.Context) { |
| | | slf.GetHistoryNew(c) |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | //获取操作详情 |
| | | detailsSearch := models.NewMoveHistorySearch() |
| | | var ( |
| | | result []*response.InventoryHistory |
| | | total uint64 |
| | | ids []int |
| | | err error |
| | | ) |
| | | if params.KeyWord != "" { |
| | | ids, total, err = service.SearchHistoryReport(params.KeyWord, params.BaseOperationType, params.Page, params.PageSize) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, err.Error()) |
| | | return |
| | | } |
| | | if len(ids) == 0 { |
| | | util.ResponseFormatList(c, code.Success, result, 0) |
| | | return |
| | | } |
| | | |
| | | historyFormsService := service.NewHistoryFormsService() |
| | | result, err := historyFormsService.Query(params) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | return |
| | | } |
| | | |
| | | detailsSearch.Orm = detailsSearch.Orm.Model(&models.MoveHistory{}). |
| | | Select("number, updated_at as date, product_name as product_name, from_location_id, operation_id,to_location_id, amount, " + |
| | | "unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc") |
| | | if len(ids) > 0 { |
| | | detailsSearch.Orm = detailsSearch.Orm.Where("id in ?", ids) |
| | | } |
| | | if params.BaseOperationType != 0 { |
| | | detailsSearch.Orm = detailsSearch.Orm.Where("base_operation_type = ?", params.BaseOperationType) |
| | | } |
| | | var t int64 |
| | | err = detailsSearch.Orm.Count(&t).Error |
| | | total, err := historyFormsService.Count(params) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询总条数失败: %v", err)) |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | return |
| | | } |
| | | total = uint64(t) |
| | | if params.Page*params.PageSize > 0 { |
| | | detailsSearch.Orm = detailsSearch.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize) |
| | | } |
| | | err = detailsSearch.Orm.Find(&result).Error |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询操作明细失败: %v", err)) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | // DownloadHistory |
| | | // @Tags 报表 |
| | | // @Summary 下载出入库明细报表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body request.GetInventoryHistory true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.MoveHistory} "成功" |
| | | // @Router /api-wms/v1/forms/downloadHistory [post] |
| | | func (slf ReportFormsController) DownloadHistory(c *gin.Context) { |
| | | var params request.GetInventoryHistory |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | historyFormsService := service.NewHistoryFormsService() |
| | | list, err := historyFormsService.FetchAll(params) |
| | | if err != nil { |
| | | logx.Errorf("DownloadHistory FetchAll err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | filename, err := historyFormsService.Export(list, params) |
| | | if err != nil { |
| | | logx.Errorf("DownloadHistory Export err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "导出数据到文件失败") |
| | | return |
| | | } |
| | | |
| | | fileContentDisposition := "attachment;filename=\"" + url.QueryEscape(filename) + "\"" |
| | | c.Header("Content-Type", "application/xlsx") |
| | | c.Header("Content-Disposition", fileContentDisposition) |
| | | c.File(filename) |
| | | defer os.Remove(filename) |
| | | } |
| | | |
| | | // GetLocationForms |
| | | // @Tags 报表 |
| | | // @Summary 获取位置报表 |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/forms/downloadHistory": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "报表" |
| | | ], |
| | | "summary": "下载出入库明细报表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | }, |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetInventoryHistory" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.MoveHistory" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/forms/downloadInventoryForms": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "tags": [ |
| | | "报表" |
| | | ], |
| | | "summary": "获取历史信息", |
| | | "summary": "获取出入库明细", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | }, |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/response.InventoryHistory" |
| | | "$ref": "#/definitions/models.MoveHistory" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.MoveHistory": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "baseOperationType": { |
| | | "description": "基础作业类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.BaseOperationType" |
| | | } |
| | | ] |
| | | }, |
| | | "createTime": { |
| | | "type": "string" |
| | | }, |
| | | "fromLocation": { |
| | | "description": "源位置", |
| | | "type": "string" |
| | | }, |
| | | "fromLocationId": { |
| | | "description": "源位置id", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationId": { |
| | | "description": "操作id", |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeId": { |
| | | "description": "作业类型id", |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeName": { |
| | | "description": "作业类型名称", |
| | | "type": "string" |
| | | }, |
| | | "operator": { |
| | | "description": "操作者", |
| | | "type": "string" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | | "type": "string" |
| | | }, |
| | | "toLocation": { |
| | | "description": "目标位置", |
| | | "type": "string" |
| | | }, |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "description": "单位", |
| | | "type": "string" |
| | | }, |
| | | "updateTime": { |
| | | "type": "string" |
| | | }, |
| | | "weight": { |
| | | "description": "重量", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "models.Operation": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | }, |
| | | "value": { |
| | | "description": "总价值", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "response.InventoryHistory": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "baseOperationType": { |
| | | "description": "基础作业类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.BaseOperationType" |
| | | } |
| | | ] |
| | | }, |
| | | "contactedName": { |
| | | "description": "完成者", |
| | | "type": "string" |
| | | }, |
| | | "date": { |
| | | "description": "日期", |
| | | "type": "string" |
| | | }, |
| | | "fromLocation": { |
| | | "description": "源位置", |
| | | "type": "string" |
| | | }, |
| | | "fromLocationId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationId": { |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeName": { |
| | | "description": "作业类型名称", |
| | | "type": "string" |
| | | }, |
| | | "productId": { |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "type": "string" |
| | | }, |
| | | "toLocation": { |
| | | "description": "目标位置", |
| | | "type": "string" |
| | | }, |
| | | "toLocationId": { |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "description": "单位", |
| | | "type": "string" |
| | | }, |
| | | "weight": { |
| | | "description": "重量", |
| | | "type": "number" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/forms/downloadHistory": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "报表" |
| | | ], |
| | | "summary": "下载出入库明细报表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | }, |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetInventoryHistory" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.MoveHistory" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/forms/downloadInventoryForms": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "tags": [ |
| | | "报表" |
| | | ], |
| | | "summary": "获取历史信息", |
| | | "summary": "获取出入库明细", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | }, |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/response.InventoryHistory" |
| | | "$ref": "#/definitions/models.MoveHistory" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.MoveHistory": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "baseOperationType": { |
| | | "description": "基础作业类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.BaseOperationType" |
| | | } |
| | | ] |
| | | }, |
| | | "createTime": { |
| | | "type": "string" |
| | | }, |
| | | "fromLocation": { |
| | | "description": "源位置", |
| | | "type": "string" |
| | | }, |
| | | "fromLocationId": { |
| | | "description": "源位置id", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationId": { |
| | | "description": "操作id", |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeId": { |
| | | "description": "作业类型id", |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeName": { |
| | | "description": "作业类型名称", |
| | | "type": "string" |
| | | }, |
| | | "operator": { |
| | | "description": "操作者", |
| | | "type": "string" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | | "type": "string" |
| | | }, |
| | | "toLocation": { |
| | | "description": "目标位置", |
| | | "type": "string" |
| | | }, |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "description": "单位", |
| | | "type": "string" |
| | | }, |
| | | "updateTime": { |
| | | "type": "string" |
| | | }, |
| | | "weight": { |
| | | "description": "重量", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "models.Operation": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | }, |
| | | "value": { |
| | | "description": "总价值", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "response.InventoryHistory": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "baseOperationType": { |
| | | "description": "基础作业类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.BaseOperationType" |
| | | } |
| | | ] |
| | | }, |
| | | "contactedName": { |
| | | "description": "完成者", |
| | | "type": "string" |
| | | }, |
| | | "date": { |
| | | "description": "日期", |
| | | "type": "string" |
| | | }, |
| | | "fromLocation": { |
| | | "description": "源位置", |
| | | "type": "string" |
| | | }, |
| | | "fromLocationId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationId": { |
| | | "type": "integer" |
| | | }, |
| | | "operationTypeName": { |
| | | "description": "作业类型名称", |
| | | "type": "string" |
| | | }, |
| | | "productId": { |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "type": "string" |
| | | }, |
| | | "toLocation": { |
| | | "description": "目标位置", |
| | | "type": "string" |
| | | }, |
| | | "toLocationId": { |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "description": "单位", |
| | | "type": "string" |
| | | }, |
| | | "weight": { |
| | | "description": "重量", |
| | | "type": "number" |
| | | } |
| | | } |
| | |
| | | description: 重量 |
| | | type: number |
| | | type: object |
| | | models.MoveHistory: |
| | | properties: |
| | | amount: |
| | | description: 数量 |
| | | type: number |
| | | baseOperationType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.BaseOperationType' |
| | | description: 基础作业类型 |
| | | createTime: |
| | | type: string |
| | | fromLocation: |
| | | description: 源位置 |
| | | type: string |
| | | fromLocationId: |
| | | description: 源位置id |
| | | type: integer |
| | | id: |
| | | type: integer |
| | | number: |
| | | description: 单号 |
| | | type: string |
| | | operationId: |
| | | description: 操作id |
| | | type: integer |
| | | operationTypeId: |
| | | description: 作业类型id |
| | | type: integer |
| | | operationTypeName: |
| | | description: 作业类型名称 |
| | | type: string |
| | | operator: |
| | | description: 操作者 |
| | | type: string |
| | | productId: |
| | | description: 产品id |
| | | type: string |
| | | productName: |
| | | description: 产品名称 |
| | | type: string |
| | | toLocation: |
| | | description: 目标位置 |
| | | type: string |
| | | toLocationId: |
| | | description: 目标位置id |
| | | type: integer |
| | | unit: |
| | | description: 单位 |
| | | type: string |
| | | updateTime: |
| | | type: string |
| | | weight: |
| | | description: 重量 |
| | | type: number |
| | | type: object |
| | | models.Operation: |
| | | properties: |
| | | accountant: |
| | |
| | | description: 总价值 |
| | | type: number |
| | | type: object |
| | | response.InventoryHistory: |
| | | properties: |
| | | amount: |
| | | description: 数量 |
| | | type: number |
| | | baseOperationType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.BaseOperationType' |
| | | description: 基础作业类型 |
| | | contactedName: |
| | | description: 完成者 |
| | | type: string |
| | | date: |
| | | description: 日期 |
| | | type: string |
| | | fromLocation: |
| | | description: 源位置 |
| | | type: string |
| | | fromLocationId: |
| | | type: integer |
| | | number: |
| | | description: 单号 |
| | | type: string |
| | | operationId: |
| | | type: integer |
| | | operationTypeName: |
| | | description: 作业类型名称 |
| | | type: string |
| | | productId: |
| | | type: string |
| | | productName: |
| | | description: 产品名称 |
| | | type: string |
| | | status: |
| | | description: 状态 |
| | | type: string |
| | | toLocation: |
| | | description: 目标位置 |
| | | type: string |
| | | toLocationId: |
| | | type: integer |
| | | unit: |
| | | description: 单位 |
| | | type: string |
| | | weight: |
| | | description: 重量 |
| | | type: number |
| | | type: object |
| | | response.LocationForms: |
| | | properties: |
| | | amount: |
| | |
| | | summary: 手动跑月度统计库存报表 |
| | | tags: |
| | | - 报表 |
| | | /api-wms/v1/forms/downloadHistory: |
| | | post: |
| | | parameters: |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.GetInventoryHistory' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/util.ResponseList' |
| | | - properties: |
| | | data: |
| | | items: |
| | | $ref: '#/definitions/models.MoveHistory' |
| | | type: array |
| | | type: object |
| | | summary: 下载出入库明细报表 |
| | | tags: |
| | | - 报表 |
| | | /api-wms/v1/forms/downloadInventoryForms: |
| | | post: |
| | | parameters: |
| | |
| | | /api-wms/v1/forms/getHistory: |
| | | post: |
| | | parameters: |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | |
| | | - properties: |
| | | data: |
| | | items: |
| | | $ref: '#/definitions/response.InventoryHistory' |
| | | $ref: '#/definitions/models.MoveHistory' |
| | | type: array |
| | | type: object |
| | | summary: 获取历史信息 |
| | | summary: 获取出入库明细 |
| | | tags: |
| | | - 报表 |
| | | /api-wms/v1/forms/getInventoryForms: |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) build() *gorm.DB { |
| | | func (slf *MoveHistorySearch) Build() *gorm.DB { |
| | | var db = slf.Orm.Model(&MoveHistory{}) |
| | | |
| | | if slf.ID != 0 { |
| | |
| | | |
| | | // Create 单条插入 |
| | | func (slf *MoveHistorySearch) Create(record *MoveHistory) error { |
| | | var db = slf.build() |
| | | var db = slf.Build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return err |
| | |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error { |
| | | var db = slf.build() |
| | | var db = slf.Build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) Update(record *MoveHistory) error { |
| | | var db = slf.build() |
| | | var db = slf.Build() |
| | | |
| | | if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | |
| | | |
| | | func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | db = slf.Build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) Delete() error { |
| | | var db = slf.build() |
| | | var db = slf.Build() |
| | | return db.Delete(&MoveHistory{}).Error |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) First() (*MoveHistory, error) { |
| | | var ( |
| | | record = new(MoveHistory) |
| | | db = slf.build() |
| | | db = slf.Build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | |
| | | var ( |
| | | records = make([]*MoveHistory, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | db = slf.Build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | |
| | | return records, total, nil |
| | | } |
| | | |
| | | // FindAs 按指定形式 |
| | | func (slf *MoveHistorySearch) FindAs(obj interface{}) (err error) { |
| | | var ( |
| | | db = slf.Build() |
| | | ) |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(obj).Error; err != nil { |
| | | return fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) { |
| | | var ( |
| | | records = make([]*MoveHistory, 0) |
| | | db = slf.build() |
| | | db = slf.Build() |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *MoveHistorySearch) Count() (int64, error) { |
| | | var ( |
| | | total int64 |
| | | db = slf.Build() |
| | | ) |
| | | |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | |
| | | |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "time" |
| | | "wms/constvar" |
| | | ) |
| | | |
| | |
| | | |
| | | type InventoryHistory struct { |
| | | Number string `json:"number"` //单号 |
| | | Date string `json:"date"` //日期 |
| | | Date time.Time `json:"date"` //日期 |
| | | ProductName string `json:"productName"` //产品名称 |
| | | FromLocation string `json:"fromLocation"` //源位置 |
| | | ToLocation string `json:"toLocation"` //目标位置 |
| | |
| | | reportFormsAPI.POST("getInventoryForms", reportFormsController.GetInventoryForms) //获取库存报表 |
| | | reportFormsAPI.POST("downloadInventoryForms", reportFormsController.DownloadInventoryForms) //下载库存报表 |
| | | reportFormsAPI.POST("getHistory", reportFormsController.GetHistory) //获取库存历史 |
| | | reportFormsAPI.POST("downloadHistory", reportFormsController.DownloadHistory) //下载库存报表 |
| | | reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms) //获取位置报表 |
| | | reportFormsAPI.POST("downloadLocationForms", reportFormsController.DownloadLocationForms) //下载位置报表 |
| | | reportFormsAPI.POST("monthStats", reportFormsController.MonthStats) //获取月度统计报表 |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/xuri/excelize/v2" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | | "wms/models" |
| | | "wms/request" |
| | | "wms/response" |
| | | ) |
| | | |
| | | type HistoryFormsService struct{} |
| | | |
| | | func NewHistoryFormsService() *HistoryFormsService { |
| | | return &HistoryFormsService{} |
| | | } |
| | | |
| | | func (slf *HistoryFormsService) Query(params request.GetInventoryHistory) (result []*response.InventoryHistory, err error) { |
| | | search, err := slf.BuildSearch(params) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | if params.Page > 0 && params.PageSize > 0 { |
| | | search = search.SetPage(params.Page, params.PageSize) |
| | | } |
| | | result = make([]*response.InventoryHistory, 0, params.PageSize) |
| | | err = search.FindAs(&result) |
| | | |
| | | return result, nil |
| | | } |
| | | |
| | | func (slf *HistoryFormsService) BuildSearch(params request.GetInventoryHistory) (search *models.MoveHistorySearch, err error) { |
| | | search = models.NewMoveHistorySearch() |
| | | var ( |
| | | ids []int |
| | | ) |
| | | if params.KeyWord != "" { |
| | | ids, _, err = SearchHistoryReport(params.KeyWord, params.BaseOperationType, params.Page, params.PageSize) |
| | | if err != nil { |
| | | return |
| | | } |
| | | if len(ids) == 0 { |
| | | return nil, nil |
| | | } |
| | | } |
| | | |
| | | search.Orm = search.Orm.Model(&models.MoveHistory{}). |
| | | Select("number, updated_at as date, product_name as product_name, from_location_id, operation_id,to_location_id, amount, " + |
| | | "unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc") |
| | | if len(ids) > 0 { |
| | | search.Orm = search.Orm.Where("id in ?", ids) |
| | | } |
| | | if params.BaseOperationType != 0 { |
| | | search.Orm = search.Orm.Where("base_operation_type = ?", params.BaseOperationType) |
| | | } |
| | | return search, err |
| | | } |
| | | |
| | | func (slf *HistoryFormsService) Count(params request.GetInventoryHistory) (total int64, err error) { |
| | | search, err := slf.BuildSearch(params) |
| | | if err != nil { |
| | | return 0, err |
| | | } |
| | | total, err = search.Count() |
| | | return |
| | | } |
| | | |
| | | func (slf *HistoryFormsService) FetchAll(params request.GetInventoryHistory) (list []*response.InventoryHistory, err error) { |
| | | total, err := slf.Count(params) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | list = make([]*response.InventoryHistory, 0, total) |
| | | params.PageSize = 500 |
| | | page := 1 |
| | | for { |
| | | params.Page = page |
| | | data, err := slf.Query(params) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | if len(data) == 0 { |
| | | break |
| | | } |
| | | list = append(list, data...) |
| | | page++ |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf *HistoryFormsService) Export(dataList []*response.InventoryHistory, params request.GetInventoryHistory) (filename string, err error) { |
| | | var fileName string |
| | | f := excelize.NewFile() |
| | | |
| | | // 自定义表头 |
| | | headers := []string{"日期", "单号", "产品", "产品编码", "业务类型", "从", "至", "数量", "单位", "重量"} |
| | | |
| | | // 设置表头 |
| | | for i, header := range headers { |
| | | cell := getColumnAlphabet(i+1) + "1" |
| | | f.SetCellValue("Sheet1", cell, header) |
| | | } |
| | | |
| | | for i, v := range dataList { |
| | | column := strconv.Itoa(i + 2) |
| | | f.SetCellValue("Sheet1", "A"+column, v.Date.Format("2006-01-02")) |
| | | f.SetCellValue("Sheet1", "B"+column, v.Number) |
| | | f.SetCellValue("Sheet1", "C"+column, v.ProductName) |
| | | f.SetCellValue("Sheet1", "D"+column, v.ProductId) |
| | | f.SetCellValue("Sheet1", "E"+column, v.OperationTypeName) |
| | | f.SetCellValue("Sheet1", "F"+column, v.FromLocation) |
| | | f.SetCellValue("Sheet1", "G"+column, v.ToLocation) |
| | | f.SetCellValue("Sheet1", "H"+column, v.Amount) |
| | | f.SetCellValue("Sheet1", "I"+column, v.Unit) |
| | | f.SetCellValue("Sheet1", "J"+column, v.Weight) |
| | | } |
| | | |
| | | if params.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | fileName = fmt.Sprintf("入库明细报表%s.xlsx", time.Now().Format("2006-01-02-1504")) |
| | | } else if params.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | fileName = fmt.Sprintf("出库明细报表%s.xlsx", time.Now().Format("2006-01-02-1504")) |
| | | } |
| | | |
| | | if err := f.SaveAs(fileName); err != nil { |
| | | return fileName, err |
| | | } |
| | | |
| | | return fileName, nil |
| | | } |