|
|
@@ -0,0 +1,146 @@ |
|
|
|
package com.xueyi.system.resource.controller; |
|
|
|
|
|
|
|
import com.xueyi.common.core.utils.core.ObjectUtil; |
|
|
|
import com.xueyi.common.core.utils.core.StrUtil; |
|
|
|
import com.xueyi.common.core.utils.file.FileTypeUtil; |
|
|
|
import com.xueyi.common.core.utils.file.MimeTypeUtil; |
|
|
|
import com.xueyi.common.core.web.result.AjaxResult; |
|
|
|
import com.xueyi.common.core.web.result.R; |
|
|
|
import com.xueyi.common.core.web.validate.V_E; |
|
|
|
import com.xueyi.common.log.annotation.Log; |
|
|
|
import com.xueyi.common.log.enums.BusinessType; |
|
|
|
import com.xueyi.common.security.annotation.RequiresPermissions; |
|
|
|
import com.xueyi.common.web.entity.controller.BaseController; |
|
|
|
import com.xueyi.file.api.domain.SysFile; |
|
|
|
import com.xueyi.file.api.feign.RemoteFileService; |
|
|
|
import com.xueyi.system.resource.domain.dto.DmResourcesDto; |
|
|
|
import com.xueyi.system.resource.domain.po.DmResourcesPo; |
|
|
|
import com.xueyi.system.resource.domain.query.DmResourcesQuery; |
|
|
|
import com.xueyi.system.resource.service.IDmResourcesService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* 静态资源管理 业务处理 |
|
|
|
* |
|
|
|
* @author xueyi |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@RequestMapping("/resources") |
|
|
|
public class DmResourcesController extends BaseController<DmResourcesQuery, DmResourcesDto, IDmResourcesService> { |
|
|
|
|
|
|
|
/** 定义节点名称 */ |
|
|
|
@Override |
|
|
|
protected String getNodeName() { |
|
|
|
return "静态资源" ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RemoteFileService remoteFileService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IDmResourcesService iDmResourcesService; |
|
|
|
/** |
|
|
|
* 查询静态资源列表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@GetMapping("/list") |
|
|
|
@RequiresPermissions(Auth.DM_RESOURCES_LIST) |
|
|
|
public AjaxResult list(DmResourcesQuery dmResources) { |
|
|
|
return super.list(dmResources); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询静态资源详细 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@GetMapping(value = "/{id}") |
|
|
|
@RequiresPermissions(Auth.DM_RESOURCES_SINGLE) |
|
|
|
public AjaxResult getInfo(@PathVariable Serializable id) { |
|
|
|
return super.getInfo(id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 静态资源修改 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@PutMapping |
|
|
|
@RequiresPermissions(Auth.DM_RESOURCES_EDIT) |
|
|
|
@Log(title = "静态资源管理", businessType = BusinessType.UPDATE) |
|
|
|
public AjaxResult edit(@Validated({V_E.class}) @RequestBody DmResourcesDto dmResources) { |
|
|
|
return super.edit(dmResources); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 静态资源批量删除 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@DeleteMapping("/batch/{idList}") |
|
|
|
@RequiresPermissions(Auth.DM_RESOURCES_DEL) |
|
|
|
@Log(title = "静态资源管理", businessType = BusinessType.DELETE) |
|
|
|
public AjaxResult batchRemove(@PathVariable List<Long> idList) { |
|
|
|
return super.batchRemove(idList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取静态资源选择框列表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@GetMapping("/option") |
|
|
|
public AjaxResult option() { |
|
|
|
return super.option(); |
|
|
|
} |
|
|
|
|
|
|
|
interface Auth { |
|
|
|
/** 系统 - 静态资源管理 - 列表 */ |
|
|
|
String DM_RESOURCES_LIST = "resource:resources:list"; |
|
|
|
/** 系统 - 静态资源管理 - 详情 */ |
|
|
|
String DM_RESOURCES_SINGLE = "resource:resources:single"; |
|
|
|
/** 系统 - 静态资源管理 - 新增 */ |
|
|
|
String DM_RESOURCES_ADD = "resource:resources:add"; |
|
|
|
/** 系统 - 静态资源管理 - 修改 */ |
|
|
|
String DM_RESOURCES_EDIT = "resource:resources:edit"; |
|
|
|
/** 系统 - 静态资源管理 - 删除 */ |
|
|
|
String DM_RESOURCES_DEL = "resource:resources:delete"; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 头像上传 |
|
|
|
*/ |
|
|
|
@PostMapping("/upload") |
|
|
|
@Log(title = "资源管理 - 上传资源", businessType = BusinessType.UPDATE) |
|
|
|
public AjaxResult upload(@RequestParam("file") MultipartFile file) { |
|
|
|
if (!file.isEmpty()) { |
|
|
|
String extension = FileTypeUtil.getExtension(file); |
|
|
|
if (!StrUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.IMAGE_EXTENSION)) { |
|
|
|
return error("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtil.IMAGE_EXTENSION) + "格式"); |
|
|
|
} |
|
|
|
R<SysFile> fileResult = remoteFileService.upload(file); |
|
|
|
if (ObjectUtil.isNull(fileResult) || ObjectUtil.isNull(fileResult.getData())) |
|
|
|
return error("文件服务异常,请联系管理员!"); |
|
|
|
String url = fileResult.getData().getUrl(); |
|
|
|
// 预留人脸识别与图像质量监测接口,如果监测异常返回错误 |
|
|
|
|
|
|
|
DmResourcesDto dto = new DmResourcesDto(); |
|
|
|
dto.setName(file.getOriginalFilename()); |
|
|
|
dto.setUrl(url); |
|
|
|
dto.setType(DmResourcesPo.TYPE_PIC); |
|
|
|
|
|
|
|
Long id = iDmResourcesService.addOne(dto); |
|
|
|
// dto.set |
|
|
|
|
|
|
|
AjaxResult ajax = success(); |
|
|
|
ajax.put(AjaxResult.URL_TAG, id); |
|
|
|
return ajax; |
|
|
|
} |
|
|
|
return error("上传图片异常,请联系管理员!"); |
|
|
|
} |
|
|
|
} |