| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | |
| | | import cn.hutool.core.lang.UUID; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.annotation.ValueClassify; |
| | | import com.yuanchu.mom.dto.DataConfigDto; |
| | | import com.yuanchu.mom.dto.DeviceDto; |
| | | import com.yuanchu.mom.pojo.DataConfig; |
| | | import com.yuanchu.mom.pojo.Device; |
| | | import com.yuanchu.mom.service.DataConfigService; |
| | | import com.yuanchu.mom.service.DeviceService; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 设备(DeviceController)表控制层 |
| | |
| | | @RestController |
| | | @RequestMapping("/deviceScope") |
| | | public class DeviceController { |
| | | |
| | | |
| | | @Resource |
| | | private DeviceService deviceService; |
| | | |
| | | @Value("${file.path}") |
| | | private String filePath; |
| | | |
| | | @Autowired |
| | | private DataConfigService dataConfigService; |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "查询设备详情列表") |
| | | @PostMapping("/selectDeviceParameter") |
| | | public Result selectDeviceParameter(@RequestBody Map<String, Object> data) throws Exception { |
| | | Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class); |
| | | Device itemParameter = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), Device.class); |
| | | DeviceDto itemParameter = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), DeviceDto.class); |
| | | return Result.success(deviceService.selectDeviceParameter(page, itemParameter)); |
| | | } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "添加设备详情参数") |
| | | @PostMapping("/addDeviceParameter") |
| | | public Result addDeviceParameter(@RequestBody Device itemParameter) { |
| | | return Result.success(deviceService.addDeviceParameter(itemParameter)); |
| | | } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "删除设备详情参数") |
| | | @PostMapping("/delDeviceParameter") |
| | | public Result<?> delDeviceParameter(Integer id) { |
| | | return Result.success(deviceService.delDeviceParameter(id)); |
| | | } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "修改设备详情参数") |
| | | @PostMapping("/upDeviceParameter") |
| | | public Result<?> upDeviceParameter(@RequestBody Device itemParameter) { |
| | |
| | | //图片上传 |
| | | @ApiOperation(value = "设备图片上传") |
| | | @PostMapping("/uploadFile") |
| | | @ValueAuth |
| | | public Result uploadFile(MultipartFile file) { |
| | | String urlString; |
| | | String pathName; |
| | |
| | | if (!realpath.exists()) { |
| | | realpath.mkdirs(); |
| | | } |
| | | pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); |
| | | pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMdd")) + "-" + file.getOriginalFilename(); |
| | | urlString = realpath + "/" + pathName; |
| | | file.transferTo(new File(urlString)); |
| | | HashMap<String, String> map = new HashMap<>(); |
| | |
| | | return Result.success(deviceService.selectDevicePrincipal()); |
| | | } |
| | | |
| | | @ApiOperation(value = "通过设备分类获取设备列表") |
| | | @ApiOperation(value = "通过项目获取设备列表") |
| | | @PostMapping("/selectDeviceByCategory") |
| | | @ValueAuth |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "category", value = "设备分类", dataTypeClass = String.class), |
| | | }) |
| | | public Result selectDeviceByCategory(String category) { |
| | | return Result.success(deviceService.selectDeviceByCategory(category)); |
| | | public Result selectDeviceByCategory(String inspectionItem, String inspectionItemSubclass) { |
| | | return Result.success(deviceService.selectDeviceByCategory(inspectionItem, inspectionItemSubclass)); |
| | | } |
| | | |
| | | @ApiOperation(value = "通过设备编号获取设备列表") |
| | | @PostMapping("/selectDeviceByCode") |
| | | @ValueAuth |
| | | public Result selectDeviceByCode(String code) { |
| | | return Result.success(deviceService.selectDeviceByCode(code)); |
| | | } |
| | | |
| | | // @ValueClassify("设备") |
| | | // @ApiOperation(value = "查询数采配置") |
| | | // @PostMapping("/getNumberCollect") |
| | | // public Result<?> getNumberCollect(Integer id) { |
| | | // DeviceDto1 deviceDto1 = new DeviceDto1(); |
| | | // BeanUtils.copyProperties(deviceService.getById(id),deviceDto1); |
| | | // return Result.success(deviceDto1); |
| | | // } |
| | | // |
| | | // @ValueClassify("设备") |
| | | // @ApiOperation(value = "维护数采配置") |
| | | // @PostMapping("/numberCollect") |
| | | // public Result<?> numberCollect(@RequestBody DeviceDto1 deviceDto1) { |
| | | // Device device = new Device(); |
| | | // BeanUtils.copyProperties(deviceDto1,device); |
| | | // return Result.success(deviceService.updateById(device)); |
| | | // } |
| | | |
| | | @ValueAuth |
| | | @ValueClassify("设备") |
| | | @ApiOperation("/数采-数据采集") |
| | | @GetMapping("/dataCollection") |
| | | public Result<?> dataAcquisition(HttpServletRequest request, @RequestParam("id") Integer id, |
| | | @RequestParam("entrustCode") String entrustCode, |
| | | @RequestParam("sampleCode") String sampleCode) { |
| | | return deviceService.dataAcquisition(request, id, entrustCode, sampleCode); |
| | | } |
| | | |
| | | @ValueAuth |
| | | @ApiOperation(value = "判断该设备是否可以数采") |
| | | @GetMapping("/determineWhetherToCollectData") |
| | | public Result<?> determineWhetherToCollectData(@RequestParam("managementNumber") String managementNumber) { |
| | | Device device = deviceService.getOne(Wrappers.<Device>lambdaQuery() |
| | | .eq(Device::getManagementNumber, managementNumber)); |
| | | if (ObjectUtils.isEmpty(device)) { |
| | | return Result.fail("设备编号错误!"); |
| | | } |
| | | if (ObjectUtils.isEmpty(device.getFileType()) || ObjectUtils.isEmpty(device.getCollectUrl())) { |
| | | return Result.success(false); |
| | | } else { |
| | | return Result.success(true); |
| | | } |
| | | } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "维护数采配置") |
| | | @PostMapping("/saveDataAcquisitionConfiguration") |
| | | public Result<?> saveDataAcquisitionConfiguration(@RequestParam(value = "deviceId") Integer deviceId, @RequestBody DataConfigDto dataConfigList) { |
| | | if (dataConfigList.getIsDevice()) { |
| | | System.out.println(); |
| | | Device device = new Device(); |
| | | device.setId(deviceId); |
| | | device.setCollectUrl(dataConfigList.getCollectUrl()); |
| | | device.setStorageUrl(dataConfigList.getStorageUrl()); |
| | | device.setIp(dataConfigList.getIp()); |
| | | device.setFileType(dataConfigList.getFileType()); |
| | | deviceService.updateById(device); |
| | | } else { |
| | | dataConfigService.saveOrUpdateBatch(dataConfigList.getDataConfigList()); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | // @ValueClassify("设备") |
| | | // @ApiOperation(value = "查询数采配置") |
| | | // @GetMapping("/queryDataAcquisitionConfiguration") |
| | | // public Result<?> queryDataAcquisitionConfiguration(@RequestParam("deviceId") Integer deviceId, @RequestParam("insProductItem") String insProductItem) { |
| | | // List<DataConfig> list = dataConfigService.list(Wrappers.<DataConfig>lambdaQuery() |
| | | // .eq(DataConfig::getDeviceId, deviceId) |
| | | // .eq(DataConfig::getInsProductItem, insProductItem)); |
| | | // return Result.success(list); |
| | | // } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "查询数采配置") |
| | | @GetMapping("/queryDataAcquisitionConfiguration") |
| | | public Result<?> queryDataAcquisitionConfiguration(@RequestParam("deviceId") Integer deviceId, |
| | | @RequestParam("isDevice") Boolean isDevice, |
| | | @RequestParam(value = "insProductItem", required = false) String insProductItem) { |
| | | if (isDevice) { |
| | | List<DataConfig> list = dataConfigService.list(Wrappers.<DataConfig>lambdaQuery() |
| | | .eq(DataConfig::getDeviceId, deviceId) |
| | | .eq(DataConfig::getInsProductItem, insProductItem)); |
| | | return Result.success(list); |
| | | } else { |
| | | return Result.success(dataConfigService.selectDataConfigList(deviceId)); |
| | | } |
| | | } |
| | | |
| | | @ValueClassify("设备") |
| | | @ApiOperation(value = "删除数采配置") |
| | | @DeleteMapping("/deleteDataAcquisitionConfiguration") |
| | | public Result<?> deleteDataAcquisitionConfiguration(@RequestParam("ids") String ids) { |
| | | List<String> split = Arrays.asList(ids.split(",")); |
| | | List<String> collect = split.stream().distinct().collect(Collectors.toList()); |
| | | dataConfigService.removeBatchByIds(collect); |
| | | return Result.success(); |
| | | } |
| | | } |
| | | |