package com.bonus.sharedstation.app.controller;


import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.sharedstation.app.dto.RepairServiceDTO;
import com.bonus.sharedstation.app.dto.RepairServiceOrderDTO;
import com.bonus.sharedstation.app.entity.RepairServiceOrder;
import com.bonus.sharedstation.app.service.RepairServiceOrderService;
import com.bonus.sharedstation.web.service.IRepairServiceWebService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/information/repairserviceorder")
public class RepairServiceOrderController {
    /**
     * 服务对象
     */
    @Resource
    private RepairServiceOrderService service;

    @Resource
    private IRepairServiceWebService repairServiceWebService;


    /**
     * 新增数据
     *
     * @param dto 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增")
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody RepairServiceOrder dto) {

        dto.setCreatedBy(SecurityUtils.getUsername());
        dto.setCreatedTime(new Date());
        dto.setUserId(String.valueOf(SecurityUtils.getUserId()));
        dto.setOrderTime(new Date());
        dto.setIsDeleted("0");
        return AjaxResult.success(service.insertToPay(dto));
    }

    /**
     * 修改数据
     *
     * @param dto 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody RepairServiceOrder dto) {
        //得到登录人
        dto.setUpdatedBy(SecurityUtils.getUsername());
        dto.setUpdatedTime(new Date());
        return AjaxResult.success(this.service.updateById(dto));
    }


    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @ApiOperation("查询全部数据APP")
    @PostMapping("/getList")
    public AjaxResult getList(@RequestBody RepairServiceOrderDTO dto) {
        return service.getListPageApp(dto);

    }

    @ApiOperation("查询全部数据WEB")
    @PostMapping("/getListWeb")
    public AjaxResult getListWeb(@RequestBody RepairServiceOrderDTO dto) {
        return service.getListWeb(dto);

    }

    @PostMapping(value = "selectById", produces = "application/json; charset=utf-8")
    @ApiOperation("查询详情")
    public AjaxResult selectInfoById(@RequestBody RepairServiceOrder dto) {
        return service.selectInfoById(dto);
    }

    @ApiOperation("查询全部数据")
    @PostMapping("/getListRepairService")
    public AjaxResult getList(@RequestBody RepairServiceDTO dto) {
        return service.getListPage(dto);
    }


    @ApiOperation("查询全部数据订单")
    @PostMapping("/getListSeller")
    public AjaxResult getListSeller(@RequestBody RepairServiceOrderDTO dto){
        return repairServiceWebService.getListWeb(dto);
    }
}

