package com.vci.web.controller;
|
|
import com.vci.constant.FrameWorkLangCodeConstant;
|
import com.vci.dto.OsAttributeDTO;
|
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
|
import com.vci.starter.web.annotation.log.VciBusinessLog;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.BaseQueryObject;
|
import com.vci.starter.web.pagemodel.BaseResult;
|
import com.vci.pagemodel.OsAttributeVO;
|
import com.vci.starter.web.util.ControllerUtil;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.web.service.OsAttributeServiceI;
|
import com.vci.web.util.Func;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
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.util.Date;
|
import java.util.List;
|
|
/**
|
* 属性控制器
|
* @author weidy
|
* @date 2022-3-26
|
*/
|
@RequestMapping("/attributeController")
|
@RestController
|
public class OsAttributeController {
|
|
/**
|
* 属性
|
*/
|
@Autowired
|
private OsAttributeServiceI attributeService;
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 属性列表
|
* @param baseQueryObject 查询对象
|
* @return 属性的显示对象
|
*/
|
@GetMapping("/gridAttribute")
|
@VciBusinessLog(operateName = "属性列表")
|
public BaseResult<OsAttributeVO> gridAttribute(BaseQueryObject baseQueryObject){
|
try {
|
return BaseResult.dataGrid(attributeService.gridAttribute(baseQueryObject));
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "属性管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 根据多个属性名称查询属性
|
* @param attrNames
|
* @return
|
*/
|
@GetMapping("/getByAttributeNames")
|
@VciBusinessLog(operateName = "根据多个属性名称查询属性")
|
public BaseResult getByAttributeNames(String[] attrNames){
|
try {
|
return BaseResult.dataList(attributeService.getByAttributeNames(attrNames));
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "属性名查询属性时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 添加单条属性到属性池
|
* @param osAttributeDTO
|
* @return 列表的内容
|
*/
|
@PostMapping( "/addAttribute")
|
@VciBusinessLog(operateName = "添加属性")
|
public BaseResult addAttribute(@RequestBody OsAttributeDTO osAttributeDTO) {
|
try {
|
return attributeService.addAttribute(osAttributeDTO) ? BaseResult.success("属性添加成功!"):BaseResult.fail("属性添加失败!");
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "增加属性时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 修改单条属性
|
* @param osAttributeDTO
|
* @return 列表的内容
|
*/
|
@PutMapping( "/updateAttribute")
|
@VciBusinessLog(operateName = "修改属性")
|
public BaseResult updateAttribute(@RequestBody OsAttributeDTO osAttributeDTO) {
|
try {
|
return attributeService.updateAttribute(osAttributeDTO) ? BaseResult.success("属性修改成功!"):BaseResult.fail("属性修改失败!");
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "修改属性时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 删除属性
|
* @param osAttributeDTOS
|
* @return 列表的内容
|
*/
|
@DeleteMapping( "/deleteAttributes")
|
@VciBusinessLog(operateName = "删除属性")
|
public BaseResult deleteAttributes(@RequestBody List<OsAttributeDTO> osAttributeDTOS) {
|
try {
|
return attributeService.deleteAttributes(osAttributeDTOS) ? BaseResult.success("属性删除成功!"):BaseResult.fail("属性删除失败!");
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "删除属性时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 查看属性的使用范围
|
* @param attributeName 属性名称
|
* @return map对象
|
*/
|
@GetMapping( "/getUsedAttributeList")
|
@VciBusinessLog(operateName = "查看属性的使用范围")
|
public BaseResult getUsedAttributeList(String attributeName) {
|
try {
|
return BaseResult.dataList(attributeService.getUsedAttributeList(attributeName));
|
}catch (Exception e) {
|
e.printStackTrace();
|
String exceptionMessage = "获取属性的使用范围时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
logger.error(exceptionMessage);
|
return BaseResult.fail(exceptionMessage);
|
}
|
}
|
|
/**
|
* 导出选中的属性
|
* @param exportFileName 导出的文件名
|
* @param attrNames 需要导出的属性英文名称
|
* @param response
|
*/
|
@GetMapping( "/exportAttributes")
|
@VciBusinessLog(operateName = "导出属性")
|
public void exportAttributes(String exportFileName,String attrNames, HttpServletResponse response){
|
try {
|
String excelPath = attributeService.exportAttributes(exportFileName,attrNames);
|
ControllerUtil.writeFileToResponse(response,excelPath);
|
} catch (Exception e) {
|
String msg = "导出枚举时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
try {
|
//出错时
|
e.printStackTrace();
|
ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
|
} catch (IOException ioException) {
|
ioException.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 下载属性导入模板
|
* @param exportFileName
|
* @param response
|
*/
|
@GetMapping( "/downloadAttributeTemplate")
|
@VciBusinessLog(operateName = "导出属性")
|
public void downloadAttributeTemplate(String exportFileName, HttpServletResponse response){
|
try {
|
String excelPath = attributeService.downloadAttributeTemplate(exportFileName);
|
ControllerUtil.writeFileToResponse(response,excelPath);
|
} catch (Exception e) {
|
String msg = "下载枚举导入模板时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
try {
|
//出错时
|
e.printStackTrace();
|
ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
|
} catch (IOException ioException) {
|
ioException.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 导入属性
|
* @param file
|
* @return
|
*/
|
@PostMapping("/importAttributes")
|
@VciBusinessLog(operateName = "导入属性")
|
public BaseResult importAttributes(MultipartFile file){
|
String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
|
File file1 = new File(excelFileName);
|
try {
|
file.transferTo(new File(excelFileName));
|
if (file != null) {
|
return attributeService.importAttributes(file1);
|
} else {
|
return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
|
}
|
}catch (Throwable e) {
|
throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e);
|
}finally {
|
file1.delete();
|
}
|
}
|
|
}
|