package com.ruoyi.collaborativeApproval.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.collaborativeApproval.dto.BroadbandCommunicationDTO;
|
import com.ruoyi.collaborativeApproval.mapper.BroadbandCommunicationMapper;
|
import com.ruoyi.collaborativeApproval.pojo.BroadbandCommunication;
|
import com.ruoyi.collaborativeApproval.service.BroadbandCommunicationService;
|
import com.ruoyi.collaborativeApproval.vo.BroadbandCommunicationVO;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDate;
|
import java.util.List;
|
|
@Service
|
public class BroadbandCommunicationServiceImpl extends ServiceImpl<BroadbandCommunicationMapper, BroadbandCommunication> implements BroadbandCommunicationService {
|
|
@Override
|
public IPage<BroadbandCommunicationVO> listPage(Page<BroadbandCommunication> page, BroadbandCommunicationDTO dto) {
|
LambdaQueryWrapper<BroadbandCommunication> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(BroadbandCommunication::getDelFlag, "0");
|
|
if (StringUtils.isNotBlank(dto.getArea())) {
|
queryWrapper.like(BroadbandCommunication::getArea, dto.getArea());
|
}
|
if (StringUtils.isNotBlank(dto.getOffice())) {
|
queryWrapper.like(BroadbandCommunication::getOffice, dto.getOffice());
|
}
|
if (StringUtils.isNotBlank(dto.getResidentStaff())) {
|
queryWrapper.like(BroadbandCommunication::getResidentStaff, dto.getResidentStaff());
|
}
|
|
if (StringUtils.isNotBlank(dto.getWarnStatus())) {
|
LocalDate today = LocalDate.now();
|
if ("expiring".equals(dto.getWarnStatus())) {
|
// 即将到期: nextPaymentDate 在今天到15天之后之间,且不包括小于今天
|
LocalDate future15 = today.plusDays(15);
|
queryWrapper.ge(BroadbandCommunication::getNextPaymentDate, today)
|
.le(BroadbandCommunication::getNextPaymentDate, future15);
|
} else if ("overdue".equals(dto.getWarnStatus())) {
|
// 已逾期: nextPaymentDate < 今天
|
queryWrapper.lt(BroadbandCommunication::getNextPaymentDate, today);
|
} else if ("normal".equals(dto.getWarnStatus())) {
|
// 正常: nextPaymentDate > 15天之后
|
LocalDate future15 = today.plusDays(15);
|
queryWrapper.gt(BroadbandCommunication::getNextPaymentDate, future15);
|
}
|
}
|
|
queryWrapper.orderByDesc(BroadbandCommunication::getCreateTime);
|
|
IPage<BroadbandCommunication> p = this.page(page, queryWrapper);
|
return p.convert(this::convertToVO);
|
}
|
|
@Override
|
public BroadbandCommunicationVO getDetail(Long id) {
|
BroadbandCommunication entity = this.getById(id);
|
if (entity != null && "0".equals(entity.getDelFlag())) {
|
return convertToVO(entity);
|
}
|
return null;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean addOrUpdate(BroadbandCommunicationDTO dto) {
|
BroadbandCommunication entity = new BroadbandCommunication();
|
BeanUtils.copyProperties(dto, entity);
|
|
// Calculate nextPaymentDate automatically if installDate and paymentCycle are present
|
if (entity.getInstallDate() != null && entity.getPaymentCycle() != null) {
|
entity.setNextPaymentDate(entity.getInstallDate().plusMonths(entity.getPaymentCycle()));
|
}
|
|
if (entity.getId() == null) {
|
return this.save(entity);
|
} else {
|
return this.updateById(entity);
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean deleteByIds(List<Long> ids) {
|
if (ids != null && !ids.isEmpty()) {
|
return this.removeByIds(ids);
|
}
|
return false;
|
}
|
|
private BroadbandCommunicationVO convertToVO(BroadbandCommunication entity) {
|
BroadbandCommunicationVO vo = new BroadbandCommunicationVO();
|
BeanUtils.copyProperties(entity, vo);
|
return vo;
|
}
|
}
|