dangsn
2024-12-03 d0ae279ff3b83358d1c07f4481a041c4ad335026
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/WebBtmTypeController.java
@@ -1,7 +1,11 @@
package com.vci.web.controller;
import com.vci.corba.common.PLException;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.dto.OsBtmTypeDTO;
import com.vci.model.IndexObject;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsBtmTypeVO;
import com.vci.pagemodel.OsERVO;
import com.vci.starter.web.annotation.log.VciBusinessLog;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.exception.VciBaseException;
@@ -9,15 +13,13 @@
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.Tree;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.BeanUtilForVCI;
import com.vci.starter.web.util.ControllerUtil;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsBtmTypeVO;
import com.vci.pagemodel.OsERVO;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBtmServiceI;
import com.vci.web.service.OsLinkTypeServiceI;
import com.vci.web.service.WebBtmIOServiceI;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -25,11 +27,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -57,6 +61,12 @@
     */
    @Autowired
    private OsBtmServiceI btmService;
    /**
     * 连接类型的服务
     */
    @Autowired
    private OsLinkTypeServiceI linkTypeService;
    /**
     * 业务类型导入导出服务
@@ -89,7 +99,6 @@
     */
    @GetMapping( "/getBizTypes")
    @VciBusinessLog(operateName = "业务类型列表(主要用于对话框使用)")
    @VciUnCheckRight
    public BaseResult getBizTypes(String btmName){
        try {
            return BaseResult.dataList(Arrays.asList(btmService.getBizTypes(btmName)));
@@ -101,35 +110,326 @@
        }
    }
    /**
     * 获取所有业务类型(树形结构)
     * @return 查询结果
     */
    @GetMapping( "/getTreeBizTypes")
    @VciBusinessLog(operateName = "获取所有业务类型(树形结构)")
    @VciUnCheckRight
    public BaseResult<List<Tree>> getTreeBizTypes(){
        try {
            return btmService.getTreeBizTypes();
            return BaseResult.dataList(btmService.getTreeBizTypes());
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "获取业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            String exceptionMessage = "查询业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 获取业务类型包含的属性
     * 获取业务类型使用范围
     * @param btmName
     * @return 查询结果
     */
    @GetMapping( "/getUsedBtmLinkList")
    @VciBusinessLog(operateName = "获取业务类型使用范围")
    public BaseResult<List<String>> getUsedBtmLinkList(String btmName){
        try {
            return BaseResult.dataList(linkTypeService.getUsedBtmLinkList(btmName));
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "获取业务类型使用范围时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 创建业务类型
     * btmTypeDTO 链接类型的保存对象
     * @return 保存结果
     */
    @PostMapping("/addBtmType")
    public BaseResult addBtmType(@RequestBody OsBtmTypeDTO btmTypeDTO){
        try {
            return btmService.addBtmType(btmTypeDTO) ? BaseResult.success("业务类型创建成功!"):BaseResult.fail("业务类型创建失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "创建业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 批量创建业务类型
     * btmTypeDTO 链接类型的保存对象
     * @return 保存结果
     */
    /*@PostMapping("/addBtmTypes")
    public BaseResult addBtmTypes(@RequestBody List<BizType> bizTypes){
        try {
            return btmService.addBtmTypes(bizTypes) ? BaseResult.success("业务类型批量创建成功!"):BaseResult.fail("业务类型批量创建失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "批量创建业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }*/
    /**
     * 修改业务类型
     * btmTypeDTO 链接类型修改的对象
     * @return 保存结果
     */
    @PutMapping("/updateBtmType")
    public BaseResult updateBtmType(@RequestBody OsBtmTypeDTO btmTypeDTO){
        try {
            return btmService.updateBtmType(btmTypeDTO) ? BaseResult.success("业务类型修改成功!"):BaseResult.fail("业务类型修改失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "修改业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 业务类型删除
     * btmTypeDTO 业务类型对象
     * @return 删除结果
     */
    @DeleteMapping("/deleteBtmType")
    public BaseResult deleteLink(@RequestBody OsBtmTypeDTO btmTypeDTO){
        try {
            return btmService.deleteBtmType(btmTypeDTO) ? BaseResult.success("删除业务类型成功!"):BaseResult.fail("删除业务类型失败!");
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = "删除业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 一致性检查
     * @return 检查结果
     */
    @GetMapping("/checkBtmConsistency")
    public BaseResult checkBtmConsistency(){
        try {
            return btmService.checkBtmConsistency();
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = "业务类型一致性检查时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 一致性检查,业务类型修复
     * @return 删除结果
     */
    @PostMapping("/executeRepair")
    public BaseResult executeRepair(@RequestBody String repairData){
        try {
            return btmService.executeRepair(repairData);
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "业务类型修复时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 创建视图
     * @return
     */
    @PostMapping("/createView")
    public BaseResult createView(){
        try {
            return btmService.createView() ? BaseResult.success("创建视图成功!"):BaseResult.fail("创建视图失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "创建视图时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 删除数据界面的数据查询
     * @return
     */
    @GetMapping("/getObjectData")
    public BaseResult getObjectData(){
        try {
            return btmService.getObjectData();
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "数据对象查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 删除数据
     * @param btmNames 业务类型名
     * @param linkNames 链接类型名
     * @return
     * @throws PLException
     */
    @DeleteMapping("/truncateTable")
    public BaseResult truncateTable(String[] btmNames,String[] linkNames){
        try {
            return BaseResult.dataList(btmService.truncateTable(btmNames,linkNames));
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "删除数据时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 删除全部类型
     * @return
     * @throws PLException
     */
    @DeleteMapping("/deleteAllType")
    public BaseResult deleteAllType(){
        try {
            return BaseResult.dataList(btmService.deleteAllType());
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "删除全部类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 获取当前业务类型下的索引
     * @return
     * @throws PLException
     */
    @GetMapping("/getIndexByCondition")
    public BaseResult getIndexByCondition(BaseQueryObject baseQueryObject){
        try {
            return BaseResult.dataList(btmService.getIndexByCondition(baseQueryObject.getConditionMap()));
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "查询当前业务类型下的索引时时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 创建索引
     * @param indexObjectList
     * @return
     */
    @PostMapping("/addIndex")
    public BaseResult addIndex(@RequestBody List<IndexObject> indexObjectList){
        try {
            return btmService.addIndex(indexObjectList) ? BaseResult.success("创建索引成功!"):BaseResult.fail("创建索引失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "创建索引时时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 删除索引
     * @param btmName
     * @param indexName
     * @return
     */
    @DeleteMapping("/delIndex")
    public BaseResult delIndex(String btmName,String indexName){
        try {
            return btmService.delIndex(btmName,indexName) ? BaseResult.success("删除索引成功!"):BaseResult.fail("删除索引失败!");
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "删除索引时时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
    /**
     * 导出业务类型
     * name 链接类型名称
     * @return
     */
    @GetMapping("/expData")
    public void expData(String name,HttpServletResponse response) throws PLException, IOException {
        btmService.expData(name, response);
    }
    /**
     * 导入业务类型
     * @param file 上传的文件
     * @return
     */
    @PostMapping("/impData")
    public BaseResult impData(MultipartFile file){try {
        return btmService.impData(file);
    }catch (Throwable e) {
        throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e);
    }
    }
    /**
     * 获取业务类型包含的属性全部为小写
     * @param btmId 业务类型名称
     * @return 属性的信息
     */
    @GetMapping(value = "/getAllAttributesByBtmId")
    @VciBusinessLog(operateName = "查看业务类型的属性")
    public BaseResult<List<OsBtmTypeAttributeVO>> getAllAttributesByBtmId(String btmId){
        List<OsBtmTypeAttributeVO> osBtmTypeAttributeVOS = btmService.listAttributeByBtmIdHasDefault(btmId);
        List<OsBtmTypeAttributeVO> osBtmTypeAttributeVOS = null;
        try {
            osBtmTypeAttributeVOS = btmService.listAttributeByBtmIdHasDefault(btmId);
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        return BaseResult.dataList(osBtmTypeAttributeVOS);
    }
    /**
     * 获取业务全部属性类型
     * @param btmName 业务类型名称
     * @return 属性的信息
     */
    @GetMapping(value = "/getBizTypeQTDs")
    @VciBusinessLog(operateName = "查看业务类型的属性")
    public BaseResult<List<OsBtmTypeAttributeVO>> getBizTypeQTDs(String btmName){
        try {
            List<OsBtmTypeAttributeVO> osBtmTypeAttributeVOS = btmService.getBizTypeQTDs(btmName);
            return BaseResult.dataList(osBtmTypeAttributeVOS);
        } catch (PLException e) {
            BaseResult objectBaseResult = new BaseResult<>();
            objectBaseResult.setCode(Integer.parseInt(e.code));
            objectBaseResult.setMsg(Arrays.toString(e.messages));
            return objectBaseResult;
        } catch (ParseException e) {
            BaseResult objectBaseResult = new BaseResult<>();
            objectBaseResult.setCode(500);
            objectBaseResult.setMsg(e.getMessage());
            return objectBaseResult;
        }
    }
    /**
@@ -158,7 +458,15 @@
        String hasDefaultAttr = baseQueryObject.getConditionMap().getOrDefault("hasDefaultAttr","false");
        String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):"";
        String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : "";
        List<OsBtmTypeAttributeVO> boAttrs = btmService.listAttributeByBtmId(btmTypeId);
        List<OsBtmTypeAttributeVO> boAttrs = null;
        try {
            boAttrs = btmService.listAttributeByBtmId(btmTypeId);
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        if(boAttrs == null){
            boAttrs = new ArrayList<>();
        }
@@ -167,9 +475,9 @@
            List<OsBtmTypeAttributeVO> finalBoAttrs = boAttrs;
            attributeService.getDefaultAttributeVOs().stream().forEach(attr->{
                OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attr,attributeVO);
                BeanUtilForVCI.convert(attr,attributeVO);
                attributeVO.setAttributeLength(attr.getAttrLength());
                attributeVO.setAttrDataType(attr.getAttributeDataType());
                attributeVO.setAttributeDataType(attr.getAttributeDataType());
                attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
                attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
                finalBoAttrs.add(attributeVO);
@@ -192,7 +500,6 @@
        return dataGrid;
    }
    /**
     * 使用主键获取业务类型包含的属性,不分页
     * @param baseQueryObject 查询对象
@@ -207,7 +514,15 @@
        String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):"";
        String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : "";
        OsBtmTypeVO btmTypeVO = btmService.selectByOid(btmTypeOid);
        List<OsBtmTypeAttributeVO> boAttrs = btmService.listAttributeByBtmId(btmTypeVO.getId());
        List<OsBtmTypeAttributeVO> boAttrs = null;
        try {
            boAttrs = btmService.listAttributeByBtmId(btmTypeVO.getId());
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        List<OsBtmTypeAttributeVO> attrList = boAttrs.stream().filter(s->{
            boolean usedFlag = true;
            if(StringUtils.isNotBlank(attrId) && !s.getId().contains(attrId)){
@@ -224,7 +539,6 @@
        return dataGrid;
    }
    /**
     * 使用主键获取业务类型的对象
     * @param oid 主键
@@ -238,6 +552,7 @@
        }
        return BaseResult.success(btmTypeVO);
    }
    /**
     * 导出业务类型的信息到word中
     * @param btmTypeIds 业务类型的编号,用逗号分割
@@ -294,8 +609,15 @@
     */
    @GetMapping("/createERDiagram")
    public BaseResult createERDiagram(String id){
        OsERVO osERVO = btmService.createERDiagram(id);
        return BaseResult.success(osERVO);
        try {
            OsERVO osERVO = btmService.createERDiagram(id);
            return BaseResult.success(osERVO);
        }catch (Exception e){
            e.printStackTrace();
            String msg = "生成业务类型使用的ER图时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e);
            logger.error(msg);
            return BaseResult.fail(msg);
        }
    }
    /**
@@ -305,6 +627,14 @@
     */
    @GetMapping("/createERUsed")
    public BaseResult createERUsed(String id){
        return BaseResult.success(btmService.createERUsed(id));
        try {
            return BaseResult.success(btmService.createERUsed(id));
        } catch (PLException e) {
            e.printStackTrace();
            String msg = "取使用这个业务类型的E-R图时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e);
            logger.error(msg);
            return BaseResult.fail(msg);
        }
    }
}