package com.vci.ubcs.code.controller;
|
|
|
import com.vci.ubcs.code.service.CodeClassifyServiceI;
|
import com.vci.starter.web.pagemodel.*;
|
import com.vci.starter.web.util.ControllerUtil;
|
import com.vci.starter.web.util.LangBaseUtil;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.web.pageModel.OsAttributeVO;
|
import org.apache.commons.lang.StringUtils;
|
import com.vci.ubcs.code.dto.CodeClassifyDTO;
|
import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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.nio.charset.StandardCharsets;
|
import java.util.Collection;
|
import java.util.List;
|
|
import static com.vci.frameworkcore.constant.FrameWorkDefaultValueConstant.FRAMEWORK_DATA_DISABLED;
|
import static com.vci.frameworkcore.constant.FrameWorkDefaultValueConstant.FRAMEWORK_DATA_ENABLED;
|
|
/**
|
* 主题库分类控制器
|
*
|
* @author weidy
|
* @date 2022-01-20
|
*/
|
@RestController
|
@RequestMapping("/codeClassifyController")
|
public class CodeClassifyController {
|
/**
|
* 主题库分类 服务
|
*/
|
@Autowired
|
private CodeClassifyServiceI codeClassifyService;
|
|
/**
|
* 主题库分类树
|
* @param treeQueryObject 树形查询对象
|
* @return 主题库分类显示树
|
*/
|
@GetMapping("/treeCodeClassify")
|
public List<Tree> treeCodeClassify(TreeQueryObject treeQueryObject) {
|
return codeClassifyService.treeCodeClassify(treeQueryObject);
|
}
|
|
/**
|
* 主题库的树
|
* @param treeQueryObject 树形查询对象
|
* @return 主题库显示树
|
*/
|
@GetMapping("/treeTopCodeClassify")
|
public List<Tree> treeTopCodeClassify(TreeQueryObject treeQueryObject){
|
return codeClassifyService.treeTopCodeClassify(treeQueryObject);
|
}
|
|
/**
|
* 增加 主题库分类
|
* @param codeClassifyDTO 主题库分类数据传输对象
|
* @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
|
*/
|
@PostMapping( "/addSave")
|
public BaseResult<CodeClassifyVO> addSave(@RequestBody CodeClassifyDTO codeClassifyDTO){
|
if(codeClassifyDTO.getOrdernum()==null){
|
codeClassifyDTO.setOrdernum(0);
|
}
|
CodeClassifyVO codeClassifyVO = codeClassifyService.addSave(codeClassifyDTO);
|
return BaseResult.success(codeClassifyVO);
|
}
|
|
/**
|
* 修改 主题库分类
|
* @param codeClassifyDTO 主题库分类数据传输对象
|
* @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
|
*/
|
@PutMapping("/editSave")
|
public BaseResult<CodeClassifyVO> editSave(@RequestBody CodeClassifyDTO codeClassifyDTO){
|
return codeClassifyService.editSave(codeClassifyDTO);
|
}
|
|
/**
|
* 检查 主题库分类是否删除
|
* @param codeClassifyDTO 主题库分类数据传输对象,必须要有oid和ts属性
|
* @return 执行结果 success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
@PostMapping( "/checkIsCanDelete")
|
public BaseResult checkIsCanDelete(CodeClassifyDTO codeClassifyDTO) {
|
return codeClassifyService.checkIsCanDelete(codeClassifyDTO);
|
}
|
|
/**
|
* 删除主题库分类
|
* @param codeClassifyDTO,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
*/
|
@DeleteMapping( "/deleteData")
|
public BaseResult delCodeClassify(CodeClassifyDTO codeClassifyDTO) {
|
return codeClassifyService.deleteCodeClassify(codeClassifyDTO);
|
}
|
|
/**
|
* 启用
|
* @param codeClassifyDTO
|
* @return
|
*/
|
@PostMapping( "/enableData")
|
public BaseResult enable(CodeClassifyDTO codeClassifyDTO) {
|
return codeClassifyService.updateLcStatus(codeClassifyDTO.getOid(),FRAMEWORK_DATA_ENABLED);
|
}
|
|
/**
|
* 停用
|
* @param codeClassifyDTO
|
* @return
|
*/
|
@PostMapping( "/disableData")
|
public BaseResult disable(CodeClassifyDTO codeClassifyDTO) {
|
return codeClassifyService.updateLcStatus(codeClassifyDTO.getOid(),FRAMEWORK_DATA_DISABLED);
|
}
|
|
/**
|
* 主键获取主题库分类
|
* @param oid 主键
|
* @return 主题库分类显示对象
|
*/
|
@GetMapping("/getObjectByOid")
|
public BaseResult<CodeClassifyVO> getObjectByOid(String oid){
|
CodeClassifyVO codeClassifyVO = codeClassifyService.getObjectByOid(oid);
|
return BaseResult.success(codeClassifyVO);
|
}
|
|
/**
|
* 主键批量获取主题库分类
|
* @param oids 主键,多个以逗号分隔,但是受性能影响,建议一次查询不超过10000个
|
* @return 主题库分类显示对象
|
*/
|
@GetMapping("/listDataByOids")
|
public BaseResult<CodeClassifyVO> listCodeClassifyByOids(String oids){
|
Collection<CodeClassifyVO> voCollection = codeClassifyService.listCodeClassifyByOids(VciBaseUtil.str2List(oids));
|
BaseResult baseResult = BaseResult.success();
|
baseResult.setData(voCollection);
|
return baseResult;
|
}
|
|
/**
|
* 参照树 主题库分类
|
* @param treeQueryObject 树形查询对象
|
* @return 主题库分类显示树
|
*/
|
@GetMapping("/referTree")
|
public List<Tree> referTree(TreeQueryObject treeQueryObject) {
|
return codeClassifyService.referTree(treeQueryObject);
|
}
|
|
/**
|
* 导出分类
|
* @param oid 分类主键
|
*/
|
@GetMapping("/exportClassify")
|
public void exportClassify(String oid, HttpServletResponse response) throws IOException {
|
String excelName = codeClassifyService.exportClassify(oid);
|
try {
|
ControllerUtil.writeFileToResponse(response,excelName);
|
} catch (Throwable e) {
|
//如果出错,把错误信息写到text
|
String msg = LangBaseUtil.getErrorMsg(e);
|
String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误.txt";
|
LocalFileUtil.writeContentToFile(msg,errorFile);
|
ControllerUtil.writeFileToResponse(response,errorFile);
|
}
|
}
|
|
/**
|
* 下载导入的模板
|
* @param response 响应对象
|
* @throws IOException 抛出异常
|
*/
|
@GetMapping("/downloadImportExcel")
|
public void downloadImportExcel(HttpServletResponse response) throws IOException {
|
String excelName = codeClassifyService.createImportExcel();
|
try {
|
ControllerUtil.writeFileToResponse(response,excelName);
|
} catch (Throwable e) {
|
//如果出错,把错误信息写到text
|
String msg = LangBaseUtil.getErrorMsg(e);
|
if(StringUtils.isBlank(msg)){
|
msg = "未知错误";
|
}
|
ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
|
}
|
}
|
|
/**
|
* 导入分类
|
* @param file excel的内容
|
* @return 执行结果,obj有值表示有错误信息,需要访问downloadErrorFile来下载
|
*/
|
@PostMapping("/importClassify")
|
public BaseResult importClassify(MultipartFile file) {
|
String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
|
File file1 = new File(excelFileName);
|
try {
|
file.transferTo(new File(excelFileName));
|
codeClassifyService.importClassify(file1);
|
return BaseResult.success();
|
}catch (Throwable e) {
|
String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误信息.txt";
|
LocalFileUtil.writeContentToFile(LangBaseUtil.getErrorMsg(e),errorFile);
|
//放到map里
|
BaseResult result = BaseResult.fail("导入失败");
|
result.setObj(ControllerUtil.putErrorFile(errorFile));
|
return result;
|
}finally {
|
file1.delete();
|
}
|
}
|
|
/**
|
* 下载错误的文件信息
|
* @param uuid 唯一标识
|
* @param response 响应对象
|
* @throws IOException 抛出异常
|
*/
|
@GetMapping("/downloadErrorFile")
|
public void downloadErrorFile(String uuid, HttpServletResponse response) throws IOException {
|
ControllerUtil.downloadErrorFile(response,uuid);
|
}
|
|
/**
|
* 获取分类关联的属性
|
* @param baseQueryObject 查询对象,必须有codeClassifyOid,支持id和name两种查询条件(不支持分页)
|
* @return 属性的信息,包含默认的属性
|
*/
|
@GetMapping("/listClassifyLinkAttr")
|
public DataGrid<OsAttributeVO> listClassifyLinkAttr(BaseQueryObject baseQueryObject){
|
return codeClassifyService.listClassifyLinkAttr(baseQueryObject);
|
}
|
|
/**
|
* 使用编号的路径获取对象
|
* @param idPath 编号的路径,一定要从最顶层节点开始,格式为xxx/yyy/zz 这样
|
* @return 分类的显示对象
|
*/
|
@GetMapping("/getObjectByIdPath")
|
public CodeClassifyVO getObjectByIdPath(String idPath){
|
return codeClassifyService.getObjectByIdPath(idPath);
|
}
|
|
}
|