2021-10-29 10:15:36 +00:00
package cn.palmte.work.service ;
2021-11-02 09:33:34 +00:00
import cn.palmte.work.bean.* ;
2021-11-15 08:53:43 +00:00
import cn.palmte.work.model.* ;
2021-11-18 09:39:31 +00:00
import cn.palmte.work.utils.InterfaceUtil ;
2021-11-15 08:53:43 +00:00
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
2021-10-29 10:15:36 +00:00
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
2021-11-25 03:34:38 +00:00
import org.springframework.transaction.annotation.Transactional ;
2021-10-29 10:15:36 +00:00
import top.jfunc.common.db.QueryHelper ;
import top.jfunc.common.db.bean.Page ;
import top.jfunc.common.db.utils.Pagination ;
2021-11-12 07:12:44 +00:00
import top.jfunc.common.utils.CollectionUtil ;
2021-10-29 10:15:36 +00:00
import top.jfunc.common.utils.StrUtil ;
2021-11-19 06:47:59 +00:00
import java.util.* ;
import java.util.stream.Collectors ;
2021-10-29 10:15:36 +00:00
/ * *
* @author xiongshiyan at 2021 / 10 / 29 , contact me with email yanshixiong @ 126. com or phone 15208384257
* /
@Service
public class ProjectService {
@Autowired
private Pagination pagination ;
2021-11-01 11:00:53 +00:00
@Autowired
private ProjectRepository projectRepository ;
2021-11-01 12:07:02 +00:00
@Autowired
2021-11-18 08:07:33 +00:00
private SysConfigService sysConfigService ;
2021-11-12 07:12:44 +00:00
@Autowired
private ActTaskDefService actTaskDefService ;
2021-11-15 08:53:43 +00:00
@Autowired
private ProjectInstanceRelationRepository projectInstanceRelationRepository ;
2021-11-19 06:47:59 +00:00
@Autowired
private DeptRepository deptRepository ;
@Autowired
private ProjectVisibleRepository projectVisibleRepository ;
@Autowired
private SysRoleRepository sysRoleRepository ;
@Autowired
private AdminRepository adminRepository ;
2021-11-25 03:34:38 +00:00
@Autowired
private ProjectEstimateService projectEstimateService ;
2021-12-28 07:42:42 +00:00
@Autowired
private ProjectInstanceService projectInstanceService ;
@Autowired
private ProjectBudgetService projectBudgetService ;
2022-08-15 02:15:21 +00:00
@Autowired
private NumSeqService numSeqService ;
2021-10-29 10:15:36 +00:00
2021-11-18 08:39:59 +00:00
private QueryHelper getQueryHelper ( Map < String , String > searchInfo ) {
2021-10-29 10:15:36 +00:00
/ * "CASE p.type WHEN 1 THEN '工程集成类' WHEN 2 THEN '设备集成类' WHEN 3 THEN '战略合作类' ELSE '未知' AS typeDesc," +
"CASE p.status WHEN 0 THEN '草稿' WHEN 1 THEN '项目创建' WHEN 5 THEN '概算完成' WHEN 10 THEN '预算完成' WHEN 15 THEN '结算中' WHEN 20 THEN '决算完成' ELSE '未知' AS statusDesc," +
"CASE p.approve_status WHEN 0 THEN '待审核' WHEN 1 THEN '审核通过' WHEN 2 THEN '审核不通过' ELSE '未知' AS approveStatusDesc," +
* /
2022-08-15 02:15:21 +00:00
QueryHelper queryHelper = new QueryHelper ( "SELECT p.*, FORMAT(p.contract_amount,2) as contractRound, FORMAT(p.huazhi_product_amount,2) as huazhiRound, FORMAT(p.huizhi_product_amount,2) as huizhiRound, FORMAT(p.huasan_product_amount,2) as huasanRound, FORMAT(p.ziguang_other_amount,2) as ziguangRound" +
", FORMAT(p.gross_profit,2) as grossProfitRound, FORMAT(p.gross_profit_margin,2) as grossProfitMarginRound, FORMAT(p.advance_interest_amount,2) as advanceInterestAmountRound, FORMAT(p.advance_peak_amount,2) as advancePeakAmountRound" , "project" , "p" ) ;
2021-11-01 03:22:37 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "status" ) ) & & ! "-1" . equals ( searchInfo . get ( "status" ) ) ) {
queryHelper . addCondition ( "p.status=?" , Integer . parseInt ( searchInfo . get ( "status" ) ) ) ;
2021-10-29 10:15:36 +00:00
}
2021-11-18 08:39:59 +00:00
///
/ * if ( StrUtil . isNotEmpty ( searchInfo . get ( "approveId" ) ) ) {
2021-11-08 08:38:02 +00:00
int approveId = Integer . parseInt ( searchInfo . get ( "approveId" ) ) ;
queryHelper . addCondition ( "p.approve_id=?" , approveId ) ;
2021-11-18 08:39:59 +00:00
} * /
2021-11-01 03:22:37 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "approveStatus" ) ) & & ! "-1" . equals ( searchInfo . get ( "approveStatus" ) ) ) {
2021-11-02 04:20:20 +00:00
int approveStatus = Integer . parseInt ( searchInfo . get ( "approveStatus" ) ) ;
//四种状态满足其一即可
2021-12-13 01:57:27 +00:00
queryHelper . addCondition ( "((p.status=? AND p.approve_status_estimate=?) OR (p.status=? AND p.approve_status_budget=?) OR (p.status=? AND p.approve_status_settle=?) OR (p.status=? AND p.approve_status_final=?))" ,
StatusEnum . ESTIMATE_ACCOUNTS . getStatus ( ) , approveStatus ,
StatusEnum . BUDGET_ACCOUNTS . getStatus ( ) , approveStatus ,
StatusEnum . SETTLE_ACCOUNTS . getStatus ( ) , approveStatus ,
StatusEnum . FINAL_ACCOUNTS . getStatus ( ) , approveStatus ) ;
2021-10-29 10:15:36 +00:00
}
2021-11-01 03:22:37 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "deptId" ) ) & & ! "-1" . equals ( searchInfo . get ( "deptId" ) ) ) {
queryHelper . addCondition ( "p.dept_id=?" , Integer . parseInt ( searchInfo . get ( "deptId" ) ) ) ;
2021-10-29 10:15:36 +00:00
}
2021-11-01 03:22:37 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "type" ) ) & & ! "-1" . equals ( searchInfo . get ( "type" ) ) ) {
queryHelper . addCondition ( "p.type=?" , Integer . parseInt ( searchInfo . get ( "type" ) ) ) ;
2021-10-29 10:15:36 +00:00
}
2022-08-15 07:50:34 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "isSecond" ) ) & & ! "-1" . equals ( searchInfo . get ( "isSecond" ) ) ) {
queryHelper . addCondition ( "p.is_second=?" , Integer . parseInt ( searchInfo . get ( "isSecond" ) ) ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "signType" ) ) & & ! "-1" . equals ( searchInfo . get ( "signType" ) ) ) {
queryHelper . addCondition ( "p.sign_type=?" , Integer . parseInt ( searchInfo . get ( "signType" ) ) ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "resolvePlan" ) ) & & ! "-1" . equals ( searchInfo . get ( "resolvePlan" ) ) ) {
queryHelper . addCondition ( "p.resolve_plan=?" , Integer . parseInt ( searchInfo . get ( "resolvePlan" ) ) ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "underwrittenMode" ) ) & & ! "-1" . equals ( searchInfo . get ( "underwrittenMode" ) ) ) {
queryHelper . addCondition ( "p.underwritten_mode=?" , Integer . parseInt ( searchInfo . get ( "underwrittenMode" ) ) ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "certainty" ) ) & & ! "-1" . equals ( searchInfo . get ( "certainty" ) ) ) {
queryHelper . addCondition ( "p.certainty=?" , Integer . parseInt ( searchInfo . get ( "certainty" ) ) ) ;
}
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "projectNo" ) ) , "p.project_no LIKE ?" , "%" + searchInfo . get ( "projectNo" ) + "%" ) ;
2021-10-29 10:15:36 +00:00
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "name" ) ) , "p.name LIKE ?" , "%" + searchInfo . get ( "name" ) + "%" ) ;
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "creatorName" ) ) , "p.creator_name LIKE ?" , "%" + searchInfo . get ( "creatorName" ) + "%" ) ;
2022-08-15 07:50:34 +00:00
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "industryScenario" ) ) , "p.industry_scenario LIKE ?" , "%" + searchInfo . get ( "industryScenario" ) + "%" ) ;
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "customer" ) ) , "p.customer LIKE ?" , "%" + searchInfo . get ( "customer" ) + "%" ) ;
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "terminalCustomer" ) ) , "p.terminal_customer LIKE ?" , "%" + searchInfo . get ( "terminalCustomer" ) + "%" ) ;
queryHelper . addCondition ( StrUtil . isNotEmpty ( searchInfo . get ( "principal" ) ) , "p.principal LIKE ?" , "%" + searchInfo . get ( "principal" ) + "%" ) ;
/ * *
2021-10-29 10:15:36 +00:00
* 只 选 择 了 一 个 时 间 的 情 况 , 就 项 目 时 间 包 括 这 个 时 间 的
* /
2021-11-01 11:00:53 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "startDate" ) ) & & StrUtil . isEmpty ( searchInfo . get ( "endDate" ) ) ) {
String time = searchInfo . get ( "startDate" ) + " 00:00:00" ;
2021-11-01 03:22:37 +00:00
queryHelper . addCondition ( "p.start_date<=? AND p.end_date>=?" , time , time ) ;
2021-10-29 10:15:36 +00:00
}
2021-11-01 11:00:53 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "endDate" ) ) & & StrUtil . isEmpty ( searchInfo . get ( "startDate" ) ) ) {
String time = searchInfo . get ( "endDate" ) + " 00:00:00" ;
2021-11-01 03:22:37 +00:00
queryHelper . addCondition ( "p.start_date<=? AND p.end_date>=?" , time , time ) ;
2021-10-29 10:15:36 +00:00
}
/ * *
* 两 个 时 间 都 选 了 , 则 包 含 项 目 时 间
* /
2021-11-01 11:00:53 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "startDate" ) ) & & StrUtil . isNotEmpty ( searchInfo . get ( "endDate" ) ) ) {
String startTime = searchInfo . get ( "startDate" ) + " 00:00:00" ;
String endTime = searchInfo . get ( "endDate" ) + " 23:59:59" ;
2021-11-01 03:22:37 +00:00
queryHelper . addCondition ( "p.start_date>=? AND p.end_date<=?" , startTime , endTime ) ;
2021-10-29 10:15:36 +00:00
}
2021-11-08 08:27:33 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "startUpdateDate" ) ) ) {
String time = searchInfo . get ( "startUpdateDate" ) + " 00:00:00" ;
queryHelper . addCondition ( "p.last_update_time>=?" , time ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "endUpdateDate" ) ) ) {
String time = searchInfo . get ( "endUpdateDate" ) + " 00:00:00" ;
queryHelper . addCondition ( "p.last_update_time<=?" , time ) ;
}
2022-08-15 07:50:34 +00:00
if ( StrUtil . isNotEmpty ( searchInfo . get ( "contractStartTime" ) ) ) {
String time = searchInfo . get ( "contractStartTime" ) + " 00:00:00" ;
queryHelper . addCondition ( "p.contract_time>=?" , time ) ;
}
if ( StrUtil . isNotEmpty ( searchInfo . get ( "contractEndTime" ) ) ) {
String time = searchInfo . get ( "contractEndTime" ) + " 00:00:00" ;
queryHelper . addCondition ( "p.contract_time<=?" , time ) ;
}
2021-11-08 08:27:33 +00:00
2021-11-18 09:39:31 +00:00
//项目可见性, 根据角色和人员id
Admin admin = InterfaceUtil . getAdmin ( ) ;
int roleId = admin . getRoleId ( ) ;
Integer adminId = admin . getId ( ) ;
2021-11-30 10:35:04 +00:00
//自己创建的肯定能看见,配置的可以看见,系统管理员可以看见
SysRole sysRole = sysRoleRepository . findSysRoleById ( roleId ) ;
if ( SysRole . ROLE_TYPE_SYSTEM ! = sysRole . getType ( ) ) {
queryHelper . addCondition ( "(p.creator_id=? OR p.id in (SELECT pv1.project_id FROM project_visible pv1 WHERE pv1.type=1 AND pv1.tid=? UNION SELECT pv2.project_id FROM project_visible pv2 WHERE pv2.type=2 AND pv2.tid=?))" , adminId , roleId , adminId ) ;
}
2021-11-18 09:39:31 +00:00
2021-11-08 08:27:33 +00:00
2021-11-22 02:12:45 +00:00
queryHelper . addDescOrderProperty ( "p.last_update_time" ) ;
2021-10-29 10:15:36 +00:00
return queryHelper ;
}
public Page < Project > list ( Map < String , String > searchInfo , int pageNumber , int pageSize ) {
2021-11-18 08:39:59 +00:00
QueryHelper queryHelper = getQueryHelper ( searchInfo ) ;
2021-10-29 10:15:36 +00:00
return pagination . paginate ( queryHelper . getSql ( ) , Project . class , pageNumber , pageSize ) ;
}
2021-11-08 09:32:25 +00:00
/ * *
* 找 到 待 我 审 核 项 目
* /
public Page < Project > findMyApproveProjects ( Map < String , String > searchInfo , int adminId , int pageNumber , int pageSize ) {
2021-11-18 08:39:59 +00:00
//待审核状态的条件
2021-11-08 09:32:25 +00:00
searchInfo . put ( "approveStatus" , "" + ApproveStatusEnum . APPROVAL_PENDING . getApproveStatus ( ) ) ;
2021-11-18 08:39:59 +00:00
QueryHelper queryHelper = getQueryHelper ( searchInfo ) ;
//在列表基础上增加审核人是我
queryHelper . addCondition ( "p.approve_id=?" , adminId ) ;
return pagination . paginate ( queryHelper . getSql ( ) , Project . class , pageNumber , pageSize ) ;
2021-11-08 09:32:25 +00:00
}
2021-11-02 06:43:42 +00:00
public Project getProject ( int id ) {
return projectRepository . findOne ( id ) ;
}
2021-10-29 10:15:36 +00:00
2021-11-02 06:43:42 +00:00
2021-11-18 08:01:09 +00:00
public Project addProject ( Project project , Admin admin , ApproveStatusEnum approveStatusEnum ) {
2022-08-15 02:15:21 +00:00
String projectNo = numSeqService . generate ( ) ;
project . setProjectNo ( projectNo ) ;
2021-11-01 11:00:53 +00:00
project . setTypeDesc ( TypeEnum . parseType ( project . getType ( ) ) . getTypeDesc ( ) ) ;
2022-08-15 02:15:21 +00:00
project . setUnderwrittenModeStr ( UnderwrittenModeEnum . parseUnderwrittenMode ( project . getUnderwrittenMode ( ) ) . getUnderwrittenModeStr ( ) ) ;
project . setCertaintyStr ( CertaintyEnum . parseCertainty ( project . getCertainty ( ) ) . getCertaintyStr ( ) ) ;
project . setIsSecondStr ( IsSecondEnum . parseIsSecond ( project . getIsSecond ( ) ) . getIsSecondStr ( ) ) ;
project . setSignTypeStr ( SignTypeEnum . parseSignType ( project . getSignType ( ) ) . getSignTypeStr ( ) ) ;
project . setResolvePlanStr ( ResolvePlanEnum . parseResolvePlan ( project . getResolvePlan ( ) ) . getResolvePlanStr ( ) ) ;
2021-11-17 02:14:01 +00:00
project . setStatus ( StatusEnum . ESTIMATE_ACCOUNTS . getStatus ( ) ) ;
project . setStatusDesc ( StatusEnum . ESTIMATE_ACCOUNTS . getStatusDesc ( ) ) ;
2021-11-02 04:20:20 +00:00
project . setApproveStatusEstimate ( approveStatusEnum . getApproveStatus ( ) ) ;
2021-11-01 11:00:53 +00:00
project . setCreatorId ( admin . getId ( ) ) ;
2022-03-04 09:03:27 +00:00
project . setCreatorName ( admin . getRealName ( ) ) ;
2021-11-01 11:00:53 +00:00
2021-11-18 08:07:33 +00:00
ProjectConfigBean projectConfigBeanConfig = sysConfigService . getProjectConfigBeanConfig ( ) ;
2021-11-05 04:19:01 +00:00
project . setProjectContributionProfitRateThreshold ( projectConfigBeanConfig . getProjectContributionProfitRateThreshold ( ) ) ;
project . setUnderwrittenTaxRate ( projectConfigBeanConfig . getUnderwrittenTaxRate ( ) ) ;
2021-11-17 03:14:52 +00:00
project . setApproveId ( 0 ) ;
2021-11-01 11:00:53 +00:00
project . setApproveName ( "" ) ;
2021-11-19 06:47:59 +00:00
Dept one = deptRepository . findOne ( admin . getDeptId ( ) ) ;
project . setDeptId ( one . getId ( ) ) ;
project . setDeptName ( one . getName ( ) ) ;
2021-11-01 11:00:53 +00:00
2021-11-08 08:27:33 +00:00
Date now = new Date ( ) ;
project . setCreateTime ( now ) ;
project . setLastUpdateTime ( now ) ;
2021-11-01 11:00:53 +00:00
project = projectRepository . saveAndFlush ( project ) ;
return project ;
}
2021-11-01 12:07:02 +00:00
2021-11-18 08:01:09 +00:00
public Project editProject ( Project project , Project projectInDb ) {
2021-11-16 01:00:26 +00:00
2021-11-02 06:43:42 +00:00
//只有如下可以修改
2022-03-10 06:54:50 +00:00
projectInDb . setName ( project . getName ( ) ) ;
projectInDb . setCustomer ( project . getCustomer ( ) ) ;
projectInDb . setTerminalCustomer ( project . getTerminalCustomer ( ) ) ;
projectInDb . setIndustryScenario ( project . getIndustryScenario ( ) ) ;
projectInDb . setType ( project . getType ( ) ) ;
2022-03-10 08:10:17 +00:00
projectInDb . setTypeDesc ( TypeEnum . parseType ( project . getType ( ) ) . getTypeDesc ( ) ) ;
2022-03-10 06:54:50 +00:00
projectInDb . setUnderwrittenMode ( project . getUnderwrittenMode ( ) ) ;
2022-08-15 02:15:21 +00:00
projectInDb . setUnderwrittenModeStr ( UnderwrittenModeEnum . parseUnderwrittenMode ( project . getUnderwrittenMode ( ) ) . getUnderwrittenModeStr ( ) ) ;
2022-08-15 06:36:21 +00:00
projectInDb . setCertainty ( project . getCertainty ( ) ) ;
projectInDb . setCertaintyStr ( CertaintyEnum . parseCertainty ( project . getCertainty ( ) ) . getCertaintyStr ( ) ) ;
projectInDb . setIsSecond ( project . getIsSecond ( ) ) ;
projectInDb . setIsSecondStr ( IsSecondEnum . parseIsSecond ( project . getIsSecond ( ) ) . getIsSecondStr ( ) ) ;
projectInDb . setSignType ( project . getSignType ( ) ) ;
projectInDb . setSignTypeStr ( SignTypeEnum . parseSignType ( project . getSignType ( ) ) . getSignTypeStr ( ) ) ;
projectInDb . setResolvePlan ( project . getResolvePlan ( ) ) ;
projectInDb . setResolvePlanStr ( ResolvePlanEnum . parseResolvePlan ( project . getResolvePlan ( ) ) . getResolvePlanStr ( ) ) ;
projectInDb . setCollaborator ( project . getCollaborator ( ) ) ;
projectInDb . setGrossProfit ( project . getGrossProfit ( ) ) ;
projectInDb . setGrossProfitMargin ( project . getGrossProfitMargin ( ) ) ;
2021-11-16 01:00:26 +00:00
projectInDb . setStartDate ( project . getStartDate ( ) ) ;
projectInDb . setEndDate ( project . getEndDate ( ) ) ;
projectInDb . setContractAmount ( project . getContractAmount ( ) ) ;
projectInDb . setHuazhiProductAmount ( project . getHuazhiProductAmount ( ) ) ;
2022-08-15 06:36:21 +00:00
projectInDb . setHuizhiProductAmount ( project . getHuizhiProductAmount ( ) ) ;
projectInDb . setHuasanProductAmount ( project . getHuasanProductAmount ( ) ) ;
2021-11-16 01:00:26 +00:00
projectInDb . setZiguangOtherAmount ( project . getZiguangOtherAmount ( ) ) ;
2022-08-15 06:36:21 +00:00
projectInDb . setPrincipal ( project . getPrincipal ( ) ) ;
projectInDb . setContractTime ( project . getContractTime ( ) ) ;
projectInDb . setBidsTime ( project . getBidsTime ( ) ) ;
projectInDb . setAdvanceInterestAmount ( project . getAdvanceInterestAmount ( ) ) ;
projectInDb . setAdvancePeakAmount ( project . getAdvancePeakAmount ( ) ) ;
2021-11-16 01:00:26 +00:00
projectInDb . setMainContractCollectionTerms ( project . getMainContractCollectionTerms ( ) ) ;
2022-08-15 06:36:21 +00:00
projectInDb . setMainContractResolvePlan ( project . getMainContractResolvePlan ( ) ) ;
projectInDb . setCalculationCollection ( project . getCalculationCollection ( ) ) ;
2021-12-29 07:37:14 +00:00
projectInDb . setValueRisk ( project . getValueRisk ( ) ) ;
2021-12-29 09:35:23 +00:00
projectInDb . setOtherName ( project . getOtherName ( ) ) ;
2021-11-01 13:09:10 +00:00
2022-04-18 10:03:19 +00:00
projectInDb . setPlanStartStr ( project . getPlanStartStr ( ) ) ;
projectInDb . setPlanEndStr ( project . getPlanEndStr ( ) ) ;
2021-11-16 01:00:26 +00:00
/// projectInDb.setApproveStatusEstimate(approveStatusEnum.getApproveStatus());
2021-11-01 13:09:10 +00:00
2021-11-16 01:00:26 +00:00
projectInDb . setLastUpdateTime ( new Date ( ) ) ;
2021-11-08 08:27:33 +00:00
2021-11-16 01:00:26 +00:00
return projectInDb ;
2021-11-02 09:33:34 +00:00
}
2021-11-15 08:53:43 +00:00
2022-04-12 09:10:48 +00:00
public ResponseMsg completeTask ( int projectId , String json , int approvetype ) {
2021-11-15 08:53:43 +00:00
List < ProjectInstanceRelation > relationList = projectInstanceRelationRepository . findByProjectIdOrderByCreateTimeDesc ( projectId ) ;
if ( relationList = = null | | relationList . isEmpty ( ) ) {
return ResponseMsg . buildFailedMsg ( "审核失败" ) ;
}
ProjectInstanceRelation projectInstanceRelation = relationList . get ( 0 ) ;
JSONObject obj = JSON . parseObject ( json ) ;
actTaskDefService . completeTaskByProcInsId ( projectInstanceRelation . getProcessInsId ( ) ,
obj . getIntValue ( "type" ) , obj . getString ( "message" ) ) ;
2022-04-12 09:10:48 +00:00
return ResponseMsg . buildSuccessMsg ( "审核成功" , approvetype ) ;
2021-11-15 08:53:43 +00:00
}
2021-11-17 06:49:11 +00:00
2022-08-10 10:24:30 +00:00
/ * *
* 会 签
*
* @param projectId
* @param json
* @param approvetype
* @return
* /
public ResponseMsg skipTask ( int projectId , String json , int approvetype ) {
2022-08-09 07:58:39 +00:00
List < ProjectInstanceRelation > relationList = projectInstanceRelationRepository . findByProjectIdOrderByCreateTimeDesc ( projectId ) ;
if ( relationList = = null | | relationList . isEmpty ( ) ) {
return ResponseMsg . buildFailedMsg ( "会签失败" ) ;
}
2022-08-10 10:24:30 +00:00
JSONObject obj = JSON . parseObject ( json ) ;
String fileUrl = obj . getString ( "fileUrl" ) ;
2022-08-09 07:58:39 +00:00
2022-08-10 10:24:30 +00:00
ProjectInstanceRelation projectInstanceRelation = relationList . get ( 0 ) ;
return actTaskDefService . skipTaskByProcInsId ( projectInstanceRelation . getProcessInsId ( ) , fileUrl , approvetype ) ;
2022-08-09 07:58:39 +00:00
}
2021-11-17 06:49:11 +00:00
/ * *
* 更 新 项 目 状 态 和 审 批 状 态
* /
2022-01-13 07:51:34 +00:00
public void updateStatusAndApproveStatus ( int projectId , StatusEnum statusEnum , ApproveStatusEnum approveStatusEnum , String otherName ) {
2021-11-17 06:49:11 +00:00
Project one = projectRepository . findOne ( projectId ) ;
one . setStatus ( statusEnum . getStatus ( ) ) ;
one . setStatusDesc ( statusEnum . getStatusDesc ( ) ) ;
2022-01-13 07:51:34 +00:00
one . setOtherName ( otherName ) ;
2021-11-17 06:49:11 +00:00
int approveStatus = approveStatusEnum . getApproveStatus ( ) ;
switch ( statusEnum ) {
case ESTIMATE_ACCOUNTS :
one . setApproveStatusEstimate ( approveStatus ) ;
break ;
case BUDGET_ACCOUNTS :
one . setApproveStatusBudget ( approveStatus ) ;
break ;
case SETTLE_ACCOUNTS :
one . setApproveStatusSettle ( approveStatus ) ;
break ;
case FINAL_ACCOUNTS :
one . setApproveStatusFinal ( approveStatus ) ;
break ;
default :
}
one . setLastUpdateTime ( new Date ( ) ) ;
projectRepository . saveAndFlush ( one ) ;
}
2021-11-19 06:47:59 +00:00
private static final String PREFIX_ROLE = "r-" ;
private static final String PREFIX_USER = "u-" ;
/ * *
* 把 所 有 的 角 色 和 人 员 按 照 层 级 返 回
* /
public List < ZTreeNode > getZTreeNodes ( int projectId ) {
List < SysRole > roleList = sysRoleRepository . findAllRole ( ) ;
2021-11-30 10:35:04 +00:00
//过滤掉系统管理员角色
roleList = roleList . stream ( ) . filter ( sysRole - > sysRole . getType ( ) ! = SysRole . ROLE_TYPE_SYSTEM ) . collect ( Collectors . toList ( ) ) ;
2021-11-19 06:47:59 +00:00
List < Admin > adminList = adminRepository . getAllEnable ( ) ;
List < ZTreeNode > zTreeNodes = new ArrayList < > ( roleList . size ( ) + adminList . size ( ) ) ;
List < ProjectVisible > projectVisibles = projectVisibleRepository . findAllByProjectIdEquals ( projectId ) ;
List < ProjectVisible > visibleRoleList = filterByType ( projectVisibles , ProjectVisible . TYPE_ROLE ) ;
List < ProjectVisible > visibleUserList = filterByType ( projectVisibles , ProjectVisible . TYPE_USER ) ;
for ( SysRole sysRole : roleList ) {
2021-11-26 11:07:12 +00:00
List < ZTreeNode > filterAdmins = filterAdmins ( adminList , sysRole , visibleUserList ) ;
if ( CollectionUtil . isNotEmpty ( filterAdmins ) ) {
//下面有人才要
zTreeNodes . add ( new ZTreeNode ( PREFIX_ROLE + sysRole . getId ( ) , "0" , sysRole . getName ( ) ,
isChecked ( visibleRoleList , sysRole . getId ( ) ) , false ) ) ;
zTreeNodes . addAll ( filterAdmins ) ;
}
2021-11-19 06:47:59 +00:00
}
return zTreeNodes ;
}
private List < ZTreeNode > filterAdmins ( List < Admin > adminList , SysRole sysRole , List < ProjectVisible > visibleUserList ) {
List < Admin > admins = adminList . stream ( )
. filter ( a - > sysRole . getId ( ) = = a . getRoleId ( ) )
. collect ( Collectors . toList ( ) ) ;
if ( CollectionUtil . isNotEmpty ( admins ) ) {
ArrayList < ZTreeNode > zTreeNodes = new ArrayList < > ( admins . size ( ) ) ;
for ( Admin admin : admins ) {
zTreeNodes . add ( new ZTreeNode ( PREFIX_USER + admin . getId ( ) , PREFIX_ROLE + sysRole . getId ( ) , admin . getRealName ( ) ,
isChecked ( visibleUserList , admin . getId ( ) ) , false ) ) ;
}
return zTreeNodes ;
}
return Collections . emptyList ( ) ;
}
private boolean isChecked ( List < ProjectVisible > visibleList , int id ) {
return visibleList . stream ( ) . anyMatch ( pv - > pv . getTid ( ) = = id ) ;
}
private List < ProjectVisible > filterByType ( List < ProjectVisible > projectVisibles , int type ) {
if ( CollectionUtil . isEmpty ( projectVisibles ) ) {
return Collections . emptyList ( ) ;
}
return projectVisibles . stream ( ) . filter ( pv - > pv . getType ( ) = = type ) . collect ( Collectors . toList ( ) ) ;
}
public void saveProjectVisible ( Integer projectId , String [ ] idss ) {
//1.先清除以前的
List < ProjectVisible > projectVisibles = projectVisibleRepository . findAllByProjectIdEquals ( projectId ) ;
if ( CollectionUtil . isNotEmpty ( projectVisibles ) ) {
projectVisibleRepository . deleteInBatch ( projectVisibles ) ;
}
//2.再保存
List < ProjectVisible > pvs = new ArrayList < > ( idss . length ) ;
for ( String s : idss ) {
//只要用户的,角色的不要
if ( s . startsWith ( PREFIX_USER ) ) {
ProjectVisible pv = new ProjectVisible ( ) ;
pv . setProjectId ( projectId ) ;
pv . setType ( ProjectVisible . TYPE_USER ) ;
//去掉前缀
pv . setTid ( Integer . parseInt ( s . substring ( PREFIX_USER . length ( ) ) ) ) ;
pvs . add ( pv ) ;
}
}
projectVisibleRepository . save ( pvs ) ;
}
2021-11-25 03:34:38 +00:00
@Transactional ( rollbackFor = Exception . class )
public ResponseMsg deleteProject ( int id ) {
Project one = projectRepository . findOne ( id ) ;
if ( one = = null ) {
return ResponseMsg . buildFailedMsg ( "项目不存在" ) ;
}
if ( one . getStatus ( ) ! = StatusEnum . ESTIMATE_ACCOUNTS . getStatus ( )
| | one . getApproveStatusEstimate ( ) ! = ApproveStatusEnum . APPROVAL_UNCOMMIT . getApproveStatus ( ) ) {
return ResponseMsg . buildFailedMsg ( "项目当前状态下不能删除" ) ;
}
projectRepository . delete ( id ) ;
projectEstimateService . deleteEstimate ( id ) ;
return ResponseMsg . buildSuccessMsg ( "删除成功" ) ;
}
2021-12-28 07:42:42 +00:00
public void saveApprove ( Project project , Admin admin ) throws Exception {
2021-12-29 02:49:01 +00:00
if ( project . getApproveStatusEstimate ( ) = = ApproveStatusEnum . APPROVAL_UNCOMMIT . getApproveStatus ( ) ) {
2021-12-28 07:42:42 +00:00
Integer approveStatusEstimate = project . getApproveStatusEstimate ( ) ;
projectEstimateService . estimateApprove ( approveStatusEstimate , project , admin ) ;
2021-12-29 02:49:01 +00:00
project . setApproveStatusEstimate ( ApproveStatusEnum . APPROVAL_PENDING . getApproveStatus ( ) ) ;
} else if ( project . getApproveStatusBudget ( ) = = ApproveStatusEnum . APPROVAL_UNCOMMIT . getApproveStatus ( ) ) {
2021-12-28 07:42:42 +00:00
Integer approveStatusBudget = project . getApproveStatusBudget ( ) ;
projectBudgetService . budgetApprove ( approveStatusBudget , project , admin ) ;
2021-12-29 02:49:01 +00:00
project . setApproveStatusBudget ( ApproveStatusEnum . APPROVAL_PENDING . getApproveStatus ( ) ) ;
} else if ( project . getApproveStatusSettle ( ) = = ApproveStatusEnum . APPROVAL_UNCOMMIT . getApproveStatus ( ) ) {
2021-12-28 07:42:42 +00:00
projectInstanceService . startSettleProcessInstance ( project , InterfaceUtil . getAdmin ( ) ) ;
2021-12-29 02:49:01 +00:00
project . setApproveStatusSettle ( ApproveStatusEnum . APPROVAL_PENDING . getApproveStatus ( ) ) ;
} else if ( project . getApproveStatusFinal ( ) = = ApproveStatusEnum . APPROVAL_UNCOMMIT . getApproveStatus ( ) ) {
2021-12-28 07:42:42 +00:00
projectInstanceService . startFinalProcessInstance ( project . getId ( ) , InterfaceUtil . getAdmin ( ) ) ;
2021-12-29 02:49:01 +00:00
project . setApproveStatusFinal ( ApproveStatusEnum . APPROVAL_PENDING . getApproveStatus ( ) ) ;
} else {
return ;
2021-12-28 07:42:42 +00:00
}
2021-12-29 02:49:01 +00:00
projectRepository . save ( project ) ;
2021-12-28 07:42:42 +00:00
}
2021-10-29 10:15:36 +00:00
}