package com.ycl.service.impl; import com.ycl.common.core.text.Convert; import com.ycl.service.IPurchaseService; import com.ycl.system.domain.Purchase; import com.ycl.mapper.PurchaseMapper; import lombok.RequiredArgsConstructor; import org.flowable.engine.HistoryService; import org.flowable.engine.IdentityService; import org.flowable.engine.RuntimeService; import org.flowable.engine.TaskService; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.runtime.ProcessInstance; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; /** * 采购Service业务层处理 * * @author shenzhanwang * @date 2022-05-28 */ @Service @Transactional @RequiredArgsConstructor public class PurchaseServiceImpl implements IPurchaseService { private final PurchaseMapper purchaseMapper; private final RuntimeService runtimeService; private final TaskService taskService; private final IdentityService identityService; private final HistoryService historyService; /** * 查询采购 * * @param id 采购主键 * @return 采购 */ @Override public Purchase selectPurchaseById(Long id) { return purchaseMapper.selectPurchaseById(id); } /** * 查询采购列表 * * @param purchase 采购 * @return 采购 */ @Override public List selectPurchaseList(Purchase purchase) { return purchaseMapper.selectPurchaseList(purchase); } /** * 新增采购 * * @param purchase 采购 * @return 结果 */ @Override public int insertPurchase(Purchase purchase) { int row = purchaseMapper.insertPurchase(purchase); // 启动采购流程 identityService.setAuthenticatedUserId(purchase.getApplyer()); HashMap variables = new HashMap<>(); variables.put("starter", purchase.getApplyer()); variables.put("purchasemanager", purchase.getPurchasemanager()); variables.put("financeName", purchase.getFinanceName()); variables.put("pay", purchase.getPay()); variables.put("managerName", purchase.getManagerName()); variables.put("money", Double.parseDouble(purchase.getTotal())); runtimeService.startProcessInstanceByKey("purchase", String.valueOf(purchase.getId()), variables); return row; } /** * 修改采购 * * @param purchase 采购 * @return 结果 */ @Override public int updatePurchase(Purchase purchase) { return purchaseMapper.updatePurchase(purchase); } /** * 批量删除采购 * * @param ids 需要删除的采购主键 * @return 结果 */ @Override public int deletePurchaseByIds(String ids) { String[] keys = Convert.toStrArray(ids); for (String key : keys) { ProcessInstance process = runtimeService.createProcessInstanceQuery().processDefinitionKey("purchase").processInstanceBusinessKey(key).singleResult(); if (process != null) { runtimeService.deleteProcessInstance(process.getId(), "删除"); } // 删除历史数据 HistoricProcessInstance history = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("purchase").processInstanceBusinessKey(key).singleResult(); if (history != null) { historyService.deleteHistoricProcessInstance(history.getId()); } purchaseMapper.deletePurchaseByIds(Convert.toStrArray(ids)); } return keys.length; } /** * 删除采购信息 * * @param id 采购主键 * @return 结果 */ @Override public int deletePurchaseById(Long id) { return purchaseMapper.deletePurchaseById(id); } }