package com.doumee.service.business.impl; import com.doumee.core.constants.Constants; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; import com.doumee.dao.business.MemberRidesMapper; import com.doumee.dao.business.join.MemberRidesJoinMapper; import com.doumee.dao.business.model.BaseParam; import com.doumee.dao.business.model.Goodsorder; import com.doumee.dao.business.model.Member; import com.doumee.dao.business.model.MemberRides; import com.doumee.dao.business.web.request.MemberRidesQuery; import com.doumee.dao.business.web.response.BikeLogDTO; import com.doumee.dao.business.web.response.MemberRidesDTO; import com.doumee.service.business.DeviceService; import com.doumee.service.business.MemberRidesService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Objects; /** * 用户骑行记录表Service实现 * @author 江蹄蹄 * @date 2023/09/27 18:06 */ @Service public class MemberRidesServiceImpl implements MemberRidesService { @Autowired private MemberRidesMapper memberRidesMapper; @Autowired private MemberRidesJoinMapper memberRidesJoinMapper; @Autowired private DeviceService deviceService; @Override public String create(MemberRides memberRides) { memberRidesMapper.insert(memberRides); return memberRides.getId(); } @Override public void deleteById(String id) { memberRidesMapper.deleteById(id); } @Override public void delete(MemberRides memberRides) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(memberRides); memberRidesMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } memberRidesMapper.deleteBatchIds(ids); } @Override public void updateById(MemberRides memberRides) { memberRidesMapper.updateById(memberRides); } @Override public void updateByIdInBatch(List memberRidess) { if (CollectionUtils.isEmpty(memberRidess)) { return; } for (MemberRides memberRides: memberRidess) { this.updateById(memberRides); } } @Override public MemberRides findById(String id) { return memberRidesMapper.selectById(id); } @Override public MemberRides findOne(MemberRides memberRides) { QueryWrapper wrapper = new QueryWrapper<>(memberRides); return memberRidesMapper.selectOne(wrapper); } @Override public List findList(MemberRides memberRides) { QueryWrapper wrapper = new QueryWrapper<>(memberRides); return memberRidesMapper.selectList(wrapper); } /** * * @param pageWrap 分页对象 * @return */ @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = initQueryParamByModel(pageWrap.getModel()); IPage memberRidesDTOIPage = memberRidesJoinMapper.selectJoinPage(page, MemberRidesDTO.class, queryWrapper); if (!CollectionUtils.isEmpty(memberRidesDTOIPage.getRecords())){ memberRidesDTOIPage.getRecords().forEach(s->{ if (Objects.nonNull(s.getBackDate())){ s.setRideTime(DateUtil.betweenMin(s.getRentDate(),s.getBackDate())); } }); } return PageData.from(memberRidesDTOIPage); } @Override public long count(MemberRides memberRides) { QueryWrapper wrapper = new QueryWrapper<>(memberRides); return memberRidesMapper.selectCount(wrapper); } @Override public PageData findBikeLog(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = initQueryParamByModel(pageWrap.getModel()); IPage bikeLogDTOIPage = memberRidesJoinMapper.selectJoinPage(page, BikeLogDTO.class, queryWrapper); if (!CollectionUtils.isEmpty(bikeLogDTOIPage.getRecords())){ bikeLogDTOIPage.getRecords().forEach(s->{ if (Objects.nonNull(s.getBackDate())){ s.setRideTime(DateUtil.betweenMin(s.getRentDate(),s.getBackDate())); } }); } return PageData.from(bikeLogDTOIPage); } private MPJLambdaWrapper initQueryParamByModel(MemberRidesQuery model) { MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); Utils.MP.blankToNull(model); queryWrapper.orderByDesc(MemberRides::getCreateDate); queryWrapper.leftJoin(Member.class,Member::getId,MemberRides::getMemberId) .leftJoin(BaseParam.class,BaseParam::getId,MemberRides::getParamId) .eq(BaseParam::getType, Constants.THREE) .like(StringUtils.isNotBlank(model.getOpenid()),Member::getOpenid,model.getOpenid()) .like(StringUtils.isNotBlank(model.getBikeCode()),MemberRides::getBikeCode,model.getBikeCode()); queryWrapper.ge(model.getRentDateStart()!=null, MemberRides::getRentDate,model.getRentDateStart()); queryWrapper.le(model.getRentDateEnd()!=null, MemberRides::getRentDate,model.getRentDateEnd()); queryWrapper.eq(model.getCloseStatus()!=null,MemberRides::getCloseStatus, model.getCloseStatus()); queryWrapper.selectAs(Member::getOpenid,MemberRidesDTO::getOpenid) .selectAs(MemberRides::getBikeCode,MemberRidesDTO::getBikeCode) .selectAs(MemberRides::getCloseStatus,MemberRidesDTO::getCloseStatus) .selectAs(MemberRides::getStatus,MemberRidesDTO::getStatus) .selectAs(BaseParam::getName,MemberRidesDTO::getBikeType) .selectAs(MemberRides::getDuration,MemberRidesDTO::getDuration) .selectAs(MemberRides::getRentDate,MemberRidesDTO::getRentDate) .selectAs(MemberRides::getBackDate,MemberRidesDTO::getBackDate); return queryWrapper; } @Override public String getOnlineBike(String memberId){ MemberRides memberRides = memberRidesMapper.selectOne(new QueryWrapper() .eq("isdeleted", Constants.ZERO) .eq("member_id",memberId) .eq("status",Constants.MEMBER_RIDES_STATUS.RIDES_RUNNING.getKey()) .last(" limit 1 ") ); if(Objects.isNull(memberRides)){ return null; } return memberRides.getBikeCode(); } }