| | |
| | | import com.ruoyi.iot.mapper.DeviceOrderMapper; |
| | | import com.ruoyi.iot.service.IDeviceOrderService; |
| | | import com.ruoyi.iot.service.IDeviceService; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.ruoyi.common.utils.SecurityUtils.getLoginUser; |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public DeviceOrder selectDeviceOrderById(int id) throws Exception { |
| | | public DeviceOrder selectDeviceOrderById(Long id) throws Exception { |
| | | return deviceOrderMapper.selectDeviceOrderById(id); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult insertDeviceOrder(DeviceOrder deviceOrder) throws Exception { |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | Device device = new Device(); |
| | | //更新订单的初始化状态 |
| | | if ("未指派".equals(deviceOrder.getErectoName())) { |
| | | deviceOrder.setState(0); |
| | |
| | | deviceOrder.setState(1); |
| | | deviceOrder.setAssginTime(new Date()); |
| | | } |
| | | |
| | | //普通用户创建维修单的时候userid=他本身登录的userid,create_userid=联营商的id |
| | | //更新订单的用户信息 |
| | | //判断userId是否大于0,大于0就执行SysUser sysUser = getLoginUser().getUser();deviceOrder.setCreateUserId(sysUser.getUserId()); |
| | | if (deviceOrder.getUserId() != null) { |
| | | //用户在小程序创建维修单的情况,userId=2,createUserId=140 |
| | | deviceOrder.setUserId(deviceOrder.getUserId()); |
| | | deviceOrder.setCreateUserId(deviceOrder.getCreateUserId()); |
| | | //用户创建CustomFlag=1 |
| | | deviceOrder.setCustomFlag(1); |
| | | } else { |
| | | //联营商创建安装单/维修单的情况,userId=0,createUserId=14 |
| | | deviceOrder.setCreateUserId(sysUser.getUserId()); |
| | | if ("2".equals(deviceOrder.getOrderType())) { |
| | | //根据deviceId反查userId填入 |
| | | Device devices = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId()); |
| | | deviceOrder.setUserId(devices.getUserId()); |
| | | //联营商创建CustomFlag=0 |
| | | deviceOrder.setCustomFlag(0); |
| | | } |
| | | } |
| | | |
| | | //判断传过来的orderType的值是否为2-维修 |
| | | if ("2".equals(deviceOrder.getOrderType())) { |
| | | log.info("orderType{}", deviceOrder.getOrderType()); |
| | | System.out.println(deviceOrder.getOrderType()); |
| | | //更新订单的用户信息 |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | deviceOrder.setCreateUserId(sysUser.getUserId()); |
| | | //插入维修单 |
| | | deviceOrder.setAssginTime(new Date()); |
| | | int rows = deviceOrderMapper.insertDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId()); |
| | | int total = deviceOrderMapper.insertDeviceOrder(deviceOrder); |
| | | if (total > 0) { |
| | | Device deviceOrders = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId()); |
| | | //更新当前设备的是否维修信息-未维修 |
| | | Device device = new Device(); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setRepairFlag(1); |
| | | device.setStatus(device1.getStatus()); |
| | | device.setStatus(deviceOrders.getStatus()); |
| | | deviceService.updateDevice(device); |
| | | return toAjax(total); |
| | | } |
| | | return toAjax(rows); |
| | | } else { |
| | | //插入安装订单 |
| | | int rows = deviceOrderMapper.insertDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | //更新当前设备状态信息--安装中 |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setStatus(5); |
| | | deviceService.updateDevice(device); |
| | | return toAjax(rows); |
| | | } |
| | | } |
| | | //更新订单的用户信息 |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | deviceOrder.setCreateUserId(sysUser.getUserId()); |
| | | //插入安装订单 |
| | | int rows = deviceOrderMapper.insertDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | //更新当前设备状态信息--安装中 |
| | | Device device = new Device(); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setStatus(5); |
| | | deviceService.updateDevice(device); |
| | | } |
| | | return toAjax(rows); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult updateDeviceOrder(DeviceOrder deviceOrder) throws Exception { |
| | | DeviceOrder deviceOrderA = deviceOrderMapper.selectDeviceOrderByIdAnderectoName(deviceOrder.getId(), deviceOrder.getErectoName()); |
| | | if (deviceOrderA == null) { |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | Device device = new Device(); |
| | | DeviceOrder deviceOrders = deviceOrderMapper.selectDeviceOrderByIdAnderectoName(deviceOrder.getId(), deviceOrder.getErectoName()); |
| | | if (deviceOrders == null) { |
| | | deviceOrder.setAssginTime(new Date()); |
| | | } |
| | | //判断传过来的orderType的值是否为1-安装,并且安装单的状态为已完成,修改设备的状态为离线状态 |
| | | if ("1".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) { |
| | | log.info("OrderType{}", deviceOrder.getOrderType()); |
| | | log.info("State{}", deviceOrder.getState()); |
| | | System.out.println(deviceOrder.getOrderType()); |
| | | System.out.println(deviceOrder.getState()); |
| | | //获取修改订单的用户信息 |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | //拿到修改安装单的用户id |
| | | deviceOrder.setUpdateUserId(sysUser.getUserId()); |
| | | deviceOrder.setFinishTime(new Date()); |
| | | int rows = deviceOrderMapper.updateDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | Device device = new Device(); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | //修改设备的状态为离线 |
| | | device.setStatus(4); |
| | | //修改设备的是否安装标识为1-已安装 |
| | | device.setInstallFlag(1); |
| | | deviceService.updateDevice(device); |
| | | } |
| | | return toAjax(rows); |
| | | } |
| | | //判断传过来的orderType的值是否为2-维修,并且维修单的状态为为已完成,修改设备的是否维修为0-已维修 |
| | | if ("2".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) { |
| | | log.info("OrderType{}", deviceOrder.getOrderType()); |
| | | log.info("State{}", deviceOrder.getState()); |
| | | System.out.println(deviceOrder.getOrderType()); |
| | | System.out.println(deviceOrder.getState()); |
| | | //获取修改订单的用户信息 |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | //拿到修维修单的用户id |
| | | deviceOrder.setUpdateUserId(sysUser.getUserId()); |
| | | deviceOrder.setFinishTime(new Date()); |
| | | int rows = deviceOrderMapper.updateDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId()); |
| | | Device device = new Device(); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setRepairFlag(0); |
| | | device.setStatus(device1.getStatus()); |
| | | deviceService.updateDevice(device); |
| | | } else { |
| | | //判断传过来的orderType的值是否为2-维修,并且维修单的状态为为已完成,修改设备的是否维修为1-已维修 |
| | | if ("2".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) { |
| | | //获取修改订单的用户信息 |
| | | //拿到修维修单的用户id |
| | | deviceOrder.setUpdateUserId(sysUser.getUserId()); |
| | | deviceOrder.setFinishTime(new Date()); |
| | | int rows = deviceOrderMapper.updateDeviceOrder(deviceOrder); |
| | | if (rows > 0) { |
| | | Device deviceRepairOrder = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId()); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setRepairFlag(0); |
| | | device.setStatus(deviceRepairOrder.getStatus()); |
| | | deviceService.updateDevice(device); |
| | | } |
| | | return toAjax(rows); |
| | | } |
| | | return toAjax(rows); |
| | | } |
| | | //获取修改订单的用户信息 |
| | | SysUser sysUser = getLoginUser().getUser(); |
| | | //拿到修改安装单的用户id |
| | | deviceOrder.setUpdateUserId(sysUser.getUserId()); |
| | | return toAjax(deviceOrderMapper.updateDeviceOrder(deviceOrder)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除设备订单信息 |
| | | * 删除设备安装单/维修单信息 |
| | | * |
| | | * @param id |
| | | * @param deviceId |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public AjaxResult deleteDeviceOrderById(Integer deviceId) throws Exception { |
| | | public AjaxResult deleteDeviceOrderById(Long id, Long deviceId) throws Exception { |
| | | Device device = new Device(); |
| | | //根据要删除安装单的id查询出安装单信息 |
| | | DeviceOrder deviceOrder = deviceOrderMapper.selectDeviceOrderById(deviceId); |
| | | DeviceOrder deviceOrders = deviceOrderMapper.selectDeviceOrderById(id); |
| | | //根据设备id查询设备信息 |
| | | Device deviceA = deviceService.selectDeviceByDeviceId(deviceId); |
| | | SysUser user = getLoginUser().getUser(); |
| | | //如果根据查询出来的安装单对象不为空的话,并且状态等于未派单才可以删除 |
| | | if (deviceOrder != null && deviceOrder.getState() == 0 && user.getUserId() != 1) { |
| | | //未派单的安装单删除后设备的状态更新为-未激活 |
| | | Device device = new Device(); |
| | | device.setDeviceId(deviceOrder.getDeviceId()); |
| | | device.setStatus(1); |
| | | if (deviceOrders != null && deviceOrders.getState() == 0 && user.getUserId() != 1 && "2".equals(deviceOrders.getOrderType())) { |
| | | device.setDeviceId(deviceA.getDeviceId()); |
| | | device.setRepairFlag(0); |
| | | device.setStatus(deviceA.getStatus()); |
| | | deviceService.updateDevice(device); |
| | | int i = deviceOrderMapper.deleteDeviceOrderById(deviceOrder.getId()); |
| | | return toAjax(i); |
| | | return toAjax(deviceOrderMapper.deleteDeviceOrderById(id)); |
| | | } else { |
| | | return AjaxResult.error(); |
| | | if (deviceOrders != null && deviceOrders.getState() == 0 && user.getUserId() != 1) { |
| | | //未派单的安装单删除后设备的状态更新为-未激活 |
| | | device.setDeviceId(deviceOrders.getDeviceId()); |
| | | device.setStatus(1); |
| | | deviceService.updateDevice(device); |
| | | int i = deviceOrderMapper.deleteDeviceOrderById(id); |
| | | return toAjax(i); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |