jiangping
2024-11-25 d0fe6ceb4dbb8531e5e7714c5d05d03ec211d3a2
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwContractBillMapper;
import com.doumee.dao.business.YwContractRoomMapper;
import com.doumee.dao.business.model.YwContract;
import com.doumee.dao.business.model.YwContractBill;
import com.doumee.dao.business.model.YwContractRoom;
import com.doumee.dao.business.model.YwCustomer;
import com.doumee.dao.system.MultifileMapper;
import com.doumee.dao.system.model.Multifile;
import com.doumee.service.business.YwContractBillService;
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.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 运维合同账单信息表Service实现
 * @author 江蹄蹄
 * @date 2024/11/19 16:07
 */
@Service
public class YwContractBillServiceImpl implements YwContractBillService {
 
    @Autowired
    private YwContractBillMapper ywContractBillMapper;
 
    @Autowired
    private YwContractRoomMapper ywContractRoomMapper;
 
    @Autowired
    private MultifileMapper multifileMapper;
 
    @Override
    public Integer create(YwContractBill ywContractBill) {
        if(Objects.isNull(ywContractBill)
        || Objects.isNull(ywContractBill.getContractId())
        || Objects.isNull(ywContractBill.getTotleFee())
        || Objects.isNull(ywContractBill.getPlanPayData())
                || Objects.isNull(ywContractBill.getCostType())
                || Objects.isNull(ywContractBill.getBillType())
                || Objects.isNull(ywContractBill.getCompanyId())
                || Objects.isNull(ywContractBill.getStartDate())
                || Objects.isNull(ywContractBill.getEndDate())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywContractBill.getLoginUserInfo();
        ywContractBill.setCreateDate(new Date());
        ywContractBill.setCreator(loginUserInfo.getId());
        ywContractBill.setIsdeleted(Constants.ZERO);
        ywContractBill.setStatus(Constants.ZERO);
        ywContractBillMapper.insert(ywContractBill);
 
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getYwContractRoomList())){
            for (YwContractRoom ywContractRoom:ywContractBill.getYwContractRoomList()) {
                if(Objects.isNull(ywContractRoom)
                || Objects.isNull(ywContractRoom.getRoomId())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择房源数据");
                }
                ywContractRoom.setCreateDate(new Date());
                ywContractRoom.setCreator(loginUserInfo.getId());
                ywContractRoom.setIsdeleted(Constants.ZERO);
                ywContractRoom.setContractId(ywContractBill.getId());
                ywContractRoom.setType(Constants.ONE);
 
            }
            ywContractRoomMapper.insert(ywContractBill.getYwContractRoomList());
        }
 
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getMultifileList())){
            for (Multifile multifile:ywContractBill.getMultifileList()) {
                if(Objects.isNull(multifile)
                || StringUtils.isBlank(multifile.getFileurl())
                || StringUtils.isBlank(multifile.getName())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"附件信息错误");
                }
                multifile.setCreator(loginUserInfo.getId());
                multifile.setCreateDate(new Date());
                multifile.setIsdeleted(Constants.ZERO);
                multifile.setObjType(Constants.MultiFile.FN_PATROL_POINT_FILE.getKey());
                multifile.setObjId(ywContractBill.getId());
            }
            multifileMapper.insert(ywContractBill.getMultifileList());
        }
 
        return ywContractBill.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        ywContractBillMapper.deleteById(id);
    }
 
    @Override
    public void delete(YwContractBill ywContractBill) {
        UpdateWrapper<YwContractBill> deleteWrapper = new UpdateWrapper<>(ywContractBill);
        ywContractBillMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        ywContractBillMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(YwContractBill ywContractBill) {
        ywContractBillMapper.updateById(ywContractBill);
    }
 
    @Override
    public void updateByIdInBatch(List<YwContractBill> ywContractBills) {
        if (CollectionUtils.isEmpty(ywContractBills)) {
            return;
        }
        for (YwContractBill ywContractBill: ywContractBills) {
            this.updateById(ywContractBill);
        }
    }
 
    @Override
    public YwContractBill findById(Integer id) {
        return ywContractBillMapper.selectById(id);
    }
 
    @Override
    public YwContractBill findOne(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwContractBill> findList(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwContractBill> findPage(PageWrap<YwContractBill> pageWrap) {
        IPage<YwContractBill> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(YwContractBill.class)
                .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
        ;
 
        return PageData.from(ywContractBillMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectCount(wrapper);
    }
}