|
@@ -0,0 +1,237 @@
|
|
|
+package com.ssj.agent.controller;
|
|
|
+
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
+import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
+import com.ssj.agent.dao.AgentEntity;
|
|
|
+import com.ssj.agent.service.IAgentService;
|
|
|
+import com.ssj.bean.common.framework.core.domain.Response;
|
|
|
+import com.ssj.bean.sys.organization.domain.Organization;
|
|
|
+import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
|
|
|
+import com.ssj.framework.basic.common.bean.SplitPage;
|
|
|
+import com.ssj.framework.core.common.controller.BaseController;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+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.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author sh
|
|
|
+ * @className AgentController
|
|
|
+ * @description 代理
|
|
|
+ * @date 2021/1/15
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping("sys/agent")
|
|
|
+public class AgentController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAgentService agentService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 栏目主页面
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/main")
|
|
|
+ public String main() {
|
|
|
+ return "sys/agent/main";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/mainTree")
|
|
|
+ @ResponseBody
|
|
|
+ public List<AgentEntity> mainTree(@RequestParam(required = false, value = "id") String pId) throws Exception {
|
|
|
+ if(pId ==null) {
|
|
|
+ pId="-1";
|
|
|
+ }
|
|
|
+ return agentService.findByPid(pId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @RequestMapping("/list")
|
|
|
+ public String list(Model model, @RequestParam(required = false, defaultValue = "-1") String EQ_pId,
|
|
|
+ @RequestParam(required = false, defaultValue = "10") int pageSize,
|
|
|
+ @RequestParam(required = false, defaultValue = "1") int pageNo) {
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ params.put("EQ_upId", EQ_pId);
|
|
|
+ params.put("LIKE_agentName",request.getParameter("LIKE_agentName")==null?"":request.getParameter("LIKE_agentName"));
|
|
|
+ Page<AgentEntity> page= agentService.findByPage(params, initPage(pageNo,pageSize, Sort.Direction.DESC, new String[] { "createTime" }));
|
|
|
+ SplitPage sp = initPage(pageNo,pageSize,params,(int) page.getTotalElements());
|
|
|
+ model.addAttribute("list", page.getContent());
|
|
|
+ model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
|
|
|
+ model.addAttribute("page", sp);
|
|
|
+ model.addAttribute("search", params);
|
|
|
+ return "sys/agent/list";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/edit")
|
|
|
+ public String edit(Model model, String id, String pId) throws Exception {
|
|
|
+ AgentEntity agent = agentService.getById(id);
|
|
|
+ if(agent ==null){
|
|
|
+ agent = new AgentEntity();
|
|
|
+ agent.setUpId(pId);
|
|
|
+ }
|
|
|
+ model.addAttribute("org", agent);
|
|
|
+ return "sys/agent/edit";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public Response save(AgentEntity org){
|
|
|
+ Response response = new Response();
|
|
|
+ Boolean isAdd = org.getId()==null?true:false;
|
|
|
+ if(isAdd){
|
|
|
+ //检查code是否重复 设置唯一索引
|
|
|
+ int count = agentService.findByCode(org.getCode());
|
|
|
+ if(count>0){
|
|
|
+ return response.failure(org.getCode()+"此编码已经存在,请更换重新添加!");
|
|
|
+ }
|
|
|
+ org.setCreateTime(new Date());
|
|
|
+ org.setSubCount(0);
|
|
|
+ }
|
|
|
+ org.setUpdateTime(new Date());
|
|
|
+ org.setLever(agentService.getById(org.getUpId()).getLever()+1);
|
|
|
+ org.setStatus(1);
|
|
|
+ org=agentService.save(org);
|
|
|
+ agentService.changeSubCount(org.getUpId(), true);
|
|
|
+
|
|
|
+ response.success(org);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public Response delete(String id,String pId){
|
|
|
+ Response response = new Response();
|
|
|
+ AgentEntity agent = agentService.getById(id);
|
|
|
+ agent.setStatus(2);
|
|
|
+ agent.setUpdateTime(new Date());
|
|
|
+ agentService.save(agent);
|
|
|
+ agentService.changeSubCount(pId, false);
|
|
|
+ response.success();
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/agentList")
|
|
|
+ @ResponseBody
|
|
|
+ public Response agentList(Model model,String name,Integer pageNo,Integer pageSize) {
|
|
|
+ Response response = new Response();
|
|
|
+ Map<String,Object> data=new HashMap<>();
|
|
|
+ if(pageNo==null) {
|
|
|
+ pageNo=1;
|
|
|
+ }
|
|
|
+ Long countNum=agentService.countByLikeName(name);
|
|
|
+ List<AgentEntity> jsonList =agentService.findByLikeName(name,pageNo,pageSize);
|
|
|
+ data.put("jsonList", jsonList);
|
|
|
+ data.put("pageNo", pageNo);
|
|
|
+ data.put("countNum", countNum);
|
|
|
+ data.put("countPage", Math.ceil((double)countNum/(double)pageSize));
|
|
|
+ response.success(data, "成功");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/agentMonthList")
|
|
|
+ public String agentMonthList(Model model,@RequestParam(required = false, defaultValue = "10") int pageSize,
|
|
|
+ @RequestParam(required = false, defaultValue = "1") int pageNo){
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ params.put("beginDate",request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
|
|
|
+ params.put("endDate",request.getParameter("endDate")==null?"":request.getParameter("endDate"));
|
|
|
+
|
|
|
+ Page<Map<String,Object>> page= agentService.agentMonthList(params, initPage(pageNo,pageSize));
|
|
|
+ SplitPage sp = initPage(pageNo,pageSize,params,(int) page.getTotalElements());
|
|
|
+ model.addAttribute("list", page.getContent());
|
|
|
+ model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
|
|
|
+ model.addAttribute("page", sp);
|
|
|
+ model.addAttribute("search", params);
|
|
|
+ return "sys/agent/monthList";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exportExcel", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public void exportExcel(){
|
|
|
+ ServletOutputStream os = null;
|
|
|
+ try {
|
|
|
+ String libName="销售订单数据";
|
|
|
+ //获得输出流
|
|
|
+ os = response.getOutputStream();
|
|
|
+ //清空输出流
|
|
|
+ response.reset();
|
|
|
+ exportExcelHead(response,libName);
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ params.put("beginDate",request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
|
|
|
+ params.put("endDate",request.getParameter("endDate")==null?"":request.getParameter("endDate"));
|
|
|
+ Page<Map<String,Object>> page= agentService.agentMonthList(params, initPage(1,10000));
|
|
|
+ List<Map<String,Object>> list = page.getContent();
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ dataList.addAll(list);
|
|
|
+ String exportHead = "学校|league_name;人数|lib_service;年份|year;个人|agentMoney;管理|managerMoney;培训|trainMoney";
|
|
|
+ List<ExcelExportEntity> entity = addEntity(exportHead);
|
|
|
+ //把我们构造好的bean对象放到params就可以了
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
|
|
|
+ dataList);
|
|
|
+ workbook.write(os);
|
|
|
+ }catch (IOException e) {
|
|
|
+ logger.error("异常", e);
|
|
|
+ }catch (Exception e1){
|
|
|
+ logger.error("异常", e1);
|
|
|
+ }finally{
|
|
|
+ if(os != null){
|
|
|
+ try {
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ExcelExportEntity> addEntity(String exportHead){
|
|
|
+ List<ExcelExportEntity> entity = new ArrayList<>();
|
|
|
+ String[] headArr = exportHead.split(";");
|
|
|
+ for (String str:headArr){
|
|
|
+ int index = str.indexOf("|");
|
|
|
+ entity.add(new ExcelExportEntity(str.substring(0,index), str.substring(index+1)));
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportExcelHead(HttpServletResponse response,String fileName) throws Exception{
|
|
|
+ String lastFileName = new String(fileName.getBytes("gb2312"), "ISO8859-1") +".xlsx";
|
|
|
+ //设定输出文件头
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename="+ lastFileName);
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ }
|
|
|
+
|
|
|
+ private SplitPage initPage(int pageNo,int pageSize,Map<String, Object> params,int rowCnt){
|
|
|
+ SplitPage sp = new SplitPage();
|
|
|
+ sp.setAction(request.getRequestURI());
|
|
|
+ sp.setPageNo(pageNo);
|
|
|
+ sp.setPageSize(pageSize);
|
|
|
+ sp.setParams(params);
|
|
|
+ sp.setRowCnt(rowCnt);
|
|
|
+ return sp;
|
|
|
+ }
|
|
|
+}
|