李林
2024-01-08 7cf8ae446e880537a38bd7ac403bd53741a5294f
修订版2.0
已修改14个文件
344 ■■■■ 文件已修改
data-server/src/main/java/com/yuanchu/mom/controller/DataReportingController.java 113 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/dto/DataReportingCsvDto.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/dto/DataReportingPageDto.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/pojo/DataReporting.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/pojo/FansSubmit.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/pojo/FinanceSubmit.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/DataReportingService.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/FansSubmitService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/FinanceSubmitService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/impl/DataReportingServiceImpl.java 60 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/impl/FansSubmitServiceImpl.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/service/impl/FinanceSubmitServiceImpl.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/resources/mapper/DataReportingMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
data-server/src/main/java/com/yuanchu/mom/controller/DataReportingController.java
@@ -15,6 +15,7 @@
import com.yuanchu.mom.dto.DataReportingPageDto;
import com.yuanchu.mom.dto.ProductCountDto;
import com.yuanchu.mom.dto.RegistrantCountDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.pojo.DataReporting;
import com.yuanchu.mom.pojo.FansSubmit;
import com.yuanchu.mom.pojo.FinanceSubmit;
@@ -36,10 +37,12 @@
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.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@RequestMapping("/dataReporting")
@RestController
@@ -112,7 +115,7 @@
    @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 = "获取财务上报列表")
@@ -137,8 +140,8 @@
    @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));
    }
    @ValueAuth
@@ -155,21 +158,47 @@
        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++) {
        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("文件中日期在转换时出现错误");
        }
        for (int i = 6; 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));
            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 "账户":
                        reporting.setName(str);
                        break;
                    case "备注":
                        String[] split = str.split("-");
                        if (split.length == 4) {
                            reporting.setName2(split[0]);
                            reporting.setChannel(split[1]);
                            reporting.setAgent(split[2]);
                            reporting.setProduct(split[3]);
                            break;
                        }
                        reporting.setProduct(str);
                        break;
                    case "展现量":
                        reporting.setShowNum(Integer.parseInt(str));
                        break;
                    case "点击量":
                        reporting.setClick(Integer.parseInt(str));
                        break;
                    case "消费":
                        reporting.setAccountConsumption(new BigDecimal(str));
                        break;
                }
            }
            list.add(reporting);
        }
        dataReportingService.addDataReporting(list);
        dataReportingService.addDataReporting(list, format);
        return Result.success();
    }
@@ -178,7 +207,7 @@
    public Result<?> addDataReporting(@RequestBody DataReporting dataReporting) {
        ArrayList<DataReporting> list = new ArrayList<>();
        list.add(dataReporting);
        dataReportingService.addDataReporting(list);
        dataReportingService.addDataReporting(list, null);
        return Result.success();
    }
