package com.izouma.awesomeadmin.web;

import java.util.*;

import com.izouma.awesomeadmin.util.ExportExcelUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.dto.Result;
import com.izouma.awesomeadmin.model.AimPlaceInfo;
import com.izouma.awesomeadmin.service.AimPlaceInfoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*  controller类
*/
@Controller
@RequestMapping("/aimPlaceInfo")
public class AimPlaceInfoController {

    @Autowired
    private AimPlaceInfoService aimPlaceInfoService;

    /**
    * <p>获取全部记录。</p>
    */
    @RequiresAuthentication
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public Result all(AimPlaceInfo record) {
        List<AimPlaceInfo> pp = aimPlaceInfoService.getAimPlaceInfoList(record);
        return new Result(true, pp);
    }

    /**
    * <p>根据Id。</p>
    */
    @RequestMapping(value = "/getAimPlaceInfo", method = RequestMethod.GET)
    @ResponseBody
    public Result getAimPlaceInfo(@RequestParam(required = false, value = "id") String id) {
        AimPlaceInfo data = aimPlaceInfoService.getAimPlaceInfoById(id);
        return new Result(true, data);
    }

    /**
    * <p>根据条件获取。</p>
    */
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    @ResponseBody
    public Result getOne(AimPlaceInfo record) {
        AimPlaceInfo data = aimPlaceInfoService.getAimPlaceInfo(record);
        return new Result(true, data);
    }


    /**
    * <p>分页查询。</p>
    */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    public Result page(Page page, AimPlaceInfo record) {
        Map<String, Object> result = new HashMap<>();

        List<AimPlaceInfo> pp =aimPlaceInfoService.getAimPlaceInfoByPage(page, record);

        result.put(AppConstant.PAGE, page);
        result.put("pp", pp);
        return new Result(true, result);
    }


    /**
    * <p>保存。</p>
    */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public Result save(AimPlaceInfo record) {
        boolean num = aimPlaceInfoService.createAimPlaceInfo(record);
        if (num) {
        return new Result(true, record.getId());
        }
        return new Result(false, "保存异常");
    }

    /**
    * <p>更新信息。</p>
    */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Result updateAimPlaceInfo(AimPlaceInfo record) {
        boolean num = aimPlaceInfoService.updateAimPlaceInfo(record);
        if (num) {
        return new Result(true, "保存成功");
        }
        return new Result(false, "保存异常");
    }

    /**
    * <p>删除。</p>
    */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ResponseBody
    public Result deleteAimPlaceInfo(AimPlaceInfo record) {

        boolean num = aimPlaceInfoService.deleteAimPlaceInfo(record);
        if (num) {
        return new Result(true, "删除成功");
        }
        return new Result(false, "删除异常");
    }

