diff --git a/pom.xml b/pom.xml index 08bacc9..f07c4b4 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,15 @@ + + + src/main/java + + **/*.xml + + false + + org.springframework.boot diff --git a/src/main/java/com/example/zxweb/common/constant/enums/WeekEnum.java b/src/main/java/com/example/zxweb/common/constant/enums/WeekEnum.java new file mode 100644 index 0000000..c9a64bb --- /dev/null +++ b/src/main/java/com/example/zxweb/common/constant/enums/WeekEnum.java @@ -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; + + } + +} diff --git a/src/main/java/com/example/zxweb/controller/CelueController.java b/src/main/java/com/example/zxweb/controller/CelueController.java index 9ba8aca..b3fcb0c 100644 --- a/src/main/java/com/example/zxweb/controller/CelueController.java +++ b/src/main/java/com/example/zxweb/controller/CelueController.java @@ -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 queryWrapper=new LambdaQueryWrapper<>(); - if (StringUtils.isNotBlank(name)) { - queryWrapper.like(ZxCelue::getName,name); - } - if (StringUtils.isNotBlank(status)) { - queryWrapper.eq(ZxCelue::getStatus,status); - } - Page pageList = zxCelueService.page(new Page<>(page, limit),queryWrapper); - return Result.OK(pageList); + public Result list(QueryCelueVO queryCelueVO){ + IPage 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 Resultadd(@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 Resultstatus(@RequestBody ZxCelue zxCelue){ - ZxCelue celue = zxCelueService.getById(zxCelue.getCelueid()); - LambdaUpdateWrapper 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"); + public Result status(@RequestBody ZxCelue zxCelue){ + 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("操作成功"); } } diff --git a/src/main/java/com/example/zxweb/controller/GatewayController.java b/src/main/java/com/example/zxweb/controller/GatewayController.java index 2255207..747f39d 100644 --- a/src/main/java/com/example/zxweb/controller/GatewayController.java +++ b/src/main/java/com/example/zxweb/controller/GatewayController.java @@ -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 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); diff --git a/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java b/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java new file mode 100644 index 0000000..17c63dd --- /dev/null +++ b/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java @@ -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 devidList; +} diff --git a/src/main/java/com/example/zxweb/mapper/ZxCelueMapper.java b/src/main/java/com/example/zxweb/mapper/ZxCelueMapper.java index 1d0dd19..f184740 100644 --- a/src/main/java/com/example/zxweb/mapper/ZxCelueMapper.java +++ b/src/main/java/com/example/zxweb/mapper/ZxCelueMapper.java @@ -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 { + IPage pageList(@Param("page") Page page,@Param("qvo") QueryCelueVO queryCelueVO); } diff --git a/src/main/java/com/example/zxweb/mapper/xml/ZxCelueMapper.xml b/src/main/java/com/example/zxweb/mapper/xml/ZxCelueMapper.xml index f5c77bd..70758a4 100644 --- a/src/main/java/com/example/zxweb/mapper/xml/ZxCelueMapper.xml +++ b/src/main/java/com/example/zxweb/mapper/xml/ZxCelueMapper.xml @@ -1,4 +1,20 @@ + + \ No newline at end of file diff --git a/src/main/java/com/example/zxweb/service/IZxCelueService.java b/src/main/java/com/example/zxweb/service/IZxCelueService.java index 8193496..532cf68 100644 --- a/src/main/java/com/example/zxweb/service/IZxCelueService.java +++ b/src/main/java/com/example/zxweb/service/IZxCelueService.java @@ -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 { + /** + * 创建策略 + */ + boolean saveZxCelue(AddZxCeluePVO addZxCeluePVO); + + /** + * 编辑策略状态 + */ + boolean editStatus(ZxCelue zxCelue); + + /** + * 删除策略 + */ + boolean deleteZxCelue(String id); + + /** + * 查询列表 + * @param queryCelueVO 查询对象 + * @return 列表 + */ + IPage pageList(QueryCelueVO queryCelueVO); + + ZxCelueDTO getDetail(String id); } diff --git a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java index 626a365..58b47ef 100644 --- a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java +++ b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java @@ -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 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 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 pageList(QueryCelueVO queryCelueVO) { + Integer page = queryCelueVO.getPage(); + Integer limit = queryCelueVO.getLimit(); + String name = queryCelueVO.getName(); + String status = queryCelueVO.getStatus(); + IPage pageList = baseMapper.pageList(new Page<>(page, limit),queryCelueVO); + for (ZxCelueDTO record : pageList.getRecords()) { + if (StringUtils.isNotBlank(record.getDevid())) { + List 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 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); + } } diff --git a/src/main/java/com/example/zxweb/utils/CronExpParserUtil.java b/src/main/java/com/example/zxweb/utils/CronExpParserUtil.java new file mode 100644 index 0000000..0ffd2dd --- /dev/null +++ b/src/main/java/com/example/zxweb/utils/CronExpParserUtil.java @@ -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 每月1日,31日 + * @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; + } + + /** + * 主要解析 斜杆 /:表示起始时间开始触发,然后每隔固定时间触发一次。 + *

+ * 范围值+开始值 - 间隔值 = 范围内最后执行的值; + *

+ * 例如在Hourss域使用3/4,则意味着从第3小时到24+3-4:23小时范围内,第3小时开始触发第一次,然后每隔4小时,即7,11,15,19,23小时等分别触发一次。 + *

+ * 例如在Minutes域使用5/20,则意味着从第5分钟到60+5-20:45分范围内,第5分钟开始触发第一次,然后每隔20分钟,即25,45分钟等分别触发一次。 + *

+ * 例如在Seconds域使用8/10,则意味着从第8秒到60+8-10:58秒范围内,第8秒开始触发第一次,然后每隔10秒,即18,28,38,48,58秒等分别触发一次。 + *

+ * * + *

+ * 对于 *:表示匹配该域的任意值。例如在Minutes域使用*, 即表示每分钟都会触发事件。 + *

+ * 对于问号 ?:只能用在DayofMonth和DayofWeek两个域,其作用为不指定 + *

+ * 对于 -:表示范围。例如在Minutes域使用5-20,表示从5分到20分钟每分钟触发一次。直接进行拼接 + *

+ * 对于逗号 ,:表示列出枚举值。例如在Minutes域使用5,20 , 则意味着在5和20分每分钟触发一次。 + *

+ * 对于L:表示最后,只能出现在DayofWeek和DayofMonth域。 + *

+ * 如果出现在DayofMonth域,只能使用L,表示当月最后一天 + *

+ * 如果在DayofWeek域 + *

+ * 使用数字(1-7)或L(和7的作用一样表示每周的最后一天周六),比如数字"5"表示每周4, "7"或"L"表示每周六 + *

+ * 使用数字(1-7)结合L,表示当月最后一周的周几,比如"5L" 表示在最后的一周的周四; "3L" 表示最后一周的周二 + *

+ * 对于#: 用于确定每个月第几个星期几,只能出现在DayofMonth域。 + *

+ * 例如 "4#2" 表示某月的第二个星期三(4表示星期三,2表示第二周); + *

+ * “6#3”表示本月第三周的星期五(6表示星期五,3表示第三周); + *

+ * “2#1”表示本月第一周的星期一; + *

+ * “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(); + + + } +} diff --git a/src/main/java/com/example/zxweb/utils/CronLowUtil.java b/src/main/java/com/example/zxweb/utils/CronLowUtil.java new file mode 100644 index 0000000..e6a6d4a --- /dev/null +++ b/src/main/java/com/example/zxweb/utils/CronLowUtil.java @@ -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 每月1日,31日 + * @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(); + } + +} diff --git a/src/main/java/com/example/zxweb/utils/IotUtils.java b/src/main/java/com/example/zxweb/utils/IotUtils.java index 8854964..9a28827 100644 --- a/src/main/java/com/example/zxweb/utils/IotUtils.java +++ b/src/main/java/com/example/zxweb/utils/IotUtils.java @@ -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 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(); diff --git a/src/main/java/com/example/zxweb/utils/NumberToCnUtil.java b/src/main/java/com/example/zxweb/utils/NumberToCnUtil.java new file mode 100644 index 0000000..175c69f --- /dev/null +++ b/src/main/java/com/example/zxweb/utils/NumberToCnUtil.java @@ -0,0 +1,283 @@ +package com.example.zxweb.utils; + +import java.util.Arrays; +import java.util.List; + +/** + * 数字转汉字的原理: + * 拆分:由于整数部分要加权值,而小数部分直接转换即可,所以首先要将数字拆分成整数+小数; + * 整数处理:按照我们的中国人的习惯,把数字格式化成4位一组,不足4位前面补0。每次处理4位,按位匹配数组中的汉字+单位。 + * 即按照数值找数字数组(num_lower 、num_upper )中对应位置的汉字,按照在4位中的偏移量在单位数组(unit_lower 、unit_upper )中的汉字。 + * 比如21,转化4位为0021,前面的0不用管,2对应数字“二”,单位是“十”,1对应数字“一”,单位是“(个)”用空字符串代替。即得到“二十一”。 + * 每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 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)); + } +} + + diff --git a/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java b/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java new file mode 100644 index 0000000..1d260c4 --- /dev/null +++ b/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java @@ -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 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; +} diff --git a/src/main/java/com/example/zxweb/vo/QueryCelueListVO.java b/src/main/java/com/example/zxweb/vo/QueryCelueVO.java similarity index 58% rename from src/main/java/com/example/zxweb/vo/QueryCelueListVO.java rename to src/main/java/com/example/zxweb/vo/QueryCelueVO.java index 62f5dbb..29f2cd0 100644 --- a/src/main/java/com/example/zxweb/vo/QueryCelueListVO.java +++ b/src/main/java/com/example/zxweb/vo/QueryCelueVO.java @@ -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; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..57bc1ae --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -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 \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000..bf25b6d --- /dev/null +++ b/src/main/resources/application-test.yml @@ -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 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 12dcc16..de35bab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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 diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 0da27b5..2a4a23e 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -129,7 +129,7 @@ style="width: 46px;height: 26px;padding: 1px;background-color: #3cb754;color: white"> 查看 - 删除 @@ -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});