@@ -206,4 +235,48 @@
        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")
    public Result<?> inputFansSubmitCsv(@RequestParam("file") MultipartFile file) 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++) {
            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 "进粉":
                        fansSubmit.setFansAdd(Integer.parseInt(str));
                        break;
                }
            }
            fansSubmitService.addFansSubmit(fansSubmit, format);
        }
        return Result.success();
    }
}
data-server/src/main/java/com/yuanchu/mom/dto/DataReportingCsvDto.java
@@ -2,7 +2,6 @@
import cn.hutool.core.annotation.Alias;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
data-server/src/main/java/com/yuanchu/mom/dto/DataReportingPageDto.java
@@ -13,12 +13,10 @@
@NoArgsConstructor
public class DataReportingPageDto extends DataReporting {
    @Alias("创建用户")
    @ValueTableShow(21)
    @ApiModelProperty(value = "创建用户")
    private String createUserName;
    @Alias("更新用户")
    @ValueTableShow(22)
    @ApiModelProperty(value = "更新用户")
    private String updateUserName;
data-server/src/main/java/com/yuanchu/mom/pojo/DataReporting.java
@@ -44,7 +44,6 @@
    /**
     * 登记人
     */
    @Alias("登记人")
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("登记人")
    @Length(max= 255,message="编码长度不能超过255")
@@ -53,7 +52,6 @@
    /**
    * 部门
    */
    @Alias("部门")
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("部门")
    @Length(max= 255,message="编码长度不能超过255")
@@ -62,25 +60,34 @@
    /**
     * 账户名
     */
    @Alias("账户名")
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("账户名")
    @Length(max= 255,message="编码长度不能超过255")
    @ValueTableShow(3)
    private String name;
    @ApiModelProperty("姓名")
    @Length(max= 255,message="编码长度不能超过255")
    @ValueTableShow(4)
    private String name2;
    /**
    * 渠道
    */
    @Alias("渠道")
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("渠道")
    @Length(max= 255,message="编码长度不能超过255")
    @ValueTableShow(4)
    private String channel;
    @ApiModelProperty("代理商")
    @Length(max= 255,message="编码长度不能超过255")
    @ValueTableShow(4)
    private String agent;
    /**
     * 项目
     */
    @Alias("项目")
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("项目")
    @Length(max= 255,message="编码长度不能超过255")
@@ -89,105 +96,90 @@
    /**
    * 展现量
    */
    @Alias("展现量")
    @ApiModelProperty("展现量")
    @ValueTableShow(6)
    private Integer showNum;
    /**
    * 点击量
    */
    @Alias("点击量")
    @ApiModelProperty("点击量")
    @ValueTableShow(7)
    private Integer click;
    /**
    * 账户消费
    */
    @Alias("账户消费")
    @ApiModelProperty("账户消费")
    @ValueTableShow(8)
    private BigDecimal accountConsumption;
    /**
    * 客户返点消费
    */
    @Alias("客户返点消费")
    @ApiModelProperty("客户返点消费")
    @ValueTableShow(9)
    private BigDecimal rebateConsumption;
    /**
    * 消费
    */
    @Alias("消费")
    @ApiModelProperty("消费")
    @ValueTableShow(10)
    private BigDecimal consumption;
    /**
    * 折后消费
    */
    @Alias("折后消费")
    @ApiModelProperty("折后消费")
    @ValueTableShow(11)
    private BigDecimal discountedConsumption;
    /**
    * 进粉
    */
    @Alias("进粉")
    @ApiModelProperty("进粉")
    @ValueTableShow(12)
    private Integer fansAdd;
    /**
    * 实际成本
    */
    @Alias("实际成本")
    @ApiModelProperty("实际成本")
    @ValueTableShow(13)
    private BigDecimal actualCost;
    /**
    * 内部成本
    */
    @Alias("内部成本")
    @ApiModelProperty("内部成本")
    @ValueTableShow(14)
    private BigDecimal internalCosts;
    /**
    * 客户成本
    */
    @Alias("客户成本")
    @ApiModelProperty("客户成本")
    @ValueTableShow(15)
    private BigDecimal customerCosts;
    /**
    * 利润
    */
    @Alias("利润")
    @ApiModelProperty("利润")
    @ValueTableShow(16)
    private BigDecimal profit;
    /**
    * 代理返点
    */
    @Alias("代理返点")
    @ApiModelProperty("代理返点")
    @ApiModelProperty("员工代理返点")
    @ValueTableShow(17)
    private BigDecimal agentRebate;
    /**
    * 客户返点
    */
    @Alias("客户返点")
    @ApiModelProperty("客户返点")
    @ValueTableShow(18)
    private BigDecimal customerRebate;
    /**
    * 备用字段
    */
    @Alias("备用字段")
    @ApiModelProperty("备用字段")
    @ApiModelProperty("做进来")
    @ValueTableShow(23)
    private BigDecimal remark;
    /**
    * 
    */
    @Alias("创建时间")
    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -196,7 +188,6 @@
    /**
    * 
    */
    @Alias("更新时间")
    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
data-server/src/main/java/com/yuanchu/mom/pojo/FansSubmit.java
@@ -97,4 +97,6 @@
    @ApiModelProperty("更新用户")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateUser;
    private Integer dataId;
}
data-server/src/main/java/com/yuanchu/mom/pojo/FinanceSubmit.java
@@ -37,6 +37,14 @@
    @TableId(type = IdType.AUTO)
    private Integer id;
    /**
     * 代理公司
     */
    @ValueTableShow
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("代理商")
    @Length(max= 255,message="编码长度不能超过255")
    private String company;
    /**
    * 账户名
    */
    @ValueTableShow
