| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.resource.ResourceUtil; |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.text.csv.CsvData; |
| | | import cn.hutool.core.text.csv.CsvReader; |
| | | import cn.hutool.core.text.csv.CsvRow; |
| | | import cn.hutool.core.text.csv.CsvUtil; |
| | | import cn.hutool.core.util.CharsetUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.dto.DataReportingCsvDto; |
| | | import com.yuanchu.mom.dto.DataReportingPageDto; |
| | | import com.yuanchu.mom.dto.ProductCountDto; |
| | | import com.yuanchu.mom.dto.RegistrantCountDto; |
| | | import com.yuanchu.mom.dto.*; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.FansSubmitMapper; |
| | | import com.yuanchu.mom.pojo.DataReporting; |
| | | import com.yuanchu.mom.pojo.FansSubmit; |
| | | import com.yuanchu.mom.pojo.FinanceSubmit; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.tomcat.util.http.fileupload.FileUtils; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RequestMapping("/dataReporting") |
| | | @RestController |
| | |
| | | private FansSubmitService fansSubmitService; |
| | | |
| | | private FinanceSubmitService financeSubmitService; |
| | | |
| | | private FansSubmitMapper fansSubmitMapper; |
| | | |
| | | @ApiOperation(value = "获取数据上报列表") |
| | | @PostMapping("/selectDataReportingList") |
| | |
| | | return Result.success(dataReportingService.selectProductCountDtoPageList(page, productCountDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取登记人汇总列表") |
| | | @ApiOperation(value = "获取员工数据统计列表") |
| | | @PostMapping("/selectRegistrantCountDtoPageList") |
| | | public Result selectRegistrantCountDtoPageList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | |
| | | public Result selectFansSubmitList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | FansSubmit fansSubmit = JSON.parseObject(JSON.toJSONString(data.get("entity")), FansSubmit.class); |
| | | if (ObjectUtil.isNotEmpty(fansSubmit.getCreateTime())) { |
| | | fansSubmit.setCreateTime(fansSubmit.getCreateTime().plusDays(1)); |
| | | } |
| | | return Result.success(fansSubmitService.selectFansSubmitList(page, fansSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取进粉上报总数") |
| | | @PostMapping("/countFansSubmitList") |
| | | @ValueAuth |
| | | public Result countFansSubmitList(@RequestBody FansSubmit fansSubmit) { |
| | | return Result.success(fansSubmitService.countFansSubmitList(fansSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除进粉上报列表") |
| | |
| | | @ApiOperation(value = "添加进粉上报信息") |
| | | @PostMapping("/addFansSubmit") |
| | | public Result<?> addFansSubmit(@RequestBody FansSubmit fansSubmit) { |
| | | return Result.success(fansSubmitService.addFansSubmit(fansSubmit)); |
| | | return Result.success(fansSubmitService.addFansSubmit(fansSubmit, null)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取财务上报列表") |
| | |
| | | public Result selectFinanceSubmitList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | FinanceSubmit financeSubmit = JSON.parseObject(JSON.toJSONString(data.get("entity")), FinanceSubmit.class); |
| | | if (ObjectUtil.isNotEmpty(financeSubmit.getCreateTime())) { |
| | | financeSubmit.setCreateTime(financeSubmit.getCreateTime().plusDays(1)); |
| | | } |
| | | return Result.success(financeSubmitService.selectFinanceSubmitList(page, financeSubmit)); |
| | | } |
| | | |
| | |
| | | |
| | | @ApiOperation(value = "添加财务上报信息") |
| | | @PostMapping("/addFinanceSubmit") |
| | | public Result<?> addFinanceSubmit(@RequestBody FinanceSubmit financeSubmit) { |
| | | return Result.success(financeSubmitService.addFinanceSubmit(financeSubmit)); |
| | | public Result<?> addFinanceSubmit(@RequestBody FinanceSubmit financeSubmit, String date) { |
| | | return Result.success(financeSubmitService.addFinanceSubmit(financeSubmit, date, financeSubmit.getParam())); |
| | | } |
| | | |
| | | @ValueAuth |
| | |
| | | |
| | | @ApiOperation(value = "导入数据上报列表") |
| | | @PostMapping("/inputCsv") |
| | | public Result<?> inputCsv(@RequestParam("file") MultipartFile file) throws IOException { |
| | | public Result<?> inputCsv(@RequestParam("file") MultipartFile file, String param) throws IOException { |
| | | CsvReader reader = CsvUtil.getReader(); |
| | | CsvData data = reader.read(new InputStreamReader(file.getInputStream(), "GB2312")); |
| | | List<CsvRow> rows = data.getRows(); |
| | | List<DataReporting> list = new ArrayList<>(); |
| | | for (int i = 5; i < rows.size(); i++) { |
| | | DataReporting reporting = new DataReporting(); |
| | | reporting.setName(rows.get(i).get(0)) |
| | | .setProduct(rows.get(i).get(1)) |
| | | .setShowNum(Integer.valueOf(rows.get(i).get(3))) |
| | | .setClick(Integer.valueOf(rows.get(i).get(4))) |
| | | // .setAvgPrice(new BigDecimal(rows.get(i).get(5))) |
| | | .setAccountConsumption(new BigDecimal(rows.get(i).get(6))); |
| | | // .setSearchBalance(new BigDecimal(rows.get(i).get(6))) |
| | | // .setInfoBalance(new BigDecimal(rows.get(i).get(7))) |
| | | // .setVxClick(Double.valueOf(rows.get(i).get(8))) |
| | | // .setClickThroughRate(rows.get(i).get(9)); |
| | | list.add(reporting); |
| | | String format; |
| | | try { |
| | | format = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyyMMdd").parse(rows.get(2).get(0).split(":")[1])); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | throw new ErrorException("文件中日期在转换时出现错误"); |
| | | } |
| | | dataReportingService.addDataReporting(list); |
| | | int fieldIndex = 5; |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | if (JSON.toJSONString(rows.get(i)).contains("账户ID")) { |
| | | fieldIndex = i; |
| | | break; |
| | | } |
| | | } |
| | | for (int i = fieldIndex + 1; i < rows.size(); i++) { |
| | | DataReporting reporting = new DataReporting(); |
| | | for (int i1 = 0; i1 < rows.get(fieldIndex).size(); i1++) { |
| | | String str = rows.get(i).get(i1); |
| | | if (str == null) continue; |
| | | switch (rows.get(fieldIndex).get(i1)) { |
| | | case "账户": |
| | | reporting.setName(str); |
| | | break; |
| | | case "备注": |
| | | String[] split = str.split("-"); |
| | | if (split.length > 3) { |
| | | reporting.setName2(split[0]); |
| | | reporting.setChannel(split[2]); |
| | | reporting.setAgent(split[3]); |
| | | reporting.setProduct(split[1]); |
| | | break; |
| | | } |
| | | reporting.setProduct(str); |
| | | break; |
| | | case "展现量": |
| | | try { |
| | | reporting.setShowNum(Integer.parseInt(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "点击量": |
| | | try { |
| | | reporting.setClick(Integer.parseInt(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "消费": |
| | | try { |
| | | reporting.setAccountConsumption(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | if (reporting.getAccountConsumption().compareTo(BigDecimal.ZERO) > 0) list.add(reporting); |
| | | } |
| | | dataReportingService.addDataReporting(list, format, param); |
| | | return Result.success(); |
| | | } |
| | | |
| | |
| | | public Result<?> addDataReporting(@RequestBody DataReporting dataReporting) { |
| | | ArrayList<DataReporting> list = new ArrayList<>(); |
| | | list.add(dataReporting); |
| | | dataReportingService.addDataReporting(list); |
| | | dataReportingService.addDataReporting(list, null, dataReporting.getVxCard()); |
| | | return Result.success(); |
| | | } |
| | | |
| | |
| | | return Result.success("导出成功", dataReportingService.downRegistrantCountFile(page, registrantCountDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "导出进粉上报列表") |
| | | @PostMapping("/downFansSubmitFile") |
| | | public Result downFansSubmitFile(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | FansSubmit fansSubmit = JSON.parseObject(JSON.toJSONString(data.get("entity")), FansSubmit.class); |
| | | return Result.success("导出成功", dataReportingService.downFansSubmitFile(page, fansSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "导入进粉上报列表") |
| | | @PostMapping("/inputFansSubmitCsv") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> inputFansSubmitCsv(@RequestParam("file") MultipartFile file) throws IOException { |
| | | List<FansSubmit> fansSubmitLists = new ArrayList<>(); |
| | | List<FansSubmit> fansSubmitList = new ArrayList<>(); |
| | | List<String> dates = new ArrayList<>(); |
| | | AtomicReference<String> product = new AtomicReference<>(); |
| | | ExcelUtil.readBySax(file.getInputStream(), 0, (i, l, list) -> { |
| | | LocalDateTime date = null; |
| | | try { |
| | | date = LocalDateTime.parse((list.get(0) + "").replace(" ", "T")).plusDays(1); |
| | | dates.add(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+" 00:00:00"); |
| | | } catch (Exception e) { |
| | | if(!(l == 0 || l == 1 || l == 2)){ |
| | | return; |
| | | } |
| | | } |
| | | if (l == 0 || l == 1 || l == 2 |
| | | || date.compareTo(LocalDateTime.now()) < 1) { |
| | | for (int i1 = 1; i1 < list.size(); i1++) { |
| | | try { |
| | | FansSubmit fansSubmit = fansSubmitList.get(i1 - 1); |
| | | fansSubmit.setId(null); |
| | | product.set(getFansSubmit(l, list.get(i1), date, fansSubmit, product.get())); |
| | | } catch (IndexOutOfBoundsException e) { |
| | | FansSubmit fansSubmit = new FansSubmit(); |
| | | product.set(getFansSubmit(l, list.get(i1), date, fansSubmit, product.get())); |
| | | fansSubmitList.add(fansSubmit); |
| | | } |
| | | } |
| | | if(l>2){ |
| | | fansSubmitLists.addAll(JSON.parseArray(JSON.toJSONString(fansSubmitList.stream().filter(a -> !Objects.equals(a.getCustom(), "合计")).collect(Collectors.toList())), FansSubmit.class)); |
| | | } |
| | | } |
| | | }); |
| | | fansSubmitMapper.delete(Wrappers.<FansSubmit>lambdaUpdate().in(FansSubmit::getCreateTime, dates)); |
| | | fansSubmitService.saveBatch(fansSubmitLists); |
| | | /*CsvReader reader = CsvUtil.getReader(); |
| | | CsvData data = reader.read(new InputStreamReader(file.getInputStream(), "GB2312")); |
| | | List<CsvRow> rows = data.getRows(); |
| | | String format; |
| | | try { |
| | | format = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyyMMdd").parse(rows.get(2).get(0).split(":")[1])); |
| | | } catch (ParseException e) { |
| | | throw new ErrorException("文件中日期在转换时出现错误"); |
| | | } |
| | | for (int i = 6; i < rows.size(); i++) { |
| | | FansSubmit fansSubmit = new FansSubmit(); |
| | | for (int i1 = 0; i1 < rows.get(5).size(); i1++) { |
| | | String str = rows.get(i).get(i1); |
| | | if (str == null) continue; |
| | | switch (rows.get(5).get(i1)) { |
| | | case "客户": |
| | | fansSubmit.setCustom(str); |
| | | break; |
| | | case "项目": |
| | | fansSubmit.setProduct(str); |
| | | break; |
| | | case "微信号": |
| | | fansSubmit.setVx(str); |
| | | break; |
| | | case "进粉": |
| | | try { |
| | | fansSubmit.setFansAdd(Integer.parseInt(str)); |
| | | }catch (Exception e){ |
| | | fansSubmit.setFansAdd(0); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | fansSubmitService.addFansSubmit(fansSubmit, format); |
| | | }*/ |
| | | return Result.success(); |
| | | } |
| | | |
| | | public String getFansSubmit(long l, Object thing, LocalDateTime date, FansSubmit fansSubmit, String product) { |
| | | String str = (thing == null ? null : thing + ""); |
| | | if(l==0){ |
| | | if (str != null) product = str; |
| | | fansSubmit.setProduct(product); |
| | | }else if(l==1){ |
| | | Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]"); |
| | | Matcher matcher = pattern.matcher(str == null ? "" : str); |
| | | if (matcher.find()) { |
| | | fansSubmit.setCustom(str); |
| | | } else { |
| | | fansSubmit.setVx(str); |
| | | } |
| | | }else if(l==2){ |
| | | if (fansSubmit.getVx() == null) { |
| | | fansSubmit.setVx(str); |
| | | } |
| | | }else{ |
| | | fansSubmit.setCreateTime(date); |
| | | fansSubmit.setFansAdd((str == null || str.equals("")) ? 0 : Integer.parseInt(str)); |
| | | } |
| | | return product; |
| | | } |
| | | |
| | | @ApiOperation(value = "获取数据对比列表") |
| | | @PostMapping("/selectDataComparisonDtoPageList") |
| | | public Result selectDataComparisonDtoPageList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | DataComparisonDto dataComparisonDto = JSON.parseObject(JSON.toJSONString(data.get("entity")), DataComparisonDto.class); |
| | | Map<String, Object> stringObjectMap = dataReportingService.selectDataComparisonDtoPageList(page, dataComparisonDto); |
| | | return Result.success(stringObjectMap); |
| | | } |
| | | |
| | | @ApiOperation(value = "导出财务上报列表") |
| | | @PostMapping("/downFinanceSubmitFile") |
| | | public Result downFinanceSubmitFile(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | FinanceSubmit financeSubmit = JSON.parseObject(JSON.toJSONString(data.get("entity")), FinanceSubmit.class); |
| | | return Result.success("导出成功", dataReportingService.downFinanceSubmitFile(page, financeSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "导入财务上报列表") |
| | | @PostMapping("/inputFinanceSubmitCsv") |
| | | public Result<?> inputFinanceSubmitCsv(@RequestParam("file") MultipartFile file, String param) throws IOException { |
| | | CsvReader reader = CsvUtil.getReader(); |
| | | CsvData data = reader.read(new InputStreamReader(file.getInputStream(), "GB2312")); |
| | | List<CsvRow> rows = data.getRows(); |
| | | String format; |
| | | try { |
| | | format = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyyMMdd").parse(rows.get(2).get(0).split(":")[1])); |
| | | } catch (ParseException e) { |
| | | throw new ErrorException("文件中日期在转换时出现错误"); |
| | | } |
| | | for (int i = 6; i < rows.size(); i++) { |
| | | FinanceSubmit financeSubmit = new FinanceSubmit(); |
| | | for (int i1 = 0; i1 < rows.get(5).size(); i1++) { |
| | | String str = rows.get(i).get(i1); |
| | | if (str == null) continue; |
| | | switch (rows.get(5).get(i1)) { |
| | | case "代理商": |
| | | financeSubmit.setCompany(str); |
| | | break; |
| | | case "账户名": |
| | | financeSubmit.setName(str); |
| | | break; |
| | | case "金额": |
| | | try { |
| | | financeSubmit.setConsumption(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "代理返点": |
| | | try { |
| | | financeSubmit.setAgentRebate(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "打款人民币": |
| | | try { |
| | | financeSubmit.setMoney(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "员工返点": |
| | | try { |
| | | financeSubmit.setEmployeeRebate(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | case "员工返点人民币": |
| | | try { |
| | | financeSubmit.setEmployeeRebateMoney(new BigDecimal(str)); |
| | | } catch (Exception e) { |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | financeSubmitService.addFinanceSubmit(financeSubmit, format, param); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "一键删除所有数据上报的数据") |
| | | @PostMapping("/deleteAllData") |
| | | public Result deleteAllData(String date) { |
| | | dataReportingService.deleteAllData(date); |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取数据上报的登记人筛选项") |
| | | @PostMapping("/selectDataReportingForCreateUserNames") |
| | | @ValueAuth |
| | | public Result selectDataReportingForCreateUserNames(String time) { |
| | | return Result.success(dataReportingService.selectDataReportingForCreateUserNames(time)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取项目数据统计的项目筛选项") |
| | | @PostMapping("/selectDataReportingForProduct") |
| | | @ValueAuth |
| | | public Result selectDataReportingForProduct(String time) { |
| | | return Result.success(dataReportingService.selectDataReportingForProduct(time)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取微信号列表") |
| | | @GetMapping("/selectVxs") |
| | | @ValueAuth |
| | | public Result selectVxs(String time) { |
| | | return Result.success(fansSubmitService.vxs(time)); |
| | | } |
| | | |
| | | @ApiOperation(value = "批量修改微信号") |
| | | @PostMapping("/updateVxCards") |
| | | public Result updateVxCards(String str) { |
| | | List<DataReporting> list = JSON.parseArray(str, DataReporting.class); |
| | | return Result.success(dataReportingService.updateVxCards(list)); |
| | | } |
| | | |
| | | @ApiOperation(value = "一键删除所有进粉上报的数据") |
| | | @PostMapping("/deleteAllFans") |
| | | public Result deleteAllFans(String date) { |
| | | fansSubmitService.deleteAllFans(date); |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "一键删除所有财务上报的数据") |
| | | @PostMapping("/deleteAllFinance") |
| | | public Result deleteAllFinance(String date) { |
| | | financeSubmitService.deleteAllFinance(date); |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "数据上报主管权限") |
| | | @GetMapping("/dataReportingPower") |
| | | public Result dataReportingPower() { |
| | | return Result.success(); |
| | | } |
| | | |
| | | } |