package com.izouma.awesomeadmin.web; import com.izouma.awesomeadmin.constant.AppConstant; import com.izouma.awesomeadmin.dto.Page; import com.izouma.awesomeadmin.dto.Result; import com.izouma.awesomeadmin.model.*; import com.izouma.awesomeadmin.service.*; import com.izouma.awesomeadmin.util.ExportExcelUtil; import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * controller类 */ @Controller @RequestMapping("/data") public class DataController { @Autowired private ExhibitionContentService exhibitionContentService; @Autowired private BannerInfoService bannerInfoService; @Autowired private MenuInfoService menuInfoService; @Autowired private SubItemService subItemService; @Autowired private ImgInfoService imgInfoService; @Autowired private MemberInfoService memberInfoService; @Autowired private FileInfoService fileInfoService; @Autowired private FinancialDataService financialDataService; @Autowired private PinpaijuzhenService pinpaijuzhenService; @Autowired private PinpaimenmianService pinpaimenmianService; @Autowired private PlayInfoService playInfoService; @Autowired private EquipmentInfoService equipmentInfoService; @Autowired private ClickHistoryService clickHistoryService; /** *

获取全部记录。

*/ @RequiresAuthentication @RequestMapping(value = "/all", method = RequestMethod.GET) @ResponseBody public Result all(MenuInfo record) { List pp = menuInfoService.getMenuInfoList(record); return new Result(true, pp); } /** *

获取公示投教数据

*/ @RequiresAuthentication @RequestMapping(value = "/gongshitoujiao", method = RequestMethod.GET) @ResponseBody public Object getGongShiTouJiao(FindPara findPara) { Object x = checkUserStationId(findPara); if (x != null) return x; GongShiTouJiao gs = new GongShiTouJiao(); ExhibitionContent ec = new ExhibitionContent(); ec.setStationId(findPara.getStationId()); ec.setId(findPara.getExhibitionId()); ec = exhibitionContentService.getExhibitionContent(ec); gs.setVersion(ec.getVersion()); BannerInfo banner = new BannerInfo(); banner.setStationId(findPara.getStationId()); List banners = bannerInfoService.getBannerInfoList(banner); gs.setBanner(banners); MenuInfo menuinfo = new MenuInfo(); menuinfo.setStationInfo(findPara.getStationId()); List menus = menuInfoService.getMenuInfoList(menuinfo); for (MenuInfo m : menus) { if ("1".equals(m.getType())) { SubItem s = new SubItem(); s.setMenuInfoId(m.getId()); List items = subItemService.getSubItemList(s); m.setSubItem(items); } else if ("2".equals(m.getType())) { ImgInfo img = new ImgInfo(); img.setFatherId(m.getId()); img.setType(2); m.setImages(imgInfoService.getImgInfoList(img)); } else if ("3".equals(m.getType())) { MemberInfo member = new MemberInfo(); member.setStationId(findPara.getStationId()); m.setMembers(memberInfoService.getMemberInfoList(member)); } } gs.setMainMenu(menus); return gs; } /** *

金融大数据

*/ @RequiresAuthentication @RequestMapping(value = "/financialData", method = RequestMethod.GET) @ResponseBody public Object getFinancialData(FindPara findPara) { Object x = checkUserStationId(findPara); if (x != null) return x; ExhibitionContent ec = new ExhibitionContent(); ec.setStationId(findPara.getStationId()); ec.setId(findPara.getExhibitionId()); ec = exhibitionContentService.getExhibitionContent(ec); FinancialData f = new FinancialData(); f.setStationId(findPara.getStationId()); f.setTypeFlag(findPara.getTypeFlag()); FinancialData fd = financialDataService.getFinancialData(f); fd.setVersion(ec.getVersion()); return fd; } private Object checkUserStationId(FindPara findPara) { Subject subject = SecurityUtils.getSubject(); UserInfo userInfo = (UserInfo) subject.getPrincipal(); int userStationId; if (userInfo != null) { userStationId = Integer.parseInt(userInfo.getDepartId()); if (userStationId == 2) { } else { if (findPara.getStationId() == null) { findPara.setStationId(userStationId); } else if (findPara.getStationId() != userStationId) { return "营业厅ID与账号不符,Mismatch"; } } } else { return "请先登录,Not logged in"; } return null; } /** *

品牌矩阵

*/ @RequiresAuthentication @RequestMapping(value = "/pinpaijuzhen", method = RequestMethod.GET) @ResponseBody public Object getPinpaijuzhen(FindPara findPara) { Object x = checkUserStationId(findPara); if (x != null) return x; ExhibitionContent ec = new ExhibitionContent(); ec.setStationId(findPara.getStationId()); ec.setId(findPara.getExhibitionId()); ec = exhibitionContentService.getExhibitionContent(ec); Pinpaijuzhen out = new Pinpaijuzhen(); out.setStationId(findPara.getStationId()); out = pinpaijuzhenService.getPinpaijuzhen(out); out.setVersion(ec.getVersion()); PlayInfo pi = new PlayInfo(); pi.setFatherId(out.getId() + ""); pi.setType(0); List pis = playInfoService.getPlayInfoList(pi); out.setPlaylist(pis); return out; } /** *

品牌门面

*/ @RequiresAuthentication @RequestMapping(value = "/pinpaimenmian", method = RequestMethod.GET) @ResponseBody public Object getPinpaimenmian(FindPara findPara) { Object x = checkUserStationId(findPara); if (x != null) return x; ExhibitionContent ec = new ExhibitionContent(); ec.setStationId(findPara.getStationId()); ec.setId(findPara.getExhibitionId()); ec = exhibitionContentService.getExhibitionContent(ec); Pinpaimenmian out = new Pinpaimenmian(); out.setStationId(findPara.getStationId()); out = pinpaimenmianService.getPinpaimenmian(out); out.setVersion(ec.getVersion()); PlayInfo pi = new PlayInfo(); pi.setFatherId(out.getId() + ""); pi.setType(1); List pis = playInfoService.getPlayInfoList(pi); out.setPlaylist_tm(pis); pi.setType(2); out.setPlaylist_b(playInfoService.getPlayInfoList(pi)); return out; } /** * 获取展项信息 * 20181225添加 * * @param findPara stationId exhibitionName * @return */ @RequiresAuthentication @RequestMapping(value = "/exhibitionInfo", method = RequestMethod.GET) @ResponseBody public Object getExhibitionInfo(FindPara findPara) { if (StringUtils.isNotEmpty(findPara.getExhibitionName())) { ExhibitionContent exhibitionContent = new ExhibitionContent(); exhibitionContent.setStationId(findPara.getStationId()); exhibitionContent.setName(findPara.getExhibitionName()); exhibitionContent = exhibitionContentService.getExhibitionContent(exhibitionContent); if (exhibitionContent != null) { findPara.setExhibitionId(exhibitionContent.getId()); if ("公示投教".equals(findPara.getExhibitionName())) { return getGongShiTouJiao(findPara); } else if ("金融大数据".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(0); return getFinancialData(findPara); } else if ("安全管家".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(1); return getFinancialData(findPara); } else if ("超级账户".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(2); return getFinancialData(findPara); } else if ("全景行情".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(3); return getFinancialData(findPara); } else if ("严选理财".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(4); return getFinancialData(findPara); } else if ("涨乐u会员".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(5); return getFinancialData(findPara); } else if ("智能家族".equals(findPara.getExhibitionName())) { findPara.setTypeFlag(6); return getFinancialData(findPara); } else if ("品牌矩阵".equals(findPara.getExhibitionName())) { return getPinpaijuzhen(findPara); } else if ("品牌门面".equals(findPara.getExhibitionName())) { return getPinpaimenmian(findPara); } } } return "展项名称不匹配,No data"; } /** *

修改设备状态

*/ @RequestMapping(value = "/editStatus", method = RequestMethod.POST) @ResponseBody public Object editStatus(EquipmentInfo equipmentInfo) { Subject subject = SecurityUtils.getSubject(); UserInfo userInfo = (UserInfo) subject.getPrincipal(); int userStationId; if (userInfo != null) { userStationId = Integer.parseInt(userInfo.getDepartId()); if (userStationId == 2) { } else { if (equipmentInfo.getStationId() == null) { equipmentInfo.setStationId(userStationId); } else if (equipmentInfo.getStationId() != userStationId) { return "营业厅ID与账号不符,Mismatch"; } } } else { return "请先登录,Not logged in"; } EquipmentInfo ei = new EquipmentInfo(); ei.setStationId(equipmentInfo.getStationId()); ei.setExhibitionId(equipmentInfo.getExhibitionId()); ei = equipmentInfoService.getEquipmentInfo(ei); ei.setStatus(equipmentInfo.getStatus()); if (equipmentInfoService.updateEquipmentInfo(ei)) { return new Result(true, ei); } else { return new Result(false, ei); } } /** *

记录点击历史

*/ @RequestMapping(value = "/addClickHistory", method = RequestMethod.POST) @ResponseBody public Object addClickHistory(ClickHistory clickHistory) { Subject subject = SecurityUtils.getSubject(); UserInfo userInfo = (UserInfo) subject.getPrincipal(); int userStationId; if (userInfo != null) { userStationId = Integer.parseInt(userInfo.getDepartId()); if (userStationId == 2) { } else { if (clickHistory.getStationId() == null) { clickHistory.setStationId(userStationId); } else if (clickHistory.getStationId() != userStationId) { return "营业厅ID与账号不符,Mismatch"; } } } else { return "请先登录,Not logged in"; } if (clickHistoryService.createClickHistory(clickHistory)) { return new Result(true, clickHistory); } else { return new Result(false, "添加错误"); } } /** *

根据Id。

*/ @RequestMapping(value = "/getMenuInfo", method = RequestMethod.GET) @ResponseBody public Result getMenuInfo(@RequestParam(required = false, value = "id") String id) { MenuInfo data = menuInfoService.getMenuInfoById(id); return new Result(true, data); } /** *

根据条件获取。

*/ @RequestMapping(value = "/getOne", method = RequestMethod.GET) @ResponseBody public Result getOne(MenuInfo record) { MenuInfo data = menuInfoService.getMenuInfo(record); return new Result(true, data); } /** *

分页查询。

*/ @RequestMapping(value = "/page", method = RequestMethod.GET) @ResponseBody public Result page(Page page, MenuInfo record) { Map result = new HashMap<>(); List pp = menuInfoService.getMenuInfoByPage(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(MenuInfo record) { boolean num = menuInfoService.createMenuInfo(record); if (num) { ImgInfo img = new ImgInfo(); img.setFatherId(record.getId()); img.setType(0); img.setUrl(record.getImgUrl()); imgInfoService.createImgInfo(img); return new Result(true, record.getId()); } return new Result(false, "保存异常"); } /** *

更新信息。

*/ @RequestMapping(value = "/update", method = RequestMethod.POST) @ResponseBody public Result updateMenuInfo(MenuInfo record) { boolean num = menuInfoService.updateMenuInfo(record); if (num) { ImgInfo img = new ImgInfo(); img.setFatherId(record.getId()); img.setType(0); img.setUrl(record.getImgUrl()); imgInfoService.createImgInfo(img); return new Result(true, "保存成功"); } return new Result(false, "保存异常"); } /** *

删除。

*/ @RequestMapping(value = "/del", method = RequestMethod.POST) @ResponseBody public Result deleteMenuInfo(MenuInfo record) { boolean num = menuInfoService.deleteMenuInfo(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, MenuInfo record) throws Exception { List menuInfos = menuInfoService.getMenuInfoList(record); String sheetName = "menu_info"; String titleName = "栏目管理数据表"; String fileName = "栏目管理表"; int columnNumber = 10; int[] columnWidth = {20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; String[] columnName = {"", "删除标识", "更新时间", "更新人", "创建时间", "创建人", "栏目名称", "公司介绍", "栏目类型", "营业厅ID"}; String[][] dataList = new String[menuInfos.size()][10]; for (int i = 0; i < menuInfos.size(); i++) { dataList[i][0] = String.valueOf(menuInfos.get(i).getId()); dataList[i][1] = String.valueOf(menuInfos.get(i).getDelFlag()); dataList[i][2] = String.valueOf(menuInfos.get(i).getUpdateTime()); dataList[i][3] = String.valueOf(menuInfos.get(i).getUpdateUser()); dataList[i][4] = String.valueOf(menuInfos.get(i).getCreateTime()); dataList[i][5] = String.valueOf(menuInfos.get(i).getCreateUser()); dataList[i][6] = String.valueOf(menuInfos.get(i).getMenuName()); dataList[i][7] = String.valueOf(menuInfos.get(i).getAbstractInfo()); dataList[i][8] = String.valueOf(menuInfos.get(i).getType()); dataList[i][9] = String.valueOf(menuInfos.get(i).getStationInfo()); } ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName, columnNumber, columnWidth, columnName, dataList, response); } }