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.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;
|
|
|
/**
|
* @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);
|
}
|
|
/**
|
* 根据id查询安装订单信息
|
*
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public DeviceOrder selectDeviceOrderById(int id) throws Exception {
|
return deviceOrderMapper.selectDeviceOrderById(id);
|
}
|
|
|
/**
|
* 添加安装设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
@Transactional
|
public AjaxResult insertDeviceOrder(DeviceOrder deviceOrder) throws Exception {
|
//更新订单的初始化状态
|
if ("未指派".equals(deviceOrder.getErectoName())) {
|
deviceOrder.setState(0);
|
} else {
|
deviceOrder.setState(1);
|
deviceOrder.setAssginTime(new Date());
|
}
|
//判断传过来的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());
|
//更新当前设备的是否维修信息-未维修
|
Device device = new Device();
|
device.setDeviceId(deviceOrder.getDeviceId());
|
device.setRepairFlag(1);
|
device.setStatus(device1.getStatus());
|
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);
|
}
|
|
/**
|
* 修改保存设备订单信息
|
*
|
* @param deviceOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
@Transactional
|
public AjaxResult updateDeviceOrder(DeviceOrder deviceOrder) throws Exception {
|
DeviceOrder deviceOrderA = deviceOrderMapper.selectDeviceOrderByIdAnderectoName(deviceOrder.getId(), deviceOrder.getErectoName());
|
if (deviceOrderA == 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);
|
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);
|
}
|
return toAjax(rows);
|
}
|
//获取修改订单的用户信息
|
SysUser sysUser = getLoginUser().getUser();
|
//拿到修改安装单的用户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) {
|
order.setUserId(order.getUserId());
|
order.setRate(1);
|
int rows = deviceOrderMapper.updateDeviceOrderScoreAndComment(order);
|
if (rows > 0) {
|
return AjaxResult.success("操作成功");
|
}
|
} else {
|
return AjaxResult.error("暂无此单");
|
}
|
} else {
|
return AjaxResult.error();
|
}
|
return null;
|
}
|
|
/**
|
* 删除设备订单信息
|
*
|
* @param deviceId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public AjaxResult deleteDeviceOrderById(Integer deviceId) throws Exception {
|
//根据要删除安装单的id查询出安装单信息
|
DeviceOrder deviceOrder = deviceOrderMapper.selectDeviceOrderById(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);
|
deviceService.updateDevice(device);
|
int i = deviceOrderMapper.deleteDeviceOrderById(deviceOrder.getId());
|
return toAjax(i);
|
} else {
|
return AjaxResult.error();
|
}
|
}
|
|
/**
|
* 批量删除设备订单安装信息
|
*
|
* @param ids
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public int deleteDeviceOrder(Integer[] ids) throws Exception {
|
return deviceOrderMapper.deleteDeviceOrder(ids);
|
}
|
}
|