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.ChannelInfo; import com.izouma.awesomeadmin.service.ChannelInfoService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller @RequestMapping("/channelInfo") public class ChannelInfoController { /*generatedStart*/ @Autowired private ChannelInfoService channelInfoService; /*generatedEnd*/ /*generatedStart*/ @RequiresAuthentication @RequestMapping(value = "/all", method = RequestMethod.GET) @ResponseBody public Result all(ChannelInfo record) { List pp = channelInfoService.getChannelInfoList(record); return new Result(true, pp); } @RequestMapping(value = "/getChannelInfo", method = RequestMethod.GET) @ResponseBody public Result getChannelInfo(@RequestParam(required = false, value = "id") String id) { ChannelInfo data = channelInfoService.getChannelInfoById(id); return new Result(true, data); } @RequestMapping(value = "/getOne", method = RequestMethod.GET) @ResponseBody public Result getOne(ChannelInfo record) { ChannelInfo data = channelInfoService.getChannelInfo(record); return new Result(true, data); } @RequestMapping(value = "/page", method = RequestMethod.GET) @ResponseBody public Result page(Page page, ChannelInfo record) { Map result = new HashMap<>(); List pp =channelInfoService.getChannelInfoByPage(page, record); result.put(AppConstant.PAGE, page); result.put("pp", pp); return new Result(true, result); } @RequestMapping(value = "/save", method = RequestMethod.POST) @ResponseBody public Result save(ChannelInfo record) { boolean num = channelInfoService.createChannelInfo(record); if (num) { return new Result(true, record.getId()); } return new Result(false, "保存异常"); } @RequestMapping(value = "/update", method = RequestMethod.POST) @ResponseBody public Result updateChannelInfo(ChannelInfo record) { boolean num = channelInfoService.updateChannelInfo(record); if (num) { return new Result(true, "保存成功"); } return new Result(false, "保存异常"); } @RequestMapping(value = "/del", method = RequestMethod.POST) @ResponseBody public Result deleteChannelInfo(ChannelInfo record) { boolean num = channelInfoService.deleteChannelInfo(record); if (num) { return new Result(true, "删除成功"); } return new Result(false, "删除异常"); } @RequestMapping(value = "/exportExcel", method = RequestMethod.GET) @ResponseBody public void exportExcel(HttpServletRequest request, HttpServletResponse response, ChannelInfo record) throws Exception { List channelInfos = channelInfoService.getChannelInfoList(record); String sheetName = "channel_info"; String titleName = "渠道信息数据表"; String fileName = "渠道信息表"; int columnNumber = 12; int[] columnWidth = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; String[] columnName = { "ID" , "删除标识" , "更新时间" , "更新人" , "创建时间" , "创建人" , "名称" , "版本号" , "地址" , "备注" , "比率" , "二级比率" }; String[][] dataList = new String[channelInfos.size()][12]; for (int i = 0; i < channelInfos.size(); i++) { dataList[i][0] = String.valueOf(channelInfos.get(i).getId()); dataList[i][1] = String.valueOf(channelInfos.get(i).getDelFlag()); dataList[i][2] = String.valueOf(channelInfos.get(i).getUpdateTime()); dataList[i][3] = String.valueOf(channelInfos.get(i).getUpdateUser()); dataList[i][4] = String.valueOf(channelInfos.get(i).getCreateTime()); dataList[i][5] = String.valueOf(channelInfos.get(i).getCreateUser()); dataList[i][6] = String.valueOf(channelInfos.get(i).getName()); dataList[i][7] = String.valueOf(channelInfos.get(i).getVersionNo()); dataList[i][8] = String.valueOf(channelInfos.get(i).getUrl()); dataList[i][9] = String.valueOf(channelInfos.get(i).getRemark()); dataList[i][10] = String.valueOf(channelInfos.get(i).getRatio()); dataList[i][11] = String.valueOf(channelInfos.get(i).getRatio2()); } ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName, columnNumber, columnWidth, columnName, dataList, response); } /*generatedEnd*/ }