package com.ruoyi.iot.service.impl;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.iot.domain.Device;
|
import com.ruoyi.iot.domain.DeviceOrder;
|
import com.ruoyi.iot.mapper.DeviceOrderMapper;
|
import com.ruoyi.iot.service.IDeviceOrderService;
|
import com.ruoyi.iot.service.IDeviceService;
|
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;
|
|
|
/**
|
* @author wmz
|
* @version v1.0
|
* @ClassName DeviceOrderServiceImpl
|
* @description 设备安装单/维修单业务层处理
|
* @createTime 2023/11/13 0:25
|
*/
|
|
@Service
|
public class DeviceOrderServiceImpl extends BaseController implements IDeviceOrderService {
|
|
@Resource
|
private DeviceOrderMapper deviceOrderMapper;
|
@Autowired
|
private IDeviceService deviceService;
|
|
/**
|
* 根据条件分页查询设备安装信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<DeviceOrder> selectDeviceOrderList(DeviceOrder deviceOrder) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderList(deviceOrder);
|
}
|
|
/**
|
* 根据登录的用户来查询自己未派单的安装单/维修单数量
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public AjaxResult selectDeviceOrderCountByUndeliveredorders(DeviceOrder deviceOrder) throws Exception {
|
//根据登录的用户来查询自己未派单的安装单/维修单数量
|
int count = deviceOrderMapper.selectDeviceOrderCountByUndeliveredorders(deviceOrder);
|
//根据登录的用户来查询自己已派单的安装单/维修单数量
|
int total = deviceOrderMapper.selectDeviceOrderCountByDispatchedorders(deviceOrder);
|
//根据登录的用户来查询自己已接单的安装单/维修单数量
|
int number = deviceOrderMapper.selectDeviceOrderCountByReceivedorders(deviceOrder);
|
//根据登录的用户来查询自己已完成的安装单/维修单数量
|
int amount = deviceOrderMapper.selectDeviceOrderCountByCompleted(deviceOrder);
|
AjaxResult ajax = new AjaxResult();
|
//未派单的安装单/维修单的数量
|
ajax.put("deviceOrderUndeliveredorders", count);
|
//已派单的安装单/维修单的数量
|
ajax.put("deviceOrderDispatchedorders", total);
|
//已接单的安装单/维修单的数量
|
ajax.put("deviceOrderReceivedorders", number);
|
//已完成的安装单/维修单的数量
|
ajax.put("deviceOrderCompleted", amount);
|
return AjaxResult.success("查询成功", ajax);
|
}
|
|
/**
|
* 根据登录的用户来查询自己已派单的安装单/维修单数量
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public int selectDeviceOrderCountByDispatchedorders(DeviceOrder deviceOrder) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderCountByDispatchedorders(deviceOrder);
|
}
|
|
/**
|
* 根据登录的用户来查询自己已接单的安装单/维修单数量
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public int selectDeviceOrderCountByReceivedorders(DeviceOrder deviceOrder) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderCountByReceivedorders(deviceOrder);
|
}
|
|
/**
|
* 根据登录的用户来查询自己已完成的安装单/维修单数量
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public int selectDeviceOrderCountByCompleted(DeviceOrder deviceOrder) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderCountByCompleted(deviceOrder);
|
}
|
|
/**
|
* 查询设备订单表中已派单/已接单所有的数据
|
*
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<DeviceOrder> selectDeviceOrderAll() throws Exception {
|
return deviceOrderMapper.selectDeviceOrderAll();
|
}
|
|
/**
|
* 根据id查询安装订单信息
|
*
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public DeviceOrder selectDeviceOrderById(Long id) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderById(id);
|
}
|
|
|
/**
|
* 添加安装设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
@Transactional
|
public AjaxResult insertDeviceOrder(DeviceOrder deviceOrder) throws Exception {
|
SysUser sysUser = getLoginUser().getUser();
|
Device device = new Device();
|
//更新订单的初始化状态
|
if ("未指派".equals(deviceOrder.getErectoName())) {
|
deviceOrder.setState(0);
|
} else {
|
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())) {
|
//更新订单的用户信息
|
//插入维修单
|
int total = deviceOrderMapper.insertDeviceOrder(deviceOrder);
|
if (total > 0) {
|
Device deviceOrders = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId());
|
//更新当前设备的是否维修信息-未维修
|
device.setDeviceId(deviceOrder.getDeviceId());
|
device.setRepairFlag(1);
|
device.setStatus(deviceOrders.getStatus());
|
deviceService.updateDevice(device);
|
return toAjax(total);
|
}
|
} else {
|
//插入安装订单
|
int rows = deviceOrderMapper.insertDeviceOrder(deviceOrder);
|
if (rows > 0) {
|
//更新当前设备状态信息--安装中
|
device.setDeviceId(deviceOrder.getDeviceId());
|
device.setStatus(5);
|
deviceService.updateDevice(device);
|
return toAjax(rows);
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 修改保存设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
@Transactional
|
public AjaxResult updateDeviceOrder(DeviceOrder deviceOrder) throws Exception {
|
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) {
|
//获取修改订单的用户信息
|
//拿到修改安装单的用户id
|
deviceOrder.setUpdateUserId(sysUser.getUserId());
|
deviceOrder.setFinishTime(new Date());
|
int rows = deviceOrderMapper.updateDeviceOrder(deviceOrder);
|
if (rows > 0) {
|
device.setDeviceId(deviceOrder.getDeviceId());
|
//修改设备的状态为离线
|
device.setStatus(4);
|
//修改设备的是否安装标识为1-已安装
|
device.setInstallFlag(1);
|
deviceService.updateDevice(device);
|
}
|
return toAjax(rows);
|
} 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);
|
}
|
}
|
//拿到修改安装单的用户id
|
deviceOrder.setUpdateUserId(sysUser.getUserId());
|
return toAjax(deviceOrderMapper.updateDeviceOrder(deviceOrder));
|
}
|
|
/**
|
* 用户对完成的安装单/维修单打分和评价
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public AjaxResult updateDeviceOrderScoreAndComment(DeviceOrder deviceOrder) throws Exception {
|
if (deviceOrder != null) {
|
DeviceOrder order = deviceOrderMapper.selectDeviceOrderById(deviceOrder.getId());
|
if (order != null) {
|
deviceOrder.setUserId(deviceOrder.getUserId());
|
deviceOrder.setIsRate(1);
|
int rows = deviceOrderMapper.updateDeviceOrderScoreAndComment(deviceOrder);
|
if (rows > 0) {
|
return AjaxResult.success("操作成功");
|
}
|
} else {
|
return AjaxResult.error("暂无此单");
|
}
|
} else {
|
return AjaxResult.error();
|
}
|
return null;
|
}
|
|
/**
|
* 删除设备安装单/维修单信息
|
*
|
* @param id
|
* @param deviceId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public AjaxResult deleteDeviceOrderById(Long id, Long deviceId) throws Exception {
|
Device device = new Device();
|
//根据要删除安装单的id查询出安装单信息
|
DeviceOrder deviceOrders = deviceOrderMapper.selectDeviceOrderById(id);
|
//根据设备id查询设备信息
|
Device deviceA = deviceService.selectDeviceByDeviceId(deviceId);
|
SysUser user = getLoginUser().getUser();
|
//如果根据查询出来的安装单对象不为空的话,并且状态等于未派单才可以删除
|
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);
|
return toAjax(deviceOrderMapper.deleteDeviceOrderById(id));
|
} else {
|
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;
|
}
|
}
|
|
/**
|
* 批量删除设备订单安装信息
|
*
|
* @param ids
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public int deleteDeviceOrder(Integer[] ids) throws Exception {
|
return deviceOrderMapper.deleteDeviceOrder(ids);
|
}
|
}
|