package com.gyee.frame.controller.recommen;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Recommenmain;
import com.gyee.frame.model.custom.*;
import com.gyee.frame.service.recommen.RecommenService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("/recommen")
@Api(value = "健康风机推荐",tags =  "健康风机推荐")
public class RecommenController {

    @Resource
    private RecommenService recommenService;

    /**
     * 获得当日健康推荐检修风机
     * @return
     */
    @PostMapping("/getRecommenmainDay1")
    @ResponseBody
    @ApiOperation(value = "获得当日健康推荐检修风机", notes = "获得当日健康推荐检修风机")
     public AjaxResult getRecommenmainDay1() {

        List<Recommenmain> vos=new ArrayList<>();

        vos=recommenService.getRecommenmainDay1();

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }

    /**
     * 获得3日健康推荐检修风机
     * @return
     */
    @PostMapping("/getRecommenmainDay3")
    @ResponseBody
    @ApiOperation(value = "获得3日健康推荐检修风机", notes = "获得3日健康推荐检修风机")
    public AjaxResult getRecommenmainDay3() {

        List<Recommenmain> vos=new ArrayList<>();

        vos=recommenService.getRecommenmainDay3();

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }

    /**
     * 获得7日健康推荐检修风机
     * @return
     */
    @PostMapping("/getRecommenmainDay7")
    @ResponseBody
    @ApiOperation(value = "获得7日健康推荐检修风机", notes = "获得7日健康推荐检修风机")
    public AjaxResult getRecommenmainDay7() {

        List<Recommenmain> vos=new ArrayList<>();

        vos=recommenService.getRecommenmainDay7();

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }

    /**
     * 确认推荐检修风机，并添加记录到生产系统
     * @param rid
     */
    @PostMapping("/confirpush")
    @ResponseBody
    @ApiOperation(value = "确认推荐检修风机，并添加记录到生产系统", notes = "确认推荐检修风机，并添加记录到生产系统")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "rid", value = "推荐记录编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult confirpush(String rid)
    {
        int result=0;
        if(StringUtils.notEmp(rid))
        {
            result= recommenService.confirpush(rid);
        }

        return AjaxResult.successData(AjaxStatus.success.code, result);
    }

