| | |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import cn.hutool.core.io.resource.ClassPathResource; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.xiaopeng.api.model.account.SysUser; |
| | |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.log.annotation.Log; |
| | | import com.xiaopeng.common.log.enums.BusinessType; |
| | | import com.xiaopeng.operation.dto.InvitationAddDto; |
| | | import com.xiaopeng.operation.exportExcle.XpInvitationCodeExportExcel; |
| | | import com.xiaopeng.operation.exportExcle.XpWhitelistExportExcel; |
| | | import com.xiaopeng.operation.importExcel.InvitationCodeImportExcel; |
| | |
| | | import com.xiaopeng.operation.service.IXpWhitelistService; |
| | | import io.swagger.annotations.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | |
| | | @RestController |
| | | @Api(tags = "邀请码管理") |
| | | @Slf4j |
| | | @RequestMapping("/api/v1/invitation") |
| | | @RequestMapping("") |
| | | public class XpInvitationCodeController { |
| | | @Resource |
| | | private IXpInvitationCodeService xpInvitationCodeService; |
| | |
| | | private IXpWhitelistService xpWhitelistService; |
| | | |
| | | @ApiOperation(value = "邀请码管理分页列表",response = XpInvitationCode.class) |
| | | @PostMapping("/pageList") |
| | | @PostMapping("/api/v1/invitation/pageList") |
| | | public R<PageInfo<XpInvitationCode>> pageList(@RequestBody InvitationPageListQuery query) { |
| | | PageInfo<XpInvitationCode> pageList = xpInvitationCodeService.pageList(query); |
| | | return R.ok(pageList); |
| | |
| | | /** |
| | | * 生成邀请码 |
| | | */ |
| | | @PutMapping("/add") |
| | | @PostMapping("/api/v1/invitation/add") |
| | | @ResponseBody |
| | | @ApiOperation(value = "生成邀请码") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "手机号 多个逗号隔开", name = "phones", dataType = "String", required = true) |
| | | }) |
| | | @Transactional |
| | | public R add(@RequestParam("phones") String phones){ |
| | | return xpInvitationCodeService.add(phones); |
| | | public R add(@RequestBody InvitationAddDto dto){ |
| | | return xpInvitationCodeService.add(dto.getPhones()); |
| | | } |
| | | /** |
| | | * 解绑 |
| | | */ |
| | | @PutMapping("/unbind") |
| | | @PutMapping("/api/v1/invitation/unbind") |
| | | @ResponseBody |
| | | @ApiOperation(value = "解绑") |
| | | @ApiImplicitParams({ |
| | |
| | | xpInvitationCodeService.update(xpInvitationCodeUpdateWrapper); |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "点位导入模板下载") |
| | | @GetMapping("/import-template") |
| | | @ApiOperation(value = "邀请码导入模板下载") |
| | | @GetMapping("/api/v1/invitation/import-template") |
| | | public void importTemplate() { |
| | | List<InvitationCodeImportExcel> invitationCodeImportExcels = new ArrayList<>(); |
| | | InvitationCodeImportExcel invitationCodeImportExcel = new InvitationCodeImportExcel(); |
| | |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), InvitationCodeImportExcel.class, invitationCodeImportExcels); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | ServletOutputStream outputStream = null; |
| | | //1.获取excel模板 |
| | | ClassPathResource classPathResource = new ClassPathResource("template/邀请码导入模板.xlsx"); |
| | | TemplateExportParams params = new TemplateExportParams(classPathResource.getPath()); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | try { |
| | | String fileName = URLEncoder.encode("邀请码导入模板.xlsx", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setHeader("Content-dispodition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("邀请码导入模板下载失败!"); |
| | |
| | | } |
| | | } |
| | | } |
| | | @Log(title = "邀请码导入", businessType = BusinessType.IMPORT) |
| | | @ApiOperation(value = "邀请码导入") |
| | | @PostMapping("/importExcel") |
| | | @PostMapping("/base/v1/invitation/importExcel") |
| | | public R<String> importExcel(@RequestPart("file") MultipartFile file) { |
| | | System.out.println("文件名 = " + file.getOriginalFilename()); |
| | | System.out.println("文件大小 = " + file.getSize()); |
| | | System.out.println("ContentType = " + file.getContentType()); |
| | | ImportParams params = new ImportParams(); |
| | | // params.setTitleRows(1); // 标题行数 |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | | // List<CustomerImportFailedData> failedData = new ArrayList<>(); |
| | | List<InvitationCodeImportExcel> invitationCodeImportExcels; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "邀请码导出") |
| | | @PostMapping(value = "/exportExcel") |
| | | @PostMapping(value = "/api/v1/invitation/exportExcel") |
| | | public void exportExcel(@RequestBody InvitationPageListQuery query) { |
| | | List<XpInvitationCode> list = xpInvitationCodeService.exportList(query); |
| | | List<XpInvitationCodeExportExcel> xpWhitelistExportExcels = new ArrayList<>(); |
| | | for (XpInvitationCode xpInvitationCode : list) { |
| | | XpInvitationCodeExportExcel xpWhitelistExportExcel = new XpInvitationCodeExportExcel(); |
| | | xpWhitelistExportExcel.setId(xpInvitationCode.getId()); |
| | | // xpWhitelistExportExcel.setId(xpInvitationCode.getId()); |
| | | xpWhitelistExportExcel.setBind_account(xpInvitationCode.getBindAccount()); |
| | | xpWhitelistExportExcel.setInvitationCode(xpInvitationCode.getInvitationCode()); |
| | | LocalDateTime createTime = xpInvitationCode.getCreateTime(); |
| | |
| | | /** |
| | | * 批量删除 |
| | | */ |
| | | @GetMapping("/deleteByIds") |
| | | @GetMapping("/api/v1/invitation/deleteByIds") |
| | | @ResponseBody |
| | | @ApiOperation(value = "批量删除") |
| | | public R deleteByIds(String ids){ |