144 lines
5.0 KiB
Java
144 lines
5.0 KiB
Java
package com.evo.equipment.controller;
|
|
|
|
import com.evo.common.annotation.Log;
|
|
import com.evo.common.core.controller.BaseController;
|
|
import com.evo.common.core.domain.AjaxResult;
|
|
import com.evo.common.core.page.TableDataInfo;
|
|
import com.evo.common.enums.BusinessType;
|
|
import com.evo.common.utils.SecurityUtils;
|
|
import com.evo.equipment.domain.EqButton;
|
|
import com.evo.equipment.service.IEqButtonService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.io.BufferedOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 按钮信息Controller
|
|
*
|
|
* @author chenyj
|
|
* @date 2024-08-15
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/equipment/button")
|
|
public class EqButtonController extends BaseController
|
|
{
|
|
@Resource
|
|
private IEqButtonService eqButtonService;
|
|
|
|
|
|
|
|
/**
|
|
* 查询按钮信息列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('equipment:button:list')")
|
|
@GetMapping("/list")
|
|
public TableDataInfo list(EqButton eqButton)
|
|
{
|
|
startPage();
|
|
List<EqButton> list = eqButtonService.selectEqButtonList(eqButton);
|
|
return getDataTable(list);
|
|
}
|
|
|
|
/**
|
|
* 获取按钮信息详细信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('equipment:button:query')")
|
|
@GetMapping(value = "/{id}")
|
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
{
|
|
return success(eqButtonService.selectEqButtonById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增按钮信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('equipment:button:add')")
|
|
@RequestMapping("/uploadImage")
|
|
@ResponseBody
|
|
public AjaxResult uploadContractPDF(@RequestParam("name") String name, @RequestParam("file") MultipartFile filePath) {
|
|
String originalFilename = filePath.getOriginalFilename();
|
|
if (originalFilename != null) {
|
|
//校验文件后缀 jpg jpeg pdf 格式的文件不允许上传
|
|
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
|
if (!"jpg".equals(suffix) && !"jpeg".equals(suffix) && !"png".equals(suffix) && !"pdf".equals(suffix)) {
|
|
return AjaxResult.error("禁止非法文件上传");
|
|
} else {
|
|
EqButton eqButton = eqButtonService.selectEqButtonByName(name);
|
|
if(eqButton != null){
|
|
return AjaxResult.error("添加按钮信息重复!");
|
|
}
|
|
FileOutputStream fos = null;
|
|
BufferedOutputStream bos = null;
|
|
InputStream is = null;
|
|
try {
|
|
is = filePath.getInputStream();
|
|
//在对应的文件夹下生成新的图片
|
|
fos = new FileOutputStream(com.evo.equipment.constant.Constants.BUTTON_ADDRESS + "/" + originalFilename);
|
|
bos = new BufferedOutputStream(fos);
|
|
// 读取输入流并写入文件
|
|
byte[] buffer = new byte[1024];
|
|
int bytesRead;
|
|
while ((bytesRead = is.read(buffer)) != -1) {
|
|
bos.write(buffer, 0, bytesRead);
|
|
}
|
|
bos.flush();
|
|
//插入表
|
|
eqButton = new EqButton();
|
|
eqButton.setCreateBy(SecurityUtils.getUsername());
|
|
eqButton.setName(name);
|
|
eqButton.setImage(com.evo.equipment.constant.Constants.STAFF_BUTTON_URL + originalFilename);
|
|
eqButtonService.insertEqButton(eqButton);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}finally {
|
|
try{
|
|
if(fos != null){
|
|
fos.close();
|
|
}
|
|
if(bos != null){
|
|
bos.close();
|
|
}
|
|
if(is != null){
|
|
is.close();
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return AjaxResult.success();
|
|
}
|
|
|
|
/**
|
|
* 修改按钮信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('equipment:button:edit')")
|
|
@Log(title = "按钮信息", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public AjaxResult edit(@RequestBody EqButton eqButton)
|
|
{
|
|
return toAjax(eqButtonService.updateEqButton(eqButton));
|
|
}
|
|
|
|
/**
|
|
* 删除按钮信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('equipment:button:remove')")
|
|
@Log(title = "按钮信息", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{id}")
|
|
public AjaxResult remove(@PathVariable Long id)
|
|
{
|
|
return eqButtonService.deleteEqButtonById(id,SecurityUtils.getUsername());
|
|
}
|
|
}
|