package com.willalp.web.controller.yiqing;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.yiqing.domain.HsOrdersLog;
import com.willalp.yiqing.domain.HsOrdersLogData;
import com.willalp.yiqing.service.IHsOrdersLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 派单记录Controller
 *
 * @author willalp
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/yiqing/orderLog")
public class HsOrdersLogController extends BaseController {
    @Resource
    private IHsOrdersLogService hsOrdersLogService;

    /**
     * 导出派单结果
     */
    @GetMapping("/exportOrderResult")
    public AjaxResult exportOrderResult(HsOrdersLog hsOrdersLog) {
        List<HsOrdersLogData> list = hsOrdersLogService.exportOrderResult(hsOrdersLog);
        ExcelUtil<HsOrdersLogData> util = new ExcelUtil<>(HsOrdersLogData.class);
        return util.exportExcel(list, "派单结果记录");
    }

    /**
     * 查询派单记录列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsOrdersLog hsOrdersLog) {
        startPage();
        List<HsOrdersLog> list = hsOrdersLogService.selectHsOrdersLogList(hsOrdersLog);
        return getDataTable(list);
    }

    /**
     * 导出派单记录列表
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:export')")
    @Log(title = "派单记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsOrdersLog hsOrdersLog) {
        List<HsOrdersLog> list = hsOrdersLogService.selectHsOrdersLogList(hsOrdersLog);
        ExcelUtil<HsOrdersLog> util = new ExcelUtil<HsOrdersLog>(HsOrdersLog.class);
        return util.exportExcel(list, "派单记录数据");
    }

    /**
     * 获取派单记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(hsOrdersLogService.getById(id));
    }

    /**
     * 新增派单记录
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:add')")
    @Log(title = "派单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsOrdersLog hsOrdersLog) {
        hsOrdersLog.setCreateBy(SecurityUtils.getUsername());
        hsOrdersLog.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsOrdersLogService.save(hsOrdersLog));
    }

    /**
     * 修改派单记录
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:edit')")
    @Log(title = "派单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsOrdersLog hsOrdersLog) {
        hsOrdersLog.setUpdateBy(SecurityUtils.getUsername());
        hsOrdersLog.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsOrdersLogService.updateById(hsOrdersLog));
    }

    /**
     * 删除派单记录
     */
    @PreAuthorize("@ss.hasPermi('yiqing:orderLog:remove')")
    @Log(title = "派单记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(hsOrdersLogService.removeByIds(Arrays.asList(ids)));
    }
}
