|
@@ -0,0 +1,192 @@
|
|
|
+package cn.rankin.cmsweb.controller.stmt;
|
|
|
+
|
|
|
+import cn.rankin.cmsweb.assist.resolver.NeedUser;
|
|
|
+import cn.rankin.cmsweb.entity.UserDetails;
|
|
|
+import cn.rankin.cmsweb.service.product.ProductService;
|
|
|
+import cn.rankin.cmsweb.service.stmt.StmtCampusService;
|
|
|
+import cn.rankin.cmsweb.service.user.TerminalUserService;
|
|
|
+import cn.rankin.common.utils.api.model.APIResult;
|
|
|
+import cn.rankin.common.utils.api.page.Page;
|
|
|
+import cn.rankin.common.utils.util.BeanUtil;
|
|
|
+import cn.rankin.common.utils.util.ListUtil;
|
|
|
+import cn.rankin.common.utils.util.ProvinceUtil;
|
|
|
+import cn.rankin.data.api.product.vo.ProductVo;
|
|
|
+import cn.rankin.data.api.user.dto.CampusSearchDTO;
|
|
|
+import cn.rankin.data.api.user.dto.TerminalUserSearchDTO;
|
|
|
+import cn.rankin.data.api.user.vo.CampusVo;
|
|
|
+import cn.rankin.data.api.user.vo.TerminalUserAuthVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/stmt/terminal/user")
|
|
|
+public class StmtTerminalUserController
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private StmtCampusService StmtService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TerminalUserService terminalUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询已开通校区报表
|
|
|
+ *
|
|
|
+ * @param user the user info
|
|
|
+ * @param searchDTO the campus search
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = {"/page", "/"}, method = RequestMethod.GET)
|
|
|
+ public APIResult<Page<TerminalUserAuthVo>> campusList(@NeedUser UserDetails user, TerminalUserSearchDTO searchDTO)
|
|
|
+ {
|
|
|
+ if (!user.isPlatForm())
|
|
|
+ {
|
|
|
+ String merchantId = user.getMerchantId();
|
|
|
+ searchDTO.setMerchantId(merchantId);
|
|
|
+ }
|
|
|
+ Page<TerminalUserAuthVo> authVoPage = terminalUserService.findAuthList(BeanUtil.convertToMap(searchDTO));
|
|
|
+
|
|
|
+ List<TerminalUserAuthVo> terminalUserAuthVos = authVoPage.getList();
|
|
|
+ setProductInfo(terminalUserAuthVos);
|
|
|
+
|
|
|
+ return APIResult.ok(authVoPage);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询已开通校区报表
|
|
|
+ *
|
|
|
+ * @param user the user info
|
|
|
+ * @param campusSearchDTO the campus search
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = {"/export", "/"}, method = RequestMethod.GET)
|
|
|
+ public String exportCampus(HttpServletResponse res, @NeedUser UserDetails user, CampusSearchDTO campusSearchDTO)
|
|
|
+ {
|
|
|
+ if (!user.isPlatForm())
|
|
|
+ {
|
|
|
+ String merchantId = user.getMerchantId();
|
|
|
+ campusSearchDTO.setMerchantId(merchantId);
|
|
|
+ }
|
|
|
+ APIResult<List<CampusVo>> apiResult = StmtService.query(BeanUtil.convertToMap(campusSearchDTO));
|
|
|
+
|
|
|
+ List<CampusVo> list = apiResult.getData();
|
|
|
+ //创建HSSFWorkbook对象(excel的文档对象)
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+ //建立新的sheet对象(excel的表单)
|
|
|
+ HSSFSheet sheet = wb.createSheet("已开通校区报表");
|
|
|
+ //设置单元格宽度
|
|
|
+ sheet.setColumnWidth(0, 50 * 256);
|
|
|
+ sheet.setColumnWidth(1, 10 * 256);
|
|
|
+ sheet.setColumnWidth(2, 10 * 256);
|
|
|
+ sheet.setColumnWidth(3, 30 * 256);
|
|
|
+ sheet.setColumnWidth(4, 10 * 256);
|
|
|
+ sheet.setColumnWidth(5, 15 * 256);
|
|
|
+ sheet.setColumnWidth(6, 15 * 256);
|
|
|
+ //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
|
|
|
+ HSSFRow row1 = sheet.createRow(0);
|
|
|
+ //创建单元格并设置单元格内容
|
|
|
+ row1.createCell(0).setCellValue("校区名");
|
|
|
+ row1.createCell(1).setCellValue("客户类型");
|
|
|
+ row1.createCell(2).setCellValue("省");
|
|
|
+ row1.createCell(3).setCellValue("市");
|
|
|
+ row1.createCell(4).setCellValue("联系人");
|
|
|
+ row1.createCell(5).setCellValue("联系方式");
|
|
|
+ row1.createCell(6).setCellValue("创建日期");
|
|
|
+
|
|
|
+ //单元格日期格式
|
|
|
+ HSSFCellStyle cellStyle = wb.createCellStyle();
|
|
|
+ HSSFDataFormat format = wb.createDataFormat();
|
|
|
+ cellStyle.setDataFormat(format.getFormat("yyyy/mm/dd"));
|
|
|
+
|
|
|
+ //插入数据
|
|
|
+ if (list != null && list.size() > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < list.size(); i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ CampusVo vo = list.get(i);
|
|
|
+ String provinceCode = vo.getProvinceCode();
|
|
|
+ String provinceName = ProvinceUtil.get(provinceCode);
|
|
|
+ vo.setProvinceName(provinceName);
|
|
|
+
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);
|
|
|
+ row.createCell(0).setCellValue(vo.getName());
|
|
|
+ row.createCell(1).setCellValue(vo.getMerchantName());
|
|
|
+ row.createCell(2).setCellValue(vo.getProvinceName());
|
|
|
+ row.createCell(3).setCellValue(vo.getCityName());
|
|
|
+ row.createCell(4).setCellValue(vo.getContactName());
|
|
|
+ row.createCell(5).setCellValue(vo.getMobile());
|
|
|
+
|
|
|
+
|
|
|
+ HSSFCell cell = row.createCell(6);
|
|
|
+ cell.setCellValue(vo.getGmtCreated());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ long currentTime = new Date().getTime();
|
|
|
+ //输出Excel文件
|
|
|
+ OutputStream output = res.getOutputStream();
|
|
|
+ res.reset();
|
|
|
+ res.setHeader("Content-disposition", "attachment; filename=lingjiao_campus_" + currentTime + ".xls");
|
|
|
+ res.setContentType("application/msexcel");
|
|
|
+ wb.write(output);
|
|
|
+ output.close();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setProductInfo(List<TerminalUserAuthVo> terminalUserAuthVos)
|
|
|
+ {
|
|
|
+ if (CollectionUtils.isEmpty(terminalUserAuthVos))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ProductVo> productVos = productService.productList();
|
|
|
+ if (CollectionUtils.isEmpty(productVos))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, ProductVo> productVoMap = ListUtil.convert(productVos, "pid", ProductVo.class);
|
|
|
+
|
|
|
+ terminalUserAuthVos.forEach(vo ->
|
|
|
+ {
|
|
|
+ ProductVo productVo = productVoMap.get(vo.getPid());
|
|
|
+ if (null != productVo)
|
|
|
+ {
|
|
|
+ vo.setPCode(productVo.getCode());
|
|
|
+ vo.setPName(productVo.getName());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log.info("not found product by pid ,pid={}", vo.getPid());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|