package com.doumee.service.business.impl;
|
|
import com.doumee.biz.system.SystemDictDataBiz;
|
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.*;
|
import com.doumee.dao.business.model.*;
|
import com.doumee.dao.system.MultifileMapper;
|
import com.doumee.dao.system.model.Multifile;
|
import com.doumee.dao.system.model.SystemUser;
|
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.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 运维合同账单信息表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;
|
|
@Autowired
|
private YwContractRevenueMapper ywContractRevenueMapper;
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Autowired
|
private YwContractMapper ywContractMapper;
|
|
|
|
@Override
|
public Integer create(YwContractBill ywContractBill) {
|
if(Objects.isNull(ywContractBill)
|
|| Objects.isNull(ywContractBill.getContractId())
|
|| Objects.isNull(ywContractBill.getTotleFee())
|
|| Objects.isNull(ywContractBill.getPlanPayDate())
|
|| Objects.isNull(ywContractBill.getCostType())
|
|| Objects.isNull(ywContractBill.getBillType())
|
|| Objects.isNull(ywContractBill.getCompanyId())
|
|| com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractBill.getYwContractRoomList())
|
|| Objects.nonNull(ywContractBill.getFeeType())
|
|| (Constants.equalsInteger(ywContractBill.getFeeType(),Constants.ZERO)&& (Objects.isNull(ywContractBill.getStartDate())
|
|| Objects.isNull(ywContractBill.getEndDate())))
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
YwContract ywContract = ywContractMapper.selectById(ywContractBill.getContractId());
|
if(Objects.isNull(ywContract)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
if(Constants.equalsInteger(ywContract.getStatus(),Constants.THREE)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"合同状态已流转,无法进行该操作");
|
}
|
|
LoginUserInfo loginUserInfo = ywContractBill.getLoginUserInfo();
|
ywContractBill.setReceivableFee(ywContractBill.getTotleFee());
|
ywContractBill.setCreateDate(new Date());
|
ywContractBill.setCreator(loginUserInfo.getId());
|
ywContractBill.setIsdeleted(Constants.ZERO);
|
ywContractBill.setType(Constants.ONE);
|
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_CONTRACT_BILL_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 getDetail(Integer id) {
|
YwContractBill ywContractBill = ywContractBillMapper.selectJoinOne(YwContractBill.class,
|
new MPJLambdaWrapper<YwContractBill>().selectAll(YwContractBill.class)
|
.select(" ( select ifnull(sum(yw.ACT_RECEIVABLE_FEE),0) from yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as actReceivableFee ")
|
.selectAs(YwContract::getCode,YwContractBill::getContractCode)
|
.selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
|
.leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
|
.leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
|
.eq(YwContractBill::getIsdeleted,Constants.ZERO)
|
.eq(YwContractBill::getId,id));
|
if(Objects.isNull(ywContractBill)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
|
//房源数据
|
ywContractBill.setYwContractRoomList(ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
|
.selectAll(YwContractRoom.class)
|
.selectAs(YwProject::getName,YwRoom::getProjectName)
|
.selectAs(YwFloor::getName,YwRoom::getFloorName)
|
.selectAs(YwBuilding::getName,YwRoom::getBuildingName)
|
.leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
|
.leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
|
.leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
|
.leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
|
.eq(YwContractRoom::getContractId,id)
|
.eq(YwContractRoom::getType,Constants.ONE)
|
));
|
|
//附件数据
|
List<Multifile> multifileList = multifileMapper.selectJoinList(Multifile.class,new MPJLambdaWrapper<Multifile>()
|
.selectAll(Multifile.class)
|
.selectAs(SystemUser::getRealname,Multifile::getUserName)
|
.leftJoin(SystemUser.class,SystemUser::getId,Multifile::getCreator)
|
.eq(Multifile::getObjId,id)
|
.eq(Multifile::getObjType,Constants.MultiFile.FN_CONTRACT_BILL_FILE.getKey()));
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){
|
String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
|
+systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_CONTRACT_BILL).getCode();
|
for (Multifile multifile:multifileList) {
|
if(StringUtils.isNotBlank(multifile.getFileurl())){
|
multifile.setFileurlFull(path + multifile.getFileurl());
|
}
|
}
|
ywContractBill.setMultifileList(multifileList);
|
}
|
return ywContractBill;
|
}
|
|
@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());
|
YwContractBill model = pageWrap.getModel();
|
IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
|
queryWrapper.selectAll(YwContractBill.class)
|
.select(" ( select ifnull(sum(yw.ACT_RECEIVABLE_FEE),0) from yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as actReceivableFee ")
|
.selectAs(YwContract::getCode,YwContractBill::getContractCode)
|
.selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
|
.leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
|
.leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
|
.eq(YwContractBill::getIsdeleted,Constants.ZERO)
|
.like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getCustomerName()),
|
YwCustomer::getName,model.getCustomerName())
|
.eq(Objects.nonNull(model)&&Objects.nonNull(model.getStatus()),
|
YwContractBill::getStatus,model.getStatus())
|
.eq(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
|
YwContractBill::getPayStatus,model.getPayStatus())
|
.eq(Objects.nonNull(model)&&Objects.nonNull(model.getType()),
|
YwContractBill::getType,model.getType())
|
.eq(Objects.nonNull(model)&&Objects.nonNull(model.getContractId()),
|
YwContractBill::getContractId,model.getContractId())
|
.ge(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateStart()),YwContractBill::getPlanPayDate, Utils.Date.getStart(model.getPlanPayDateStart()))
|
.le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd())) )
|
;
|
this.dealRoomDetail(iPage.getRecords());
|
for (YwContractBill ywContractBill:iPage.getRecords()) {
|
//需收金额
|
ywContractBill.setNeedReceivableFee(
|
ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
|
);
|
//是否逾期
|
if(Constants.equalsInteger(ywContractBill.getStatus(),Constants.ZERO) && (Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ZERO)
|
|| Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.TWO)
|
|| Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.THREE)
|
|| Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.FOUR))
|
&& ywContractBill.getEndDate().getTime() < System.currentTimeMillis()){
|
ywContractBill.setIsOverdue(Constants.ONE);
|
}else{
|
ywContractBill.setIsOverdue(Constants.ZERO);
|
}
|
//楼宇名称
|
List<YwContractRoom> ywContractRoomList = ywContractBill.getYwContractRoomList();
|
StringBuilder roomPathName = new StringBuilder();
|
for (YwContractRoom ywContractRoom:ywContractRoomList) {
|
if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
|
roomPathName.append(ywContractRoom.getProjectName());
|
}
|
if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
|
roomPathName.append(ywContractRoom.getBuildingName());
|
}
|
if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
|
roomPathName.append(ywContractRoom.getFloorName());
|
}
|
if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
|
roomPathName.append(ywContractRoom.getRoomName());
|
}
|
if(StringUtils.isNotBlank(roomPathName)){
|
roomPathName.append(";");
|
}
|
}
|
ywContractBill.setRoomPathName(roomPathName.toString());
|
}
|
|
return PageData.from(iPage);
|
}
|
|
public void dealRoomDetail(List<YwContractBill> ywContractBillList){
|
//查询账单下的楼宇数据
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
|
//获取所有数据
|
List<Integer> billIdList = ywContractBillList.stream().map(i->i.getId()).collect(Collectors.toList());
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(billIdList)){
|
List<YwContractRoom> ywContractRoomList = ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
|
.selectAll(YwContractRoom.class)
|
.selectAs(YwProject::getName,YwRoom::getProjectName)
|
.selectAs(YwFloor::getName,YwRoom::getFloorName)
|
.selectAs(YwBuilding::getName,YwRoom::getBuildingName)
|
.selectAs(YwRoom::getName,YwContractRoom::getRoomName)
|
.leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
|
.leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
|
.leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
|
.leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
|
.in(YwContractRoom::getContractId,billIdList)
|
.eq(YwContractRoom::getType,Constants.ONE)
|
);
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
|
for (YwContractBill ywContractBill:ywContractBillList) {
|
ywContractBill.setYwContractRoomList(
|
ywContractRoomList.stream().filter(i->Constants.equalsInteger(i.getContractId(),ywContractBill.getId())).collect(Collectors.toList())
|
);
|
}
|
}
|
}
|
}
|
}
|
|
|
@Override
|
public long count(YwContractBill ywContractBill) {
|
QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
|
return ywContractBillMapper.selectCount(wrapper);
|
}
|
|
|
|
@Override
|
public void dealDayBillCode(){
|
List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,
|
new MPJLambdaWrapper<YwContractBill>()
|
.selectAll(YwContractBill.class)
|
.select(" DATE(CREATE_DATE) as codeDate")
|
.isNull(YwContractBill::getCode)
|
.orderByAsc(YwContractBill::getId)
|
);
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
|
List<String> codeDateList = ywContractBillList.stream().map(i->i.getCodeDate()).collect(Collectors.toList());
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(codeDateList)){
|
Set<String> codeDateSet = new HashSet<String>(codeDateList);
|
for (String codeDate:codeDateSet) {
|
//获取当前日期的数据
|
List<YwContractBill> codeDateBillList =
|
ywContractBillList.stream().filter(i->i.getCodeDate().equals(codeDate)).collect(Collectors.toList());
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(codeDateBillList)){
|
continue;
|
}
|
//查询最大的单号
|
YwContractBill ywContractBill = ywContractBillMapper.selectOne(new QueryWrapper<YwContractBill>().lambda()
|
.isNotNull(YwContractBill::getCode)
|
.apply(" CREATE_DATE like '"+codeDate+"%' ")
|
.orderByDesc(YwContractBill::getId)
|
);
|
Integer maxCode = Constants.ONE;
|
if(Objects.nonNull(ywContractBill)){
|
maxCode = Integer.valueOf(ywContractBill.getCode().replace("ZD"+codeDate,""));
|
}
|
for (YwContractBill contractBill:codeDateBillList) {
|
maxCode = maxCode + 1;
|
contractBill.setCode("ZD" + codeDate + "-" + StringUtils.leftPad(maxCode.toString() , 4,"0"));
|
ywContractBillMapper.update(null, new UpdateWrapper<YwContractBill>().lambda().set(YwContractBill::getCode,contractBill.getCode())
|
.eq(YwContractBill::getId,ywContractBill.getId()));
|
}
|
}
|
}
|
}
|
}
|
|
|
|
}
|