/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.property.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springblade.common.utils.SpringUtils;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.support.Kv;
|
import org.springblade.core.tool.utils.DateUtil;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.flow.business.service.IFlowService;
|
import org.springblade.flow.core.constant.ProcessConstant;
|
import org.springblade.flow.core.entity.BladeFlow;
|
import org.springblade.flow.core.utils.FlowUtil;
|
import org.springblade.flow.core.utils.TaskUtil;
|
import org.springblade.modules.district.entity.DistrictEntity;
|
import org.springblade.modules.district.service.IDistrictService;
|
import org.springblade.modules.ownersCommittee.entity.OwnersCommitteeEntity;
|
import org.springblade.modules.ownersCommittee.service.IOwnersCommitteeService;
|
import org.springblade.modules.property.entity.PropertyCapitalApplyEntity;
|
import org.springblade.modules.property.mapper.PropertyCapitalApplyMapper;
|
import org.springblade.modules.property.service.IPropertyCapitalApplyService;
|
import org.springblade.modules.property.vo.PropertyCapitalApplyVO;
|
import org.springblade.modules.system.entity.Dept;
|
import org.springblade.modules.system.entity.Region;
|
import org.springblade.modules.system.entity.User;
|
import org.springblade.modules.system.service.IDeptService;
|
import org.springblade.modules.system.service.IRegionService;
|
import org.springblade.modules.system.service.IUserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
/**
|
* 物业维修资金申请表 服务实现类
|
*
|
* @author BladeX
|
* @since 2023-11-23
|
*/
|
@Service
|
public class PropertyCapitalApplyServiceImpl extends ServiceImpl<PropertyCapitalApplyMapper, PropertyCapitalApplyEntity> implements IPropertyCapitalApplyService {
|
|
@Override
|
public IPage<PropertyCapitalApplyVO> selectPropertyCapitalApplyPage(IPage<PropertyCapitalApplyVO> page, PropertyCapitalApplyVO propertyCapitalApply) {
|
return page.setRecords(baseMapper.selectPropertyCapitalApplyPage(page, propertyCapitalApply));
|
}
|
|
@Autowired
|
private IFlowService flowService;
|
// private final IFlowService flowService;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean startProcess(PropertyCapitalApplyVO propertyCapitalApplyVO) {
|
String businessTable = FlowUtil.getBusinessTable(ProcessConstant.LEAVE_KEY);
|
// if (Func.isEmpty(propertyCapitalApplyVO.getId())) {
|
// 保存leave
|
propertyCapitalApplyVO.setApplyTime(DateUtil.now());
|
// save(propertyCapitalApplyVO);
|
// 判断是否有业委会
|
IOwnersCommitteeService bean = SpringUtils.getBean(IOwnersCommitteeService.class);
|
OwnersCommitteeEntity one = bean.getOne(Wrappers.<OwnersCommitteeEntity>lambdaQuery()
|
.eq(OwnersCommitteeEntity::getAreaId, propertyCapitalApplyVO.getDistrictId())
|
.last("limit 1"));
|
Integer ownersCommitteeFlag = 2;
|
if (one != null && one.getPrincipalId() != null) {
|
ownersCommitteeFlag = 1;
|
}
|
// 查询街道负责人 通过小区id 查询街道编码
|
// 通过街道编码查询街道名称,
|
// 通过街道名称查询 人的部门是街道名称的
|
|
IUserService user = SpringUtils.getBean(IUserService.class);
|
IDistrictService district = SpringUtils.getBean(IDistrictService.class);
|
IRegionService region = SpringUtils.getBean(IRegionService.class);
|
IDeptService dept = SpringUtils.getBean(IDeptService.class);
|
DistrictEntity one1 = district.getOne(Wrappers.<DistrictEntity>lambdaQuery()
|
.eq(DistrictEntity::getId, propertyCapitalApplyVO.getDistrictId()));
|
Region one2 = region.getOne(Wrappers.<Region>lambdaQuery().eq(Region::getCode, one1.getCommunityCode().substring(0, 9)));
|
Dept one3 = dept.getOne(Wrappers.<Dept>lambdaQuery().eq(Dept::getDeptName, one2.getName()));
|
User one4 = user.getOne(Wrappers.<User>lambdaQuery().eq(User::getDeptId, one3.getId()).last("limit 1"));
|
// 查询住建局负责人
|
Region region2 = region.getOne(Wrappers.<Region>lambdaQuery().eq(Region::getCode, one1.getCommunityCode().substring(0, 6)));
|
Dept dept3 = dept.getOne(Wrappers.<Dept>lambdaQuery().eq(Dept::getDeptName, region2.getName() + "住建局").last("limit 1"));
|
User user4 = user.getOne(Wrappers.<User>lambdaQuery().eq(User::getDeptId, dept3.getId()).last("limit 1"));
|
|
|
Kv variables = null;
|
// 启动流程
|
if (ownersCommitteeFlag.equals(1)) {
|
propertyCapitalApplyVO.setProcessDefinitionId("haveMaintenanceFundApply:1:c4117561-9fa6-11ee-8617-dc41a96f50f5");
|
// 经过业委会
|
variables = Kv.create()
|
.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName())
|
.set("ownersCommitteeUser", TaskUtil.getTaskUser(one.getPrincipalId().toString()))
|
.set("streetUser", TaskUtil.getTaskUser(one4.getId().toString()))
|
.set("constructionUser", TaskUtil.getTaskUser(user4.getId().toString()))
|
.set("applyUser", TaskUtil.getTaskUser(AuthUtil.getUserId().toString()))
|
.set("ownersCommitteeFlag", ownersCommitteeFlag);
|
} else {
|
propertyCapitalApplyVO.setProcessDefinitionId("notMaintenanceFundApply:1:289ac20c-9f43-11ee-8186-dc41a96f50f5");
|
// 经过街道
|
variables = Kv.create()
|
.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName())
|
.set("streetUser", TaskUtil.getTaskUser(one4.getId().toString()))
|
.set("constructionUser", TaskUtil.getTaskUser(user4.getId().toString()))
|
.set("applyUser", TaskUtil.getTaskUser(AuthUtil.getUserId().toString()))
|
.set("ownersCommitteeFlag", ownersCommitteeFlag);
|
}
|
BladeFlow flow = flowService.startProcessInstanceById(propertyCapitalApplyVO.getProcessDefinitionId(),
|
FlowUtil.getBusinessKey(businessTable, String.valueOf(propertyCapitalApplyVO.getId())), variables);
|
if (Func.isNotEmpty(flow)) {
|
log.debug("流程已启动,流程ID:" + flow.getProcessInstanceId());
|
// 返回流程id写入leave
|
propertyCapitalApplyVO.setProcessInstanceId(flow.getProcessInstanceId());
|
updateById(propertyCapitalApplyVO);
|
} else {
|
throw new ServiceException("开启流程失败");
|
}
|
// } else {
|
// updateById(propertyCapitalApplyVO);
|
// }
|
return true;
|
}
|
|
|
}
|