package com.zbf.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.zbf.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.TBaseStorage;
import com.zbf.system.domain.TCallNotice;
import com.zbf.system.service.ITBaseStorageService;
import com.zbf.system.service.ITCallNoticeService;
import com.zbf.web.controller.section.EnhanceDataList;

/**
 * 【请填写功能名称】Controller
 *
 * @author tony
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/system/callNotice")
public class TCallNoticeController extends BaseController
{
    @Autowired
    private ITCallNoticeService tCallNoticeService;

    @Autowired
    private ITBaseStorageService baseStorageService;




    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TCallNotice tCallNotice)
    {
        startPage();
        List<TCallNotice> list = tCallNoticeService.selectTCallNoticeList(tCallNotice);
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/selectList")
    @EnhanceDataList(entityType = TCallNotice.class)
    public AjaxResult selectList(TCallNotice tCallNotice)
    {
        List<TCallNotice> list = tCallNoticeService.selectTCallNoticeList(tCallNotice);
        list.forEach(tCallNotice1 -> {
            if(StringUtils.isNotBlank(tCallNotice1.getShelfCtl())){
                tCallNotice1.setCtl(tCallNotice1.getShelfCtl());
            }else if(StringUtils.isNotBlank(tCallNotice1.getPickCtl())){
                tCallNotice1.setCtl(tCallNotice1.getPickCtl());
            }
            if(StringUtils.isNotBlank(tCallNotice1.getrLocationId())){
                tCallNotice1.setLocationId(tCallNotice1.getrLocationId());
            }else if(StringUtils.isNotBlank(tCallNotice1.getcLocationId())){
                tCallNotice1.setLocationId(tCallNotice1.getcLocationId());
            }
        });
        return success(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCallNotice tCallNotice)
    {
        List<TCallNotice> list = tCallNoticeService.selectTCallNoticeList(tCallNotice);
        ExcelUtil<TCallNotice> util = new ExcelUtil<TCallNotice>(TCallNotice.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tCallNoticeService.selectTCallNoticeById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCallNotice tCallNotice)
    {
        return toAjax(tCallNoticeService.insertTCallNotice(tCallNotice));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCallNotice tCallNotice)
    {
        return toAjax(tCallNoticeService.updateTCallNotice(tCallNotice));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tCallNoticeService.deleteTCallNoticeByIds(ids));
    }

    /**
     * 启用
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable String[] ids)
    {
        return toAjax(tCallNoticeService.disabledTCallNoticeByIds(ids));
    }

    /**
     * 禁用
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable String[] ids)
    {
        return toAjax(tCallNoticeService.enableTCallNoticeByIds(ids));
    }

    /**
     * 修改状态
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TCallNotice tCallNotice) {
        return toAjax(tCallNoticeService.updateStatus(tCallNotice));
    }

    /**
     * 获取部门权限
     * @return
     */
    @GetMapping("/getStorageList")
    public AjaxResult list()
    {
        getDeptId();
        List<TBaseStorage> storageList = getStorageList(getDeptId());
        return success(storageList);
    }


    private List<TBaseStorage> getStorageList(Long deptId){
        TBaseStorage baseStorage = new TBaseStorage();
        baseStorage.setDeptId(deptId);
        return baseStorageService.selectTBaseStorageList(baseStorage);

    }

}

