| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.aizuda.bpm.engine.entity.FlwHisTask; |
| | | import com.aizuda.bpm.mybatisplus.mapper.FlwHisTaskMapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.constant.DictConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.ProcessCategoryEnum; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.bo.ProcessStartBO; |
| | | import com.ruoyi.system.dto.SignContractDTO; |
| | | import com.ruoyi.system.dto.TerminateContractDTO; |
| | | import com.ruoyi.system.mapper.TBillMapper; |
| | |
| | | import com.ruoyi.system.query.TContractAppletQuery; |
| | | import com.ruoyi.system.query.TContractBillQuery; |
| | | import com.ruoyi.system.query.TContractQuery; |
| | | import com.ruoyi.system.service.StateProcessTemplateService; |
| | | import com.ruoyi.system.service.TBillService; |
| | | import com.ruoyi.system.service.TContractRentTypeService; |
| | | import com.ruoyi.system.service.TContractService; |
| | |
| | | import com.ruoyi.system.vo.CheckAcceptRecordVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private TBillService billService; |
| | | @Resource |
| | | private TContractMapper contractMapper; |
| | | @Autowired |
| | | private StateProcessTemplateService stateProcessTemplateService; |
| | | @Autowired |
| | | private FlwHisTaskMapper flwHisTaskMapper; |
| | | |
| | | @Override |
| | | public PageInfo<TContract> contractList(TContractQuery query) { |
| | |
| | | for (TContract tContract : list) { |
| | | tContract.setPayType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_PAY_TYPE,tContract.getPayType())); |
| | | tContract.setStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_STATUS,tContract.getStatus())); |
| | | FlwHisTask flwHisTask = flwHisTaskMapper.selectOne(new LambdaQueryWrapper<FlwHisTask>() |
| | | .like(FlwHisTask::getVariable, tContract.getId()) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(flwHisTask)){ |
| | | tContract.setInstanceId(flwHisTask.getInstanceId()); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | |
| | | contract.setTerminateRemark(dto.getTerminateRemark()); |
| | | contract.setStatus("4"); |
| | | this.baseMapper.updateById(contract); |
| | | |
| | | // 进入合同提前终止审批流程 |
| | | ProcessStartBO processStartBO = new ProcessStartBO(); |
| | | processStartBO.setCategory(ProcessCategoryEnum.CATEGORY3.getValue().toString()); |
| | | processStartBO.setModuleName("合同提前终止审批"); |
| | | processStartBO.setName(contract.getContractName()); |
| | | processStartBO.setRemark(""); |
| | | Map<String, Object> variable = new HashMap<>(); |
| | | variable.put("projectId", dto.getId()); |
| | | processStartBO.setVariable(variable); |
| | | //开启工作流程 |
| | | stateProcessTemplateService.start(processStartBO); |
| | | |
| | | // 生成验收记录 |
| | | TCheckAcceptRecord tCheckAcceptRecord = new TCheckAcceptRecord(); |
| | | tCheckAcceptRecord.setContractId(dto.getId()); |
| | |
| | | contract.setFirstPayTime(contract.getStartTime().plusDays(10)); |
| | | contractMapper.updateById(contract); |
| | | |
| | | // TODO 进入签订审批流程 |
| | | |
| | | // 进入签订审批流程 |
| | | ProcessStartBO processStartBO = new ProcessStartBO(); |
| | | processStartBO.setCategory(ProcessCategoryEnum.CATEGORY2.getValue().toString()); |
| | | processStartBO.setModuleName("合同签订审批"); |
| | | processStartBO.setName(contract.getContractName()); |
| | | processStartBO.setRemark(""); |
| | | Map<String, Object> variable = new HashMap<>(); |
| | | variable.put("projectId", dto.getId()); |
| | | processStartBO.setVariable(variable); |
| | | //开启工作流程 |
| | | stateProcessTemplateService.startApplet(processStartBO); |
| | | |
| | | List<TContractRentType> contractRentTypes = contractRentTypeService.list(); |
| | | // 生成第一笔账单 |
| | |
| | | rentBill.setContractId(contract.getId()); |
| | | rentBill.setContractNumber(contract.getContractNumber()); |
| | | rentBill.setPayableFeesTime(firstPayTime.toLocalDate()); |
| | | if (firstPayTime.toLocalDate().equals(LocalDate.now())){ |
| | | rentBill.setPayFeesStatus("1"); |
| | | }else { |
| | | rentBill.setPayFeesStatus("2"); |
| | | } |
| | | |
| | | rentBill.setBillType("1"); |
| | | rentBill.setStartTime(contract.getStartPayTime()); |
| | | TContractRentType tContractRentType = contractRentTypes.stream().filter(e -> e.getContractId().equals(contract.getId())).findFirst().orElse(null); |
| | |
| | | } |
| | | }else{ |
| | | if (contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).isAfter(contract.getEndTime())){ |
| | | rentBill.setEndTime(contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12)); |
| | | }else{ |
| | | rentBill.setEndTime(contract.getEndTime()); |
| | | |
| | | }else{ |
| | | LocalDateTime firstPayTime1 = contract.getFirstPayTime(); |
| | | // 将firstPayTime1的日设置为当月最后一天 |
| | | rentBill.setEndTime(firstPayTime1.with(TemporalAdjusters.lastDayOfMonth())); |
| | | } |
| | | // 不走递增递减 |
| | | long allDays = ChronoUnit.DAYS.between(contract.getFirstPayTime(), rentBill.getEndTime()); |
| | | long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime().minusDays(1), rentBill.getEndTime()); |
| | | rentBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays))); |
| | | rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney()); |
| | | |
| | |
| | | depositBill.setStartTime(contract.getStartPayTime()); |
| | | depositBill.setEndTime(contract.getEndTime()); |
| | | depositBill.setPayableFeesTime(firstPayTime.toLocalDate()); |
| | | if (firstPayTime.toLocalDate().equals(LocalDate.now())){ |
| | | |
| | | depositBill.setPayFeesStatus("1"); |
| | | |
| | | }else { |
| | | depositBill.setPayFeesStatus("2"); |
| | | |
| | | } |
| | | depositBill.setBillType("2"); |
| | | this.updateById(contract); |
| | | billService.save(rentBill); |
| | |
| | | |
| | | |
| | | while(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).isBefore(contract.getEndTime())){ |
| | | |
| | | TBill tBill = new TBill(); |
| | | tBill.setContractId(contract.getId()); |
| | | tBill.setContractNumber(contract.getContractNumber()); |
| | |
| | | |
| | | } |
| | | }else{ |
| | | long allDays = ChronoUnit.DAYS.between(beforeBill.getEndTime(), (contract.getPayType().equals("1")? |
| | | beforeBill.getEndTime().plusMonths(1):contract.getPayType().equals("2")? |
| | | beforeBill.getEndTime().plusMonths(3):beforeBill.getEndTime().plusMonths(12)).with(TemporalAdjusters.lastDayOfMonth())); |
| | | tBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays))); |
| | | |
| | | tBill.setPayableFeesMoney(contract.getMonthRent()); |
| | | tBill.setOutstandingMoney(tBill.getPayableFeesMoney()); |
| | | |
| | | } |
| | |
| | | beforeBill.getEndTime().plusMonths(1).withDayOfMonth(15).toLocalDate():contract.getPayType().equals("2")? |
| | | beforeBill.getEndTime().plusMonths(3).withDayOfMonth(15).toLocalDate():beforeBill.getEndTime().withDayOfMonth(15).plusMonths(12).toLocalDate())); |
| | | } |
| | | tBill.setPayFeesStatus("2"); |
| | | tBill.setPayFeesStatus("1"); |
| | | tBill.setBillType("1"); |
| | | tBill.setStartTime(beforeBill.getEndTime().plusDays(1)); |
| | | tBill.setEndTime(contract.getEndTime()); |
| | | } |
| | | tBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).with(TemporalAdjusters.lastDayOfMonth())); |
| | | billMapper.insert(tBill); |
| | | } |
| | | beforeBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).with(TemporalAdjusters.lastDayOfMonth())); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime) |
| | | TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getStartTime) |
| | | .last("limit 1").one(); |
| | | // 生成最后一笔账单 |
| | | if (!(beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate())) |
| | | && |
| | | (contract.getPayType().equals("1")? |
| | | beforeBill.getEndTime().plusMonths(1):contract.getPayType().equals("2")? |
| | | beforeBill.getEndTime().plusMonths(3):beforeBill.getEndTime().plusMonths(12)) |
| | | .with(TemporalAdjusters.lastDayOfMonth()).isAfter(contract.getEndTime()) |
| | | && beforeBill.getEndTime().isBefore(contract.getEndTime()) |
| | | ){ |
| | | TBill tBill = new TBill(); |
| | |
| | | |
| | | } |
| | | tBill.setContractNumber(contract.getContractNumber()); |
| | | if (beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).getDayOfMonth()<=15){ |
| | | if (contract.getEndTime().getDayOfMonth()<=15){ |
| | | tBill.setPayableFeesTime(contract.getEndTime().withHour(0).withMinute(0).withSecond(0).toLocalDate()); |
| | | }else{ |
| | | tBill.setPayableFeesTime((contract.getPayType().equals("1")? |
| | |
| | | tBill.setPayFeesStatus("1"); |
| | | tBill.setBillType("1"); |
| | | tBill.setStartTime(beforeBill.getEndTime().plusDays(1)); |
| | | tBill.setEndTime(beforeBill.getEndTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12)); |
| | | tBill.setEndTime(contract.getEndTime()); |
| | | billService.save(tBill); |
| | | } |
| | | |