package com.yonyou.mm.plmpd.app.psdm.rule.standard.bom.unsubmit;
import com.yonyou.mm.plmpd.app.psdm.constant.FieldConst;
import com.yonyou.mm.plmpd.app.psdm.constant.FullNameConst;
import com.yonyou.mm.plmpd.app.psdm.util.Constants;
import com.yonyou.ucf.mdd.common.model.rule.RuleExecuteResult;
import com.yonyou.ucf.mdd.ext.bill.rule.base.AbstractCommonRule;
import com.yonyou.ucf.mdd.ext.dao.meta.MetaDaoHelper;
import com.yonyou.ucf.mdd.ext.model.BillContext;
import org.imeta.orm.base.BizObject;
import org.imeta.orm.base.EntityStatus;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component(“ebomAfterUnSubmitRule”)
public class EBomAfterUnSubmitRule extends AbstractCommonRule {
@Override
public RuleExecuteResult execute(BillContext billContext, Map<String, Object> paramMap) throws Exception {
List bills = getBills(billContext, paramMap);
for (BizObject bill : bills) {
String id = bill.getString(“id”);
updateById(id);
System.out.println(“EBOM更新为待提交审批中状态”);
}
return new RuleExecuteResult();
}
private void updateById(String id) throws Exception {
List<BizObject> list = new ArrayList<>();
BizObject obj = new BizObject();
obj.put(FieldConst.FIELD_ID, Long.valueOf(id));
obj.put(Constants.WF_STATE, null);
obj.put(Constants.BOM_VIEWER_BUSTYPE, null);
obj.put(Constants.BOM_VIEWER_WFID, null);
obj.put(Constants.BOM_VIEWER_LIFECYCLE_TARGETATTRID, null);
obj.setEntityStatus(EntityStatus.Update);
list.add(obj);
MetaDaoHelper.update(FullNameConst.EBOM_VIEWER, list);
}
}
package com.yonyou.mm.plmpd.app.psdm.rule.standard.bom.unsubmit;
import com.yonyou.mm.plmpd.app.psdm.constant.AuthIdConstants;
import com.yonyou.mm.plmpd.app.psdm.constant.FieldConst;
import com.yonyou.mm.plmpd.app.psdm.constant.FullNameConst;
import com.yonyou.mm.plmpd.app.psdm.entity.ebom.EBomViewerEntity;
import com.yonyou.mm.plmpd.app.psdm.enums.EditStatus;
import com.yonyou.mm.plmpd.app.psdm.exceptions.ExceptionEnum;
import com.yonyou.mm.plmpd.app.psdm.exceptions.PSMException;
import com.yonyou.mm.plmpd.app.psdm.service.standard.IStaffUserService;
import com.yonyou.mm.plmpd.app.psdm.util.BusinessUtil;
import com.yonyou.mm.plmpd.app.psdm.util.Constants;
import com.yonyou.mm.plmpd.app.psdm.vo.StaffOrgVo;
import com.yonyou.ucf.mdd.common.constant.MddConstants;
import com.yonyou.ucf.mdd.common.model.rule.RuleExecuteResult;
import com.yonyou.ucf.mdd.ext.bill.rule.base.AbstractCommonRule;
import com.yonyou.ucf.mdd.ext.bpm.model.VerifyState;
import com.yonyou.ucf.mdd.ext.core.AppContext;
import com.yonyou.ucf.mdd.ext.model.BillContext;
import com.yonyou.ucf.mdd.ext.util.OrgPermissionUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.imeta.orm.base.BizObject;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Component(“ebomBeforeUnSubmitRule”)
public class EBomBeforeUnSubmitRule extends AbstractCommonRule {
@Override
public RuleExecuteResult execute(BillContext billContext, Map<String, Object> paramMap) throws Exception {
List bills = getBills(billContext, paramMap);
for (BizObject bill : bills) {
Long id = MapUtils.getLong(bill, Constants.ID);
Map<String, Object> bomViewer = BusinessUtil.findById(id, FullNameConst.EBOM_VIEWER, EBomViewerEntity.class, false);
// 状态和流程控制检查
if (!MapUtils.getBoolean(bomViewer, MddConstants.PARAM_BPM_IS_WF_CONTROLLED) ||
MapUtils.getInteger(bomViewer, MddConstants.PARAM_BPM_VERIFYSTATE) != VerifyState.SUBMITED.getValue() &&
MapUtils.getInteger(bomViewer, MddConstants.PARAM_BPM_VERIFYSTATE) != VerifyState.REJECTED_TO_MAKEBILL.getValue()) {
throw new PSMException(ExceptionEnum.CHECK_ACTION_UNSUBMIT_STATUS_CHECK_ERROR);
}
this.hasOperationPermission(bomViewer, billContext);
this.canLockOrUnLockCheck(bomViewer);
}
return new RuleExecuteResult();
}
public void hasOperationPermission(Map<String, Object> detail, BillContext billContext) throws Exception {
IStaffUserService staffUserService = AppContext.getBean(IStaffUserService.class);
boolean canOperationPermission = false;
StaffOrgVo staffOrgVo = staffUserService.getStaffOrgByUserId(AppContext.getUserId());
Set<String> orgs = OrgPermissionUtils.getOrgPermissionsByAuth("plm_pbm_bom");
if( (BusinessUtil.hasAdminAuth(AuthIdConstants.IMP_PLM_P_EBOM_ADMIN) && CollectionUtils.isNotEmpty(orgs) && orgs.contains(MapUtils.getString(detail, FieldConst.FIELD_OWNEDORG)))
|| StringUtils.equals(staffOrgVo.getStaffId(), MapUtils.getString(detail, Constants.BOM_VIEWER_OWNEDBY)) ){
canOperationPermission = true;
}
if( ! canOperationPermission ){
throw new PSMException(ExceptionEnum.NOT_OPERATION_PERMISSION);
}
}
protected void canLockOrUnLockCheck(Map<String, Object> detail) {
if (!canLockOrUnLock(detail)) {
throw new PSMException("BOM被其他人锁定!");
}
}
private boolean canLockOrUnLock(Map<String, Object> detail) {
return canLock(detail) || canUnLock(detail);
}
private boolean canLock(Map<String, Object> detail) {
return MapUtils.getIntValue(detail, Constants.BOM_VIEWER_EDITING_STATE) == EditStatus.unlock.getStatus();
}
private boolean canUnLock(Map<String, Object> detail) {
return MapUtils.getIntValue(detail, Constants.BOM_VIEWER_EDITING_STATE) == EditStatus.lock.getStatus()
&& StringUtils.equals(MapUtils.getString(detail, Constants.BOM_VIEWER_LOCKEDBY), AppContext.getUserId());
}
}