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.AimPlaceContent;
import com.izouma.awesomeadmin.service.AimPlaceContentService;

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

/**
*  controller类
*/
@Controller
@RequestMapping("/aimPlaceContent")
public class AimPlaceContentController {

    @Autowired
    private AimPlaceContentService aimPlaceContentService;

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

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

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


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

        List<AimPlaceContent> pp =aimPlaceContentService.getAimPlaceContentByPage(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(AimPlaceContent record) {
        boolean num = aimPlaceContentService.createAimPlaceContent(record);
        if (num) {
        return new Result(true, record.getId());
        }
        return new Result(false, "保存异常");
    }

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

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

        boolean num = aimPlaceContentService.deleteAimPlaceContent(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, AimPlaceContent record) throws Exception {

    List<AimPlaceContent> aimPlaceContents = aimPlaceContentService.getAimPlaceContentList(record);


        String sheetName = "aim_place_content";
        String titleName = "目标点-内容数据表";
        String fileName = "目标点-内容表";
        int columnNumber = 29;
        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 };
        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绑定识别图区域标记编号" ,   "备注1" ,   "备注2" ,   "备注3" ,   "备注4" ,   "备注5" ,   "备注6"  };
        String[][] dataList = new String[aimPlaceContents.size()][29];

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

                        dataList[i][0] = String.valueOf(aimPlaceContents.get(i).getId());
                        dataList[i][1] = String.valueOf(aimPlaceContents.get(i).getDelFlag());
                        dataList[i][2] = String.valueOf(aimPlaceContents.get(i).getUpdateTime());
                        dataList[i][3] = String.valueOf(aimPlaceContents.get(i).getUpdateUser());
                        dataList[i][4] = String.valueOf(aimPlaceContents.get(i).getCreateTime());
                        dataList[i][5] = String.valueOf(aimPlaceContents.get(i).getCreateUser());
                        dataList[i][6] = String.valueOf(aimPlaceContents.get(i).getName());
                        dataList[i][7] = String.valueOf(aimPlaceContents.get(i).getType());
                        dataList[i][8] = String.valueOf(aimPlaceContents.get(i).getOwnedLandMarkId());
                        dataList[i][9] = String.valueOf(aimPlaceContents.get(i).getArContentGroupId());
                        dataList[i][10] = String.valueOf(aimPlaceContents.get(i).getArKitPosX());
                        dataList[i][11] = String.valueOf(aimPlaceContents.get(i).getArKitPosY());
                        dataList[i][12] = String.valueOf(aimPlaceContents.get(i).getArKitPosZ());
                        dataList[i][13] = String.valueOf(aimPlaceContents.get(i).getArKitScale());
                        dataList[i][14] = String.valueOf(aimPlaceContents.get(i).getArKitAngle());
                        dataList[i][15] = String.valueOf(aimPlaceContents.get(i).getArKitShowLenth());
                        dataList[i][16] = String.valueOf(aimPlaceContents.get(i).getGyroPosX());
                        dataList[i][17] = String.valueOf(aimPlaceContents.get(i).getGyroPosY());
                        dataList[i][18] = String.valueOf(aimPlaceContents.get(i).getGyroPosZ());
                        dataList[i][19] = String.valueOf(aimPlaceContents.get(i).getGyroPosScale());
                        dataList[i][20] = String.valueOf(aimPlaceContents.get(i).getGyroPosAngle());
                        dataList[i][21] = String.valueOf(aimPlaceContents.get(i).getGyroPosShowLenth());
                        dataList[i][22] = String.valueOf(aimPlaceContents.get(i).getVuforiaImageInfoAreaMarking());
                        dataList[i][23] = String.valueOf(aimPlaceContents.get(i).getRemark1());
                        dataList[i][24] = String.valueOf(aimPlaceContents.get(i).getRemark2());
                        dataList[i][25] = String.valueOf(aimPlaceContents.get(i).getRemark3());
                        dataList[i][26] = String.valueOf(aimPlaceContents.get(i).getRemark4());
                        dataList[i][27] = String.valueOf(aimPlaceContents.get(i).getRemark5());
                        dataList[i][28] = String.valueOf(aimPlaceContents.get(i).getRemark6());
                    }


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


        }
    }

