package com.doumee.service.business.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Utils; import com.doumee.dao.business.join.LabelsJoinMapper; import com.doumee.dao.business.join.MonthlySettlementJoinMapper; import com.doumee.dao.business.model.Areas; import com.doumee.dao.business.model.Fund; import com.doumee.dao.business.model.Labels; import com.doumee.dao.business.model.MonthlySettlement; import com.doumee.service.business.MonthlySettlementService; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class MonthlySettlementServiceImpl implements MonthlySettlementService { @Autowired private MonthlySettlementJoinMapper monthlySettlementJoinMapper; @Override public MonthlySettlement findOne(MonthlySettlement monthlySettlement) { MPJLambdaWrapper query = new MPJLambdaWrapper<>(); // query.eq("DATE_FORMAT(t.CREATE_DATE, '%Y-%m')","DATE_FORMAT( LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)), '%Y-%m')"); query.orderByDesc(MonthlySettlement::getCreateTime); query.last("limit 1"); MonthlySettlement result=monthlySettlementJoinMapper.selectOne(query); return result; } @Override public void update(MonthlySettlement monthlySettlement) { monthlySettlementJoinMapper.updateById(monthlySettlement); } @Override public Integer intsert(MonthlySettlement monthlySettlement) { return monthlySettlementJoinMapper.insert(monthlySettlement); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); queryWrapper.selectAll(MonthlySettlement.class); queryWrapper.select("(select sum(NUM) from fund f " + " where f.ISDELETED=0 and f.TYPE=0 and DATE_FORMAT(t.CREATE_TIME, '%Y-%m')= DATE_FORMAT(f.CREATE_DATE, '%Y-%m') ) as monthAdd"); queryWrapper.select("(select sum(NUM) from fund f " + " where f.ISDELETED=0 and f.TYPE=1 and DATE_FORMAT(t.CREATE_TIME, '%Y-%m')= DATE_FORMAT(f.CREATE_DATE, '%Y-%m') ) as monthSub"); queryWrapper.eq(pageWrap.getModel().getYear()!=null,MonthlySettlement::getYear,pageWrap.getModel().getYear()); queryWrapper.orderByDesc(MonthlySettlement::getCreateTime); IPage result = monthlySettlementJoinMapper.selectJoinPage(page, MonthlySettlement.class, queryWrapper); return PageData.from(result); } @Override public List Listall(MonthlySettlement pageWrap) { MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); queryWrapper.selectAll(MonthlySettlement.class); queryWrapper.select("(select sum(NUM) from fund f " + " where f.ISDELETED=0 and f.TYPE=0 and DATE_FORMAT(t.CREATE_TIME, '%Y-%m')= DATE_FORMAT(f.CREATE_DATE, '%Y-%m') ) as monthAdd"); queryWrapper.select("(select sum(NUM) from fund f " + " where f.ISDELETED=0 and f.TYPE=1 and DATE_FORMAT(t.CREATE_TIME, '%Y-%m')= DATE_FORMAT(f.CREATE_DATE, '%Y-%m') ) as monthSub"); queryWrapper.eq(pageWrap.getYear()!=null,MonthlySettlement::getYear,pageWrap.getYear()); queryWrapper.orderByDesc(MonthlySettlement::getCreateTime); List result = monthlySettlementJoinMapper.selectJoinList(MonthlySettlement.class, queryWrapper); return result; } }