ludc
2024-07-26 696c68a9f7645bc35a9382a4e2271910b222f7b5
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java
@@ -13,9 +13,11 @@
import com.vci.dto.OsStatusDTO;
import com.vci.model.OsStatusDO;
import com.vci.pagemodel.OsStatusVO;
import com.vci.starter.web.util.WebThreadLocalUtil;
import com.vci.web.service.OsLifeCycleServiceI;
import com.vci.web.service.OsStatusServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
@@ -26,6 +28,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.swing.*;
import java.util.*;
import java.util.stream.Collectors;
@@ -78,11 +81,12 @@
     * @return 显示对象
     */
    @Override
    public OsStatusVO statusDO2VO(com.vci.corba.omd.stm.StatePool statePool) {
    public OsStatusVO statusDO2VO(StatePool statePool) {
        OsStatusVO statusVO = new OsStatusVO();
        if(statePool!=null){
            statusVO.setOid(statePool.oid);
            statusVO.setCreator(statePool.creator);
            statusVO.setImagePath(statePool.imagePath);
            statusVO.setLastModifier(statePool.modifier);
            try {
                statusVO.setCreateTime(new Date(statePool.createTime));
@@ -105,7 +109,7 @@
     * @return 显示对象
     */
    @Override
    public List<OsStatusVO> statusDO2VOs(Collection<com.vci.corba.omd.stm.StatePool> statePools) {
    public List<OsStatusVO> statusDO2VOs(Collection<StatePool> statePools) {
        List<OsStatusVO> statusVOS = new ArrayList<>();
        if(!CollectionUtils.isEmpty(statePools)){
            statePools.stream().forEach(statePool -> {
@@ -169,7 +173,7 @@
     * @param statePoolList 状态内容
     */
    @Override
    public void batchAddStatus(List<StatePool> statePoolList) {
    public boolean batchAddStatus(List<StatePool> statePoolList) throws Exception{
        if(!CollectionUtils.isEmpty(statePoolList)){
            for(StatePool statePool : statePoolList) {
                try {
@@ -179,6 +183,7 @@
                }
            }
        }
        return true;
    }
    /**
@@ -186,7 +191,7 @@
     * @param statePoolList 状态内容
     */
    @Override
    public void batchEditSave(List<StatePool> statePoolList) {
    public boolean batchEditSave(List<StatePool> statePoolList) {
        if(!CollectionUtils.isEmpty(statePoolList)){
            for(StatePool statePool : statePoolList) {
                try {
@@ -196,6 +201,7 @@
                }
            }
        }
        return true;
    }
    /**
@@ -255,26 +261,46 @@
     * @param statusDTO 状态的数据传输对象
     */
    @Override
    public void addSave(OsStatusDTO statusDTO) {
        VciBaseUtil.alertNotNull(statusDTO,"状态的信息",statusDTO.getId(),"状态的英文名称",statusDTO.getName(),"状态的中文名称");
    public boolean addSave(OsStatusDTO statusDTO) throws Exception {
        VciBaseUtil.alertNotNull(
            statusDTO,"状态的信息",
            statusDTO.getId(),"状态的英文名称",
            statusDTO.getName(),"状态的中文名称"
        );
        StatePool dbStatePool = platformClientUtil.getStatePoolService().getStatePool(statusDTO.getName());
        if (Func.isNotEmpty(dbStatePool) || Func.isNotBlank(dbStatePool.oid)) {
            throw new PLException("500",new String[]{"名称重复请更换名称!"});
        }
        // 状态池名称只能为英文字母
        String regex = "[a-z A-Z]*";
        if ((!dbStatePool.name.matches(regex))) {
            throw new PLException("500",new String[]{"名称只能为英文!"});
        }
        //虽然会自动生成oid,但是这儿设置主键,避免放入缓存的数据是没有oid的
        statusDTO.setOid(VciBaseUtil.getPk());
        StatePool pool = statusDTO2DO(statusDTO);
        List<StatePool> poolList = new ArrayList<>();
        poolList.add(pool);
        batchAddStatus(poolList);
        clearCache();
        //clearCache();
        self.selectAllStatusMap();
        return true;
    }
    /**
     * 编辑状态
     * @param statusDTO 状态的数据传输对象
     */
    @Override
    public void editSave(OsStatusDTO statusDTO){
        VciBaseUtil.alertNotNull(statusDTO,"状态的信息",statusDTO.getId(),"状态的英文名称",statusDTO.getName(),"状态的中文名称",statusDTO.getOid(),"主键");
    public boolean editSave(OsStatusDTO statusDTO) throws Exception {
        VciBaseUtil.alertNotNull(statusDTO,"状态的信息",
                statusDTO.getId(),"状态的英文名称",
                statusDTO.getName(),"状态的中文名称",
                statusDTO.getOid(),"主键");
        OsStatusVO statusVO = getObjectByOid(statusDTO.getOid());
        if(Func.isEmpty(statusVO) || Func.isBlank(statusVO.getOid())){
            throw new PLException("500",new String[]{"修改的状态对象不存在!"});
        }
        StatePool pool = statusDTO2DO(statusDTO);
        pool.creator = statusVO.getCreator();
        pool.createTime = VciDateUtil.getTime(statusVO.getCreateTime());
@@ -283,6 +309,7 @@
        batchEditSave(poolList);
        clearCache();
        self.selectAllStatusMap();
        return true;
    }
    /**
@@ -290,7 +317,7 @@
     * @param oids 主键
     */
    @Override
    public void delete(String oids){
    public boolean delete(String oids){
        VciBaseUtil.alertNotNull(oids,"主键");
        //判断是否被引用
        List<OsStatusVO> statusVOList1 = selectByOidCollection(VciBaseUtil.str2List(oids));
@@ -306,6 +333,7 @@
        });
        clearCache();
        self.selectAllStatusMap();
        return true;
    }
    /**
@@ -319,8 +347,9 @@
        statePool.oid = statusDTO.getOid();
        statePool.id = "";
        statePool.name = statusDTO.getId();
        statePool.imagePath = statusDTO.getImagePath();
        statePool.description = statusDTO.getDescription()==null?"":statusDTO.getDescription();
        String userId = VciBaseUtil.getCurrentUserId();
        String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
        long now = VciDateUtil.getNowTime();
        statePool.creator = userId;
        statePool.createTime = now;