package com.xintong.visualinspection.controller.gettway;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.FwqCheckOther;
import com.xintong.visualinspection.controller.BaseController;
import com.xintong.visualinspection.service.CheckOtherService_F;
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 javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/f/checkOther")
public class CheckOtherController_F extends BaseController {

    @Reference(version = "1.0.0",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}")
    private CheckOtherService_F checkOtherService_f;

    /**
     * 第三方暗访稽查查询(查询条件:时间,道管,服务区)
     * @param request
     * @param page
     * @param size
     * @param fwqCheckOther
     * @return
     */
    @RequestMapping(value = "/getAllCheckOther/{page}/{size}")
    public String getAllCheckOther(HttpServletRequest request, @PathVariable Integer page, @PathVariable Integer size, @RequestBody FwqCheckOther fwqCheckOther){
        Object result = checkOtherService_f.getAllCheckOther(page,size,fwqCheckOther);
        return super.returnSuccessResult(result);
    }

    /**
     * 添加其他稽查查记录
     * @param request
     * @param fwqCheckOther
     * @return
     */
    @RequestMapping(value = "/add")
    public String add(HttpServletRequest request, @Valid @RequestBody FwqCheckOther fwqCheckOther) {
        checkOtherService_f.addCheckOther(fwqCheckOther);
        return super.returnSuccessResult("添加成功");
    }

    /**
     * 更新稽查记录
     * @param fwqCheckOther
     * @return
     */
    @RequestMapping(value = "/update")
    public String update(@RequestBody FwqCheckOther fwqCheckOther){
        if(fwqCheckOther.getId()==null){
            throw new BusinessException(20002);
        }
        checkOtherService_f.updateCheckOther(fwqCheckOther);
        return super.returnSuccessResult("修改成功");
    }

    /**
     * 根据id删除稽查记录
     * @param fwqCheckOther
     * @return
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody FwqCheckOther fwqCheckOther){
        if(fwqCheckOther.getId()==null){
            throw new BusinessException(20002);
        }
        checkOtherService_f.deleteCheckOther(fwqCheckOther.getId());
        return super.returnSuccessResult("删除成功");
    }

    /**根据id获取稽查记录
     * @param fwqCheckOther
     * @return
     */
    @RequestMapping(value = "/getCheckById")
    public String getCheckById(@RequestBody FwqCheckOther fwqCheckOther){
        if(fwqCheckOther.getId()==null){
            throw new BusinessException(20002);
        }
        FwqCheckOther result =checkOtherService_f.selectCheckById(fwqCheckOther.getId());
        return super.returnSuccessResult(result);
    }

    @RequestMapping(value = "/getOtherCheckStatistics")
    public String getOtherCheckStatistics(@RequestBody FwqCheckOther fwqCheckOther){
        Map<String,Object> checkStatistics = checkOtherService_f.getCheckOtherStatistics(fwqCheckOther);
        return super.returnSuccessResult(checkStatistics);
    }
}
