| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.io.file.FileReader; |
| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.DataComparisonDto; |
| | | import com.yuanchu.mom.dto.DataReportingPageDto; |
| | | import com.yuanchu.mom.dto.ProductCountDto; |
| | | import com.yuanchu.mom.dto.RegistrantCountDto; |
| | | import com.yuanchu.mom.mapper.AuthMapper; |
| | | import com.yuanchu.mom.mapper.FansSubmitMapper; |
| | | import com.yuanchu.mom.mapper.FinanceSubmitMapper; |
| | | import com.yuanchu.mom.pojo.DataReporting; |
| | | import com.yuanchu.mom.pojo.FansSubmit; |
| | | import com.yuanchu.mom.pojo.FinanceSubmit; |
| | | import com.yuanchu.mom.service.DataReportingService; |
| | | import com.yuanchu.mom.mapper.DataReportingMapper; |
| | | import com.yuanchu.mom.service.FansSubmitService; |
| | | import com.yuanchu.mom.service.FinanceSubmitService; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.utils.ServletUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.tomcat.util.http.fileupload.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | |
| | | @Value("${outPath}") |
| | | private String outPath; |
| | | |
| | | @Resource |
| | | private FansSubmitMapper fansSubmitMapper; |
| | | |
| | | @Resource |
| | | private FansSubmitService fansSubmitService; |
| | | |
| | | @Resource |
| | | private FinanceSubmitService financeSubmitService; |
| | | |
| | | @Resource |
| | | private FinanceSubmitMapper financeSubmitMapper; |
| | | |
| | | @Resource |
| | | private AuthMapper authMapper; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if (map1.get("look") == 1) dataReportingPageDto.setCreateUser(map1.get("userId")); |
| | | if (map1.get("look") == 1) dataReportingPageDto.setUpdateUser(map1.get("userId")); |
| | | Integer power = authMapper.isPower(map1.get("userId"), "dataReportingPower"); |
| | | if (power == 1) { |
| | | dataReportingPageDto.setDepartment(dataReportingMapper.getUserDepartmentById(map1.get("userId"))); |
| | | } |
| | | map.put("head", PrintChina.printChina(DataReportingPageDto.class)); |
| | | map.put("body", dataReportingMapper.selectDataReportingDtoPageList(page, QueryWrappers.queryWrappers(dataReportingPageDto))); |
| | | return map; |
| | |
| | | dataReporting2.setCustomerCosts(dataReporting.getCustomerCosts()); |
| | | dataReporting2.setCustomerRebate(dataReporting.getCustomerRebate()); |
| | | dataReporting2.setRemark(dataReporting.getRemark()); |
| | | dataReporting2.setVxCard(dataReporting.getVxCard()); |
| | | try { |
| | | dataReporting2.setRebateConsumption(dataReporting.getAccountConsumption().divide(dataReporting.getCustomerRebate(), 2, RoundingMode.HALF_UP)); |
| | | } catch (Exception e) { |
| | |
| | | try { |
| | | dataReporting2.setConsumption(dataReporting.getCustomerCosts().multiply(BigDecimal.valueOf(dataReporting.getFansAdd()))); |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | dataReporting2.setDiscountedConsumption(dataReporting.getConsumption().divide(dataReporting.getAgentRebate(), 2, RoundingMode.HALF_UP)); |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | dataReporting2.setActualCost(dataReporting.getAccountConsumption().divide(new BigDecimal(dataReporting.getFansAdd()), 2, RoundingMode.HALF_UP)); |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | dataReporting2.setProfit(dataReporting.getRebateConsumption().subtract(dataReporting.getConsumption())); |
| | | } catch (Exception e) { |
| | | } |
| | | String format = dataReportingMapper.selectById(dataReporting.getId()).getCreateTime().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | List<FansSubmit> fansSubmits = fansSubmitMapper.selectList(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getProduct, dataReporting.getProduct()).eq(FansSubmit::getVx, dataReporting.getVxCard()).select(FansSubmit::getFansAdd).like(FansSubmit::getCreateTime, format)); |
| | | Integer sum = 0; |
| | | for (FansSubmit fansSubmit : fansSubmits) { |
| | | sum += fansSubmit.getFansAdd(); |
| | | } |
| | | if (dataReporting.getFansAdd() != null || dataReporting.getFansAdd() != 0) { |
| | | dataReporting2.setFansAdd(dataReporting.getFansAdd()); |
| | | } else { |
| | | dataReporting2.setFansAdd(sum); |
| | | } |
| | | return dataReportingMapper.updateById(dataReporting2); |
| | | } |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(RegistrantCountDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectRegistrantCountDtoPageList"); |
| | | if (map1.get("look") == 1) registrantCountDto.setCreateUser(map1.get("userId")); |
| | | map.put("body", dataReportingMapper.selectRegistrantCountDtoPageList(page, QueryWrappers.queryWrappers(registrantCountDto))); |
| | | if (map1.get("look") == 1) { |
| | | String name = dataReportingMapper.getUserNameById(map1.get("userId")); |
| | | registrantCountDto.setName2(name); |
| | | } |
| | | ; |
| | | String department = dataReportingMapper.getUserDepartmentById(map1.get("userId")); |
| | | registrantCountDto.setDepartment(department); |
| | | map.put("body", dataReportingMapper.selectRegistrantCountDtoPageList(page, QueryWrappers.queryWrappers(registrantCountDto), registrantCountDto.getStartTime(), registrantCountDto.getEndTime())); |
| | | return map; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addDataReporting(List<DataReporting> list) { |
| | | public void addDataReporting(List<DataReporting> list, String date, String param) { |
| | | int userId = Integer.parseInt(JSONUtil.parseObj(new Jwt().readJWT(ServletUtils.getRequest().getHeader("token")).get("data")).get("id") + ""); |
| | | Map<String, String> map = dataReportingMapper.selectUser(userId); |
| | | String date2 = date; |
| | | if (date == null) { |
| | | date2 = fansSubmitService.getYesterday(); |
| | | date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | } else |
| | | date = LocalDateTime.parse(date + "T00:00:00").plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | for (DataReporting dataReporting : list) { |
| | | if (dataReporting.getName() == null) dataReporting.setName(map.get("account")); |
| | | DataReporting one = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, dataReporting.getProduct()).eq(DataReporting::getName, dataReporting.getName())); |
| | | FinanceSubmit financeSubmit = financeSubmitMapper.selectOne(Wrappers.<FinanceSubmit>lambdaQuery().eq(FinanceSubmit::getCompany, dataReporting.getAgent()).eq(FinanceSubmit::getName, dataReporting.getName()).select(FinanceSubmit::getEmployeeRebate).like(FinanceSubmit::getCreateTime, date).orderByDesc(FinanceSubmit::getId).last("limit 1")); |
| | | if (ObjectUtil.isNotEmpty(financeSubmit)) { |
| | | dataReporting.setAgentRebate(financeSubmit.getEmployeeRebate()); |
| | | } |
| | | if (dataReporting.getName() == null || dataReporting.getName().equals("")) |
| | | dataReporting.setName(map.get("account")); |
| | | // DataReporting one = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, dataReporting.getProduct()).eq(DataReporting::getName, dataReporting.getName()).eq(DataReporting::getCreateUser, userId).like(DataReporting::getCreateTime, date)); |
| | | try { |
| | | dataReporting.setRebateConsumption(dataReporting.getAccountConsumption().divide(dataReporting.getCustomerRebate(), 2, RoundingMode.HALF_UP)); |
| | | } catch (Exception e) { |
| | |
| | | dataReporting.setRemark(dataReporting.getConsumption().subtract(dataReporting.getRebateConsumption())); |
| | | } catch (Exception e) { |
| | | } |
| | | if (ObjectUtil.isEmpty(one)) { |
| | | dataReporting.setRegistrant(map.get("name")); |
| | | dataReporting.setDepartment(map.get("department")); |
| | | dataReportingMapper.insert(dataReporting); |
| | | } else { |
| | | dataReporting.setId(one.getId()); |
| | | dataReporting.setName(null); |
| | | dataReporting.setRegistrant(map.get("name")); |
| | | dataReporting.setDepartment(map.get("department")); |
| | | dataReporting.setCreateTime(LocalDateTime.parse(date2 + " " + new SimpleDateFormat("HH:mm:ss").format(new Date()), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | DataReporting dataReporting1 = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery() |
| | | .eq(DataReporting::getName, dataReporting.getName()) |
| | | .eq(DataReporting::getAccountConsumption, dataReporting.getAccountConsumption()) |
| | | .eq(DataReporting::getShowNum, dataReporting.getShowNum()) |
| | | .eq(DataReporting::getClick, dataReporting.getClick())); |
| | | if (BeanUtil.isNotEmpty(dataReporting1)) { |
| | | dataReporting.setId(dataReporting1.getId()); |
| | | dataReportingMapper.updateById(dataReporting); |
| | | } else { |
| | | dataReportingMapper.insert(dataReporting); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Integer delDataReporting(Integer id) { |
| | | return dataReportingMapper.deleteById(id); |
| | |
| | | String name = "数据上报" + time + ".csv"; |
| | | String path = outPath + name; |
| | | CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); |
| | | writer.write(new String[]{"导出时间:"+time}); |
| | | writer.write(new String[]{"导出时间:" + time}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{"时间范围:" + dataReportingPageDto.getCreateTime().format(DateTimeFormatter.ofPattern("yyyyMMdd"))}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | List<Map<String, String>> head = JSON.parseObject(JSON.toJSONString(map.get("head")), List.class); |
| | |
| | | str[i] = head.get(i).get("value"); |
| | | } |
| | | writer.write(str); |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a->{ |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a -> { |
| | | Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = map1.get(head.get(i).get("label"))==null?null:map1.get(head.get(i).get("label"))+""; |
| | | str[i] = map1.get(head.get(i).get("label")) == null ? null : map1.get(head.get(i).get("label")) + ""; |
| | | } |
| | | writer.write(str); |
| | | }); |
| | |
| | | String name = "项目数据统计" + time + ".csv"; |
| | | String path = outPath + name; |
| | | CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); |
| | | writer.write(new String[]{"导出时间:"+time}); |
| | | writer.write(new String[]{"导出时间:" + time}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | |
| | | str[i] = head.get(i).get("value"); |
| | | } |
| | | writer.write(str); |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a->{ |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a -> { |
| | | Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = map1.get(head.get(i).get("label"))==null?null:map1.get(head.get(i).get("label"))+""; |
| | | str[i] = map1.get(head.get(i).get("label")) == null ? null : map1.get(head.get(i).get("label")) + ""; |
| | | } |
| | | writer.write(str); |
| | | }); |
| | |
| | | String name = "员工数据统计" + time + ".csv"; |
| | | String path = outPath + name; |
| | | CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); |
| | | writer.write(new String[]{"导出时间:"+time}); |
| | | writer.write(new String[]{"导出时间:" + time}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | |
| | | str[i] = head.get(i).get("value"); |
| | | } |
| | | writer.write(str); |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a->{ |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a -> { |
| | | Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = map1.get(head.get(i).get("label"))==null?null:map1.get(head.get(i).get("label"))+""; |
| | | str[i] = map1.get(head.get(i).get("label")) == null ? null : map1.get(head.get(i).get("label")) + ""; |
| | | } |
| | | writer.write(str); |
| | | }); |
| | | writer.close(); |
| | | return name; |
| | | } |
| | | |
| | | @Override |
| | | public String downFansSubmitFile(IPage<FansSubmit> page, FansSubmit fansSubmit) { |
| | | Map<String, Object> map = fansSubmitService.selectFansSubmitList(page, fansSubmit); |
| | | String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); |
| | | String name = "粉丝上报" + time + ".csv"; |
| | | String path = outPath + name; |
| | | CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); |
| | | writer.write(new String[]{"导出时间:" + time}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{"时间范围:" + fansSubmit.getCreateTime().format(DateTimeFormatter.ofPattern("yyyyMMdd"))}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | List<Map<String, String>> head = JSON.parseObject(JSON.toJSONString(map.get("head")), List.class); |
| | | String[] str = new String[head.size()]; |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = head.get(i).get("value"); |
| | | } |
| | | writer.write(str); |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a -> { |
| | | Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = map1.get(head.get(i).get("label")) == null ? null : map1.get(head.get(i).get("label")) + ""; |
| | | } |
| | | writer.write(str); |
| | | }); |
| | | writer.close(); |
| | | return name; |
| | | } |
| | | |
| | | @Override |
| | | public String downFinanceSubmitFile(IPage<FinanceSubmit> page, FinanceSubmit financeSubmit) { |
| | | Map<String, Object> map = financeSubmitService.selectFinanceSubmitList(page, financeSubmit); |
| | | String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); |
| | | String name = "财务上报" + time + ".csv"; |
| | | String path = outPath + name; |
| | | CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_GBK); |
| | | writer.write(new String[]{"导出时间:" + time}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{"时间范围:" + financeSubmit.getCreateTime().format(DateTimeFormatter.ofPattern("yyyyMMdd"))}); |
| | | writer.write(new String[]{}); |
| | | writer.write(new String[]{}); |
| | | List<Map<String, String>> head = JSON.parseObject(JSON.toJSONString(map.get("head")), List.class); |
| | | String[] str = new String[head.size()]; |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = head.get(i).get("value"); |
| | | } |
| | | writer.write(str); |
| | | JSON.parseObject(JSON.toJSONString(map.get("body")), IPage.class).getRecords().forEach(a -> { |
| | | Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(a), Map.class); |
| | | for (int i = 0; i < head.size(); i++) { |
| | | str[i] = map1.get(head.get(i).get("label")) == null ? null : map1.get(head.get(i).get("label")) + ""; |
| | | } |
| | | writer.write(str); |
| | | }); |
| | | writer.close(); |
| | | return name; |
| | | } |
| | | |
| | | /** |
| | | * 获取数据对比列表 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> selectDataComparisonDtoPageList(Page page, DataComparisonDto dataComparisonDto) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(DataComparisonDto.class)); |
| | | |
| | | if (StringUtils.isEmpty(dataComparisonDto.getName()) |
| | | || StringUtils.isEmpty(dataComparisonDto.getComparisonName())) { |
| | | map.put("body", new Page<DataComparisonDto>()); |
| | | } else { |
| | | IPage<DataComparisonDto> dataReportingPageDtoIPage = dataReportingMapper.selectDataComparisonDtoPageList(page, dataComparisonDto); |
| | | map.put("body", dataReportingPageDtoIPage); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteAllData(String date) { |
| | | List<DataReporting> list = dataReportingMapper.selectList(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getCreateUser, getLook.selectPowerByMethodAndUserId("selectDataReportingList").get("userId")).like(DataReporting::getCreateTime, date)); |
| | | for (DataReporting reporting : list) { |
| | | delDataReporting(reporting.getId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectDataReportingForCreateUserNames(String time) { |
| | | return dataReportingMapper.selectDataReportingForCreateUserNames(time.split(" ")[0]); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectDataReportingForProduct(String time) { |
| | | return dataReportingMapper.selectDataReportingForProduct(time.split(" ")[0]); |
| | | } |
| | | |
| | | @Override |
| | | public int updateVxCards(List<DataReporting> list) { |
| | | for (DataReporting reporting : list) { |
| | | updateDataReporting(reporting); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | } |
| | | |
| | | |