李林
2024-02-28 780578502875aa0c339cb73f11b1e635df458c77
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.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.QueryWrappers;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
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::getProduct,FansSubmit::getVx,FansSubmit::getCreateTime));
        fansSubmitMapper.deleteById(id);
        List<FansSubmit> fansSubmits = fansSubmitMapper.selectList(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getProduct, fansSubmit.getProduct()).eq(FansSubmit::getVx, fansSubmit.getVx()).select(FansSubmit::getFansAdd).like(FansSubmit::getCreateTime, fansSubmit.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
        Integer sum = 0;
        for (FansSubmit fansSubmit2 : fansSubmits) {
            sum += fansSubmit2.getFansAdd();
        }
        List<DataReporting> dataReportings = dataReportingMapper.selectList(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, fansSubmit.getProduct()).eq(DataReporting::getVxCard, fansSubmit.getVx()).like(DataReporting::getCreateTime, fansSubmit.getCreateTime().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
        for (DataReporting dataReporting : dataReportings) {
            dataReporting.setFansAdd(sum);
            dataReportingMapper.updateById(dataReporting);
        }
        return 1;
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateFansSubmit(FansSubmit fansSubmit3) {
        fansSubmitMapper.updateById(fansSubmit3);
        FansSubmit fansSubmit = fansSubmitMapper.selectOne(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getId, fansSubmit3.getId()).select(FansSubmit::getFansAdd,FansSubmit::getProduct,FansSubmit::getVx,FansSubmit::getCreateTime));
        List<FansSubmit> fansSubmits = fansSubmitMapper.selectList(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getProduct, fansSubmit.getProduct()).eq(FansSubmit::getVx, fansSubmit.getVx()).select(FansSubmit::getFansAdd).like(FansSubmit::getCreateTime, fansSubmit.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
        Integer sum = 0;
        for (FansSubmit fansSubmit2 : fansSubmits) {
            sum += fansSubmit2.getFansAdd();
        }
        List<DataReporting> dataReportings = dataReportingMapper.selectList(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, fansSubmit.getProduct()).eq(DataReporting::getVxCard, fansSubmit.getVx()).like(DataReporting::getCreateTime, fansSubmit.getCreateTime().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
        for (DataReporting dataReporting : dataReportings) {
            dataReporting.setFansAdd(sum);
            dataReportingMapper.updateById(dataReporting);
        }
        return 1;
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int addFansSubmit(FansSubmit fansSubmit, String date) {
        String date2 = null;
        if(date == null) {
            date = getToday();
            date2 = getYesterday();
        }else{
            date = LocalDateTime.parse(date + "T00:00:00").plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            date2 = LocalDateTime.parse(date + "T00:00:00").minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            fansSubmit.setCreateTime(LocalDateTime.parse(date + "T00:00:00"));
        }
        fansSubmitMapper.insert(fansSubmit);
        List<FansSubmit> fansSubmits = fansSubmitMapper.selectList(Wrappers.<FansSubmit>lambdaQuery().eq(FansSubmit::getProduct, fansSubmit.getProduct()).eq(FansSubmit::getVx, fansSubmit.getVx()).select(FansSubmit::getFansAdd).like(FansSubmit::getCreateTime, date));
        Integer sum = 0;
        for (FansSubmit fansSubmit2 : fansSubmits) {
            sum += fansSubmit2.getFansAdd();
        }
        List<DataReporting> dataReportings = dataReportingMapper.selectList(Wrappers.<DataReporting>lambdaQuery().eq(DataReporting::getProduct, fansSubmit.getProduct()).eq(DataReporting::getVxCard, fansSubmit.getVx()).like(DataReporting::getCreateTime, date2).orderByDesc(DataReporting::getAccountConsumption));
        for (DataReporting dataReporting : dataReportings) {
            dataReporting.setFansAdd(sum);
            dataReportingMapper.updateById(dataReporting);
        }
        return 1;
    }
 
    @Override
    public String getYesterday(){
        return LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
 
    public String getToday(){
        return LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
 
    @Override
    public List<FansSubmit> vxs(String date) {
        String format = LocalDateTime.parse(date.replace(" ", "T")).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        QueryWrapper<FansSubmit> queryWrapper = new QueryWrapper<FansSubmit>();
        queryWrapper.select("DISTINCT vx").like("create_time", format);
        return fansSubmitMapper.selectList(queryWrapper);
    }
}