【admin】新增# 1.完成订单定时任务 2.新增大屏websocket通信
parent
30a2c159c6
commit
42b44cdf83
|
@ -1,6 +1,8 @@
|
||||||
package com.hcy.admin;
|
package com.hcy.admin;
|
||||||
|
|
||||||
|
import com.hcy.admin.netty.NettyWebsocketServer;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
|
||||||
|
@ -9,6 +11,8 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动器
|
* 启动器
|
||||||
*/
|
*/
|
||||||
|
@ -18,11 +22,20 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@SpringBootApplication(exclude = {RedisRepositoriesAutoConfiguration.class})
|
@SpringBootApplication(exclude = {RedisRepositoriesAutoConfiguration.class})
|
||||||
public class AdminApplication {
|
public class AdminApplication implements CommandLineRunner {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NettyWebsocketServer nettyWebsocketServer;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(AdminApplication.class, args);
|
SpringApplication.run(AdminApplication.class, args);
|
||||||
System.out.println("(♥◠‿◠)ノ゙ charging_pile启动成功 ლ(´ڡ`ლ)゙");
|
System.out.println("(♥◠‿◠)ノ゙ charging_pile启动成功 ლ(´ڡ`ლ)゙");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
//启动websocket服务
|
||||||
|
new Thread(nettyWebsocketServer).start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.hcy.admin.controller.system;
|
||||||
|
|
||||||
|
import com.hcy.admin.config.aop.Log;
|
||||||
|
import com.hcy.admin.validate.system.SystemAuthAdminParam;
|
||||||
|
import com.hcy.common.core.AjaxResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("api/system/notification")
|
||||||
|
public class SystemNotificationController {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统通知
|
||||||
|
* @author dabin
|
||||||
|
* @param systemAuthAdminParam 参数
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@Log(title = "系统通知send")
|
||||||
|
@GetMapping("/send")
|
||||||
|
public Object add(SystemAuthAdminParam systemAuthAdminParam) {
|
||||||
|
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.hcy.admin.netty;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* netty配置
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "netty")
|
||||||
|
public class NettyConfig {
|
||||||
|
|
||||||
|
//netty监听端口
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
//websocket访问路径
|
||||||
|
private String path;
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.hcy.admin.netty;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
import io.netty.handler.logging.LogLevel;
|
||||||
|
import io.netty.handler.logging.LoggingHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Netty的Websocket服务器
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class NettyWebsocketServer implements Runnable{
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NettyConfig nettyConfig;
|
||||||
|
@Resource
|
||||||
|
private WebsocketChannelInit websocketChannelInit;
|
||||||
|
|
||||||
|
private final NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||||
|
private final NioEventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
// 1.创建服务端启动助手
|
||||||
|
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||||
|
// 2.设置线程组
|
||||||
|
serverBootstrap.group(bossGroup, workerGroup);
|
||||||
|
// 3.设置参数
|
||||||
|
serverBootstrap.channel(NioServerSocketChannel.class)
|
||||||
|
.handler(new LoggingHandler(LogLevel.DEBUG))
|
||||||
|
.childHandler(websocketChannelInit);
|
||||||
|
// 4.启动服务端
|
||||||
|
ChannelFuture channelFuture = serverBootstrap.bind(nettyConfig.getPort()).sync();
|
||||||
|
System.out.println("------Netty Admin 服务端启动成功------");
|
||||||
|
channelFuture.channel().closeFuture().sync();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
bossGroup.shutdownGracefully();
|
||||||
|
workerGroup.shutdownGracefully();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
bossGroup.shutdownGracefully();
|
||||||
|
workerGroup.shutdownGracefully();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭资源-容器销毁时候关闭
|
||||||
|
*/
|
||||||
|
@PreDestroy
|
||||||
|
public void close() {
|
||||||
|
bossGroup.shutdownGracefully();
|
||||||
|
workerGroup.shutdownGracefully();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package com.hcy.admin.netty;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||||
|
import io.netty.handler.codec.http.HttpServerCodec;
|
||||||
|
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
||||||
|
import io.netty.handler.stream.ChunkedWriteHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.security.KeyStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通道初始化对象
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WebsocketChannelInit extends ChannelInitializer {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NettyConfig nettyConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WebsocketHandler websocketHandler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initChannel(Channel channel) throws Exception {
|
||||||
|
ChannelPipeline pipeline = channel.pipeline();
|
||||||
|
|
||||||
|
// 对HTTP协议的支持
|
||||||
|
pipeline.addLast(new HttpServerCodec());
|
||||||
|
|
||||||
|
// 对大数据流的支持
|
||||||
|
pipeline.addLast(new ChunkedWriteHandler());
|
||||||
|
|
||||||
|
// post请求分为三个部分:request line/request header/message body
|
||||||
|
// 对POST请求的支持,将多个信息转化成单一的request/response对象
|
||||||
|
pipeline.addLast(new HttpObjectAggregator(8000));
|
||||||
|
|
||||||
|
// 对WebSocket协议的支持
|
||||||
|
// 将http协议升级为ws协议
|
||||||
|
pipeline.addLast(new WebSocketServerProtocolHandler(nettyConfig.getPath()));
|
||||||
|
|
||||||
|
// // SSL处理器
|
||||||
|
// SSLContext sslContext = createSslContext("JKS", "D:\\jks\\xcx\\xcx.jks","1234567");
|
||||||
|
// //SSLEngine 此类允许使用ssl安全套接层协议进行安全通信
|
||||||
|
// SSLEngine sslEngine = sslContext.createSSLEngine();
|
||||||
|
// sslEngine.setNeedClientAuth(false);
|
||||||
|
// sslEngine.setUseClientMode(false);
|
||||||
|
// pipeline.addFirst("ssl", new SslHandler(sslEngine));
|
||||||
|
|
||||||
|
// 自定义处理handler
|
||||||
|
pipeline.addLast(websocketHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type 证书类型
|
||||||
|
* @param path 证书路径
|
||||||
|
* @param password 证书密码
|
||||||
|
* @return SSLContext
|
||||||
|
*/
|
||||||
|
public SSLContext createSslContext(String type , String path , String password) throws Exception {
|
||||||
|
InputStream inputStream = Files.newInputStream(Paths.get(path));
|
||||||
|
char[] passArray = password.toCharArray();
|
||||||
|
SSLContext sslContext = SSLContext.getInstance("SSLv3");
|
||||||
|
KeyStore ks = KeyStore.getInstance(type);
|
||||||
|
//加载keytool 生成的文件
|
||||||
|
ks.load(inputStream, passArray);
|
||||||
|
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||||
|
kmf.init(ks, passArray);
|
||||||
|
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||||
|
inputStream.close();
|
||||||
|
return sslContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.hcy.admin.netty;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.hcy.common.core.AjaxResult;
|
||||||
|
import com.hcy.common.entity.staff.Staff;
|
||||||
|
import com.hcy.common.enums.staff.StaffReceiveOrderTypeEnum;
|
||||||
|
import com.hcy.common.mapper.staff.StaffMapper;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义Websocket处理类
|
||||||
|
* Websocket数据以帧的形式进行处理
|
||||||
|
* 需要设置通道共享
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
@ChannelHandler.Sharable
|
||||||
|
public class WebsocketHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
|
||||||
|
|
||||||
|
public static List<Channel> clientList = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void sendMessageToClient(String msg){
|
||||||
|
for (Channel channel : clientList) {
|
||||||
|
channel.writeAndFlush(new TextWebSocketFrame(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
clientList.add(ctx.channel());
|
||||||
|
ctx.channel().writeAndFlush(new TextWebSocketFrame("数据大屏客户端连接成功"));
|
||||||
|
super.channelActive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
System.out.println("客户端与服务端连接关闭");
|
||||||
|
clientList.remove(ctx.channel());
|
||||||
|
super.channelInactive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
ctx.flush();
|
||||||
|
super.channelReadComplete(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame tf) {
|
||||||
|
String text = tf.text();
|
||||||
|
for (Channel channel : clientList) {
|
||||||
|
if(ctx.channel() != channel){
|
||||||
|
channel.writeAndFlush(new TextWebSocketFrame(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
clientList.remove(ctx.channel());
|
||||||
|
super.exceptionCaught(ctx, cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -350,8 +350,8 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
||||||
.eq("is_delete", 0)
|
.eq("is_delete", 0)
|
||||||
.last("limit 1"));
|
.last("limit 1"));
|
||||||
|
|
||||||
if (model != null){
|
if (ObjectUtil.isNotNull(model) && model.getId().equals(bo.getId())) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.hcy.admin.service.crontab.impl;
|
|
||||||
|
|
||||||
import com.hcy.admin.service.coupon.ICouponService;
|
|
||||||
import com.hcy.admin.service.coupon.IUserCouponService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service(value = "couponCrontab")
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class CouponCrontab {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ICouponService iCouponService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IUserCouponService iUserCouponService;
|
|
||||||
|
|
||||||
public void sendCoupon(){
|
|
||||||
log.info("发放优惠券");
|
|
||||||
iCouponService.sendCoupon();
|
|
||||||
log.info("停用优惠券");
|
|
||||||
iCouponService.stopSendTimeEndOrUseTimeEndCoupon();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteUserGetCoupon(){
|
|
||||||
log.info("删除用户过期5天的优惠券");
|
|
||||||
iUserCouponService.deleteUserGetCoupon();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -64,6 +64,7 @@ public class OrderCrontab {
|
||||||
ClientMapper clientMapper;
|
ClientMapper clientMapper;
|
||||||
|
|
||||||
public void orderTimeOut(){
|
public void orderTimeOut(){
|
||||||
|
log.info("orderTimeOut 被执行......");
|
||||||
SystemConfiguration systemConfiguration = systemConfigurationMapper.selectById(1);
|
SystemConfiguration systemConfiguration = systemConfigurationMapper.selectById(1);
|
||||||
//检修单和巡检单超时时间
|
//检修单和巡检单超时时间
|
||||||
Integer repairerAutoOrderTime = systemConfiguration.getRepairerAutoOrderTime();
|
Integer repairerAutoOrderTime = systemConfiguration.getRepairerAutoOrderTime();
|
||||||
|
@ -138,6 +139,7 @@ public class OrderCrontab {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void equipmentPollingPeriod(){
|
public void equipmentPollingPeriod(){
|
||||||
|
log.info("equipmentPollingPeriod 被执行......");
|
||||||
//获取当前时间
|
//获取当前时间
|
||||||
Calendar currentTime = Calendar.getInstance();
|
Calendar currentTime = Calendar.getInstance();
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.hcy.admin.AdminThreadLocal;
|
import com.hcy.admin.AdminThreadLocal;
|
||||||
|
import com.hcy.admin.netty.WebsocketHandler;
|
||||||
import com.hcy.admin.service.order.IMaintenanceOrderService;
|
import com.hcy.admin.service.order.IMaintenanceOrderService;
|
||||||
import com.hcy.admin.service.region.IDevRegionService;
|
import com.hcy.admin.service.region.IDevRegionService;
|
||||||
import com.hcy.admin.validate.common.PageParam;
|
import com.hcy.admin.validate.common.PageParam;
|
||||||
|
@ -328,6 +329,8 @@ public class MaintenanceOrderServiceImpl implements IMaintenanceOrderService {
|
||||||
MaintenanceOrder maintenanceOrder = maintenanceOrderMapper.findLastMaintenanceOrderByTime(TimeUtil.getCurrentTimeYYYYMMDD());
|
MaintenanceOrder maintenanceOrder = maintenanceOrderMapper.findLastMaintenanceOrderByTime(TimeUtil.getCurrentTimeYYYYMMDD());
|
||||||
model.setOrderNo(OrderUtil.getOrderNo(maintenanceOrder == null ? "" :maintenanceOrder.getOrderNo()));
|
model.setOrderNo(OrderUtil.getOrderNo(maintenanceOrder == null ? "" :maintenanceOrder.getOrderNo()));
|
||||||
model.setCreatorId(AdminThreadLocal.getAdminId().longValue());
|
model.setCreatorId(AdminThreadLocal.getAdminId().longValue());
|
||||||
|
Date date = new Date();
|
||||||
|
model.setCreateTime(date);
|
||||||
maintenanceOrderMapper.insert(model);
|
maintenanceOrderMapper.insert(model);
|
||||||
|
|
||||||
//新增订单操作记录
|
//新增订单操作记录
|
||||||
|
@ -345,6 +348,12 @@ public class MaintenanceOrderServiceImpl implements IMaintenanceOrderService {
|
||||||
,"【"+AdminThreadLocal.get("username")+"】指派检修单给检修员【"+user.getUsername()+"】");
|
,"【"+AdminThreadLocal.get("username")+"】指派检修单给检修员【"+user.getUsername()+"】");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemAuthAdmin systemAuthAdmin = systemAuthAdminMapper.findSystemAuthAdminById(AdminThreadLocal.getAdminId());
|
||||||
|
Client client = clientMapper.findClientById(maintenanceOrderParam.getClientId());
|
||||||
|
if(client != null && systemAuthAdmin != null){
|
||||||
|
WebsocketHandler.sendMessageToClient("【"+systemAuthAdmin.getUsername()+"】于【"+TimeUtil.dateTransitionString(date)+"】为客户【"+client.getClientName()+"】新建检修工单,报修设备【"+equipment.getName()+"】;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.hcy.admin.AdminThreadLocal;
|
import com.hcy.admin.AdminThreadLocal;
|
||||||
|
import com.hcy.admin.netty.WebsocketHandler;
|
||||||
import com.hcy.admin.service.order.IRoutingInspectionOrderService;
|
import com.hcy.admin.service.order.IRoutingInspectionOrderService;
|
||||||
import com.hcy.admin.service.region.IDevRegionService;
|
import com.hcy.admin.service.region.IDevRegionService;
|
||||||
import com.hcy.admin.validate.common.PageParam;
|
import com.hcy.admin.validate.common.PageParam;
|
||||||
|
@ -28,6 +29,7 @@ import com.hcy.common.mapper.fault.FaultMapper;
|
||||||
import com.hcy.common.mapper.order.RoutingInspectionOrderMapper;
|
import com.hcy.common.mapper.order.RoutingInspectionOrderMapper;
|
||||||
import com.hcy.common.mapper.system.SystemAuthAdminMapper;
|
import com.hcy.common.mapper.system.SystemAuthAdminMapper;
|
||||||
import com.hcy.common.mapper.user.UserMapper;
|
import com.hcy.common.mapper.user.UserMapper;
|
||||||
|
import com.hcy.common.utils.TimeUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -193,12 +195,20 @@ public class RoutingInspectionOrderServiceImpl implements IRoutingInspectionOrde
|
||||||
model.setRemark(routingInspectionOrderParam.getRemark()); // 备注
|
model.setRemark(routingInspectionOrderParam.getRemark()); // 备注
|
||||||
model.setReceiverType(routingInspectionOrderParam.getReceiverType()); // 接单类型 0-区域派单;1-距离派单
|
model.setReceiverType(routingInspectionOrderParam.getReceiverType()); // 接单类型 0-区域派单;1-距离派单
|
||||||
model.setOrderDistance(routingInspectionOrderParam.getOrderDistance()); // 抢单最大公里数
|
model.setOrderDistance(routingInspectionOrderParam.getOrderDistance()); // 抢单最大公里数
|
||||||
model.setCreateTime(new Date()); //创建时间
|
Date currentTime = new Date();
|
||||||
|
model.setCreateTime(currentTime); //创建时间
|
||||||
|
|
||||||
// 获取当前的用户
|
// 获取当前的用户
|
||||||
String adminId = AdminThreadLocal.get("adminId").toString();
|
model.setCreatorId(AdminThreadLocal.getAdminId()); // 创建人id
|
||||||
model.setCreatorId(Integer.parseInt(adminId)); // 创建人id
|
|
||||||
routingInspectionOrderMapper.insert(model);
|
routingInspectionOrderMapper.insert(model);
|
||||||
|
|
||||||
|
|
||||||
|
SystemAuthAdmin systemAuthAdmin = systemAuthAdminMapper.findSystemAuthAdminById(AdminThreadLocal.getAdminId());
|
||||||
|
Client client = clientMapper.findClientById(routingInspectionOrderParam.getClientId());
|
||||||
|
Equipment equipment = equipmentMapper.findEquipmentById(routingInspectionOrderParam.getEquipmentId());
|
||||||
|
if(client != null && systemAuthAdmin != null && equipment != null){
|
||||||
|
WebsocketHandler.sendMessageToClient("【"+systemAuthAdmin.getUsername()+"】于【"+TimeUtil.dateTransitionString(currentTime)+"】为客户【"+client.getClientName()+"】新建巡检工单,报修设备【"+equipment.getName()+"】;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -121,7 +121,6 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||||
BeanUtils.copyProperties(param,systemAuthAdminDto);
|
BeanUtils.copyProperties(param,systemAuthAdminDto);
|
||||||
|
|
||||||
IPage<SystemAuthAdminDto> iPage = systemAuthAdminMapper.list(new Page<>(page, limit), systemAuthAdminDto);
|
IPage<SystemAuthAdminDto> iPage = systemAuthAdminMapper.list(new Page<>(page, limit), systemAuthAdminDto);
|
||||||
long total = 0;
|
|
||||||
List<SystemAuthAdminVo> list = new LinkedList<>();
|
List<SystemAuthAdminVo> list = new LinkedList<>();
|
||||||
for (SystemAuthAdminDto dto : iPage.getRecords()) {
|
for (SystemAuthAdminDto dto : iPage.getRecords()) {
|
||||||
|
|
||||||
|
@ -166,6 +165,7 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||||
vo.setReceiveOrderStatus(user.getReceiveOrderStatus());
|
vo.setReceiveOrderStatus(user.getReceiveOrderStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||||
|
@ -366,55 +366,41 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||||
systemAuthAdminMapper.insert(model);
|
systemAuthAdminMapper.insert(model);
|
||||||
//获取管理员id
|
//获取管理员id
|
||||||
Long adminId = model.getId().longValue();
|
Long adminId = model.getId().longValue();
|
||||||
//新增用户的时候,角色是检修员或维修员,就在检修员仓库或者维修员仓库下新增一个仓库
|
|
||||||
Integer role = Integer.valueOf(systemAuthAdminParam.getRole()); //获取角色
|
|
||||||
Map<Long, String> regionMap = regionService.getRegionMap();
|
Map<Long, String> regionMap = regionService.getRegionMap();
|
||||||
String province = regionMap.get(model.getProvinceId());
|
String province = regionMap.get(model.getProvinceId());
|
||||||
String city = regionMap.get(model.getCityId());
|
String city = regionMap.get(model.getCityId());
|
||||||
String district = regionMap.get(model.getDistrictId());
|
String district = regionMap.get(model.getDistrictId());
|
||||||
|
|
||||||
if(role == RoleEnum.OVERHAUL_RESULT.getStatus()){
|
//新增用户的时候,角色是检修员或维修员,就在检修员仓库或者维修员仓库下新增一个仓库
|
||||||
Warehouse warehouse = new Warehouse();
|
//获取当前新增用户角色
|
||||||
warehouse.setPid(Long.valueOf(WarehouseEnum.MAINTANCE_WAREHOUSE.getStatus())); //仓库上级id
|
List<String> roleList = Arrays.asList(systemAuthAdminParam.getRole().split(","));
|
||||||
warehouse.setWarehouseName(systemAuthAdminParam.getNickname()); //仓库名称
|
if(roleList.contains(String.valueOf(RoleEnum.OVERHAUL_RESULT.getStatus()))){
|
||||||
warehouse.setWarehouseCoding(systemAuthAdminParam.getNickname() + "-" + systemAuthAdminParam.getPhone()); // 仓库编码
|
addWarehouse(systemAuthAdminParam,province + city + district,adminId,WarehouseEnum.MAINTANCE_WAREHOUSE.getStatus());
|
||||||
warehouse.setWarehouseAddress(province + city + district); // 仓库地址
|
|
||||||
warehouseMapper.insert(warehouse);
|
|
||||||
//获取仓库id
|
|
||||||
Long warehouseId = warehouse.getId().longValue();
|
|
||||||
//获取小程序用户id
|
|
||||||
SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne(
|
|
||||||
new QueryWrapper<SystemAuthAdmin>()
|
|
||||||
.eq("id", adminId)
|
|
||||||
.eq("is_delete", 0));
|
|
||||||
User user= userMapper.selectOne(
|
|
||||||
new QueryWrapper<User>()
|
|
||||||
.eq("id", authAdmin.getUserId())
|
|
||||||
.eq("is_delete", 0));
|
|
||||||
user.setWarehouseId(warehouseId);
|
|
||||||
userMapper.updateById(user);//绑定仓库
|
|
||||||
|
|
||||||
}else if(role == RoleEnum.MAINTENANCE_MAN.getStatus()){
|
|
||||||
Warehouse warehouse = new Warehouse();
|
|
||||||
warehouse.setPid(Long.valueOf(WarehouseEnum.REPAIR_WAREHOUSE.getStatus())); //仓库上级id
|
|
||||||
warehouse.setWarehouseName(systemAuthAdminParam.getNickname()); //仓库名称
|
|
||||||
warehouse.setWarehouseCoding(systemAuthAdminParam.getNickname() + "-" + systemAuthAdminParam.getPhone()); // 仓库编码
|
|
||||||
warehouse.setWarehouseAddress(province + city + district); // 仓库地址
|
|
||||||
warehouseMapper.insert(warehouse);
|
|
||||||
//获取仓库id
|
|
||||||
Long warehouseId = warehouse.getId().longValue();
|
|
||||||
//获取小程序用户id
|
|
||||||
SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne(
|
|
||||||
new QueryWrapper<SystemAuthAdmin>()
|
|
||||||
.eq("id", adminId)
|
|
||||||
.eq("is_delete", 0));
|
|
||||||
User user= userMapper.selectOne(
|
|
||||||
new QueryWrapper<User>()
|
|
||||||
.eq("id", authAdmin.getUserId())
|
|
||||||
.eq("is_delete", 0));
|
|
||||||
user.setWarehouseId(warehouseId);
|
|
||||||
userMapper.updateById(user);//绑定仓库
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(roleList.contains(String.valueOf(RoleEnum.MAINTENANCE_MAN.getStatus()))){
|
||||||
|
addWarehouse(systemAuthAdminParam,province + city + district,adminId,WarehouseEnum.REPAIR_WAREHOUSE.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addWarehouse(SystemAuthAdminParam systemAuthAdminParam,String addressDetail,Long adminId,Integer roleType) {
|
||||||
|
Warehouse warehouse = new Warehouse();
|
||||||
|
warehouse.setPid(Long.valueOf(roleType)); //仓库上级id
|
||||||
|
warehouse.setWarehouseName(systemAuthAdminParam.getNickname()); //仓库名称
|
||||||
|
warehouse.setWarehouseCoding(systemAuthAdminParam.getUsername() + "-" + systemAuthAdminParam.getPhone()); // 仓库编码
|
||||||
|
warehouse.setWarehouseAddress(addressDetail); // 仓库地址
|
||||||
|
warehouseMapper.insert(warehouse);
|
||||||
|
//获取仓库id
|
||||||
|
Long warehouseId = warehouse.getId();
|
||||||
|
//获取小程序用户id
|
||||||
|
SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne(
|
||||||
|
new QueryWrapper<SystemAuthAdmin>()
|
||||||
|
.eq("id", adminId)
|
||||||
|
.eq("is_delete", 0));
|
||||||
|
User user= userMapper.findUserById(authAdmin.getUserId());
|
||||||
|
user.setWarehouseId(warehouseId);
|
||||||
|
userMapper.updateById(user);//绑定仓库
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -69,5 +69,8 @@ mybatis-plus:
|
||||||
table-prefix: la_ # 设置表前缀
|
table-prefix: la_ # 设置表前缀
|
||||||
configuration-properties:
|
configuration-properties:
|
||||||
prefix: la_ # 自定义表前缀标签${prefix}
|
prefix: la_ # 自定义表前缀标签${prefix}
|
||||||
# configuration: #打印sql日志
|
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
netty:
|
||||||
|
port: 8081
|
||||||
|
path: /admin
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ public enum OrderOperateRecordEnum {
|
||||||
RECEIVE_GOODS(8,"收货"),
|
RECEIVE_GOODS(8,"收货"),
|
||||||
FILL_IN_RECEIPT(10,"填写回单"),
|
FILL_IN_RECEIPT(10,"填写回单"),
|
||||||
FINISH(11,"完成"),
|
FINISH(11,"完成"),
|
||||||
|
REFUND(11,"退单"),
|
||||||
|
|
||||||
// 描述类型
|
// 描述类型
|
||||||
QUOTATION(0,"报价"),
|
QUOTATION(0,"报价"),
|
||||||
|
|
|
@ -14,6 +14,6 @@ import org.apache.ibatis.annotations.Select;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PlantMapper extends IBaseMapper<Plant> {
|
public interface PlantMapper extends IBaseMapper<Plant> {
|
||||||
|
|
||||||
@Select("select * from la_plant where is_delete = 0 and id = #{adminId}")
|
@Select("select * from la_plant where is_delete = 0 and id = #{id}")
|
||||||
Plant findPlantByAdminId(@Param("adminId") Integer adminId);
|
Plant findPlantByAdminId(@Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public interface UserMapper extends IBaseMapper<User> {
|
||||||
* @param phone 手机号
|
* @param phone 手机号
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
@Select("select * from la_user where mobile = #{phone}")
|
@Select("select * from la_user where is_delete = 0 and mobile = #{phone}")
|
||||||
User getUserByPhone(@Param("phone") String phone);
|
User getUserByPhone(@Param("phone") String phone);
|
||||||
|
|
||||||
@Select("select * from la_user where is_delete = 0 and id = #{id}")
|
@Select("select * from la_user where is_delete = 0 and id = #{id}")
|
||||||
|
|
|
@ -19,6 +19,10 @@ public class TimeUtil {
|
||||||
|
|
||||||
private static final SimpleDateFormat SDF_YYYY_MM_DD = new SimpleDateFormat("yyyyMMdd");
|
private static final SimpleDateFormat SDF_YYYY_MM_DD = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
|
||||||
|
public static String dateTransitionString(Date date) {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间戳转日期(默认格式)
|
* 时间戳转日期(默认格式)
|
||||||
*
|
*
|
||||||
|
|
|
@ -106,7 +106,7 @@ public interface IMaintenanceOrderService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计工单状态数量
|
* 统计工单状态数量
|
||||||
* @return
|
* @return OrderStatusCountVo
|
||||||
*/
|
*/
|
||||||
OrderStatusCountVo orderStatusCount(MaintenanceOrderParam maintenanceOrderParam);
|
OrderStatusCountVo orderStatusCount(MaintenanceOrderParam maintenanceOrderParam);
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,6 +327,7 @@ public class MaintenanceOrderServiceImpl implements IMaintenanceOrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void refundOrder(MaintenanceOrderParam maintenanceOrderParam) {
|
public void refundOrder(MaintenanceOrderParam maintenanceOrderParam) {
|
||||||
MaintenanceOrder maintenanceOrder = maintenanceOrderMapper.findMaintenanceOrderById(maintenanceOrderParam.getId());
|
MaintenanceOrder maintenanceOrder = maintenanceOrderMapper.findMaintenanceOrderById(maintenanceOrderParam.getId());
|
||||||
Assert.notNull(maintenanceOrder, "数据不存在");
|
Assert.notNull(maintenanceOrder, "数据不存在");
|
||||||
|
@ -340,6 +341,11 @@ public class MaintenanceOrderServiceImpl implements IMaintenanceOrderService {
|
||||||
maintenanceOrder.getOrderStatus() == MaintenanceOrderStatusEnum.PENDING_ORDER.getStatus()){
|
maintenanceOrder.getOrderStatus() == MaintenanceOrderStatusEnum.PENDING_ORDER.getStatus()){
|
||||||
maintenanceOrder.setOrderStatus(MaintenanceOrderStatusEnum.CLOSED.getStatus());
|
maintenanceOrder.setOrderStatus(MaintenanceOrderStatusEnum.CLOSED.getStatus());
|
||||||
maintenanceOrderMapper.updateById(maintenanceOrder);
|
maintenanceOrderMapper.updateById(maintenanceOrder);
|
||||||
|
|
||||||
|
//新增检修单操作记录
|
||||||
|
orderOperateRecordService.addMaintenanceOrder(maintenanceOrder.getId()
|
||||||
|
,OrderOperateRecordEnum.REFUND.getDesc()
|
||||||
|
,"客户【"+FrontThreadLocal.get("username")+"】已退单。退单原因:"+maintenanceOrderParam.getCancelCause());
|
||||||
}else{
|
}else{
|
||||||
throw new OperateException("当前订单状态不可退单");
|
throw new OperateException("当前订单状态不可退单");
|
||||||
}
|
}
|
||||||
|
@ -354,6 +360,11 @@ public class MaintenanceOrderServiceImpl implements IMaintenanceOrderService {
|
||||||
maintenanceOrder.setOrderStatus(MaintenanceOrderStatusEnum.CHARGEBACK.getStatus());
|
maintenanceOrder.setOrderStatus(MaintenanceOrderStatusEnum.CHARGEBACK.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//新增检修单操作记录
|
||||||
|
orderOperateRecordService.addMaintenanceOrder(maintenanceOrder.getId()
|
||||||
|
,OrderOperateRecordEnum.REFUND.getDesc()
|
||||||
|
,"【"+FrontThreadLocal.get("username")+"】已退单。退单原因:"+maintenanceOrderParam.getCancelCause());
|
||||||
|
|
||||||
maintenanceOrderMapper.updateById(maintenanceOrder);
|
maintenanceOrderMapper.updateById(maintenanceOrder);
|
||||||
}else{
|
}else{
|
||||||
throw new OperateException("当前订单状态不可退单");
|
throw new OperateException("当前订单状态不可退单");
|
||||||
|
|
|
@ -133,8 +133,7 @@ public class RepairOrderServiceImpl implements IRepairOrderService {
|
||||||
|
|
||||||
List<RepairOrderDto> repairOrderDtoList = repairOrderMapper.list(repairOrderDto);
|
List<RepairOrderDto> repairOrderDtoList = repairOrderMapper.list(repairOrderDto);
|
||||||
SystemAuthAdmin systemAuthAdmin = systemAuthAdminMapper.findSystemAuthAdminByUserId(FrontThreadLocal.getUserId());
|
SystemAuthAdmin systemAuthAdmin = systemAuthAdminMapper.findSystemAuthAdminByUserId(FrontThreadLocal.getUserId());
|
||||||
//获取工厂
|
|
||||||
Plant plant = plantMapper.findPlantByAdminId(systemAuthAdmin.getPlantId());
|
|
||||||
|
|
||||||
List<RepairOrderListVo> returnData = new LinkedList<>();
|
List<RepairOrderListVo> returnData = new LinkedList<>();
|
||||||
for (RepairOrderDto item : repairOrderDtoList) {
|
for (RepairOrderDto item : repairOrderDtoList) {
|
||||||
|
@ -145,19 +144,14 @@ public class RepairOrderServiceImpl implements IRepairOrderService {
|
||||||
, repairOrderParam.getLongitude(), repairOrderParam.getLatitude());
|
, repairOrderParam.getLongitude(), repairOrderParam.getLatitude());
|
||||||
|
|
||||||
if(item.getReceiverType() == OrderStateEnum.REGIONAL_DISPATCH.getStatus()){
|
if(item.getReceiverType() == OrderStateEnum.REGIONAL_DISPATCH.getStatus()){
|
||||||
/*if(item.getEquipmentProvinceId().equals(systemAuthAdmin.getProvinceId()) &&
|
|
||||||
item.getEquipmentCityId().equals(systemAuthAdmin.getCityId()) &&
|
|
||||||
item.getEquipmentDistrictId().equals(systemAuthAdmin.getDistrictId()) ){
|
|
||||||
|
|
||||||
// 计算距离
|
SystemAuthAdmin systemAuthAdminByUserId = systemAuthAdminMapper.findSystemAuthAdminByUserId(Math.toIntExact(item.getCreatorId()));
|
||||||
RepairOrderListVo vo = new RepairOrderListVo();
|
//获取工厂
|
||||||
BeanUtils.copyProperties(item, vo);
|
Plant plant = plantMapper.findPlantByAdminId(Long.valueOf(systemAuthAdminByUserId.getPlantId()));
|
||||||
vo.setDistance(distance);
|
|
||||||
returnData.add(vo);
|
if(systemAuthAdmin.getProvinceId().equals(plant.getProvinceId()) &&
|
||||||
}*/
|
systemAuthAdmin.getCityId().equals(plant.getCityId()) &&
|
||||||
if(item.getEquipmentProvinceId().equals(plant.getProvinceId()) &&
|
systemAuthAdmin.getDistrictId().equals(plant.getDistrictId()) ){
|
||||||
item.getEquipmentCityId().equals(plant.getCityId()) &&
|
|
||||||
item.getEquipmentDistrictId().equals(plant.getDistrictId()) ){
|
|
||||||
|
|
||||||
// 计算距离
|
// 计算距离
|
||||||
RepairOrderListVo vo = new RepairOrderListVo();
|
RepairOrderListVo vo = new RepairOrderListVo();
|
||||||
|
|
Loading…
Reference in New Issue