hsy
2026-08-28 a8e4132c3e2e9c3b3fcb0360901b35571b6464ea
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
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;
    }
}