package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.hospital.domain.HospitalProductLogs;
import com.fs.hospital.service.IHospitalProductLogsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 商品记录Controller
 *
 * @author fs
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/hospital/hospitalProductLogs")
public class HospitalProductLogsController extends BaseController
{
    @Autowired
    private IHospitalProductLogsService hospitalProductLogsService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询商品记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalProductLogs hospitalProductLogs)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalProductLogs.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalProductLogs> list = hospitalProductLogsService.selectHospitalProductLogsList(hospitalProductLogs);
        return getDataTable(list);
    }

    /**
     * 导出商品记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:export')")
    @Log(title = "商品记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalProductLogs hospitalProductLogs)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalProductLogs.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalProductLogs> list = hospitalProductLogsService.selectHospitalProductLogsList(hospitalProductLogs);
        ExcelUtil<HospitalProductLogs> util = new ExcelUtil<HospitalProductLogs>(HospitalProductLogs.class);
        return util.exportExcel(list, "商品记录数据");
    }

    /**
     * 获取商品记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:query')")
    @GetMapping(value = "/{logsId}")
    public AjaxResult getInfo(@PathVariable("logsId") Long logsId)
    {
        return AjaxResult.success(hospitalProductLogsService.selectHospitalProductLogsByLogsId(logsId));
    }

    /**
     * 新增商品记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:add')")
    @Log(title = "商品记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalProductLogs hospitalProductLogs)
    {
        return toAjax(hospitalProductLogsService.insertHospitalProductLogs(hospitalProductLogs));
    }

    /**
     * 修改商品记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:edit')")
    @Log(title = "商品记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalProductLogs hospitalProductLogs)
    {
        return toAjax(hospitalProductLogsService.updateHospitalProductLogs(hospitalProductLogs));
    }

    /**
     * 删除商品记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductLogs:remove')")
    @Log(title = "商品记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logsIds}")
    public AjaxResult remove(@PathVariable Long[] logsIds)
    {
        return toAjax(hospitalProductLogsService.deleteHospitalProductLogsByLogsIds(logsIds));
    }
}
