| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.TCrmSalespersonDTO; |
| | | import com.ruoyi.system.model.TCrmBranch; |
| | | import com.ruoyi.system.model.TCrmChangePoints; |
| | | import com.ruoyi.system.model.TCrmSalesperson; |
| | | import com.ruoyi.system.export.TCrmSalespersonExport; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.TCrmSalespersonQuery; |
| | | import com.ruoyi.system.query.TErpGoodsQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCrmBranchService; |
| | | import com.ruoyi.system.service.TCrmChangePointsService; |
| | | import com.ruoyi.system.service.TCrmSalespersonService; |
| | | import com.ruoyi.system.vo.TCrmSalespersonVO; |
| | | import com.ruoyi.system.vo.TErpGoodsVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | |
| | | crmChangePointsService.save(changePoints); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Log(title = "crm业务员管理信息-crm业务员管理信息导出", businessType = BusinessType.EXPORT) |
| | | @ApiOperation(value = "crm业务员管理信息导出") |
| | | @PostMapping("/export") |
| | | public void listExport(@RequestBody TCrmSalespersonQuery query) |
| | | { |
| | | Long userId = tokenService.getLoginUser().getUser().getUserId(); |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | if(roleType == 2){ |
| | | // 查询分公司信息 |
| | | TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) |
| | | .eq(TCrmBranch::getUserId, userId) |
| | | .last("LIMIT 1")); |
| | | query.setBranchId(crmBranch.getId()); |
| | | } |
| | | List<TCrmSalespersonExport> crmSalespersonExports = crmSalespersonService.listExport(query); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmSalespersonExport.class, crmSalespersonExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | assert response != null; |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("业务员管理信息.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |