//package com.fdage.controller;
//
//import com.alibaba.fastjson.JSONObject;
//import com.fdage.aop.WebControllerLog;
//import com.fdage.constant.ConstantUrl;
//import com.fdage.enums.ResponEnum;
//import com.fdage.pojo.TbInformation;
//import com.fdage.request.RequestInformation;
//import com.fdage.respon.ResponInformation;
//import com.fdage.service.IInformationService;
//import com.fdage.util.AjaxJson;
//import com.fdage.util.DateUtil;
//import com.fdage.util.FileUtil;
//import com.github.pagehelper.PageInfo;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.util.List;
//
///**
// * Created by Hb_zzZ on 2019/9/11.
// */
//@Controller
//@RequestMapping("/zhoushan/information")
//@Slf4j
//@Api(tags = "轮播管理模块")
//public class InformationController {
//
//    @Autowired
//    private IInformationService service;
//
//    @Value("${upload.information}")
//    private String uploadPath;
//
//    @PostMapping("addInformation")
//    @ResponseBody
//    @WebControllerLog(description = "轮播管理-新增")
//    @ApiOperation("新增")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "name", value = "资讯名称", dataType = "String"),
//            @ApiImplicitParam(name = "type", value = "资讯类型", dataType = "String"),
//            @ApiImplicitParam(name = "contentUrl", value = "轮播内容，视频为url,图片类型为json", dataType = "String"),
//            @ApiImplicitParam(name = "contentNum", value = "轮播板式", dataType = "String"),
//            @ApiImplicitParam(name = "description", value = "资讯说明", dataType = "String"),
//            @ApiImplicitParam(name = "orderNum", value = "展示顺序编码", dataType = "String"),
//            @ApiImplicitParam(name = "startTime", value = "轮播开始时间", dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "轮播结束时间", dataType = "String"),
//            @ApiImplicitParam(name = "state", value = "状态,0：启用，1：禁用", dataType = "String")})
//    public AjaxJson addInformation(@RequestBody RequestInformation bo){
//        if(bo == null || StringUtils.isEmpty(bo.getName()) ||
//                bo.getType() == null  || StringUtils.isEmpty(bo.getContentUrl())){
//            return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
//        }
//
//        TbInformation information = new TbInformation();
//        BeanUtils.copyProperties(bo, information);
//        service.insert(information);
//        //发送sse消息
//        SseController.send("data:" + "1\r\n");
//        return AjaxJson.success();
//    }
//
//    @PostMapping("updateInformation")
//    @ResponseBody
//    @WebControllerLog(description = "轮播管理-修改")
//    @ApiOperation("修改")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "id", dataType = "String"),
//            @ApiImplicitParam(name = "name", value = "资讯名称", dataType = "String"),
//            @ApiImplicitParam(name = "type", value = "资讯类型", dataType = "String"),
//            @ApiImplicitParam(name = "contentUrl", value = "轮播内容，视频为url,图片类型为json", dataType = "String"),
//            @ApiImplicitParam(name = "contentNum", value = "轮播板式", dataType = "String"),
//            @ApiImplicitParam(name = "description", value = "资讯说明", dataType = "String"),
//            @ApiImplicitParam(name = "orderNum", value = "展示顺序编码", dataType = "String"),
//            @ApiImplicitParam(name = "startTime", value = "轮播开始时间", dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "轮播结束时间", dataType = "String"),
//            @ApiImplicitParam(name = "state", value = "状态,0：启用，1：禁用", dataType = "String")})
//    public AjaxJson updateInformation(@RequestBody RequestInformation bo){
//        if(bo == null || StringUtils.isEmpty(bo.getName()) ||
//                bo.getType() == null  || StringUtils.isEmpty(bo.getContentUrl())){
//            return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
//        }
//
//        TbInformation information = new TbInformation();
//        BeanUtils.copyProperties(bo, information);
//        service.update(information);
//
//        //发送sse消息
//        SseController.send("data:" + "1\r\n");
//        return AjaxJson.success();
//    }
//
//    @PostMapping("deleteInformation")
//    @ResponseBody
//    @WebControllerLog(description = "轮播管理-删除")
//    @ApiOperation("删除")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "id", dataType = "String")})
//    public AjaxJson deleteInformation(@RequestBody RequestInformation bo){
//        if(bo == null || bo.getId() == null ){
//            return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
//        }
//        service.delete(bo.getId());
//
//        //发送sse消息
//        SseController.send("data:" + "1\r\n");
//        return AjaxJson.success();
//    }
//
//    @PostMapping("list")
//    @ResponseBody
//    @WebControllerLog(description = "轮播管理-列表")
//    @ApiOperation("列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "type", value = "资讯类型，0表示海报，1表示视频", dataType = "String"),
//            @ApiImplicitParam(name = "name", value = "资讯名称", dataType = "String"),
//            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
//            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "String")})
//    public AjaxJson list(@RequestBody RequestInformation bo){
//        List<ResponInformation> list = service.findList(bo);
//        for(ResponInformation information : list){
//            if(StringUtils.isNotEmpty(information.getStartTime())){
//                information.setStartTime(String.valueOf(DateUtil.convert2CST(information.getStartTime())));
//            }
//            if(StringUtils.isNotEmpty(information.getEndTime())){
//                information.setEndTime(String.valueOf(DateUtil.convert2CST(information.getEndTime())));
//            }
//            if(StringUtils.isNotEmpty(information.getCreateTime())){
//                information.setCreateTime(String.valueOf(DateUtil.convert2CST(information.getCreateTime())));
//            }
//        }
//        PageInfo<ResponInformation> pageInfo = new PageInfo<>(list);
//        return AjaxJson.success(pageInfo);
//    }
//
//    @PostMapping("listAll")
//    @ResponseBody
//    @ApiOperation("所有资讯")
//    public AjaxJson listAll(){
//        return AjaxJson.success(service.listAll());
//    }
//
//    @PostMapping("/upload")
//    @ResponseBody
//    @ApiOperation("上传资讯图片")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "file", value = "文件流", dataType = "String")})
//    public AjaxJson upload(@RequestParam(value = "filename", defaultValue = "") String name, @RequestParam("file") MultipartFile file){
//        if(file == null){
//            return AjaxJson.failure("参数不能为空");
//        }
//        String fileName = System.currentTimeMillis() + "_";
//        if(StringUtils.isNotEmpty(name)){
//            fileName = fileName + name;
//        }else {
//            fileName = fileName + file.getOriginalFilename();
//        }
//        log.info("图片地址：" + fileName);
//        boolean flag = FileUtil.upload(file, uploadPath, fileName);
//
//        if(!flag){
//            return AjaxJson.failure("上传图片失败");
//        }
//
////        Map<String, String> map = new HashMap<>();
////        map.put(path + "/" + fileName, "company/" + fileName);
////        uploadToAlibabaService.upload(map);
//
//        return AjaxJson.success((Object) ("/information/" + fileName));
//    }
//}