@@ -45,37 +53,35 @@
    @Length(max= 255,message="编码长度不能超过255")
    private String name;
    /**
    * 代理公司
    */
    @ValueTableShow
    @Size(max= 255,message="编码长度不能超过255")
    @ApiModelProperty("代理公司")
    @Length(max= 255,message="编码长度不能超过255")
    private String company;
    /**
    * 消费金额
    */
    @ValueTableShow
    @ApiModelProperty("消费金额")
    @ApiModelProperty("金额")
    private BigDecimal consumption;
    /**
    * 充值金额
    */
    @ValueTableShow
    @ApiModelProperty("充值金额")
    private BigDecimal recharge;
    /**
    * 退款金额
    */
    @ValueTableShow
    @ApiModelProperty("退款金额")
    private BigDecimal refund;
    /**
    * 代理返点
    */
     * 代理返点
     */
    @ValueTableShow
    @ApiModelProperty("代理返点")
    private BigDecimal agentRebate;
    /**
    * 打款人民币
    */
    @ValueTableShow
    @ApiModelProperty("打款人民币")
    private BigDecimal money;
    /**
    * 员工返点
    */
    @ValueTableShow
    @ApiModelProperty("员工返点")
    private BigDecimal employeeRebate;
    /**
     * 员工返点人民币
     */
    @ValueTableShow
    @ApiModelProperty("员工返点人民币")
    private BigDecimal employeeRebateMoney;
    /**
     * 创建时间
     */
@@ -109,5 +115,7 @@
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateUser;
    private Integer dataId;
}
data-server/src/main/java/com/yuanchu/mom/service/DataReportingService.java
@@ -6,6 +6,7 @@
import com.yuanchu.mom.dto.RegistrantCountDto;
import com.yuanchu.mom.pojo.DataReporting;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yuanchu.mom.pojo.FansSubmit;
import java.util.List;
import java.util.Map;
@@ -27,7 +28,7 @@
    Map<String, Object> getDataList();
    void addDataReporting(List<DataReporting> list);
    void addDataReporting(List<DataReporting> list, String date);
    Integer delDataReporting(Integer id);
