控制策略-状态更改
控制策略-删除
main
周文涛 2 years ago
parent 122f2bd2fe
commit bc265ee302

@ -107,6 +107,15 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>

@ -0,0 +1,124 @@
package com.example.zxweb.common.constant.enums;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/14 9:53
*/
public enum WeekEnum {
SECONDS("1", "星期天", "Sunday "), MONDAY("2", "星期一", "Monday "), TUESDAY("3", "星期二", "Tuesday "), WEDNESDAY("4",
"星期三", "Wednesday "), THURSDAY("5", "星期四",
"Thursday "), FRIDAY("6", "星期五", "Friday "), SATURDAY("7", "星期六", "Saturday ");
private String key;
private String nameCn;
private String nameEn;
WeekEnum(String key, String nameCn, String nameEn) {
this.key = key;
this.nameCn = nameCn;
this.nameEn = nameEn;
}
public static String matchNameCn(String code) {
for (WeekEnum m : WeekEnum.values()) {
if (m.getKey().equals(code)) {
return m.getNameCn();
}
}
return "";
}
public static String matchNameEn(String code) {
for (WeekEnum m : WeekEnum.values()) {
if (m.getKey().equals(code)) {
return m.getNameEn();
}
}
return "";
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getNameCn() {
return nameCn;
}
public void setNameCn(String nameCn) {
this.nameCn = nameCn;
}
public String getNameEn() {
return nameEn;
}
public void setNameEn(String nameEn) {
this.nameEn = nameEn;
}
}

@ -2,10 +2,14 @@ package com.example.zxweb.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zxweb.common.api.vo.Result;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.service.IZxCelueService;
import com.example.zxweb.vo.AddZxCeluePVO;
import com.example.zxweb.vo.QueryCelueVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
@ -13,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @Description
@ -28,17 +33,9 @@ public class CelueController {
@ApiOperation(value = "策略列表")
@GetMapping(value = "/list")
public Result<?> list(@RequestParam(value = "page",defaultValue = "1")Integer page,@RequestParam(value = "limit",defaultValue = "10")Integer limit,
@RequestParam(value = "name",defaultValue = "")String name,@RequestParam(value = "status",defaultValue = "")String status){
LambdaQueryWrapper<ZxCelue> queryWrapper=new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(name)) {
queryWrapper.like(ZxCelue::getName,name);
}
if (StringUtils.isNotBlank(status)) {
queryWrapper.eq(ZxCelue::getStatus,status);
}
Page<ZxCelue> pageList = zxCelueService.page(new Page<>(page, limit),queryWrapper);
return Result.OK(pageList);
public Result<?> list(QueryCelueVO queryCelueVO){
IPage<ZxCelueDTO> list= zxCelueService.pageList(queryCelueVO);
return Result.OK(list);
}
@ApiOperation(value = "策略列表-全部")
@ -50,13 +47,13 @@ public class CelueController {
@ApiOperation(value = "详情")
@GetMapping
public Result<?> getDetail(@RequestParam String id){
return Result.OK(zxCelueService.getById(id));
return Result.OK(zxCelueService.getDetail(id));
}
@ApiOperation(value = "新增")
@PostMapping
public Result<?>add(@RequestBody ZxCelue zxCelue){
zxCelueService.save(zxCelue);
public Result<?> add(@RequestBody AddZxCeluePVO addZxCeluePVO){
zxCelueService.saveZxCelue(addZxCeluePVO);
return Result.OK();
}
@ -67,19 +64,14 @@ public class CelueController {
return Result.OK();
}
@ApiOperation(value = "编辑")
@ApiOperation(value = "编辑状态")
@PutMapping("/status")
public Result<?> status(@RequestBody ZxCelue zxCelue){
ZxCelue celue = zxCelueService.getById(zxCelue.getCelueid());
LambdaUpdateWrapper<ZxCelue> updateWrapper=new LambdaUpdateWrapper<>();
updateWrapper.eq(ZxCelue::getCelueid,celue.getCelueid());
if ("0".equals(celue.getStatus())) {
updateWrapper.set(ZxCelue::getStatus,"1");
}else{
updateWrapper.set(ZxCelue::getStatus,"0");
boolean b = zxCelueService.editStatus(zxCelue);
if (b) {
return Result.OK("操作成功");
}
zxCelueService.update(updateWrapper);
return Result.OK();
return Result.error("操作失败");
}
/**
*
@ -87,8 +79,9 @@ public class CelueController {
@ApiOperation(value="删除", notes="删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id") String id) {
zxCelueService.removeById(id);
return Result.OK();
zxCelueService.deleteZxCelue(id);
//zxCelueService.removeById(id);
return Result.OK("操作成功");
}
}

@ -5,7 +5,7 @@ import com.example.zxweb.common.api.vo.Result;
import com.example.zxweb.common.constant.enums.IotApiEnum;
import com.example.zxweb.utils.AssertUtils;
import com.example.zxweb.utils.IotUtils;
import com.example.zxweb.vo.QueryCelueListVO;
import com.example.zxweb.vo.QueryCelueVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
@ -32,14 +32,14 @@ public class GatewayController {
private static final List<String> gatewayDevIdList=new ArrayList<>(Arrays.asList("0cefafd605f7","0cefafd295a4"));
/**
*
* @param queryCelueListVO
* @param queryCelueVO
* @return
*/
@GetMapping(value = "/celueListQuery")
public Result<?> celueListQuery(QueryCelueListVO queryCelueListVO){
String devid = queryCelueListVO.getDevid();
Integer pageNum = queryCelueListVO.getPageNum();
Integer pageSize = queryCelueListVO.getPageSize();
public Result<?> celueListQuery(QueryCelueVO queryCelueVO){
String devid = queryCelueVO.getDevid();
Integer pageNum = queryCelueVO.getPage();
Integer pageSize = queryCelueVO.getLimit();
AssertUtils.notEmpty(devid,"请输入-[devid]");
String format = String.format("{\"serial\":\"%s\",\"productId\":\"\",\"methodName\":\"celueListQuery\",\"inputData\":{\"devid\":\"%s\"}}", devid,devid);
JSONObject requestBody = JSONObject.parseObject(format);

@ -0,0 +1,20 @@
package com.example.zxweb.dto;
import com.example.zxweb.entity.ZxCelue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/14 13:28
*/
@Data
@ApiModel(value = "策略信息查询返回对象")
public class ZxCelueDTO extends ZxCelue {
@ApiModelProperty(value = "选择设备id集合")
private List<String> devidList;
}

@ -1,8 +1,13 @@
package com.example.zxweb.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.vo.QueryCelueVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @Description
@ -11,4 +16,5 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ZxCelueMapper extends BaseMapper<ZxCelue> {
IPage<ZxCelueDTO> pageList(@Param("page") Page<ZxCelueDTO> page,@Param("qvo") QueryCelueVO queryCelueVO);
}

@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.zxweb.mapper.ZxCelueMapper">
<!--
获取策略表
devid不为空的
可根据name、status条件检索
-->
<select id="pageList" resultType="com.example.zxweb.dto.ZxCelueDTO">
SELECT * FROM zx_celue
WHERE 1=1 AND devid IS NOT NULL
<if test="qvo.name!=null and qvo.name !=''">
and name like concat('%',#{qvo.name},'%')
</if>
<if test="qvo.status!=null and qvo.status !=''">
and status = #{qvo.status}
</if>
order by update_time,create_time desc
</select>
</mapper>

@ -1,7 +1,11 @@
package com.example.zxweb.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.vo.AddZxCeluePVO;
import com.example.zxweb.vo.QueryCelueVO;
/**
* @Description
@ -9,4 +13,27 @@ import com.example.zxweb.entity.ZxCelue;
* @Date 2023/9/13 14:07
*/
public interface IZxCelueService extends IService<ZxCelue> {
/**
*
*/
boolean saveZxCelue(AddZxCeluePVO addZxCeluePVO);
/**
*
*/
boolean editStatus(ZxCelue zxCelue);
/**
*
*/
boolean deleteZxCelue(String id);
/**
*
* @param queryCelueVO
* @return
*/
IPage<ZxCelueDTO> pageList(QueryCelueVO queryCelueVO);
ZxCelueDTO getDetail(String id);
}

@ -1,13 +1,29 @@
package com.example.zxweb.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.exception.BusinessException;
import com.example.zxweb.mapper.ZxCelueMapper;
import com.example.zxweb.service.IZxCelueService;
import com.example.zxweb.utils.IotUtils;
import com.example.zxweb.vo.AddZxCeluePVO;
import com.example.zxweb.vo.QueryCelueVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Description
@ -17,4 +33,107 @@ import javax.annotation.Resource;
@Service
@Slf4j
public class ZxCelueServiceImpl extends ServiceImpl<ZxCelueMapper, ZxCelue> implements IZxCelueService {
@Value("${iot.active}")
private boolean active;
@Override
public boolean saveZxCelue(AddZxCeluePVO addZxCeluePVO) {
return false;
}
@Override
public boolean editStatus(ZxCelue zxCelue) {
String status="0";
try {
ZxCelue celue = getById(zxCelue.getCelueid());
LambdaUpdateWrapper<ZxCelue> updateWrapper=new LambdaUpdateWrapper<>();
updateWrapper.eq(ZxCelue::getCelueid,celue.getCelueid());
if ("0".equals(celue.getStatus())) {
status="1";
updateWrapper.set(ZxCelue::getStatus,status);
}else{
updateWrapper.set(ZxCelue::getStatus,status);
}
update(updateWrapper);
//请求更改策略方法
if (active) {
//向网关发生更改状态指令
IotUtils.editCelueStatus(celue.getCelueid(),status);
}
}catch (Exception e){
throw new BusinessException(e);
}
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteZxCelue(String id) {
//删除数据库中策略
removeById(id);
if (active) {
//向网关发生删除指令
IotUtils.deleteCelue(id);
}
return true;
}
@Override
public IPage<ZxCelueDTO> pageList(QueryCelueVO queryCelueVO) {
Integer page = queryCelueVO.getPage();
Integer limit = queryCelueVO.getLimit();
String name = queryCelueVO.getName();
String status = queryCelueVO.getStatus();
IPage<ZxCelueDTO> pageList = baseMapper.pageList(new Page<>(page, limit),queryCelueVO);
for (ZxCelueDTO record : pageList.getRecords()) {
if (StringUtils.isNotBlank(record.getDevid())) {
List<String> collect = Arrays.stream(record.getDevid().split(",")).collect(Collectors.toList());
record.setDevidList(collect);
}
}
return pageList;
}
@Override
public ZxCelueDTO getDetail(String id) {
ZxCelue zxCelue = getById(id);
ZxCelueDTO zxCelueDTO = new ZxCelueDTO();
BeanUtils.copyProperties(zxCelue,zxCelueDTO);
//拆分 所选设备id
String devid = zxCelue.getDevid();
if (StringUtils.isNotBlank(devid)) {
List<String> collect = Arrays.stream(devid.split(",")).collect(Collectors.toList());
zxCelueDTO.setDevidList(collect);
}
return zxCelueDTO;
}
public static void main(String[] args) {
String timeType="day";
String exeTime="08:30";
String cron=null;
String weeklyDay="1,2,3";//周一,周二,周三
String day="1,31";
String[] time = exeTime.split(":");
Integer hour=Integer.parseInt(time[0]);//小时
Integer minute=Integer.parseInt(time[1]);//分钟
String startDate="2023-09-10";//开始时间
String endDate="2023-09-30";//结束时间
//每天
if ("everyDay".equals(timeType)) {
cron = String.format("0 %s %s * * ? *",minute,hour);
} else if ("weekly".equals(timeType)) {
//每周
cron = String.format("0 %s %s ? * %s",minute,hour,weeklyDay);
} else if("day".equals(timeType)){
//单日
cron = String.format("0 %s %s %s * ? ",minute,hour,day);
} else if ("date".equals(timeType)){
//日期段
System.out.println("在"+startDate+"到"+endDate);
cron = String.format("0 %s %s * * ? *",minute,hour);
}
System.out.println(cron);
}
}

@ -0,0 +1,355 @@
package com.example.zxweb.utils;
import com.example.zxweb.common.constant.enums.WeekEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/14 9:53
*/
public class CronExpParserUtil {
protected final static String[] CRON_TIME_CN = new String[]{"秒", "分钟", "小时", "天", "月", "周", "年"};
private final static Integer HOURS = 24;
private final static Integer TIMESCALE = 60;
public static void main(String[] args) {
System.out.println(translateToChinese("* 0,3 6,7,18 * * ?", CRON_TIME_CN));
}
/**
*
* @param timeType (everyDay:,weekly:,day:,date:)
* @param exeTime (HH:mm 08:30)
* @param weeklyDay 1,2,3,
* @param day ,1,31 131
* @param startDate 2023-09-10
* @param endDate 2023-09-30
* @return cron
*/
public static String getCron(String timeType,String exeTime,String weeklyDay,String day,String startDate,String endDate) {
String[] time = exeTime.split(":");
Integer hour=Integer.parseInt(time[0]);//小时
Integer minute=Integer.parseInt(time[1]);//分钟
String cron=null;
//每天
if ("everyDay".equals(timeType)) {
cron = String.format("0 %s %s * * ? *",minute,hour);
} else if ("weekly".equals(timeType)) {
//每周
cron = String.format("0 %s %s ? * %s",minute,hour,weeklyDay);
} else if("day".equals(timeType)){
//单日
cron = String.format("0 %s %s %s * ? ",minute,hour,day);
} else if ("date".equals(timeType)){
//日期段
System.out.println("在"+startDate+"到"+endDate);
cron = String.format("0 %s %s * * ? *",minute,hour);
}
return cron;
}
/**
* /
* <p>
* + - =
* <p>
* Hourss使3/4,324+3-42334711151923
* <p>
* Minutes使5/20,560+5-20455202545
* <p>
* Seconds使8/10,860+8-10588101828384858
* <p>
* *
* <p>
* *Minutes使*,
* <p>
* ?DayofMonthDayofWeek
* <p>
* -Minutes使5-20520
* <p>
* ,Minutes使5,20 520
* <p>
* LDayofWeekDayofMonth
* <p>
* DayofMonth使L
* <p>
* DayofWeek
* <p>
* 使1-7L7"5"4 "7""L"
* <p>
* 使1-7L"5L" "3L"
* <p>
* #: DayofMonth
* <p>
* "4#2" 42;
* <p>
* 6#363;
* <p>
* 2#1;
* <p>
* 4#5
*
* @param cronExp
* @param cronTimeArr
* @return
*/
public static String translateToChinese(String cronExp, String[] cronTimeArr) {
if (cronExp == null || cronExp.length() < 1) {
return "cron表达式为空";
}
String[] tmpCorns = cronExp.split(" ");
StringBuffer sBuffer = new StringBuffer();
if (tmpCorns.length == 6 || tmpCorns.length == 7) {
if (tmpCorns.length == 7) {
//解析年 Year
String year = tmpCorns[6];
if ((!year.equals("*") && !year.equals("?"))) {
sBuffer.append(year).append(cronTimeArr[6]);
}
}
//解析月 Month 主要解析 /
String months = tmpCorns[4];
if (!months.equals("*") && !months.equals("?")) {
if (months.contains("/")) {
sBuffer.append("从").append(months.split("/")[0]).append("号开始").append(",每")
.append(months.split("/")[1]).append(cronTimeArr[4]);
} else {
sBuffer.append("每年").append(months).append(cronTimeArr[4]);
}
}
//解析周 DayofWeek 主要解析 , - 1~7/L 1L~7L
String dayofWeek = tmpCorns[5];
if (!dayofWeek.equals("*") && !dayofWeek.equals("?")) {
if (dayofWeek.contains(",")) {// 多个数字,逗号隔开
sBuffer.append("每周的第").append(dayofWeek).append(cronTimeArr[3]);
} else if (dayofWeek.contains("L") && dayofWeek.length() > NumberUtils.INTEGER_ONE) {// 1L-7L
String weekNum = dayofWeek.split("L")[0];
String weekName = judgeWeek(weekNum);
sBuffer.append("每月的最后一周的");
sBuffer.append(weekName);
} else if (dayofWeek.contains("-")) {
String[] splitWeek = dayofWeek.split("-");
String weekOne = judgeWeek(splitWeek[0]);
String weekTwo = judgeWeek(splitWeek[1]);
sBuffer.append("每周的").append(weekOne).append("到").append(weekTwo);
} else { // 1-7/L
if ("L".equals(dayofWeek)) { // L 转换为7便于识别
dayofWeek = "7";
}
int weekNums = Integer.parseInt(dayofWeek);
if (weekNums < 0 || weekNums > 7) {
return "cron表达式有误dayofWeek数字应为1-7";
}
sBuffer.append("每周的");
String weekName = judgeWeek(dayofWeek);
sBuffer.append(weekName);
}
}
//解析日 days -- DayofMonth 需要解析的 / # L W
// * “6#3”表示本月第三周的星期五6表示星期五3表示第三周;
// * “2#1”表示本月第一周的星期一;
// * “4#5”表示第五周的星期三。
String days = tmpCorns[3];
if (!days.equals("?") && !days.equals("*")) {
if (days.contains("/")) {
sBuffer.append("每周从第").append(days.split("/")[0]).append("天开始").append(",每")
.append(days.split("/")[1]).append(cronTimeArr[3]);
} else if ("L".equals(days)) { // 处理L 每月的最后一天
sBuffer.append("每月最后一天");
} else if ("W".equals(days)) { // 处理W 暂时不懂怎么处理
sBuffer.append(days);
} else if (days.contains("#")) {
String[] splitDays = days.split("#");
String weekNum = splitDays[0]; // 前面数字表示周几
String weekOfMonth = splitDays[1]; // 后面的数字表示第几周 范围1-4 一个月最多4周
String weekName = judgeWeek(weekNum);
sBuffer.append("每月第").append(weekOfMonth).append(cronTimeArr[5]).append(weekName);
} else {
sBuffer.append("每月第").append(days).append(cronTimeArr[3]);
}
} else {
if (sBuffer.toString().length() == 0 || tmpCorns.length == 7) { // 前面没有内容的话,拼接下
sBuffer.append("每").append(cronTimeArr[3]);
}
}
//解析时 Hours 主要解析 /
String hours = tmpCorns[2];
if (!hours.equals("*")) {
if (hours.contains("/")) {
// sBuffer.append("内,从").append(hours.split("/")[0]).append("时开始").append(",每")
// .append(hours.split("/")[1]).append(cronTimeArr[2]);
sBuffer.append(appendGapInfo(hours, HOURS, 2));
} else {
if (!(sBuffer.toString().length() > 0)) { // 对于 , 的情况,直接拼接
sBuffer.append("每天 ").append(hours).append(cronTimeArr[2]);
} else {
sBuffer.append(hours).append(cronTimeArr[2]);
}
}
}
//解析分 Minutes 主要解析 /
String minutes = tmpCorns[1];
if (!minutes.equals("*")) {
if (minutes.contains("/")) {
// sBuffer.append("内,从第").append(minutes.split("/")[0]).append("分开始").append(",每")
// .append(minutes.split("/")[1]).append(cronTimeArr[1]);
sBuffer.append(appendGapInfo(minutes, TIMESCALE, 1));
} else if (minutes.equals("0")) {
} else if (minutes.contains("-")) {
String[] splitMinute = minutes.split("-");
sBuffer.append(splitMinute[0]).append(cronTimeArr[1]).append("到").append(splitMinute[1])
.append(cronTimeArr[1]).append("每分钟");
} else {
sBuffer.append(minutes).append(cronTimeArr[1]);
}
}
//解析秒 Seconds 主要解析 /
String seconds = tmpCorns[0];
if (!seconds.equals("*")) {
if (seconds.contains("/")) {
// sBuffer.append("内,从第").append(seconds.split("/")[0]).append("秒开始").append(",每")
// .append(seconds.split("/")[0]).append(cronTimeArr[0]);
sBuffer.append(appendGapInfo(seconds, TIMESCALE, 0));
} else if (!seconds.equals("0")) {
sBuffer.append(seconds).append(cronTimeArr[0]);
}
}
if (sBuffer.toString().length() > 0) {
//sBuffer.append("执行一次");
} else {
sBuffer.append("表达式中文转换异常");
}
}
return sBuffer.toString();
}
public static String judgeWeek(String weekNum) {
String weekName = WeekEnum.matchNameCn(String.valueOf(weekNum));
int weekNums = Integer.parseInt(weekNum);
if (weekNums < 0 || weekNums > 7) {
return "cron表达式有误dayofWeek 数字应为1-7";
}
return StringUtils.isNotEmpty(weekName) ? weekName : String.valueOf(weekNum);
}
private static String appendGapInfo(String time, int rangeNum, int index) {
StringBuffer sBufferTemp = new StringBuffer();
String[] splitTime = time.split("/");
String startNum = splitTime[0];
String gapNum = splitTime[1];
int endNum = rangeNum + Integer.parseInt(startNum) - Integer.parseInt(gapNum);
String endStr = String.valueOf(endNum);
String timeUnit = CRON_TIME_CN[index];
sBufferTemp.append("从").append(startNum).append(timeUnit).append("开始")
.append("到").append(endStr).append(timeUnit).append("范围内")
.append(",每隔").append(gapNum).append(timeUnit);
return sBufferTemp.toString();
}
}

@ -0,0 +1,137 @@
package com.example.zxweb.utils;
import com.example.zxweb.common.constant.enums.WeekEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.text.DecimalFormat;
/**
* @Description Cron
* @Author ZhouWenTao
* @Date 2023/9/14 10:35
*/
public class CronLowUtil {
public static void main(String[] args) {
String timeType="everyDay";
String exeTime="08:30";
String weeklyDay="1,2,3";//周一,周二,周三
String day="1,31";
String startDate="2023-09-10";//开始时间
String endDate="2023-09-30";//结束时间
System.out.println(getCron(timeType,exeTime,weeklyDay,day,startDate,endDate));
//cron转 显示文本
System.out.println(cronToText(getCron(timeType,exeTime,weeklyDay,day,startDate,endDate)));
}
/**
*
* @param timeType (everyDay:,weekly:,day:,date:)
* @param exeTime (HH:mm 08:30)
* @param weeklyDay 1,2,3,
* @param day ,1,31 131
* @param startDate 2023-09-10
* @param endDate 2023-09-30
* @return cron
*/
public static String getCron(String timeType,String exeTime,String weeklyDay,String day,String startDate,String endDate) {
String[] time = exeTime.split(":");
Integer hour=Integer.parseInt(time[0]);//小时
Integer minute=Integer.parseInt(time[1]);//分钟
String cron=null;
//每天
if ("everyDay".equals(timeType)) {
cron = String.format("0 %s %s * * ? *",minute,hour);
} else if ("weekly".equals(timeType)) {
//每周
cron = String.format("0 %s %s ? * %s",minute,hour,weeklyDay);
} else if("day".equals(timeType)){
//单日
cron = String.format("0 %s %s %s * ? ",minute,hour,day);
} else if ("date".equals(timeType)){
//日期段
System.out.println("在"+startDate+"到"+endDate);
cron = String.format("0 %s %s * * ? *",minute,hour);
}
return cron;
}
/**
* Cron
* @param cron cron
* @return
*/
public static String cronToText(String cron){
if (StringUtils.isBlank(cron)) {
return "未知";
}
StringBuilder sb=new StringBuilder();
String[] cronSplit = cron.split(" ");
for (int i = cronSplit.length-1; i >= 0;i--) {
String c = cronSplit[i];
if (i==0) {
//秒
}else if(i==1){
//分钟
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
for (String s : split) {
sb.append(new DecimalFormat("00").format(Integer.parseInt(s))).append("");
}
}else{
sb.append("00");
}
}else if(i==2){
//小时
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
for (String s : split) {
sb.append(new DecimalFormat("00").format(Integer.parseInt(s))).append(":");
}
}
}else if(i==3){
//天
StringBuilder daySb=new StringBuilder();
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
for (String s : split) {
daySb.append(s+"日").append(",");
}
}
if (StringUtils.isNotBlank(daySb)) {
sb.append(daySb.toString().substring(0,daySb.length()-1));
}
}else if(i==4){//目前不需要做月
}else if(i==5){
//周
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
//sb.append("每周的 ");
for (String s : split) {
sb.append("周").append(NumberToCnUtil.toChineseLower(Integer.parseInt(s))).append(" ");
}
}
}
}
for (int i = 0; i < cronSplit.length; i++) {
if (i==0) {
//秒
}else if(i==1){
//分钟
}else if(i==2){
//小时
}else if(i==3){
//天
}else if(i==4){//目前不需要做月
}else if(i==5){
//周
}else if(i==6){
//年 不需要
}
}
System.out.println(sb);
return sb.toString();
}
}

@ -2,10 +2,12 @@ package com.example.zxweb.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.zxweb.common.constant.DevConstant;
import com.example.zxweb.common.constant.enums.IotApiEnum;
import com.example.zxweb.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@ -19,7 +21,7 @@ import java.util.List;
public class IotUtils {
//请求服务地址 https://10.0.10.153:2443/api/iot/v1
private static final String API_PREFIX = "https://10.0.10.153:2443/api/iot/v1";
private static String serial = DevConstant.gateway.gateway_5lqh;
private static final JSONObject headers=JSONObject.parseObject("{\"x-consumer-username\":\"dwVendor\",\"appCode\":\"42142fd0jkbf4515853b7fcec64748f6\"}");
public static List<JSONObject> devicesMethodsNews(JSONObject queryData){
@ -47,6 +49,60 @@ public class IotUtils {
return list;
}
/**
*
* @param celueId id
* @param status 1- 0-
* @return true/false
*/
public static boolean editCelueStatus(String celueId,String status){
String serial = DevConstant.gateway.gateway_5lqh;
JSONObject requestBody=JSONObject.parseObject(String.format("{\t\"serial\":\"%s\",\t\"productId\":\"\",\t\"methodName\":\"celueCmd\",\t\"inputData\":{\t\t\"devid\":\"%s\",\t\t\"celueid\":\"%s\",\t\t\"startStop\":\"%s\"\t}}",serial,serial,celueId,status));
System.out.println(requestBody.toJSONString());
try {
JSONObject jsonObject = postApi(IotApiEnum.getPathByText("向设备发送消息"), requestBody);
Integer code = jsonObject.getInteger("code");
if (code==0) {
JSONObject data = jsonObject.getJSONObject("data");
if (data!=null) {
JSONObject outputData = data.getJSONObject("outputData");
if (outputData!=null) {
String code1 = outputData.getString("code");
if (StringUtils.isNotBlank(code1) && "1".equals(code1)) {
return true;//更改成功
}
}
}
}
}catch (Exception e){
throw new BusinessException(e);
}
return false;
}
/**
*
* @param celueId id
*/
public static boolean deleteCelue(String celueId) {
String request=String.format("{\"serial\":\"%s\",\"productId\":\"\",\"methodName\":\"celueDelete\",\"inputData\":{\"devid\":\"%s\",\t\"celueid\":\"%s\"}}",serial,serial,celueId);
try {
JSONObject requestBody = JSONObject.parseObject(request);
JSONObject responseBody = postApi(IotApiEnum.getPathByText("向设备发送消息"), requestBody);
JSONObject data = responseBody.getJSONObject("data");
if (data!=null) {
JSONObject outputData = data.getJSONObject("outputData");
if (outputData != null) {
Integer code = outputData.getInteger("code");
return code == 1;
}
}
}catch (Exception e){
throw new BusinessException(e);
}
return false;
}
public static JSONObject getApi(String apiUrl,JSONObject queryData) {
StringBuilder sb=new StringBuilder();

@ -0,0 +1,283 @@
package com.example.zxweb.utils;
import java.util.Arrays;
import java.util.List;
/**
*
* +
* 4404+
* num_lower num_upper 4unit_lower unit_upper
* 2140021021
* 4亿
*
*
* @author wanglin
* @version 1.0
* @date 2022-04-08
*/
@SuppressWarnings(value = "all")
public class NumberToCnUtil {
//num 表示数字对应的中文lower表示小写upper表示大写
private static final String[] num_lower = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
private static final String[] num_upper = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
//unit 表示单位对应的中文lower表示小写upper表示大写
private static final String[] unit_lower = {"", "十", "百", "千"};
private static final String[] unit_upper = {"", "拾", "佰", "仟"};
private static final String[] unit_common = {"", "万", "亿", "兆", "京", "垓", "秭", "穰", "沟", "涧", "正", "载"};
//允许的数据类型格式
private static final List<String> promissTypes = Arrays.asList("INTEGER", "INT", "LONG", "DECIMAL", "FLOAT", "DOUBLE", "STRING", "BYTE", "TYPE", "SHORT");
/**
*
*
* @param num
* @return
*/
public static String toChineseLower(Object num) {
return format(num, num_lower, unit_lower);
}
/**
*
*
* @param num
* @return
*/
public static String toChineseUpper(Object num) {
return format(num, num_upper, unit_upper);
}
/**
*
*
* @param num
* @param numArray
* @param unit
* @return
*/
private static String format(Object num, String[] numArray, String[] unit) {
if (!promissTypes.contains(num.getClass().getSimpleName().toUpperCase())) {
throw new RuntimeException("不支持的格式类型");
}
//获取整数部分
String intnum = getInt(String.valueOf(num));
//获取小数部分
String decimal = getFraction(String.valueOf(num));
//格式化整数部分
String result = formatIntPart(intnum, numArray, unit);
if (!"".equals(decimal)) {//小数部分不为空
//格式化小数
result += "点" + formatFractionalPart(decimal, numArray);
}
return result;
}
/**
*
*
* @param num
* @param numArray
* @return
*/
private static String formatIntPart(String num, String[] numArray, String[] unit) {
//按4位分割成不同的组不足四位的前面补0
Integer[] intnums = split2IntArray(num);
boolean zero = false;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < intnums.length; i++) {
//格式化当前4位
String r = formatInt(intnums[i], numArray, unit);
if ("".equals(r)) {//
if ((i + 1) == intnums.length) {
sb.append(numArray[0]);//结果中追加“零”
} else {
zero = true;
}
} else {//当前4位格式化结果不为空即不为0
if (zero || (i > 0 && intnums[i] < 1000)) {//如果前4位为0当前4位不为0
sb.append(numArray[0]);//结果中追加“零”
}
sb.append(r);
sb.append(unit_common[intnums.length - 1 - i]);//在结果中添加权值
zero = false;
}
}
return sb.toString();
}
/**
*
*
* @param decimal
* @param numArray
* @return
*/
private static String formatFractionalPart(String decimal, String[] numArray) {
char[] val = String.valueOf(decimal).toCharArray();
StringBuilder sb = new StringBuilder();
for (char c : val) {
int n = Integer.parseInt(c + "");
sb.append(numArray[n]);
}
return sb.toString();
}
//拆分整数和小数的方法在下面-----------------
/**
*
*
* @param num
* @return
*/
private static String getInt(String num) {
//检查格式
checkNum(num);
char[] val = String.valueOf(num).toCharArray();
StringBuilder sb = new StringBuilder();
int t, s = 0;
for (char c : val) {
if (c == '.') {
break;
}
t = Integer.parseInt(c + "", 16);
if (s + t == 0) {
continue;
}
sb.append(t);
s += t;
}
return (sb.length() == 0 ? "0" : sb.toString());
}
/**
*
*
* @param num
* @return
*/
private static String getFraction(String num) {
int i = num.lastIndexOf(".");
if (num.indexOf(".") != i) {
throw new RuntimeException("数字格式不正确,最多只能有一位小数点!");
}
String fraction = "";
if (i >= 0) {
fraction = getInt(new StringBuffer(num).reverse().toString());
if ("0".equals(fraction)) {
return "";
}
}
return new StringBuffer(fraction).reverse().toString();
}
/**
*
*
* @param num
*/
private static void checkNum(String num) {
if (num.indexOf(".") != num.lastIndexOf(".")) {
throw new RuntimeException("数字[" + num + "]格式不正确!");
}
if (num.indexOf("-") != num.lastIndexOf("-") || num.lastIndexOf("-") > 0) {
throw new RuntimeException("数字[" + num + "]格式不正确!");
}
if (num.indexOf("+") != num.lastIndexOf("+")) {
throw new RuntimeException("数字[" + num + "]格式不正确!");
}
if (num.indexOf("+") != num.lastIndexOf("+")) {
throw new RuntimeException("数字[" + num + "]格式不正确!");
}
if (num.replaceAll("[\\d|\\.|\\-|\\+]", "").length() > 0) {
throw new RuntimeException("数字[" + num + "]格式不正确!");
}
}
/**
* 4
*
* @param num
* @return
*/
private static Integer[] split2IntArray(String num) {
String prev = num.substring(0, num.length() % 4);
String stuff = num.substring(num.length() % 4);
if (!"".equals(prev)) {
num = String.format("%04d", Integer.valueOf(prev)) + stuff;
}
Integer[] ints = new Integer[num.length() / 4];
int idx = 0;
for (int i = 0; i < num.length(); i += 4) {
String n = num.substring(i, i + 4);
ints[idx++] = Integer.valueOf(n);
}
return ints;
}
/**
* 4
*
* @param num
* @param numArray
* @return
*/
private static String formatInt(int num, String[] numArray, String[] unit) {
char[] val = String.valueOf(num).toCharArray();
int len = val.length;
StringBuilder sb = new StringBuilder();
boolean isZero = false;
for (int i = 0; i < len; i++) {
//获取当前位的数值
int n = Integer.parseInt(val[i] + "");
if (n == 0) {
isZero = true;
} else {
if (isZero) {
sb.append(numArray[Integer.parseInt(val[i - 1] + "")]);
}
sb.append(numArray[n]);
sb.append(unit[(len - 1) - i]);
isZero = false;
}
}
return sb.toString();
}
public static void main(String[] args) {
short s = 10;
byte b = 10;
char c = 'A';
Object[] nums = {s, b, c, 0, 1001, 100100001L, 21., 205.23F, 205.23D, "01000010", "1000000100105.0123", ".142", "20.00", "1..2", true};
System.out.println("将任意数字转化为汉字(包括整数、小数以及各种类型的数字)");
System.out.println("--------------------------------------------");
for (Object num : nums) {
try {
System.out.print("[" + num.getClass().getSimpleName() + "]" + num);
for (int i = 0; i < 25 - (num + num.getClass().getSimpleName()).length(); i += 4) {
System.out.print("\t");
}
//调用转化为小写和大写
System.out.print(" format:" + toChineseLower(num));
System.out.println("【" + toChineseUpper(num) + "】");
} catch (Exception e) {
System.out.println(" 错误信息:" + e.getMessage());
}
}
//测试:6--->>六
System.out.println("-----------------------------");
Integer a = 6;
System.out.println("6转为" + toChineseLower(a));
}
}

@ -0,0 +1,38 @@
package com.example.zxweb.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/14 9:44
*/
@ApiModel(value = "新建策略信息对象")
public class AddZxCeluePVO implements Serializable {
@ApiModelProperty(value = "选择设备id集合")
private List<String> devidList;
@ApiModelProperty(value = "策略名称")
private String name;
@ApiModelProperty(value = "执行类型(放电/断电/开灯/关灯....)")
private String type;
@ApiModelProperty(value = "时间类型(everyDay:每天,weekly:每周,day:每天,date:日期段)")
private String timeType;//时间类型(everyDay:每天,weekly:每周,day:每天,date:日期段)
@ApiModelProperty(value = "执行时间(HH:mm 例08:30)")
private String exeTime;//执行时间(HH:mm 例08:30)
@ApiModelProperty(value = "1,2,3周一,周二,周三")
private String weeklyDay;//1,2,3周一,周二,周三
@ApiModelProperty(value = "每月的第几天,1,31 每月1日31日")
private String day;//每月的第几天,1,31 每月1日31日
@ApiModelProperty(value = "范围型,开始日期 2023-09-10")
private String startDate;//范围型,开始日期 2023-09-10
@ApiModelProperty(value = "范围型,截止日期 2023-09-30")
private String endDate;//范围型,截止日期 2023-09-30
@ApiModelProperty(value = "备注")
private String description;
}

@ -11,11 +11,15 @@ import java.io.Serializable;
* @Date 2023/9/12 13:38
*/
@Data
public class QueryCelueListVO implements Serializable {
public class QueryCelueVO implements Serializable {
@ApiModelProperty(value = "设备id")
private String devid;
@ApiModelProperty(value = "策略名称")
private String name;
@ApiModelProperty(value = "策略状态")
private String status;
@ApiModelProperty(value = "页数")
private Integer pageNum=1;
private Integer page=1;
@ApiModelProperty(value = "分页大小")
private Integer pageSize=10;
private Integer limit=10;
}

@ -0,0 +1,92 @@
server:
port: 10011
knife4j:
enable: true
spring:
kafka:
#???????
topic: sourcetopic
producer:
bootstrap-servers: 10.0.10.153:29551,10.0.10.153:29552,10.0.10.153:29553,10.0.10.153:29554
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
retries: 3
properties:
retry.backoff.ms: 100 #?????????100
linger.ms: 0 #???0???????????????????batch???
max.request.size: 1048576 #??1MB??????????
connections.max.idle.ms: 540000 #??9???????????????
receive.buffer.bytes: 32768 #??32KB???socket????????????-1??????????
send.buffer.bytes: 131072 #??128KB???socket???????????-1??????????
request.timeout.ms: 10000 #??30000ms??????????????
transaction.timeout.ms: 5000
# thymeleaf 页面配置
thymeleaf:
cache: false
prefix: classpath:/templates/
encoding: UTF-8 #编码
suffix: .html #模板后缀
mode: HTML #模板
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
#数据源
datasource:
druid:
stat-view-servlet:
enabled: false
loginUsername: admin
loginPassword: 123456
allow:
web-stat-filter:
enabled: true
dynamic:
druid: # 全局druid参数绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
# 连接池的配置信息
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
filters: stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能慢SQL记录
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://47.103.213.109:3306/zx-java?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
#password: zqzxdx123@321
password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:com/example/zxweb/**/xml/*Mapper.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
#主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
id-type: ASSIGN_ID
# 默认数据库表下划线命名
table-underline: true
configuration:
# 这个配置会将执行的sql打印出来在开发或测试的时候可以用
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 返回类型为Map,显示null对应的字段
call-setters-on-nulls: true
iot:
active: false

@ -0,0 +1,91 @@
server:
port: 10011
knife4j:
enable: true
spring:
kafka:
#???????
topic: sourcetopic
producer:
bootstrap-servers: 10.0.10.153:29551,10.0.10.153:29552,10.0.10.153:29553,10.0.10.153:29554
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
retries: 3
properties:
retry.backoff.ms: 100 #?????????100
linger.ms: 0 #???0???????????????????batch???
max.request.size: 1048576 #??1MB??????????
connections.max.idle.ms: 540000 #??9???????????????
receive.buffer.bytes: 32768 #??32KB???socket????????????-1??????????
send.buffer.bytes: 131072 #??128KB???socket???????????-1??????????
request.timeout.ms: 10000 #??30000ms??????????????
transaction.timeout.ms: 5000
# thymeleaf 页面配置
thymeleaf:
cache: false
prefix: classpath:/templates/
encoding: UTF-8 #编码
suffix: .html #模板后缀
mode: HTML #模板
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
#数据源
datasource:
druid:
stat-view-servlet:
enabled: false
loginUsername: admin
loginPassword: 123456
allow:
web-stat-filter:
enabled: true
dynamic:
druid: # 全局druid参数绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
# 连接池的配置信息
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
filters: stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能慢SQL记录
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://47.103.213.109:3306/zx-java?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
#password: zqzxdx123@321
password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:com/example/zxweb/**/xml/*Mapper.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
#主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
id-type: ASSIGN_ID
# 默认数据库表下划线命名
table-underline: true
configuration:
# 这个配置会将执行的sql打印出来在开发或测试的时候可以用
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 返回类型为Map,显示null对应的字段
call-setters-on-nulls: true
iot:
active: true

@ -1,92 +1,6 @@
server:
port: 10011
knife4j:
enable: true
spring:
kafka:
#???????
topic: sourcetopic
producer:
bootstrap-servers: 10.0.10.153:29551,10.0.10.153:29552,10.0.10.153:29553,10.0.10.153:29554
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
retries: 3
properties:
retry.backoff.ms: 100 #?????????100
linger.ms: 0 #???0???????????????????batch???
max.request.size: 1048576 #??1MB??????????
connections.max.idle.ms: 540000 #??9???????????????
receive.buffer.bytes: 32768 #??32KB???socket????????????-1??????????
send.buffer.bytes: 131072 #??128KB???socket???????????-1??????????
request.timeout.ms: 10000 #??30000ms??????????????
transaction.timeout.ms: 5000
# thymeleaf 页面配置
thymeleaf:
cache: false
prefix: classpath:/templates/
encoding: UTF-8 #编码
suffix: .html #模板后缀
mode: HTML #模板
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
#数据源
datasource:
druid:
stat-view-servlet:
enabled: false
loginUsername: admin
loginPassword: 123456
allow:
web-stat-filter:
enabled: true
dynamic:
druid: # 全局druid参数绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
# 连接池的配置信息
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
filters: stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能慢SQL记录
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://47.103.213.109:3306/zx-java?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
#password: zqzxdx123@321
password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:com/example/zxweb/**/xml/*Mapper.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
#主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
id-type: ASSIGN_ID
# 默认数据库表下划线命名
table-underline: true
configuration:
# 这个配置会将执行的sql打印出来在开发或测试的时候可以用
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 返回类型为Map,显示null对应的字段
call-setters-on-nulls: true
profiles:
active: dev
key: dwVendor
secret: fEVcb^QFB;IN$K5

@ -129,7 +129,7 @@
style="width: 46px;height: 26px;padding: 1px;background-color: #3cb754;color: white">
查看
</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit"
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-on="delete-confirm" id="{{=d.celueid}}"
style="width: 46px;height: 26px;padding: 1px;border: #f52f64 solid 1px;color: #f52f64">
删除
</a>
@ -148,6 +148,7 @@ function loadTable(){
layui.use('table', function () {
var table = layui.table;
var $=layui.$;
var util = layui.util;
form = layui.form;
name=$("#name").val();
status = $("#status").val();
@ -197,6 +198,37 @@ function loadTable(){
//,limit: 5 // 每页默认显示的数量
});
// 事件
var util = layui.util;
// 事件
util.on('lay-on', {
"delete-confirm": function(){
var id = this.id;
console.log(id)
layer.confirm('确定删除吗?', {icon: 3}, function(){
$.ajax({
type: "DELETE",
url: "/celue/delete?id="+id,
/*data: obj,
contentType: 'application/json;charset=utf-8',*/
success: function(res){
console.log(res)
if(res.success){
layer.msg('删除成功', {icon: 1});
loadTable();
}else{
layer.msg('删除失败,'+res.message, {icon: 1});
}
},error:function (res){
layer.msg('删除失败,'+res.message, {icon: 1});
}
});
}, function(){
//layer.msg('点击取消的回调');
});
},
})
form.on('switch(demo-templet-status)', function(obj){
var id = this.id;
var obj = JSON.stringify({'celueid':id});

Loading…
Cancel
Save