| | |
| | | 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.FansSubmitMapper; |
| | | import com.yuanchu.mom.pojo.DataReporting; |
| | | import com.yuanchu.mom.pojo.FansSubmit; |
| | | import com.yuanchu.mom.service.DataReportingService; |
| | | import com.yuanchu.mom.mapper.DataReportingMapper; |
| | | import com.yuanchu.mom.service.FansSubmitService; |
| | | 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; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addDataReporting(List<DataReporting> list) { |
| | | public void addDataReporting(List<DataReporting> list, String date) { |
| | | int userId = Integer.parseInt(JSONUtil.parseObj(new Jwt().readJWT(ServletUtils.getRequest().getHeader("token")).get("data")).get("id") + ""); |
| | | Map<String, String> map = dataReportingMapper.selectUser(userId); |
| | | 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())); |
| | | if (dataReporting.getName() == null || dataReporting.getName().equals("")) dataReporting.setName(map.get("account")); |
| | | if (date == null) { |
| | | date = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | }; |
| | | DataReporting one = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, dataReporting.getProduct()).eq(DataReporting::getName, dataReporting.getName()).like(DataReporting::getCreateTime, date)); |
| | | try { |
| | | dataReporting.setRebateConsumption(dataReporting.getAccountConsumption().divide(dataReporting.getCustomerRebate(), 2, RoundingMode.HALF_UP)); |
| | | } catch (Exception e) { |
| | |
| | | if (ObjectUtil.isEmpty(one)) { |
| | | dataReporting.setRegistrant(map.get("name")); |
| | | dataReporting.setDepartment(map.get("department")); |
| | | dataReporting.setCreateTime(LocalDateTime.parse(date + " " + new SimpleDateFormat("HH:mm:ss").format(new Date()), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | dataReportingMapper.insert(dataReporting); |
| | | } else { |
| | | dataReporting.setId(one.getId()); |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Integer delDataReporting(Integer id) { |
| | | List<FansSubmit> fansSubmits = fansSubmitMapper.selectList(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getDataId, id).select(FansSubmit::getId)); |
| | | fansSubmitMapper.deleteBatchIds(fansSubmits); |
| | | return dataReportingMapper.deleteById(id); |
| | | } |
| | | |
| | |
| | | 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[]{}); |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | |