|
|
@@ -0,0 +1,179 @@
|
|
|
+package platform.modules.sys.task;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Configurable;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import platform.common.Constant;
|
|
|
+import platform.common.util.AlibabaSMSUtil;
|
|
|
+import platform.common.util.DateUtil;
|
|
|
+import platform.common.util.StringUtils;
|
|
|
+import platform.modules.api.dto.CompanyInfoDto;
|
|
|
+import platform.modules.build.service.CompanyService;
|
|
|
+import platform.modules.carrier.service.ContractFloorService;
|
|
|
+import platform.modules.company.entity.StockLand;
|
|
|
+import platform.modules.company.service.StockLandService;
|
|
|
+import platform.modules.government.entity.User;
|
|
|
+import platform.modules.government.service.UserService;
|
|
|
+import platform.modules.sys.entity.Approval;
|
|
|
+import platform.modules.sys.service.ApprovalService;
|
|
|
+import platform.modules.sys.service.GroupService;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 自动审批存量用地单据
|
|
|
+ * 超过5天未审批的单据自动全部通过
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@EnableScheduling
|
|
|
+@Slf4j
|
|
|
+public class StocklandAutoFinishFlowTask {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GroupService groupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockLandService stockLandService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApprovalService approvalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ // 默认wei.pp的电话号码
|
|
|
+ @Value("${company-master-phone:18362602202}")
|
|
|
+ private String companyMasterPhone;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?") // 每天凌晨12点执行
|
|
|
+ public void autoFinishFlow() {
|
|
|
+
|
|
|
+ List<StockLand> allNeedJudgeStockLand = stockLandService.findAllNeedJudgeStockLand();
|
|
|
+ System.out.println(allNeedJudgeStockLand);
|
|
|
+ if (!allNeedJudgeStockLand.isEmpty()) {
|
|
|
+ for (StockLand stockLand : allNeedJudgeStockLand) {
|
|
|
+ try {
|
|
|
+ autoJudge(stockLand);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void autoJudge(StockLand stockLand) throws ParseException, ClientException, InterruptedException {
|
|
|
+ Approval latestApproval = approvalService.getLatestApproval(stockLand.getId(), Constant.DictionaryType.STOCKLAND);
|
|
|
+ // 最后一个审批超过5天的 开始自动审批
|
|
|
+ Boolean overTime = DateUtil.isOverTime(latestApproval.getCreate_time(), 5);
|
|
|
+ if (!overTime) return;
|
|
|
+ log.info("开始自动审批单据, apply_no: " + stockLand.getApply_no());
|
|
|
+ String nextchecker = latestApproval.getNextchecker();
|
|
|
+ if (!StringUtils.isEmpty(nextchecker)) {
|
|
|
+ List<String> checkers = new ArrayList<>(Arrays.asList(nextchecker.split(",")));
|
|
|
+ // 审批到最后一个人的时候,需要判断下一个审批人是到哪里?
|
|
|
+ if (!checkers.isEmpty()) {
|
|
|
+ Iterator<String> checkersIterator = checkers.iterator();
|
|
|
+ while (checkersIterator.hasNext()) {
|
|
|
+ String currentChecker = checkersIterator.next();
|
|
|
+ checkersIterator.remove();
|
|
|
+ if (checkers.isEmpty()) {
|
|
|
+ //下一审核人到“协调工作组”,
|
|
|
+ String nextChecker = stockLandService.findGroupName(Constant.XTGZXZ);
|
|
|
+ // 最后一个人了,下一个审批人的选择
|
|
|
+ if (Objects.equals(stockLand.getApprove_status(), Constant.LandApproveStatus.JYLCHQ)) {
|
|
|
+ // 简易流程会签,后面是简易流程汇总
|
|
|
+ //当最后一个人审核后,将该单据的状态设为“简易流程汇总”
|
|
|
+ log.info("开始自动审批单据, apply_no: " + stockLand.getApply_no() + ",currentChecker: " + currentChecker +" 自动置为简易流程汇总");
|
|
|
+
|
|
|
+ stockLand.setApprove_status(Constant.LandApproveStatus.JYLCHZ);
|
|
|
+ stockLandService.save(stockLand);
|
|
|
+ stockLandService.autoSaveApproval(stockLand.getId(),
|
|
|
+ "超时自动审批通过",
|
|
|
+ currentChecker,
|
|
|
+ nextChecker,
|
|
|
+ latestApproval.getAfter_approvalstatus(),
|
|
|
+ Constant.LandApproveStatus.JYLCHZ,
|
|
|
+ Constant.OperType.SUBMIT_COMMENT,
|
|
|
+ latestApproval.getApproval_round());
|
|
|
+
|
|
|
+ } else if (Objects.equals(stockLand.getApprove_status(), Constant.LandApproveStatus.COMPLIANCE_AUDIT)) {
|
|
|
+ // 合规行审查,后面是合规性审查汇总
|
|
|
+ //当最后一个人审核后,将该单据的状态设为“后面是合规性审查汇总”
|
|
|
+ log.info("开始自动审批单据, apply_no: " + stockLand.getApply_no() + ",currentChecker: " + currentChecker+ "自动置为合规性审查汇总");
|
|
|
+ stockLand.setApprove_status(Constant.LandApproveStatus.HGXSCTG);
|
|
|
+ stockLandService.save(stockLand);
|
|
|
+ stockLandService.autoSaveApproval(stockLand.getId(),
|
|
|
+ "超时自动审批通过",
|
|
|
+ currentChecker,
|
|
|
+ nextChecker,
|
|
|
+ latestApproval.getAfter_approvalstatus(),
|
|
|
+ Constant.LandApproveStatus.HGXSCTG,
|
|
|
+ Constant.OperType.SUBMIT_COMMENT,
|
|
|
+ latestApproval.getApproval_round());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ // 获取申请单的创建人,并获取该创建人的公司
|
|
|
+ Integer userid = stockLand.getCreate_by();
|
|
|
+ CompanyInfoDto company = companyService.findByUserId(userid);
|
|
|
+
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("company_name", company.getCompany_name());
|
|
|
+
|
|
|
+ String tempCode = Constant.SMS_TemplateCode.STOCKLAND_HGXSCTG;
|
|
|
+
|
|
|
+ for (String checkerId : nextChecker.split(",")) {
|
|
|
+ User checker = userService.findById(Integer.valueOf(checkerId));
|
|
|
+ AlibabaSMSUtil.sendSMS(
|
|
|
+ checker.getPhone(),
|
|
|
+ tempCode,
|
|
|
+ Constant.SINGNAMW,
|
|
|
+ JSONObject.toJSONString(params)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // wangjiang@2022-10-09 20:54:48 发送给魏培培通知所有审查通过
|
|
|
+ if (stockLandService.isNeedNoticeAfterDispatch(stockLand.getApply_type())) {
|
|
|
+ AlibabaSMSUtil.sendSMS(
|
|
|
+ companyMasterPhone,
|
|
|
+ Constant.SMS_TemplateCode.STOCKLAND_JUDGE_FINISH_DISPATCH,
|
|
|
+ Constant.SINGNAMW,
|
|
|
+ JSONObject.toJSONString(params)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.info("开始自动审批单据, apply_no: " + stockLand.getApply_no() + ",currentChecker: " + currentChecker+" 超时自动审批通过");
|
|
|
+ stockLandService.autoSaveApproval(stockLand.getId(),
|
|
|
+ "超时自动审批通过",
|
|
|
+ currentChecker,
|
|
|
+ String.join(",", checkers) + ",",
|
|
|
+ stockLand.getApprove_status(),
|
|
|
+ stockLand.getApprove_status(),
|
|
|
+ Constant.OperType.SUBMIT_COMMENT,
|
|
|
+ latestApproval.getApproval_round());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|