package com.aucma.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aucma.base.domain.BaseMonitorInfo;
import com.aucma.base.domain.BaseProductLine;
import com.aucma.base.domain.TreeSelects;
import com.aucma.base.service.IBaseProductLineService;
import com.aucma.common.utils.DateUtils;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.BaseWorkUnit;
import com.aucma.base.service.IBaseWorkUnitService;
import com.aucma.common.utils.poi.ExcelUtil;

/**
 * 统计单元信息Controller
 *
 * @author Yinq
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/base/workUnit")
public class BaseWorkUnitController extends BaseController {
    @Autowired
    private IBaseWorkUnitService baseWorkUnitService;
    @Autowired
    private IBaseProductLineService baseProductLineService;

    /**
     * 查询统计单元信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseWorkUnit baseWorkUnit) {
        List<BaseWorkUnit> list = baseWorkUnitService.selectBaseWorkUnitList(baseWorkUnit);
        return success(list);
    }

    /**
     * 查询计量设备信息下拉树结构
     */
    @PostMapping("/workUnitTree")
    public AjaxResult getMonitorInfoTree(BaseWorkUnit baseWorkUnit) {
        List<TreeSelects> list = baseWorkUnitService.selectBaseWorkUnitTreeList(baseWorkUnit);
        return success(list);
    }

    /**
     * 导出统计单元信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:export')")
    @Log(title = "统计单元信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseWorkUnit baseWorkUnit) {
        List<BaseWorkUnit> list = baseWorkUnitService.selectBaseWorkUnitList(baseWorkUnit);
        ExcelUtil<BaseWorkUnit> util = new ExcelUtil<BaseWorkUnit>(BaseWorkUnit.class);
        util.exportExcel(response, list, "统计单元信息数据");
    }

    /**
     * 获取统计单元信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(baseWorkUnitService.selectBaseWorkUnitByObjId(objId));
    }

    /**
     * 新增统计单元信息
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:add')")
    @Log(title = "统计单元信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseWorkUnit baseWorkUnit) {
        baseWorkUnit.setCreatedBy(getUsername());
        baseWorkUnit.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseWorkUnitService.insertBaseWorkUnit(baseWorkUnit));
    }

    /**
     * 修改统计单元信息
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:edit')")
    @Log(title = "统计单元信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseWorkUnit baseWorkUnit) {
        baseWorkUnit.setUpdatedBy(getUsername());
        baseWorkUnit.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseWorkUnitService.updateBaseWorkUnit(baseWorkUnit));
    }

    /**
     * 删除统计单元信息
     */
    @PreAuthorize("@ss.hasPermi('base:workUnit:remove')")
    @Log(title = "统计单元信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseWorkUnitService.deleteBaseWorkUnitByObjIds(objIds));
    }
}