    /**
    * 导出Excel
    * @param request
    * @param response
    * @param record
    * @throws Exception
    */
    @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
    @ResponseBody
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, AimPlaceInfo record) throws Exception {

    List<AimPlaceInfo> aimPlaceInfos = aimPlaceInfoService.getAimPlaceInfoList(record);


        String sheetName = "aim_place_info";
        String titleName = "点标信息表数据表";
        String fileName = "点标信息表表";
        int columnNumber = 49;
        int[] columnWidth = { 20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20 };
        String[] columnName = {  "ID" ,   "删除标识" ,   "更新时间" ,   "更新人" ,   "创建时间" ,   "创建人" ,   "名称" ,   "类别" ,   "所属地标ID" ,   "AR内容组ID" ,   "ArKit坐标X" ,   "ArKit坐标Y" ,   "ArKit坐标Z" ,   "ArKit缩放" ,   "ArKit角度" ,   "ArKit一定距离显示" ,   "Gyro坐标X" ,   "Gyro坐标Y" ,   "Gyro坐标Z" ,   "Gyro缩放" ,   "Gyro角度" ,   "Gyro一定距离显示" ,   "Gyro绑定识别图区域标记编号" ,   "模型X" ,   "模型Y" ,   "模型Z" ,   "显示摄像头前" ,   "备注5" ,   "备注6" ,   "地图index" ,   "坐标X" ,   "坐标Y" ,   "坐标Z" ,   "备注7" ,   "备注8" ,   "备注9" ,   "上级ID" ,   "图标" ,   "图标顺序" ,   "是否独占" ,   "自动触发" ,   "自动显示" ,   "显示层级" ,   "上级模板" ,   "权限" ,   "区域ID" ,   "事物ID" ,   "点标组ID" ,   "模板点标ID"  };
        String[][] dataList = new String[aimPlaceInfos.size()][49];

        for (int i = 0; i < aimPlaceInfos.size(); i++) {

                        dataList[i][0] = String.valueOf(aimPlaceInfos.get(i).getId());
                        dataList[i][1] = String.valueOf(aimPlaceInfos.get(i).getDelFlag());
                        dataList[i][2] = String.valueOf(aimPlaceInfos.get(i).getUpdateTime());
                        dataList[i][3] = String.valueOf(aimPlaceInfos.get(i).getUpdateUser());
                        dataList[i][4] = String.valueOf(aimPlaceInfos.get(i).getCreateTime());
                        dataList[i][5] = String.valueOf(aimPlaceInfos.get(i).getCreateUser());
                        dataList[i][6] = String.valueOf(aimPlaceInfos.get(i).getName());
                        dataList[i][7] = String.valueOf(aimPlaceInfos.get(i).getType());
                        dataList[i][8] = String.valueOf(aimPlaceInfos.get(i).getOwnedLandMarkId());
                        dataList[i][9] = String.valueOf(aimPlaceInfos.get(i).getArContentGroupId());
                        dataList[i][10] = String.valueOf(aimPlaceInfos.get(i).getArKitPosX());
                        dataList[i][11] = String.valueOf(aimPlaceInfos.get(i).getArKitPosY());
                        dataList[i][12] = String.valueOf(aimPlaceInfos.get(i).getArKitPosZ());
                        dataList[i][13] = String.valueOf(aimPlaceInfos.get(i).getArKitScale());
                        dataList[i][14] = String.valueOf(aimPlaceInfos.get(i).getArKitAngle());
                        dataList[i][15] = String.valueOf(aimPlaceInfos.get(i).getArKitShowLenth());
                        dataList[i][16] = String.valueOf(aimPlaceInfos.get(i).getGyroPosX());
                        dataList[i][17] = String.valueOf(aimPlaceInfos.get(i).getGyroPosY());
                        dataList[i][18] = String.valueOf(aimPlaceInfos.get(i).getGyroPosZ());
                        dataList[i][19] = String.valueOf(aimPlaceInfos.get(i).getGyroPosScale());
                        dataList[i][20] = String.valueOf(aimPlaceInfos.get(i).getGyroPosAngle());
                        dataList[i][21] = String.valueOf(aimPlaceInfos.get(i).getGyroPosShowLenth());
                        dataList[i][22] = String.valueOf(aimPlaceInfos.get(i).getVuforiaImageInfoAreaMarking());
                        dataList[i][23] = String.valueOf(aimPlaceInfos.get(i).getRemark1());
                        dataList[i][24] = String.valueOf(aimPlaceInfos.get(i).getRemark2());
                        dataList[i][25] = String.valueOf(aimPlaceInfos.get(i).getRemark3());
                        dataList[i][26] = String.valueOf(aimPlaceInfos.get(i).getRemark4());
                        dataList[i][27] = String.valueOf(aimPlaceInfos.get(i).getRemark5());
                        dataList[i][28] = String.valueOf(aimPlaceInfos.get(i).getRemark6());
                        dataList[i][29] = String.valueOf(aimPlaceInfos.get(i).getMapIndex());
                        dataList[i][30] = String.valueOf(aimPlaceInfos.get(i).getPosX());
                        dataList[i][31] = String.valueOf(aimPlaceInfos.get(i).getPosY());
                        dataList[i][32] = String.valueOf(aimPlaceInfos.get(i).getPosZ());
                        dataList[i][33] = String.valueOf(aimPlaceInfos.get(i).getRemark7());
                        dataList[i][34] = String.valueOf(aimPlaceInfos.get(i).getRemark8());
                        dataList[i][35] = String.valueOf(aimPlaceInfos.get(i).getRemark9());
                        dataList[i][36] = String.valueOf(aimPlaceInfos.get(i).getFrontLevelId());
                        dataList[i][37] = String.valueOf(aimPlaceInfos.get(i).getIcon());
                        dataList[i][38] = String.valueOf(aimPlaceInfos.get(i).getIconRank());
                        dataList[i][39] = String.valueOf(aimPlaceInfos.get(i).getAloneFlag());
                        dataList[i][40] = String.valueOf(aimPlaceInfos.get(i).getAutoPlay());
                        dataList[i][41] = String.valueOf(aimPlaceInfos.get(i).getAutoDisplay());
                        dataList[i][42] = String.valueOf(aimPlaceInfos.get(i).getShowLevel());
                        dataList[i][43] = String.valueOf(aimPlaceInfos.get(i).getTemplateId());
                        dataList[i][44] = String.valueOf(aimPlaceInfos.get(i).getPower());
                        dataList[i][45] = String.valueOf(aimPlaceInfos.get(i).getAreaId());
                        dataList[i][46] = String.valueOf(aimPlaceInfos.get(i).getThingId());
                        dataList[i][47] = String.valueOf(aimPlaceInfos.get(i).getAimGroupId());
                        dataList[i][48] = String.valueOf(aimPlaceInfos.get(i).getTemplateAimId());
                    }


        ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName,
        columnNumber, columnWidth, columnName, dataList, response);


        }
    }

