|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.ruoyi.common.annotation.Log; | 
|---|
|  |  |  | import com.ruoyi.common.basic.PageInfo; | 
|---|
|  |  |  | import com.ruoyi.common.constant.DictConstants; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.R; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.model.LoginUserApplet; | 
|---|
|  |  |  | import com.ruoyi.common.enums.BusinessType; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DateUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DictUtils; | 
|---|
|  |  |  | import com.ruoyi.framework.web.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.system.dto.RevokeDTO; | 
|---|
|  |  |  | import com.ruoyi.system.dto.SignContractDTO; | 
|---|
|  |  |  | import com.ruoyi.system.model.TContract; | 
|---|
|  |  |  | import com.ruoyi.system.model.TContractRentType; | 
|---|
|  |  |  | import com.ruoyi.system.model.THouse; | 
|---|
|  |  |  | import com.ruoyi.system.model.TTenant; | 
|---|
|  |  |  | import com.ruoyi.system.query.TContractAppletQuery; | 
|---|
|  |  |  | import com.ruoyi.system.query.TContractQuery; | 
|---|
|  |  |  | import com.ruoyi.system.service.TBillService; | 
|---|
|  |  |  | import com.ruoyi.system.service.TContractRentTypeService; | 
|---|
|  |  |  | import com.ruoyi.system.service.TContractService; | 
|---|
|  |  |  | import com.ruoyi.system.service.THouseService; | 
|---|
|  |  |  | import com.ruoyi.system.service.*; | 
|---|
|  |  |  | import com.ruoyi.system.vo.TContractAppletVO; | 
|---|
|  |  |  | import com.ruoyi.system.vo.TContractVO; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | 
|---|
|  |  |  | private TBillService billService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  | @ApiOperation(value = "签订合同") | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TTenantService tTenantService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StateProcessTemplateService stateProcessTemplateService; | 
|---|
|  |  |  | @ApiOperation(value = " 签订合同") | 
|---|
|  |  |  | @PostMapping(value = "/signContract") | 
|---|
|  |  |  | public R signContract(@RequestBody SignContractDTO dto) { | 
|---|
|  |  |  | return contractService.signContract(dto); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "我的合同分页列表") | 
|---|
|  |  |  | @PostMapping(value = "/contractList") | 
|---|
|  |  |  | public R<PageInfo<TContract>> contractList(@RequestBody TContractAppletQuery query) { | 
|---|
|  |  |  | // todo 获取登陆人id | 
|---|
|  |  |  | LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet(); | 
|---|
|  |  |  | if (loginUserApplet==null){ | 
|---|
|  |  |  | return R.fail(401,"登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | query.setTenantId(loginUserApplet.getUserId()); | 
|---|
|  |  |  | return R.ok(contractService.contractAppletList(query)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Log(title = "合同管理-撤销审批", businessType =  BusinessType.UPDATE) | 
|---|
|  |  |  | @ApiOperation(value = "撤销审批") | 
|---|
|  |  |  | @PostMapping(value = "/updateContractStatus") | 
|---|
|  |  |  | public R<Boolean> updateContractStatus(@RequestBody RevokeDTO dto) { | 
|---|
|  |  |  | TContract contract = contractService.getById(dto.getContractId()); | 
|---|
|  |  |  | contract.setStatus("1"); | 
|---|
|  |  |  | contractService.updateById(contract); | 
|---|
|  |  |  | // 撤销审批实例 | 
|---|
|  |  |  | stateProcessTemplateService.revoke(dto.getInstanceId()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation(value = "查询合同信息信息") | 
|---|
|  |  |  | @GetMapping(value = "/getContractById") | 
|---|
|  |  |  | public R<TContractVO> getContractById(@RequestParam String id) { | 
|---|
|  |  |  | TContractVO res = new TContractVO(); | 
|---|
|  |  |  | public R<TContractAppletVO> getContractById(@RequestParam String id) { | 
|---|
|  |  |  | LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet(); | 
|---|
|  |  |  | if (loginUserApplet==null){ | 
|---|
|  |  |  | return R.fail(401,"登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TContractAppletVO res = new TContractAppletVO(); | 
|---|
|  |  |  | TContract contract = contractService.getById(id); | 
|---|
|  |  |  | BeanUtils.copyProperties(contract,res); | 
|---|
|  |  |  | res.setStartTimeString(DateUtils.localDateTimeToStringYear(contract.getStartTime())); | 
|---|
|  |  |  | res.setEndTimeString(DateUtils.localDateTimeToStringYear(contract.getEndTime())); | 
|---|
|  |  |  | res.setPayType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_PAY_TYPE,res.getPayType())); | 
|---|
|  |  |  | res.setStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_STATUS,res.getStatus())); | 
|---|
|  |  |  | TContractRentType contractRentType = contractRentTypeService.lambdaQuery().eq(TContractRentType::getContractId, id).one(); | 
|---|
|  |  |  | if (contractRentType!=null){ | 
|---|
|  |  |  | BeanUtils.copyProperties(contractRentType,res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TTenant tTenant = tTenantService.getById(contract.getTenantId()); | 
|---|
|  |  |  | res.setTenant(tTenant); | 
|---|
|  |  |  | TContract oldContract = contractService.getOne(new LambdaQueryWrapper<TContract>() | 
|---|
|  |  |  | .eq(TContract::getHouseId,contract.getHouseId()) | 
|---|
|  |  |  | .eq(TContract::getTenantId,loginUserApplet.getUserId()) | 
|---|
|  |  |  | .eq(TContract::getStatus, 4) | 
|---|
|  |  |  | .le(TContract::getStartTime, LocalDateTime.now()) | 
|---|
|  |  |  | .ge(TContract::getEndTime, LocalDateTime.now())); | 
|---|