李林
2024-01-09 d0c3258ed4871f2b9f03357bfd39b6caeff156b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
 
/**
 * @author Administrator
 * @description 针对表【fans_sumbit(进粉上报)】的数据库操作Service实现
 * @createDate 2023-12-25 00:36:16
 */
@Service
@AllArgsConstructor
public class FansSubmitServiceImpl extends ServiceImpl<FansSubmitMapper, FansSubmit>
        implements FansSubmitService {
 
    private FansSubmitMapper fansSubmitMapper;
 
    private GetLook getLook;
 
    private DataReportingMapper dataReportingMapper;
 
    @Override
    public Map<String, Object> selectFansSubmitList(IPage<FansSubmit> page, FansSubmit fansSubmit) {
        Map<String, Object> map = new HashMap<>();
        map.put("head", PrintChina.printChina(FansSubmit.class));
        Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectFansSubmitList");
        if(map1.get("look")==1) fansSubmit.setCreateUser(map1.get("userId"));
        map.put("body", fansSubmitMapper.selectFansSubmitPageList(page, QueryWrappers.queryWrappers(fansSubmit)));
        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, String date) {
        if(date == null) date = getYesterday();
        DataReporting dataReporting = dataReportingMapper.selectOne(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getName, fansSubmit.getCustom()).eq(DataReporting::getProduct, fansSubmit.getProduct()).eq(DataReporting::getCreateUser, getLook.selectPowerByMethodAndUserId("selectRegistrantCountDtoPageList").get("userId")).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"));
    }
}