|
@@ -0,0 +1,96 @@
|
|
|
+package com.sky.ioc.controller.information;
|
|
|
+
|
|
|
+import com.sky.ioc.entity.domain.information.StaffConfiguration;
|
|
|
+import com.sky.ioc.entity.domain.information.StaffConfigurationStaff;
|
|
|
+import com.sky.ioc.service.information.StaffConfigurationService;
|
|
|
+import com.sky.ioc.service.information.StaffConfigurationStaffService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.system.ApplicationHome;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Api(tags = "信息管理--安保人员配置")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/information")
|
|
|
+public class StaffConfigurationController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StaffConfigurationService staffConfigurationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StaffConfigurationStaffService staffConfigurationStaffService;
|
|
|
+
|
|
|
+ @ApiOperation("删除安保人员信息配置")
|
|
|
+ @DeleteMapping(value = "/staff_configuration")
|
|
|
+ public ReturnMsg delStaffConfiguration(@RequestParam(name="id") Integer id) {
|
|
|
+ return staffConfigurationService.delStaffConfiguration(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("添加安保人员信息配置")
|
|
|
+ @PostMapping(value = "/staff_configuration")
|
|
|
+ public ReturnMsg addStaffConfiguration(StaffConfiguration staffConfiguration) {
|
|
|
+ return staffConfigurationService.addStaffConfiguration(staffConfiguration);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("获取安保人员信息配置")
|
|
|
+ @GetMapping(value = "/staff_configuration")
|
|
|
+ public ReturnMsg getStaffConfiguration(Integer configuration_id,@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "20")Integer page_size) {
|
|
|
+ return staffConfigurationStaffService.getList(configuration_id,page,page_size);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("获取人员历史记录")
|
|
|
+ @GetMapping(value = "/staff_configuration_history")
|
|
|
+ public ReturnMsg getStaffConfigurationHistory(Integer configuration_id,@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "20")Integer page_size) {
|
|
|
+ return staffConfigurationStaffService.getHistoryList(configuration_id,page,page_size);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("上传图片")
|
|
|
+ @PostMapping("/upload_pictures")
|
|
|
+ public ReturnMsg upload(@RequestParam("file") MultipartFile file) {
|
|
|
+ //图片校验(图片是否为空,图片大小,上传的是不是图片、图片类型(例如只能上传png)等等)
|
|
|
+ String savePath = File.separator +"upload"+File.separator+ "images" + File.separator;
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return ReturnMsg.fail("图片上传失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //可以自己加一点校验 例如上传的是不是图片或者上传的文件是不是png格式等等 这里省略
|
|
|
+ //获取原来的文件名和后缀
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+// String ext = "." + FilenameUtils.getExtension(orgFileName); --需要导依赖
|
|
|
+ String ext = "." + originalFilename.split("\\.")[1];
|
|
|
+ String type = originalFilename.indexOf(".") != -1 ? originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length()) : null;
|
|
|
+ if (type != null) {// 判断文件类型是否为空
|
|
|
+ if ("GIF".equals(type.toUpperCase()) || "PNG".equals(type.toUpperCase()) || "JPG".equals(type.toUpperCase())) {
|
|
|
+ //生成一个新的文件名(以防有重复的名字存在导致被覆盖)
|
|
|
+ String uuid = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ String newName = uuid + ext;
|
|
|
+ //拼接图片上传的路径 url+图片名
|
|
|
+ ApplicationHome applicationHome = new ApplicationHome(this.getClass());
|
|
|
+ //String pre = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() + savePath;
|
|
|
+ String path = savePath + newName;
|
|
|
+ try {
|
|
|
+ file.transferTo(new File(path));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok("/image/" + newName);
|
|
|
+ } else {
|
|
|
+ return ReturnMsg.fail("文件类型符合要求");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return ReturnMsg.fail("文件类型为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|