package com.evo.personnelMatters.controller; import com.alibaba.fastjson2.JSONObject; import com.evo.common.core.controller.BaseController; import com.evo.common.core.domain.AjaxResult; import com.evo.common.core.page.TableDataInfo; import com.evo.equipment.constant.Constants; import com.evo.equipment.domain.vo.StaffData; import com.evo.equipment.domain.vo.StaffDto; import com.evo.framework.websocket.WebSocketUsers; import com.evo.personnelMatters.domain.EqOverStaff; import com.evo.personnelMatters.domain.SpecialOverTime; import com.evo.personnelMatters.service.SpecialOverTimeService; 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.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.List; @RestController @RequestMapping("/personnelMatters/specialOverTime") public class SpecialOverTimeController extends BaseController { @Resource private SpecialOverTimeService specialOverTimeService; @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:query')") @GetMapping(value = "/getOverTimeById") public SpecialOverTime getInfo() { return specialOverTimeService.selectSpecialOverTimeById(); } /** * 保存时间管理 */ @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:update')") @PostMapping public AjaxResult updateSpecialOverTime(@RequestBody SpecialOverTime specialOverTime) { return specialOverTimeService.addSpecialOverTime(specialOverTime); } @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:list')") @GetMapping("/list") public TableDataInfo list(EqOverStaff eqOverStaff) { startPage(); List list = specialOverTimeService.selectEqOverStaffList(eqOverStaff); return getDataTable(list); } /** * 获取照片管理详细信息 */ @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(specialOverTimeService.selectEqOverStaffById(id)); } /** * 新增照片管理 */ @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:add')") @RequestMapping("/addOverStaff") public AjaxResult add(@RequestBody EqOverStaff eqOverStaff) { return toAjax(specialOverTimeService.insertEqOverStaff(eqOverStaff)); } /** * 修改照片管理 */ @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:edit')") @PutMapping public AjaxResult edit(@RequestBody EqOverStaff eqOverStaff) { return toAjax(specialOverTimeService.updateEqOverStaff(eqOverStaff)); } /** * 删除照片管理 */ @PreAuthorize("@ss.hasPermi('personnelMatters:specialOverTime:remove')") @DeleteMapping("/{id}") public AjaxResult remove(@PathVariable Long id) { return toAjax(specialOverTimeService.deleteEqOverStaffById(id)); } @RequestMapping("/uploadDispatchings") @ResponseBody public AjaxResult uploadPDF(@RequestParam("id") Long id,@RequestParam("file") MultipartFile filePath){ String originalFilename = filePath.getOriginalFilename(); //校验文件后缀 String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1); // 输出 "txt" //判断是否是图片文件 if(!"jpg".equals(suffix)&&!"jpeg".equals(suffix)&&!"png".equals(suffix)){ return AjaxResult.error("非法文件不允许上传"); }else{ //根据ID查询员工信息 EqOverStaff eqOverStaff = specialOverTimeService.selectEqOverStaffById(id); try { InputStream is = filePath.getInputStream(); byte[] bytes = new byte[is.available()]; is.read(bytes); File file = new File(Constants.STAFF_IMAGE_ADDRESS+originalFilename); FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(bytes); bos.flush(); is.close(); fos.close(); bos.close(); eqOverStaff.setImageUrl(Constants.STAFF_IMAGE_URL_OVER_TIME+originalFilename); specialOverTimeService.updateEqOverStaff(eqOverStaff); //需要推送的数据 String message = ""; //需要返回的对象 StaffDto cau = new StaffDto(); //发送的数据 StaffData caud = new StaffData(); //该接口固定为to_device,发送给设备用于识别对应哪个指令 cau.setCmd("to_device"); //无用值,空串 cau.setForm(""); //设备号 cau.setTo(Constants.EQ_DEVICE_OVER_TIME_CODE); //给服务端预留的补充字段,设备端不处理这个字段内容。设备在响应这条指令时原样返回 cau.setExtra(""); //发送的数据 // caud.setCmd("addUser"); caud.setUser_id(eqOverStaff.getUserId().toString()); caud.setName(eqOverStaff.getStaffName()); caud.setTts_name(""); caud.setFace_template(eqOverStaff.getImageUrl()); caud.setEffect_time(""); caud.setId_valid(""); caud.setIc(""); caud.setPhone(""); caud.setMode(0); cau.setData(caud); //Java对象转换成JSON字符串 message = JSONObject.toJSONString(cau); //调用websocket,推送给设备 WebSocketUsers.sendMessageToUsersByText(message); } catch (Exception e) { e.printStackTrace(); } return AjaxResult.success("文件上传成功"); } } }