/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.inventorymanage.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.inventorymanage.appservice.ITraceNoAppService;
import com.openhis.web.inventorymanage.dto.TraceNoInfoParam;
import com.openhis.web.inventorymanage.dto.TraceNoSearchParam;

import lombok.extern.slf4j.Slf4j;

/**
 * 追溯码管理 controller
 *
 * @author yuxj
 * @date 2025-07-07
 */
@RestController
@RequestMapping("/inventory-manage/traceNo")
@Slf4j
public class TraceNoManageController {

    @Resource
    private ITraceNoAppService traceNoAppService;

    /**
     * 追溯码管理页面初始化
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> traceNoInit() {
        return traceNoAppService.traceNoInit();
    }

    /**
     * 追溯码管理列表
     *
     * @param traceNoSearchParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求数据
     * @return
     */
    @GetMapping(value = "/inventory-receipt-page")
    public R<?> getPage(TraceNoSearchParam traceNoSearchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return traceNoAppService.getPage(traceNoSearchParam, pageNo, pageSize, searchKey, request);
    }

    /**
     * 添加追溯码信息
     *
     * @param traceNoInfoList 追溯码信息
     * @return 操作结果
     */
    @PutMapping("/inventory-receipt")
    public R<?> addTraceNoInfo(@Validated @RequestBody List<TraceNoInfoParam> traceNoInfoList) {
        return traceNoAppService.addTraceNoInfo(traceNoInfoList);
    }

}