    /**
     * 全部确认不同时间段的推荐检修风机
     * @param typeid 1代表全部确认当日推荐  2 代表全部确认三天推荐 3 代表全部确认未来七天推荐
     */
    @PostMapping("/confirpushAll")
    @ResponseBody
    @ApiOperation(value = "全部确认不同时间段的推荐检修风机", notes = "全部确认不同时间段的推荐检修风机")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "typeid", value = "类型编号 1代表全部确认当日推荐  2 代表全部确认三天推荐 3 代表全部确认未来七天推荐", required = true, dataType = "string", paramType = "query")})

    public AjaxResult confirpushAll(String typeid)
    {

        List<Recommenmain> vos=new ArrayList<>();

        if (StringUtils.notEmp(typeid)) {
            switch(typeid) {
                case "1":
                    vos=recommenService.getRecommenmainDay1();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.confirpush(vo.getRid());
                        }
                    }
                    break;
                case "2":
                    vos=recommenService.getRecommenmainDay3();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.confirpush(vo.getRid());
                        }
                    }
                    break;
                case "3":
                    vos=recommenService.getRecommenmainDay7();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.confirpush(vo.getRid());
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        return AjaxResult.successData(AjaxStatus.success.code, 1);
    }
    /**
     * 取消推荐检修风机
     * @param rid
     */
    @PostMapping("/ignorepush")
    @ResponseBody
    @ApiOperation(value = "取消推荐检修风机", notes = "取消推荐检修风机")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "rid", value = "推荐记录编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult ignorepush(String rid)
    {
        int result=0;
        if(StringUtils.notEmp(rid))
        {
            result= recommenService.ignorepush(rid);
        }

        return AjaxResult.successData(AjaxStatus.success.code, result);
    }

    /**
     * 全部取消不同时间段的推荐检修风机
     * @param typeid 1代表全部取消当日推荐  2 代表全部取消三天推荐 3 代表全部取消未来七天推荐
     */
    @PostMapping("/ignorepushAll")
    @ResponseBody
    @ApiOperation(value = "全部取消不同时间段的推荐检修风机", notes = "全部取消不同时间段的推荐检修风机")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "typeid", value = "类型编号 1代表全部取消当日推荐  2 代表全部取消三天推荐 3 代表全部取消未来七天推荐", required = true, dataType = "string", paramType = "query")})

    public AjaxResult ignorepushAll(String typeid)
    {

        List<Recommenmain> vos=new ArrayList<>();

        if (StringUtils.notEmp(typeid)) {
            switch(typeid) {
                case "1":
                    vos=recommenService.getRecommenmainDay1();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.ignorepush(vo.getRid());
                        }
                    }
                    break;
                case "2":
                    vos=recommenService.getRecommenmainDay3();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.ignorepush(vo.getRid());
                        }
                    }
                    break;
                case "3":
                    vos=recommenService.getRecommenmainDay7();
                    if(!vos.isEmpty())
                    {
                        for(Recommenmain vo:vos)
                        {
                            recommenService.ignorepush(vo.getRid());
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        return AjaxResult.successData(AjaxStatus.success.code, 1);
    }

    /**
     * 获得已经确认检修风机
     * @return
     */
    @PostMapping("/recommenConfirmedList")
    @ResponseBody
    @ApiOperation(value = "获得已经确认检修风机", notes = "获得已经确认检修风机")

    public AjaxResult recommenConfirmedList() {

        List<Recommenmain> vos=new ArrayList<>();

        vos=recommenService.recommenConfirmedList();

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }


    }

    /**
     * 获得健康状态预测
     * @param wpId
     * @param type 1 表示24小时健康趋势，2 表示七天健康趋势 3 表示30天健康趋势，
     * @return map.put(" yslchart ", yslchart); //优数量
     *             map.put("lslchart", lslchart);//良数量
     *             map.put("cslchart", cslchart);//差数量
     *             map.put("lvchart", lvchart);//健康率
     *             map.put("datechart", datechart);//日期
     * @throws Exception
     */
    @PostMapping("/findAllChartjz")
    @ResponseBody
    @ApiOperation(value = "获得健康状态预测", notes = "获得健康状态预测")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型编号 1 表示24小时健康趋势，2 表示七天健康趋势 3 表示30天健康趋势", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findAllChartjz(String wpId,  String type) throws Exception {

        Map<String, Object[]> map = new HashMap<String, Object[]>();

        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(type) ) {

            map=recommenService.findAllChartjz(wpId, type);

        }
        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        }

    }


    /**
     * 通过消缺单获得详细信息
     * @param rid
     * @return
     */
    @PostMapping("/findMainTrack")
    @ResponseBody
    @ApiOperation(value = "通过消缺单获得详细信息", notes = "通过消缺单获得详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rid", value = "推荐检修编号", required = true, dataType = "string", paramType = "query")
        })

    public AjaxResult findMainTrack(String rid) {

        MainTrackVo vo = new MainTrackVo();

        if(StringUtils.notEmp(rid))
        {
            vo =recommenService.findMainTrack(rid);
        }

        return AjaxResult.successData(AjaxStatus.success.code, vo);

    }

    /**
     * 获得未完成消缺单列表
     * @return
     */
    @PostMapping("/unfinishedList")
    @ResponseBody
    @ApiOperation(value = "获得未完成消缺单列表", notes = "获得未完成消缺单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult unfinishedList(String wpId, String wtId, String beginDate, String endDate) {

        List<WoBugEqVo> vos=new ArrayList<>();

        if(StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate))
        {
            vos=recommenService.unfinishedList(wpId,wtId, DateUtils.parseDate(beginDate),DateUtils.parseDate(endDate));
        }

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }
    /**
     * 获得完成消缺单列表
     * @return
     */
    @PostMapping("/finishedList")
    @ResponseBody
    @ApiOperation(value = "获得完成消缺单列表", notes = "获得完成消缺单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult finishedList(String wpId, String wtId, String beginDate, String endDate) {

        List<WoBugEqVo> vos=new ArrayList<>();

        if(StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate))
        {
            vos=recommenService.finishedList(wpId,wtId, DateUtils.parseDate(beginDate),DateUtils.parseDate(endDate) );
        }

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }


    /**
     * 通过用户姓名和开始检修时间和结束检修时间获取手环实时和历史数据
     * @param name
     * @param beginDate
     * @param endDate
     * @return
     * @throws Exception
     */
    @PostMapping("/findShbraceletList")
    @ResponseBody
    @ApiOperation(value = "通过用户姓名和开始检修时间和结束检修时间获取手环实时和历史数据", notes = "通过用户姓名和开始检修时间和结束检修时间获取手环实时和历史数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult findShbraceletList(String name,String beginDate,String endDate) throws Exception {

        Map<String,Map<String,Object>> result=new HashMap<>();

        if(StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate))
        {
            result=recommenService.findShbraceletList(name,beginDate,endDate);
        }

        if (null!=result) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        }

    }


    /**
     * 获取部件结构树
     * @return
     */
    @PostMapping("/findLocationTreeByWtId")
    @ResponseBody
    @ApiOperation(value = "获取部件结构树", notes = "获取部件结构树")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = false, dataType = "string", paramType = "query")
    })

    public AjaxResult findLocationTreeByWtId(String wtId) throws Exception {

        List<ElementNode> vos=new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            vos=recommenService.findLocationTreeByWtId(wtId);
        }

        return AjaxResult.successData(AjaxStatus.success.code, vos);

    }

    /**
     * 通过位置编号获得缺陷单信息
     * @return
     */
    @PostMapping("/findWobugeqByLocation")
    @ResponseBody
    @ApiOperation(value = "通过位置编号获得缺陷单信息", notes = "通过位置编号获得缺陷单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = false, dataType = "Tablepar", paramType = "query"),
            @ApiImplicitParam(name = "location", value = "位置", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult findWobugeqByLocation(Tablepar tablepar, String location) throws Exception {

        List<WoBugVo> vos=new ArrayList<>();

        if(StringUtils.notEmp(tablepar) && StringUtils.notEmp(location))
        {
            Calendar c = Calendar.getInstance();

            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND,0);

            c.set(Calendar.DAY_OF_YEAR, c.getActualMinimum(Calendar.DAY_OF_YEAR));
            Date beginDate = DateUtils.truncate(c.getTime());
            c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
            Date endDate = DateUtils.truncate(c.getTime());
            vos=recommenService.findWobugeqByLocation(tablepar,location, beginDate, endDate);
        }

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }


    /**
     * 获得对应风机的1个月健康推荐检修记录
     * @return
     */
    @PostMapping("/getRecommenmainMonth")
    @ResponseBody
    @ApiOperation(value = "获得对应风机的1个月健康推荐检修记录", notes = "获得对应风机的1个月健康推荐检修记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult getRecommenmainMonth(String wtId) throws Exception {

        List<Recommenmain> result=new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            result=recommenService.getRecommenmainMonth(wtId);
        }

        if (null!=result) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        }

    }
}