@@ -37,4 +38,6 @@
    String downRegistrantCountFile(IPage<RegistrantCountDto> page, RegistrantCountDto registrantCountDto);
    String downFansSubmitFile(IPage<FansSubmit> page, FansSubmit fansSubmit);
}
data-server/src/main/java/com/yuanchu/mom/service/FansSubmitService.java
@@ -20,6 +20,6 @@
    int updateFansSubmit(FansSubmit fansSubmit);
    int addFansSubmit(FansSubmit fansSubmit);
    int addFansSubmit(FansSubmit fansSubmit, String date);
}
data-server/src/main/java/com/yuanchu/mom/service/FinanceSubmitService.java
@@ -20,6 +20,6 @@
    int updateFinanceSubmit(FinanceSubmit financeSubmit);
    int addFinanceSubmit(FinanceSubmit financeSubmit);
    int addFinanceSubmit(FinanceSubmit financeSubmit, String date);
}
data-server/src/main/java/com/yuanchu/mom/service/impl/DataReportingServiceImpl.java
@@ -19,15 +19,19 @@
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;
@@ -35,12 +39,12 @@
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;
/**
@@ -60,6 +64,12 @@
    @Value("${outPath}")
    private String outPath;
    @Resource
    private FansSubmitMapper fansSubmitMapper;
    @Resource
    private FansSubmitService fansSubmitService;
    @Override
    public Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) {
@@ -123,12 +133,15 @@
    @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) {
@@ -156,6 +169,7 @@
            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());
@@ -165,8 +179,11 @@
        }
    }
    @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);
    }
@@ -256,6 +273,35 @@
        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;
    }
}
data-server/src/main/java/com/yuanchu/mom/service/impl/FansSubmitServiceImpl.java
@@ -1,17 +1,28 @@
package com.yuanchu.mom.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.DataReportingPageDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.DataReportingMapper;
import com.yuanchu.mom.pojo.DataReporting;
import com.yuanchu.mom.pojo.FansSubmit;
import com.yuanchu.mom.service.FansSubmitService;
import com.yuanchu.mom.mapper.FansSubmitMapper;
import com.yuanchu.mom.utils.Jwt;
import com.yuanchu.mom.utils.QueryWrappers;
import com.yuanchu.mom.utils.ServletUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
@@ -29,6 +40,8 @@
    private GetLook getLook;
    private DataReportingMapper dataReportingMapper;
    @Override
    public Map<String, Object> selectFansSubmitList(IPage<FansSubmit> page, FansSubmit fansSubmit) {
        Map<String, Object> map = new HashMap<>();
@@ -39,20 +52,42 @@
        return map;
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int delFansSubmit(Integer id) {
        FansSubmit fansSubmit = fansSubmitMapper.selectOne(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getId, id).select(FansSubmit::getFansAdd, FansSubmit::getDataId));
        DataReporting dataReporting = dataReportingMapper.selectById(fansSubmit.getDataId());
        dataReporting.setFansAdd(dataReporting.getFansAdd() - fansSubmit.getFansAdd());
        dataReportingMapper.updateById(dataReporting);
        return fansSubmitMapper.deleteById(id);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateFansSubmit(FansSubmit fansSubmit) {
        DataReporting dataReporting = dataReportingMapper.selectById(fansSubmit.getDataId());
        dataReporting.setFansAdd(dataReporting.getFansAdd() + fansSubmit.getFansAdd() - fansSubmitMapper.selectOne(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getId, fansSubmit.getId()).select(FansSubmit::getFansAdd)).getFansAdd());
        dataReportingMapper.updateById(dataReporting);
        return fansSubmitMapper.updateById(fansSubmit);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int addFansSubmit(FansSubmit fansSubmit) {
    public int addFansSubmit(FansSubmit fansSubmit, String date) {
        if(date == null) date = getYesterday();
        DataReporting dataReporting = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getName, fansSubmit.getCustom()).eq(DataReporting::getProduct, fansSubmit.getProduct()).like(DataReporting::getCreateTime, date));
        if(ObjectUtil.isEmpty(dataReporting)){
            throw new ErrorException(date+" 客户:"+fansSubmit.getCustom()+" 并未上报过 "+fansSubmit.getProduct()+" 项目");
        }
        dataReporting.setFansAdd((dataReporting.getFansAdd()==null?0:dataReporting.getFansAdd()) + fansSubmit.getFansAdd());
        dataReportingMapper.updateById(dataReporting);
        fansSubmit.setDataId(dataReporting.getId());
        return fansSubmitMapper.insert(fansSubmit);
    }
    public String getYesterday(){
        return LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}
data-server/src/main/java/com/yuanchu/mom/service/impl/FinanceSubmitServiceImpl.java
@@ -1,9 +1,14 @@
package com.yuanchu.mom.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.DataReportingMapper;
import com.yuanchu.mom.pojo.DataReporting;
import com.yuanchu.mom.pojo.FansSubmit;
import com.yuanchu.mom.pojo.FinanceSubmit;
import com.yuanchu.mom.service.FinanceSubmitService;
@@ -12,6 +17,8 @@
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
@@ -28,6 +35,8 @@
    private FinanceSubmitMapper financeSubmitMapper;
    private GetLook getLook;
    private DataReportingMapper dataReportingMapper;
    @Override
    public Map<String, Object> selectFinanceSubmitList(IPage<FinanceSubmit> page, FinanceSubmit financeSubmit) {
@@ -50,9 +59,21 @@
    }
    @Override
    public int addFinanceSubmit(FinanceSubmit financeSubmit) {
    public int addFinanceSubmit(FinanceSubmit financeSubmit, String date) {
        if(date == null) date = getYesterday();
        DataReporting dataReporting = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getAgent, financeSubmit.getCompany()).eq(DataReporting::getName, financeSubmit.getName()).like(DataReporting::getCreateTime, date));
        if(ObjectUtil.isEmpty(dataReporting)){
            throw new ErrorException(date+" 账户:"+financeSubmit.getName()+" 的代理商:"+financeSubmit.getCompany()+" 并未上报过");
        }
        dataReporting.setAgentRebate(financeSubmit.getEmployeeRebate());
        dataReportingMapper.updateById(dataReporting);
        financeSubmit.setDataId(dataReporting.getId());
        return financeSubmitMapper.insert(financeSubmit);
    }
    public String getYesterday(){
        return LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}
data-server/src/main/resources/mapper/DataReportingMapper.xml
@@ -45,7 +45,7 @@
        select * from (
        select update_time, create_time, product, sum(consumption) consumption, sum(fans_add) fans_add, sum(customer_costs) customer_costs, create_user
        from data_reporting
        group by product
        group by product,date_format(create_time, '%Y-%m-%d')
        ) a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
@@ -55,7 +55,7 @@
        select * from (
        select id, department, registrant, product, name, sum(show_num) show_num, sum(click) click, sum(account_consumption)account_consumption, sum(rebate_consumption) rebate_consumption,(sum(rebate_consumption)+sum(remark)) rebate_consumption2, sum(discounted_consumption) discounted_consumption, sum(fans_add) fans_add, sum(actual_cost) actual_cost, sum(customer_costs) customer_costs, sum(profit) profit, sum(agent_rebate) agent_rebate, sum(customer_rebate) customer_rebate, sum(remark) remark, create_time, update_time, create_user
        from data_reporting
        group by registrant
        group by registrant,date_format(create_time, '%Y-%m-%d')
        ) a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java
@@ -183,7 +183,7 @@
    public Result<?> requestNotReadable(HttpMessageNotReadableException e) {
        e.printStackTrace();
        response.setStatus(201);
        return Result.fail("Http消息不可读");
        return Result.fail("参数传递错误");
    }
    /**