田源
2023-05-09 d2570148ec3884de3af721bd99c4b7acbbdee075
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeButtonServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,204 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill åº„骞 (smallchill@163.com)
 */
package com.vci.ubcs.code.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.vci.ubcs.code.entity.CodeButton;
import com.vci.ubcs.code.enumpack.FrameworkDataLCStatus;
import com.vci.ubcs.code.mapper.CodeButtonMapper;
import com.vci.ubcs.code.service.ICodeButtonService;
import com.vci.ubcs.code.vo.pagemodel.CodeButtonVO;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.web.util.BeanUtilForVCI;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * æ¨¡æ¿æ‰©å±•æ±  æœåŠ¡å®žçŽ°ç±»
 *
 * @author yuxc
 * @since 2023-03-29
 */
@Service
public class CodeButtonServiceImpl implements ICodeButtonService {
   @Resource
   CodeButtonMapper codeButtonMapper;
   @Override
   public IPage<CodeButtonVO> selectcodebuttonPage(IPage<CodeButtonVO> page, CodeButtonVO codebutton) {
      return page.setRecords(codeButtonMapper.selectcodebuttonPage(page, codebutton));
   }
   /**
    * ä¸»é”®æ‰¹é‡èŽ·å–ä¸»æ•°æ®ä¸­çš„æŒ‰é’®æ‰©å±•
    * @param oidCollections ä¸»é”®é›†åˆï¼Œä½†æ˜¯å—性能影响,建议一次查询不超过10000个
    * @return ä¸»æ•°æ®ä¸­çš„æŒ‰é’®æ‰©å±•显示对象
    * @throws VciBaseException æŸ¥è¯¢å‡ºçŽ°å¼‚å¸¸æ—¶ä¼šæŠ›å‡º
    */
   @Override
   public Collection<CodeButtonVO> listCodeButtonByOids(Collection<String> oidCollections) throws VciBaseException {
      VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合");
      List<CodeButton> codeButtonDOList = listCodeButtonDOByOidCollections(oidCollections);
      return codeButtonDO2VOs(codeButtonDOList);
   }
   /**
    * æ‰¹é‡æ•°æ®å¯¹è±¡è½¬æ¢ä¸ºæ˜¾ç¤ºå¯¹è±¡
    * @param codeButtonDOs æ•°æ®å¯¹è±¡åˆ—表
    * @return æ˜¾ç¤ºå¯¹è±¡
    * @throws VciBaseException å‚数为空或者不存在的时候会抛出异常
    */
   @Override
   public List<CodeButtonVO> codeButtonDO2VOs(Collection<CodeButton>  codeButtonDOs) throws VciBaseException{
      List<CodeButtonVO> voList = new ArrayList<CodeButtonVO>();
      if(!CollectionUtils.isEmpty(codeButtonDOs)){
         for(CodeButton s: codeButtonDOs){
            CodeButtonVO vo =  codeButtonDO2VO(s);
            if(vo != null){
               voList.add(vo);
            }
         }
      }
      return voList;
   }
   /**
    * æ•°æ®å¯¹è±¡è½¬æ¢ä¸ºæ˜¾ç¤ºå¯¹è±¡
    * @param  codeButtonDO æ•°æ®å¯¹è±¡
    * @return æ˜¾ç¤ºå¯¹è±¡
    * @throws VciBaseException æ‹·è´å±žæ€§å‡ºé”™çš„æ—¶å€™ä¼šæŠ›å‡ºå¼‚常
    */
   @Override
   public  CodeButtonVO codeButtonDO2VO(CodeButton codeButtonDO) throws VciBaseException{
      CodeButtonVO vo = new CodeButtonVO();
      if(codeButtonDO != null){
         BeanUtilForVCI.copyPropertiesIgnoreCase(codeButtonDO,vo);
         //如果有lcstatus的类的话
         vo.setLcStatusText(FrameworkDataLCStatus.getTextByValue(vo.getLcStatus()));
      }
      return vo;
   }
   @Override
   public List<CodeButton> selectByPrimaryKeyCollection(Collection<String> oids) {
      VciBaseUtil.alertNotNull(oids,"主键集合");
      return codeButtonMapper.selectBatchIds(oids);
   }
   /**
    * ä½¿ç”¨ä¸»é”®é›†åˆæŸ¥è¯¢æ•°æ®å¯¹è±¡
    * @param oidCollections ä¸»é”®çš„集合
    * @return æ•°æ®å¯¹è±¡åˆ—表
    */
   private List<CodeButton> listCodeButtonDOByOidCollections(Collection<String> oidCollections){
      List<CodeButton> codeButtonDOList = new ArrayList<CodeButton>();
      if(!CollectionUtils.isEmpty(oidCollections)){
         Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections);
         for(Collection<String> oids: oidCollectionsList){
            List<CodeButton> tempDOList =  codeButtonMapper.selectBatchIds(oids);
            if(!CollectionUtils.isEmpty(tempDOList)){
               codeButtonDOList.addAll(tempDOList);
            }
         }
      }
      return  codeButtonDOList;
   }
   @Override
    public R enableCodeButton(String id) {
      CodeButton codebutton = codeButtonMapper.selectById(id);
      return changeLcStatus(codebutton,true);
    }
   /**
    * åœç”¨
    *
    * @param oid æ•°æ®ä¼ è¾“对象
    * @return æ‰§è¡Œç»“æžœ
    */
   @Override
   public R disableOrgDuty(String oid) {
      CodeButton codebutton = codeButtonMapper.selectById(oid);
      return changeLcStatus(codebutton,false);
   }
   //   @Override
