package com.vci.web.controller; import com.vci.constant.FrameWorkLangCodeConstant; import com.vci.corba.common.PLException; import com.vci.corba.omd.ltm.LinkType; import com.vci.pagemodel.OsBtmTypeAttributeVO; import com.vci.pagemodel.OsLinkTypeAttributeVO; import com.vci.pagemodel.OsLinkTypeVO; import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.BaseQueryObject; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.DataGrid; import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.web.service.OsLinkTypeServiceI; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.text.ParseException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 链接类型的控制器 * @author weidy * @date 2022-3-26 */ @RequestMapping("/linkTypeController") @RestController public class OsLinkTypeController { /** * 链接类型 */ @Autowired private OsLinkTypeServiceI linkTypeService; /** * 日志 */ private Logger logger = LoggerFactory.getLogger(getClass()); /** * 链接类型的列表 * @param baseQueryObject 查询对象 * @return 链接类型的显示对象 */ @GetMapping("/gridLinkType") public DataGrid gridLinkType(BaseQueryObject baseQueryObject){ return linkTypeService.gridLinkType(baseQueryObject); } /** * 查询所有的链接类型名称,可用于属性池的连接类型选择时的对话框 * @return 链接类型的显示对象 */ @GetMapping("/getAllLtName") public BaseResult getAllLtName(){ try { return BaseResult.dataList(linkTypeService.getAllLtName()); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "链接类型列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } /** * 获取链接类型包含的属性 * @param linkTypeOid 链接类型的主键 * @param baseQueryObject 查询对象 * @return 属性的信息 */ @GetMapping("/gridAttributeByLinkTypeOid") public DataGrid gridAttributeByLinkTypeOid(String linkTypeOid, BaseQueryObject baseQueryObject){ if(StringUtils.isBlank(linkTypeOid)){ return new DataGrid(); } String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):""; String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : ""; OsLinkTypeVO linkTypeVO = linkTypeService.selectByOid(linkTypeOid); List boAttrs = null; try { boAttrs = linkTypeService.listAttributeByLinkId(linkTypeVO.getId()); }catch (Exception e){ e.printStackTrace(); String errorLog = "查询链接类型关联的属性时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e); logger.error(errorLog); throw new VciBaseException(errorLog); } List attrList = boAttrs.stream().filter(s->{ boolean usedFlag = true; if(StringUtils.isNotBlank(attrId) && !s.getId().contains(attrId)){ usedFlag = false; } if(StringUtils.isNotBlank(attrName) && !s.getName().contains(attrName)){ usedFlag = false; } return usedFlag; }).collect(Collectors.toList()); DataGrid dataGrid = new DataGrid(); dataGrid.setTotal(attrList.size());; dataGrid.setData(attrList); return dataGrid; } /** * 获取链接类型包含的属性 * @param name 链接类型的编号 * @return 属性的信息 */ @GetMapping("/getAllAttributeByLink") public BaseResult> getAllAttributeByLink(String name){ try { List osLinkTypeAttributeVOS = linkTypeService.getAllAttributeByLink(name); return BaseResult.dataList(osLinkTypeAttributeVOS); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } catch (ParseException e) { throw new RuntimeException(e); } } /** * 检查链接类型中关联的业务类型的属性有不同的内容 * @param linkTypeOid 链接类型的主键 * @return 差异的属性 */ @PostMapping("/checkAttributeTypeDifferent") public BaseResult checkAttributeTypeDifferent(String linkTypeOid){ if(StringUtils.isBlank(linkTypeOid)){ return BaseResult.success(); } List attributeVOList = linkTypeService.checkAttributeTypeDifferent(linkTypeOid); if(!CollectionUtils.isEmpty(attributeVOList)) { BaseResult result = BaseResult.fail("有不同"); result.setData(attributeVOList); return result; }else{ return BaseResult.success(); } } /** * 链接类型的列表 * * @return 链接类型的显示对象 */ @GetMapping("/gridLink") public BaseResult> gridLink(){ try { return linkTypeService.gridLink(); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } } /** * 链接类型保存 * linkType 链接类型的保存对象 * addFlag 是否为新增 true新增,false修改 * @return 保存结果 */ @PostMapping("/addAndEditLink") public BaseResult addAndEditLink(@RequestBody LinkType linkType, Boolean addFlag){ try { return linkTypeService.addAndEditLink(linkType, addFlag); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } } /** * 链接类型删除 * linkType 链接类型对象 * @return 删除结果 */ @DeleteMapping("/deleteLink") public BaseResult deleteLink(@RequestBody LinkType linkType){ try { return linkTypeService.deleteLink(linkType); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } } /** * 一致性检查 * @return 删除结果 */ @GetMapping("/checkLinkType") public BaseResult checkLinkType(){ try { return linkTypeService.checkLinkType(); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } } /** * 一致性检查修复数据库表 * repairData 需要修复的数据 * @return 修复结果 */ @PostMapping("/repairTable") public BaseResult repairTable(@RequestBody String repairData){ try { return linkTypeService.repairTable(repairData); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } catch (IOException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(500); objectBaseResult.setMsg(e.getMessage()); return objectBaseResult; } } /** * 创建视图 * @return 创建结果 */ @PostMapping("/createView") public BaseResult createView(){ try { return linkTypeService.createView(); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } } /** * 导出链接类型 * name 链接类型名称 * @return */ @GetMapping("/expData") public void expData(String name,HttpServletResponse response) throws PLException, IOException { linkTypeService.expData(name, response); } /** * 导入链接类型 * @param file 上传的文件 * @return */ @PostMapping("/impData") public BaseResult impData(MultipartFile file){ try { return linkTypeService.impData(file); }catch (Throwable e) { throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e); } } /** * 获取设置排序字段的排序字段 * @param linkType 链接类型的编号 * @param btmType 业务类型的编号 * @param direction 正/反向 * @return 属性的信息 */ @GetMapping("/getAllOrderbyAttributeByLink") public BaseResult> getAllOrderbyAttributeByLink(String linkType, String btmType, String direction){ try { List osLinkTypeAttributes = linkTypeService.getAllOrderbyAttributeByLink(linkType, btmType, direction); return BaseResult.dataList(osLinkTypeAttributes); } catch (PLException e) { BaseResult objectBaseResult = new BaseResult<>(); objectBaseResult.setCode(Integer.parseInt(e.code)); objectBaseResult.setMsg(Arrays.toString(e.messages)); return objectBaseResult; } catch (ParseException e) { throw new RuntimeException(e); } } }