| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.SpecialDevice; |
| | | import com.moral.api.entity.SysDictData; |
| | | import com.moral.api.entity.Version; |
| | | import com.moral.api.mapper.SysDictDataMapper; |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.moral.api.service.SpecialDeviceService; |
| | | import com.moral.api.service.VersionService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.WebUtils; |
| | | import io.swagger.annotations.Api; |
| | |
| | | @Resource |
| | | private SpecialDeviceService specialDeviceService; |
| | | |
| | | @Resource |
| | | private OrganizationService organizationService; |
| | | |
| | | @Resource |
| | | private VersionService versionService; |
| | | |
| | | @Resource |
| | | private SysDictDataMapper sysDictDataMapper; |
| | | |
| | | @RequestMapping(value = "getSpecialDeviceByCondition", method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public ResultMessage getSpecialDeviceByCondition(HttpServletRequest request) { |
| | |
| | | @RequestMapping(value = "insert", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public ResultMessage insert(@RequestBody SpecialDevice specialDevice){ |
| | | System.out.println(specialDevice); |
| | | Map<String,Object> resultMap = specialDeviceService.insert(specialDevice); |
| | | String msg = resultMap.get("msg").toString(); |
| | | int code = Integer.parseInt(resultMap.get("code").toString()); |
| | |
| | | } |
| | | return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString()); |
| | | } |
| | | |
| | | @RequestMapping(value = "update", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public ResultMessage update (@RequestBody SpecialDevice specialDevice){ |
| | | if (specialDevice.getId() == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | if (specialDevice.getMac() != null) { |
| | | //判断mac是否已存在 |
| | | QueryWrapper<SpecialDevice> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("mac", specialDevice.getMac()); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | if (specialDeviceService.getOne(queryWrapper) != null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg()); |
| | | } |
| | | } |
| | | if (specialDevice.getOrganizationId() != null) { |
| | | //判断组织是否已存在 |
| | | QueryWrapper<Organization> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", specialDevice.getOrganizationId()); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | if (ObjectUtils.isEmpty(organizationService.getOne(queryWrapper))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); |
| | | } |
| | | } |
| | | if (specialDevice.getDeviceVersionId() != null) { |
| | | //判断型号是否已存在 |
| | | QueryWrapper<Version> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", specialDevice.getDeviceVersionId()); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | if (ObjectUtils.isEmpty(versionService.getOne(queryWrapper))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.VERSION_NOT_EXIST.getCode(), ResponseCodeEnum.VERSION_NOT_EXIST.getMsg()); |
| | | } |
| | | } |
| | | if (specialDevice.getSpecialType() != null) { |
| | | //判断组织是否已存在 |
| | | QueryWrapper<SysDictData> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("dict_type_id", 27); |
| | | queryWrapper.eq("dataKey", specialDevice.getSpecialType()); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | if (ObjectUtils.isEmpty(sysDictDataMapper.selectOne(queryWrapper))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.DICTDATA_KEY_NOT_EXIST.getCode(), ResponseCodeEnum.DICTDATA_KEY_NOT_EXIST.getMsg()); |
| | | } |
| | | } |
| | | specialDeviceService.update(specialDevice); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "delete", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public ResultMessage delete(@RequestBody Map map){ |
| | | if (map.get("id") == null){ |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | specialDeviceService.delete(Integer.parseInt(map.get("id").toString())); |
| | | return ResultMessage.ok(); |
| | | } |
| | | } |