//   public R deleteCodeButton(String ids) {
////      VciBaseUtil.alertNotNull(codeButtonDTO,"主数据中的按钮扩展数据对象",codeButtonDTO.getOid(),"主数据中的按钮扩展的主键");
//      if(StringUtils.isEmpty(ids)){
//         return R.fail("传入非法数据!");
//      }
//      CodeButtonEntity codebutton = codeButtonMapper.selectById(ids);
//
//      CodeButtonDO codeButtonDO = selectByOid(codeButtonDTO.getOid());
//      BaseResult baseResult = checkIsCanDeleteForDO(codeButtonDTO,codeButtonDO);
//      if(baseResult.isSuccess()) {
//      }else{
//         return baseResult;
//      }
//      //执行删除操作
//      BatchCBO batchCBO = codeButtonMapper.deleteByPrimaryKey(codeButtonDO.getOid());
//      return (batchCBO!=null && batchCBO.getDeleteCbos() !=null &&batchCBO.getDeleteCbos().size() > 0)?BaseResult.successMsg(DELETE_SUCCESS):BaseResult.fail(DELETE_FAIL);
//   }
   /**
    * ä¿®æ”¹ç”Ÿå‘½å‘¨æœŸçš„状态,如停用和启用
    * @param buttonDTO æ•°æ®ä¼ è¾“对象,必须要有oid和ts
    * @param disable æ˜¯å¦ä¸ºåœç”¨
    * @return æ‰§è¡Œçš„结果
    */
   private R changeLcStatus(CodeButton buttonDTO, boolean disable){
//      VciBaseUtil.alertNotNull(buttonDTO,"数据对象",buttonDTO.getOid(),"主键");
      if(disable){
         buttonDTO.setLcstatus(FrameworkDataLCStatus.ENABLED.getValue());
      }else{
         buttonDTO.setLcstatus(FrameworkDataLCStatus.DISABLED.getValue());
      }
      return SqlHelper.retBool(codeButtonMapper.updateById(buttonDTO))?
         R.success(FrameworkDataLCStatus.ENABLED.getValue()):R.fail(FrameworkDataLCStatus.DISABLED.getValue());
   }
   //   /**
//    * æ ¡éªŒæ˜¯å¦å¯ä»¥åˆ é™¤ï¼Œå¦‚果存在下级,并且下级有数据引用则不能删除
//    * @param codeButtonDTO æ•°æ®ä¼ è¾“对象
//    * @param codeButtonDO æ•°æ®åº“中的数据对象
//    * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
//    */
//   private R checkIsCanDeleteForDO(CodeButtonEntity codeButtonDTO, CodeButtonVO codeButtonDO) {
//      CodeButtonVO buttonDO = new CodeButtonVO();
//      BeanUtil.convert(codeButtonDTO,buttonDO);
//      boService.checkTs(buttonDO);
//      if(!checkIsLinked(codeButtonDO.getOid())) {
//         return BaseResult.success();
//      }else{
//         return BaseResult.fail(DATA_LINKED_NOT_DELETE,new String[]{""});
//      }
//   }
}