| | |
| | | package com.zy.sc.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.sc.common.service.GeoService; |
| | | import com.zy.sc.common.web.BaseController; |
| | | import com.zy.sc.manager.controller.param.MobileIssueParam; |
| | | import com.zy.sc.manager.controller.result.AppHostIssueVo; |
| | | import com.zy.sc.manager.controller.result.AppIssueVo; |
| | | import com.zy.sc.manager.entity.Issue; |
| | | import com.zy.sc.manager.entity.IssueType; |
| | | import com.zy.sc.manager.service.IssueService; |
| | | import com.zy.sc.manager.service.IssueTypeService; |
| | | import com.zy.sc.system.entity.Host; |
| | | import com.zy.sc.system.service.HostService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by vincent on 2021/12/20 |
| | |
| | | @RequestMapping("app") |
| | | public class AppController extends BaseController { |
| | | |
| | | public static final String REGEX_MOBILE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$"; |
| | | |
| | | @Autowired |
| | | private HostService hostService; |
| | | @Autowired |
| | | private IssueTypeService issueTypeService; |
| | | @Autowired |
| | | private IssueService issueService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private GeoService geoService; |
| | | |
| | |
| | | return R.ok().add(issueTypes); |
| | | } |
| | | |
| | | // @RequestMapping("/sensor/save/auth") |
| | | // @ManagerAuth(memo = "移动端添加设备") |
| | | // public R issueSave(MobileSensorParam param){ |
| | | // Long hostId = getHostId(); |
| | | // if (hostId == null) { |
| | | // return R.error("请使用正确账号登录"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getUuid())) { |
| | | // return R.error("请填写设备编号"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getSensorType())) { |
| | | // return R.error("请选择设备类型"); |
| | | // } |
| | | // SensorType sensorType = sensorTypeService.selectById(param.getSensorType()); |
| | | // if (sensorType == null) { |
| | | // return R.error("请选择正确的设备类型"); |
| | | // } |
| | | // Sensor sensor = sensorService.selectByCode(param.getUuid()); |
| | | // if (sensor != null) { |
| | | // return R.error("设备编号已存在,请联系管理员"); |
| | | // } else { |
| | | // sensor = new Sensor(); |
| | | // } |
| | | // Date now = new Date(); |
| | | // sensor.setUuid(param.getUuid()); |
| | | // sensor.setHostId(hostId); |
| | | // sensor.setSensorType(param.getSensorType()); |
| | | // sensor.setCcid(param.getCcid()); |
| | | // sensor.setAddr(param.getAddr()); |
| | | // sensor.setDesc(param.getDesc()); |
| | | // sensor.setThreshold(String.valueOf(param.getThreshold())); |
| | | // List<String> imgArr = param.getImgArr(); |
| | | // if (!Cools.isEmpty(imgArr)) { |
| | | // sensor.setImg(JSONArray.toJSONString(imgArr)); |
| | | // } |
| | | // if (!Cools.isEmpty(param.getLocationObj())) { |
| | | // LocationObj locationObj = JSON.parseObject(param.getLocationObj(), LocationObj.class); |
| | | // sensor.setLon(Double.parseDouble(locationObj.getLongitude())); |
| | | // sensor.setLat(Double.parseDouble(locationObj.getLatitude())); |
| | | // GeoCodeDto geoCode = geoService.getGeoCode(sensor.getLon(), sensor.getLat()); |
| | | // if (geoCode != null && geoCode.getAddressComponent() != null) { |
| | | // sensor.setProvince(geoCode.getAddressComponent().getProvince()); |
| | | // sensor.setCity(geoCode.getAddressComponent().getCity()); |
| | | // sensor.setDistrict(geoCode.getAddressComponent().getDistrict()); |
| | | // sensor.setTownship(geoCode.getAddressComponent().getTownship()); |
| | | // } |
| | | // } |
| | | // sensor.setStatus(1); |
| | | // sensor.setCreateBy(getUserId()); |
| | | // sensor.setCreateTime(now); |
| | | // sensor.setUpdateBy(getUserId()); |
| | | // sensor.setUpdateTime(now); |
| | | // sensor.setMemo(param.getMemo()); |
| | | // if (!sensorService.insert(sensor)) { |
| | | // throw new CoolException("添加失败,请联系管理员"); |
| | | // } |
| | | // return R.ok("添加设备成功"); |
| | | // } |
| | | // |
| | | // @RequestMapping("/sensor/list/auth") |
| | | // @ManagerAuth |
| | | // public R sensorList(@RequestParam(required = false) String condition){ |
| | | // Wrapper<Sensor> wrapper = new EntityWrapper<Sensor>() |
| | | // .like("uuid", condition) |
| | | // .orderBy("sensor_type").orderBy("create_time"); |
| | | // Long hostId = getHostId(); |
| | | // if (hostId != null) { |
| | | // wrapper.eq("host_id", hostId); |
| | | // } |
| | | // List<Sensor> sensors = sensorService.selectList(wrapper); |
| | | // List<AppSensorTypeVo> result = new ArrayList<>(); |
| | | // Set<Long> sensorTypeSet = new HashSet<>(); |
| | | // for (Sensor sensor : sensors) { |
| | | // AppSensorVo sensorVo = new AppSensorVo(); |
| | | // sensorVo.setSensorId(sensor.getId()); |
| | | // sensorVo.setUuid(sensor.getUuid()); |
| | | // String addr = sensor.getProvince()+sensor.getCity()+sensor.getDistrict(); |
| | | //// String addr = sensor.getProvince()+","+sensor.getCity()+","+sensor.getDistrict(); |
| | | // if (Cools.isEmpty(addr)) { |
| | | // addr = "未知定位"; |
| | | // } |
| | | // sensorVo.setAddr(addr); |
| | | // |
| | | // if (!sensorTypeSet.contains(sensor.getSensorType())) { |
| | | // sensorTypeSet.add(sensor.getSensorType()); |
| | | // SensorType sensorType = sensorTypeService.selectById(sensor.getSensorType()); |
| | | // AppSensorTypeVo vo = new AppSensorTypeVo(); |
| | | // vo.setSensorTypeFlag(sensorType.getFlag()); |
| | | // vo.setSensorTypeId(sensor.getSensorType()); |
| | | // vo.setSensorTypeName(sensorType.getName()); |
| | | // result.add(vo); |
| | | // vo.getSensors().add(sensorVo); |
| | | // } else { |
| | | // for (AppSensorTypeVo vo : result) { |
| | | // if (vo.getSensorTypeId().equals(sensor.getSensorType())) { |
| | | // vo.getSensors().add(sensorVo); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // return R.ok().add(result); |
| | | // } |
| | | // |
| | | // @RequestMapping("/sensor/detl/auth") |
| | | // @ManagerAuth |
| | | // public R sensorDetl(@RequestParam Long sensorId){ |
| | | // return R.ok().add(sensorService.selectById(sensorId)); |
| | | // } |
| | | @RequestMapping("/issue/save/auth") |
| | | @ManagerAuth(memo = "故障上报") |
| | | public R issueSave(MobileIssueParam param){ |
| | | if (Cools.isEmpty(param.getHostName())) { |
| | | return R.error("请选择所属项目"); |
| | | } |
| | | Host host = hostService.selectByName(param.getHostName()); |
| | | if (Cools.isEmpty(param.getIssueTypeName())) { |
| | | return R.error("请选择故障类型"); |
| | | } |
| | | IssueType issueType = issueTypeService.selectByName(param.getIssueTypeName()); |
| | | if (Cools.isEmpty(param.getTel())) { |
| | | return R.error("请输入联系方式"); |
| | | } |
| | | if (!param.getTel().matches(REGEX_MOBILE)) { |
| | | return R.error("请输入正确的手机号"); |
| | | } |
| | | if (Cools.isEmpty(param.getTitle())) { |
| | | return R.error("请输入问题概述"); |
| | | } |
| | | Date now = new Date(); |
| | | Date startTime = DateUtils.convert(param.getStartTime(), DateUtils.yyyyMMdd_F); |
| | | // 保存故障 |
| | | Issue issue = new Issue( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 故障编号 |
| | | host.getId(), // 所属项目 |
| | | issueType.getId(), // 故障类型 |
| | | param.getTitle(), // 问题概述 |
| | | null, // 故障原因 |
| | | null, // 解决办法 |
| | | JSONArray.toJSONString(param.getVideoSrc()), // 文件列表 |
| | | JSONArray.toJSONString(param.getImgArr()), // 图片 |
| | | startTime, // 发生日期 |
| | | null, // 处理日期 |
| | | null, // 更新日期 |
| | | param.getDiscoverer(), // 发现人 |
| | | param.getTel(), // 联系方式 |
| | | null, // 供应商 |
| | | 2, // |
| | | 1, // 状态 |
| | | getUserId(), // 添加人员 |
| | | now, // 添加时间 |
| | | getUserId(), // 修改人员 |
| | | now, // 修改时间 |
| | | param.getMemo() // 备注 |
| | | ); |
| | | if (!issueService.insert(issue)) { |
| | | throw new CoolException("反馈失败,请联系管理员"); |
| | | } |
| | | return R.ok("问题上报成功"); |
| | | } |
| | | |
| | | @RequestMapping("/issue/list/auth") |
| | | @ManagerAuth |
| | | public R sensorList(@RequestParam(required = false) String condition){ |
| | | Wrapper<Issue> wrapper = new EntityWrapper<Issue>() |
| | | .like("title", condition) |
| | | .orderBy("settle").orderBy("create_time", false); |
| | | Long hostId = getHostId(); |
| | | if (hostId != null) { |
| | | wrapper.eq("host_id", hostId); |
| | | } |
| | | List<Issue> issues = issueService.selectList(wrapper); |
| | | List<AppHostIssueVo> result = new ArrayList<>(); |
| | | Set<Long> hostSet = new HashSet<>(); |
| | | for (Issue issue : issues) { |
| | | AppIssueVo vo = new AppIssueVo(); |
| | | vo.setIssueId(issue.getId()); |
| | | vo.setTitle(issue.getTitle().length()>12?issue.getTitle().substring(0, 12):issue.getTitle()); |
| | | vo.setStartTime(issue.getStartTime$().length()>11?issue.getStartTime$().substring(0, 11):issue.getStartTime$()); |
| | | vo.setSettle(issue.getSettle$()); |
| | | |
| | | if (!hostSet.contains(issue.getHostId())) { |
| | | hostSet.add(issue.getHostId()); |
| | | Host host = hostService.selectById(issue.getHostId()); |
| | | AppHostIssueVo hostVo = new AppHostIssueVo(); |
| | | hostVo.setHostId(host.getId()); |
| | | hostVo.setHostName(host.getName()); |
| | | result.add(hostVo); |
| | | hostVo.getIssues().add(vo); |
| | | } else { |
| | | for (AppHostIssueVo hostVo : result) { |
| | | if (hostVo.getHostId().equals(issue.getHostId())) { |
| | | hostVo.getIssues().add(vo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @RequestMapping("/issue/detl/auth") |
| | | @ManagerAuth |
| | | public R issueDetl(@RequestParam Long issueId){ |
| | | return R.ok().add(issueService.selectById(issueId)); |
| | | } |
| | | |
| | | } |