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);
|
}
|
}
|