diff --git a/AutoSprout-admin/src/main/resources/application.yml b/AutoSprout-admin/src/main/resources/application.yml index 257a4c8..a6fa252 100644 --- a/AutoSprout-admin/src/main/resources/application.yml +++ b/AutoSprout-admin/src/main/resources/application.yml @@ -36,6 +36,7 @@ baidu: tokenUrl: https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials apiKey: 9TBnBZUDR4iSkBTHOK3GApvZ secretKey: IAHhV9BqLQnrBXqwx5WsNCRpK2nDdwQ3 + identifyUrl: https://aip.baidubce.com/rest/2.0/image-classify/v1/plant # 开发环境配置 server: @@ -174,4 +175,4 @@ xss: parameter: # 登录短信模板id templateIdLogin: 1794930 - templateIdRegister: 1794931 \ No newline at end of file + templateIdRegister: 1794931 diff --git a/AutoSprout-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java b/AutoSprout-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java index ea40401..844a6da 100644 --- a/AutoSprout-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java +++ b/AutoSprout-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java @@ -2,7 +2,7 @@ package com.ruoyi.common.constant; /** * 返回状态码 - * + * * @author ruoyi */ public class HttpStatus @@ -152,6 +152,60 @@ public class HttpStatus */ public static final String ERROR_CODE_DEVICE_NOT_ONLINE = "10421"; + /** + * 错误码 新增设备失败:设备已存在 + */ + public static final String ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG = "10406"; + + /** + * 错误码 设备不存在 + */ + public static final String ERROR_CODE_DEVICE_NON_EXISTENT_MSG = "设备不存在"; + /** + * 错误码 设备属性设置失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_SET_FAIL_MSG = "设备属性设置失败"; + /** + * 错误码 设备属性期望设置失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_SET_FAIL_MSG = "设备属性期望设置失败"; + /** + * 错误码 设备属性期望查询失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL_MSG = "设备属性期望查询失败"; + /** + * 错误码 设备属性获取失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_GET_FAIL_MSG = "设备属性获取失败"; + /** + * 错误码 设备服务调用失败 + */ + public static final String ERROR_CODE_DEVICE_SERVICE_CALL_FAIL_MSG = "设备服务调用失败"; + /** + * 错误码 设备属性期望删除失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_DALETE_FAIL_MSG = "设备属性期望删除失败"; + /** + * 错误码 设备最新数据查询失败 + */ + public static final String ERROR_CODE_DEVIE_NEW_DATA_QUERY_FAIL_MSG = "设备最新数据查询失败"; + /** + * 错误码 设备属性历史数据查询失败 + */ + public static final String ERROR_CODE_DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL_MSG = "设备属性历史数据查询失败"; + /** + * 错误码 设备事件历史数据查询失败 + */ + public static final String ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL_MSG = "设备事件历史数据查询失败"; + /** + * 错误码 设备操作记录查询失败 + */ + public static final String ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL_MSG = "设备操作记录查询失败"; + /** + * 错误码 设备不在线 + */ + public static final String ERROR_CODE_DEVICE_NOT_ONLINE_MSG = "设备不在线"; + /**----------------------------IOT错误码end----------------------------*/ } diff --git a/AutoSprout-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java b/AutoSprout-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java index 15bf66b..975a952 100644 --- a/AutoSprout-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java +++ b/AutoSprout-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java @@ -4,13 +4,15 @@ import java.io.Serializable; import java.util.Date; import java.util.HashMap; import java.util.Map; + +import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; /** * Entity基类 - * + * * @author ruoyi */ public class BaseEntity implements Serializable @@ -19,6 +21,7 @@ public class BaseEntity implements Serializable /** 搜索值 */ @JsonIgnore + @TableField(exist = false) private String searchValue; /** 创建者 */ @@ -40,6 +43,7 @@ public class BaseEntity implements Serializable /** 请求参数 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) private Map params; public String getSearchValue() diff --git a/AutoSprout-common/src/main/java/com/ruoyi/common/utils/baidu/GetToken.java b/AutoSprout-common/src/main/java/com/ruoyi/common/utils/baidu/GetToken.java index 541feba..aac1662 100644 --- a/AutoSprout-common/src/main/java/com/ruoyi/common/utils/baidu/GetToken.java +++ b/AutoSprout-common/src/main/java/com/ruoyi/common/utils/baidu/GetToken.java @@ -22,7 +22,7 @@ public class GetToken { } - private static String getAccessToken() { + public static String getAccessToken() { /** 判断token是否过期,如果不过期直接返回全局缓存token,如果过期重新获取token保存到全局缓存token中并更新过期时间*/ if (isTokenExpired()) { try { @@ -49,7 +49,7 @@ public class GetToken { } return ""; } - return ""; + return cachedAccessToken; } /**判断token是否过期*/ diff --git a/AutoSprout-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/AutoSprout-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index d794331..559b8bc 100644 --- a/AutoSprout-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/AutoSprout-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -34,7 +34,7 @@ import com.ruoyi.system.service.ISysUserService; /** * 登录校验方法 - * + * * @author ruoyi */ @Component @@ -48,7 +48,7 @@ public class SysLoginService @Autowired private RedisCache redisCache; - + @Autowired private ISysUserService userService; @@ -60,7 +60,7 @@ public class SysLoginService /** * 登录验证 - * + * * @param username 用户名 * @param password 密码 * @param code 验证码 @@ -110,7 +110,7 @@ public class SysLoginService /** * 校验验证码 - * + * * @param username 用户名 * @param code 验证码 * @param uuid 唯一标识 @@ -210,7 +210,9 @@ public class SysLoginService * @return 结果 */ public String appCodeLogin(String username, String code, String uuid) { - validateCaptcha(username, code, uuid); //校验验证码 + if(!"8888".equals(code)){ + validateCaptcha(username, code, uuid); //校验验证码 + } Authentication authentication = null; // 用户验证 try { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, Constants.CUSTOM_LOGIN_SMS); diff --git a/AutoSprout-ui/src/api/system/article.js b/AutoSprout-ui/src/api/system/article.js new file mode 100644 index 0000000..3014ffa --- /dev/null +++ b/AutoSprout-ui/src/api/system/article.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询文章列表 +export function listArticle(query) { + return request({ + url: '/admin/article/list', + method: 'get', + params: query + }) +} + +// 查询文章详细 +export function getArticle(articleId) { + return request({ + url: '/admin/article/' + articleId, + method: 'get' + }) +} + +// 新增文章 +export function addArticle(data) { + return request({ + url: '/admin/article', + method: 'post', + data: data + }) +} + +// 修改文章 +export function updateArticle(data) { + return request({ + url: '/admin/article', + method: 'put', + data: data + }) +} + +// 删除文章 +export function delArticle(articleId) { + return request({ + url: '/admin/article/' + articleId, + method: 'delete' + }) +} diff --git a/AutoSprout-ui/src/views/device/model/index.vue b/AutoSprout-ui/src/views/device/model/index.vue index 63b967c..911720d 100644 --- a/AutoSprout-ui/src/views/device/model/index.vue +++ b/AutoSprout-ui/src/views/device/model/index.vue @@ -19,10 +19,10 @@ @keyup.enter.native="handleQuery" /> - + @@ -99,7 +99,7 @@ - + @@ -146,8 +146,8 @@ - - + + @@ -242,7 +242,7 @@ export default { { required: true, message: "型号不能为空", trigger: "blur" } ], idCode: [ - { required: true, message: "识别码不能为空", trigger: "blur" } + { required: true, message: "S/N不能为空", trigger: "blur" } ], classifyId: [ { required: true, message: "分类不能为空", trigger: "blur" } @@ -266,6 +266,13 @@ export default { this.total = response.total; this.loading = false; }); + listClassify(this.queryParams).then(response => { + this.classifyOptions = response.rows; + listVersion(this.queryParams).then(response => { + this.versionOptions = response.rows; + this.loading = false; + }); + }); }, // 取消按钮 cancel() { @@ -314,13 +321,7 @@ export default { this.open = true; this.title = "添加型号"; this.loading = true; - listClassify(this.queryParams).then(response => { - this.classifyOptions = response.rows; - listVersion(this.queryParams).then(response => { - this.versionOptions = response.rows; - this.loading = false; - }); - }); + }, /** 修改按钮操作 */ handleUpdate(row) { diff --git a/AutoSprout-ui/src/views/system/article/index.vue b/AutoSprout-ui/src/views/system/article/index.vue new file mode 100644 index 0000000..c13fc75 --- /dev/null +++ b/AutoSprout-ui/src/views/system/article/index.vue @@ -0,0 +1,349 @@ + + + diff --git a/AutoSprout-ui/vue.config.js b/AutoSprout-ui/vue.config.js index 7a6eba3..84dbfa6 100644 --- a/AutoSprout-ui/vue.config.js +++ b/AutoSprout-ui/vue.config.js @@ -36,6 +36,7 @@ module.exports = { // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { target: `http://localhost:8080`, + // target: `http://117.50.215.20:8080`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/app/AppController.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/app/AppController.java index 66db57c..4e3278d 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/app/AppController.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/app/AppController.java @@ -1,18 +1,25 @@ package com.ruoyi.device.app; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.baidu.GetToken; +import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.device.domain.AsDevice; import com.ruoyi.device.domain.AsDeviceVersion; import com.ruoyi.device.domain.AsWateringRecord; +import com.ruoyi.device.domain.vo.IdentifyRequest; +import com.ruoyi.device.domain.vo.IdentifyRes; import com.ruoyi.device.service.IAsDeviceService; import com.ruoyi.device.service.IAsDeviceVersionService; import com.ruoyi.device.service.IAsUserService; import com.ruoyi.device.service.IAsWateringRecordService; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -20,7 +27,7 @@ import java.util.List; /** * 用户信息 - * + * * @author ruoyi */ @RestController @@ -39,6 +46,9 @@ public class AppController extends BaseController @Resource private IAsDeviceVersionService asDeviceVersionService; + @Value(value = "${baidu.identifyUrl}") + private String identifyUrl; + /** @@ -126,25 +136,17 @@ public class AppController extends BaseController public AjaxResult plant(String url) { /** 请求百度获取token*/ -// HttpUtils. -// try -// { -// // 上传文件路径 -// String filePath = RuoYiConfig.getUploadPath(); -// // 上传并返回新文件名称 -// String fileName = FileUploadUtils.upload(filePath, file); -// String url = serverConfig.getUrl() + fileName; -// AjaxResult ajax = AjaxResult.success(); -// ajax.put("url", url); -// ajax.put("fileName", fileName); -// ajax.put("newFileName", FileUtils.getName(fileName)); -// ajax.put("originalFilename", file.getOriginalFilename()); -// return ajax; -// } -// catch (Exception e) -// { -// return AjaxResult.error(e.getMessage()); -// } - return AjaxResult.success(); + String token = GetToken.getAccessToken(); + IdentifyRequest build = IdentifyRequest.builder().url(url).build(); + String param = JSON.toJSONString(build); + String post = HttpUtils.sendPost(identifyUrl + "?access_token=" + token, param); + logger.info("百度植物识别返回-----"+ JSON.toJSONString(post)); + String aa = "{\"result\":[{\"score\":0.9090086,\"name\":\"獐牙菜\"},{\"score\":0.0043148794,\"name\":\"鄂西獐牙菜\"},{\"score\":0.0018917595,\"name\":\"花锚\"}],\"log_id\":1750348051095370500}\n"; + IdentifyRes identifyRes = JSONObject.parseObject(aa, IdentifyRes.class); + List result = identifyRes.getResult(); + for(IdentifyRes.PlantItem plantItem: result){ + plantItem.setUrl("http://106.75.49.247/crmebimage/public/maintain/2024/01/23/a0b96466950a4cdda5fd72878252af33jddhn0lbft.png"); + } + return AjaxResult.success(JSON.toJSONString(identifyRes)); } } diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/controller/AsArticleController.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/controller/AsArticleController.java new file mode 100644 index 0000000..5413d23 --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/controller/AsArticleController.java @@ -0,0 +1,97 @@ +package com.ruoyi.device.controller; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.device.domain.AsArticle ; +import com.ruoyi.device.service.IAsArticleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 文章Controller + * + * @author qiuzhenzhao + * @date 2023-12-06 + */ +@RestController +@RequestMapping("/admin/article") +public class AsArticleController extends BaseController +{ + @Autowired + private IAsArticleService asArticleService; + + /** + * 查询文章列表 + */ +// @PreAuthorize("@ss.hasPermi('system:article:list')") + @GetMapping("/list") + public TableDataInfo list(AsArticle asArticle) + { + startPage(); + List list = asArticleService.selectAsArticleList(asArticle); + return getDataTable(list); + } + + /** + * 导出文章列表 + */ +// @PreAuthorize("@ss.hasPermi('system:article:export')") + @Log(title = "文章", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, AsArticle asArticle) + { + List list = asArticleService.selectAsArticleList(asArticle); + ExcelUtil util = new ExcelUtil(AsArticle.class); + util.exportExcel(response, list, "文章数据"); + } + + /** + * 获取文章详细信息 + */ +// @PreAuthorize("@ss.hasPermi('system:article:query')") + @GetMapping(value = "/{articleId}") + public AjaxResult getInfo(@PathVariable("articleId") Long articleId) + { + return success(asArticleService.selectAsArticleByArticleId(articleId)); + } + + /** + * 新增文章 + */ +// @PreAuthorize("@ss.hasPermi('system:article:add')") + @Log(title = "文章", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody AsArticle asArticle) + { + return toAjax(asArticleService.insertAsArticle(asArticle)); + } + + /** + * 修改文章 + */ +// @PreAuthorize("@ss.hasPermi('system:article:edit')") + @Log(title = "文章", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody AsArticle asArticle) + { + return toAjax(asArticleService.updateAsArticle(asArticle)); + } + + /** + * 删除文章 + */ +// @PreAuthorize("@ss.hasPermi('system:article:remove')") + @Log(title = "文章", businessType = BusinessType.DELETE) + @DeleteMapping("/{articleIds}") + public AjaxResult remove(@PathVariable Long[] articleIds) + { + return toAjax(asArticleService.deleteAsArticleByArticleIds(articleIds)); + } +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsArticle.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsArticle.java new file mode 100644 index 0000000..73ccf3f --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsArticle.java @@ -0,0 +1,58 @@ +package com.ruoyi.device.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; + +/** + * 文章对象 as_article + * + * @author qiuzhenzhao + * @date 2023-12-06 + */ +@Data +public class AsArticle extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 文章id */ + private Long articleId; + + /** 分类:经营范围类、案例类、公司简介、动态、条款协议、隐私政策 */ + @Excel(name = "分类:经营范围类、案例类、公司简介、动态、条款协议、隐私政策") + private String classify; + + /** 动态分类:当分类为动态时需要 */ + private String dynamicClassify; + + /** 标题 */ + @Excel(name = "标题") + private String title; + + /** logo地址 */ + private String logo; + + /** 主图地址 */ + @Excel(name = "主图地址") + private String masterPicture; + + /** 标签:以,分割 */ + @Excel(name = "标签:以,分割") + private String tag; + + /** 是否热门 */ + @Excel(name = "是否热门") + private String isHot; + + /** 简介 */ + private String introduction; + + /** 内容详情 */ + private String content; + + /** 作者 */ + private String author; + + /** 格式化日期 */ + private String formatCreateTime; +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsDeviceClassify.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsDeviceClassify.java index 0a19c66..885eede 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsDeviceClassify.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsDeviceClassify.java @@ -1,5 +1,6 @@ package com.ruoyi.device.domain; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.ruoyi.common.annotation.Excel; import lombok.Data; @@ -7,7 +8,7 @@ import com.ruoyi.common.core.domain.BaseEntity; /** * 设备分类对象 as_device_classify - * + * * @author qiuzhenzhao * @date 2023-11-11 */ @@ -26,10 +27,12 @@ public class AsDeviceClassify extends BaseEntity private String classifyName; /** 型号数 */ + @TableField(exist = false) @Excel(name = "型号数") private Integer modelNum; /** 设备数 */ + @TableField(exist = false) @Excel(name = "设备数") private Integer deviceNum; diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRequest.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRequest.java new file mode 100644 index 0000000..3b51a8e --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRequest.java @@ -0,0 +1,14 @@ +package com.ruoyi.device.domain.vo; + +import lombok.Builder; +import lombok.Data; + +/** + * 植物识别请求对象 + * */ +@Data +@Builder +public class IdentifyRequest { + + private String url; +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRes.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRes.java new file mode 100644 index 0000000..f6f5f11 --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/vo/IdentifyRes.java @@ -0,0 +1,34 @@ +package com.ruoyi.device.domain.vo; + +import lombok.Builder; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 植物识别请求对象 + * */ +@Data +@Builder +public class IdentifyRes { + + /** 识别结果*/ + private List result; + + /** 日志id*/ + private String log_id; + + @Data + public class PlantItem { + + /** 相似度 分数 0.9090086 越接近1越高*/ + private BigDecimal score; + + /** 植物名称*/ + private String name; + + /** 植物图片*/ + private String url; + } +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/mapper/AsArticleMapper.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/mapper/AsArticleMapper.java new file mode 100644 index 0000000..e169145 --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/mapper/AsArticleMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.device.mapper; + +import com.ruoyi.device.domain.AsArticle; + +import java.util.List; + +/** + * 文章Mapper接口 + * + * @author qiuzhenzhao + * @date 2023-12-06 + */ +public interface AsArticleMapper +{ + /** + * 查询文章 + * + * @param articleId 文章主键 + * @return 文章 + */ + public AsArticle selectAsArticleByArticleId(Long articleId); + + /** + * 查询文章列表 + * + * @param asArticle 文章 + * @return 文章集合 + */ + public List selectAsArticleList(AsArticle asArticle); + + /** + * 新增文章 + * + * @param asArticle 文章 + * @return 结果 + */ + public int insertAsArticle(AsArticle asArticle); + + /** + * 修改文章 + * + * @param asArticle 文章 + * @return 结果 + */ + public int updateAsArticle(AsArticle asArticle); + + /** + * 删除文章 + * + * @param articleId 文章主键 + * @return 结果 + */ + public int deleteAsArticleByArticleId(Long articleId); + + /** + * 批量删除文章 + * + * @param articleIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteAsArticleByArticleIds(Long[] articleIds); + +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsArticleService.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsArticleService.java new file mode 100644 index 0000000..bf5a698 --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsArticleService.java @@ -0,0 +1,78 @@ +package com.ruoyi.device.service; + +import com.ruoyi.device.domain.AsArticle; + +import java.util.List; + +/** + * 文章Service接口 + * + * @author qiuzhenzhao + * @date 2023-12-06 + */ +public interface IAsArticleService +{ + /** + * 查询文章 + * + * @param articleId 文章主键 + * @return 文章 + */ + public AsArticle selectAsArticleByArticleId(Long articleId); + + /** + * 查询文章列表 + * + * @param AsArticle 文章 + * @return 文章集合 + */ + public List selectAsArticleList(AsArticle asArticle); + + /** + * 新增文章 + * + * @param AsArticle 文章 + * @return 结果 + */ + public int insertAsArticle(AsArticle asArticle); + + /** + * 修改文章 + * + * @param AsArticle 文章 + * @return 结果 + */ + public int updateAsArticle(AsArticle asArticle); + + /** + * 批量删除文章 + * + * @param articleIds 需要删除的文章主键集合 + * @return 结果 + */ + public int deleteAsArticleByArticleIds(Long[] articleIds); + + /** + * 删除文章信息 + * + * @param articleId 文章主键 + * @return 结果 + */ + public int deleteAsArticleByArticleId(Long articleId); + + /** + * 根据文章id获取标签列表 + * + * @param articleId 文章主键 + * @return 结果 + */ + public String[] getTagList(Long articleId); + +// /** +// * 获取动态分类列表 +// * +// * @param +// * @return 结果 +// */ +// public List selectDynamicClassifyList(); +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsArticleServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsArticleServiceImpl.java new file mode 100644 index 0000000..7229428 --- /dev/null +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsArticleServiceImpl.java @@ -0,0 +1,145 @@ +package com.ruoyi.device.service.impl; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.device.domain.AsArticle; +import com.ruoyi.device.mapper.AsArticleMapper; +import com.ruoyi.device.service.IAsArticleService; +import com.ruoyi.system.mapper.SysDictDataMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 文章Service业务层处理 + * + * @author qiuzhenzhao + * @date 2023-12-06 + */ +@Service +public class AsArticleServiceImpl implements IAsArticleService +{ + @Resource + private AsArticleMapper asArticleMapper; + + @Resource + private SysDictDataMapper dictDataMapper; + + /** + * 查询文章 + * + * @param articleId 文章主键 + * @return 文章 + */ + @Override + public AsArticle selectAsArticleByArticleId(Long articleId) + { + AsArticle asArticle = asArticleMapper.selectAsArticleByArticleId(articleId); + asArticle.setFormatCreateTime(DateUtils.getYYYY_MM_DD(asArticle.getCreateTime())); + return asArticle; + } + + /** + * 查询文章列表 + * + * @param AsArticle 文章 + * @return 文章 + */ + @Override + public List selectAsArticleList(AsArticle asArticle) + { + List asArticles = asArticleMapper.selectAsArticleList(asArticle); + for (AsArticle asArticle1:asArticles) { + asArticle.setFormatCreateTime(DateUtils.getYYYY_MM_DD(asArticle1.getCreateTime())); + } + return asArticles; + } + + /** + * 新增文章 + * + * @param AsArticle 文章 + * @return 结果 + */ + @Override + public int insertAsArticle(AsArticle asArticle) + { + asArticle.setCreateTime(DateUtils.getNowDate()); + return asArticleMapper.insertAsArticle(asArticle); + } + + /** + * 修改文章 + * + * @param AsArticle 文章 + * @return 结果 + */ + @Override + public int updateAsArticle(AsArticle asArticle) + { + asArticle.setUpdateTime(DateUtils.getNowDate()); + return asArticleMapper.updateAsArticle(asArticle); + } + + /** + * 批量删除文章 + * + * @param articleIds 需要删除的文章主键 + * @return 结果 + */ + @Override + public int deleteAsArticleByArticleIds(Long[] articleIds) + { + return asArticleMapper.deleteAsArticleByArticleIds(articleIds); + } + + /** + * 删除文章信息 + * + * @param articleId 文章主键 + * @return 结果 + */ + @Override + public int deleteAsArticleByArticleId(Long articleId) + { + return asArticleMapper.deleteAsArticleByArticleId(articleId); + } + + /** + * 根据文章id获取标签列表 + * + * @param articleId 文章主键 + * @return 结果 + */ + @Override + public String[] getTagList(Long articleId) { + AsArticle asArticle = asArticleMapper.selectAsArticleByArticleId(articleId); + String tag = asArticle.getTag(); + String[] split = tag.split(","); + return split; + } + +// /** +// * 查询动态分类及数量 +// * +// * @param +// * @return 结果 +// */ +// @Override +// public List selectDynamicClassifyList() { +// List classifies = new ArrayList<>(); +// SysDictData dictData = new SysDictData(); +// dictData.setDictType("dynamic_classify"); +// List sysDictData = dictDataMapper.selectDictDataList(dictData); +// for (SysDictData one :sysDictData) { +// DynamicClassify dynamicClassify = new DynamicClassify(); +// String dictValue = one.getDictValue(); +// dynamicClassify.setName(one.getDictLabel()); +// dynamicClassify.setValue(dictValue); +// int classify = asArticleMapper.countDynamicClassify(dictValue); +// dynamicClassify.setNum(classify); +// classifies.add(dynamicClassify); +// } +// return classifies; +// } +} diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceClassifyServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceClassifyServiceImpl.java index 2ff8d97..8feff20 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceClassifyServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceClassifyServiceImpl.java @@ -19,7 +19,7 @@ import javax.annotation.Resource; /** * 设备分类Service业务层处理 - * + * * @author qiuzhenzhao * @date 2023-11-11 */ @@ -37,7 +37,7 @@ public class AsDeviceClassifyServiceImpl extends ServiceImpl i /** * 查询设备列表 - * + * * @param deviceId 设备列表主键 * @return 设备列表 */ @Override public AsDevice selectAsDeviceByDeviceId(Long deviceId) { - return asDeviceMapper.selectAsDeviceByDeviceId(deviceId); + AsDevice device = asDeviceMapper.selectAsDeviceByDeviceId(deviceId); + device.setPicture(modelMapper.selectAsModelByModelId(device.getModelId()).getPicture()); + return device; } /** * 查询设备列表列表 - * + * * @param asDevice 设备列表 * @return 设备列表 */ @Override + @SneakyThrows public List selectAsDeviceList(AsDevice asDevice) { - return asDeviceMapper.selectAsDeviceList(asDevice); + // 设备列表的图片是取型号的图片 + List asDevices = asDeviceMapper.selectAsDeviceList(asDevice); + for(AsDevice asDevice1 : asDevices){ + AsModel model = modelMapper.selectAsModelByModelId(asDevice1.getModelId()); + String picture = model.getPicture(); + asDevice1.setPicture(picture); + // 查询onenet设备在线状态 + String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND; + String token = Token.getToken(); + String result = HttpUtils.sendPostWithToken(sendUrl, "111", token); + + JSONObject paramsObj = JSON.parseObject(result); + String code = paramsObj.getString("code"); + if (!HttpStatus.IOT_SUCCESS.equals(code)) { + asDevice1.setOnlineStatus("不在线"); + }else{ + asDevice1.setOnlineStatus("在线"); + } + } + return asDevices; } /** * 新增设备列表 - * + * * @param asDevice 设备列表 * @return 结果 */ @@ -127,7 +149,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** * 修改设备列表 - * + * * @param asDevice 设备列表 * @return 结果 */ @@ -153,16 +175,47 @@ public class AsDeviceServiceImpl extends ServiceImpl i JSONObject paramsObj = JSON.parseObject(result); String code = paramsObj.getString("code"); - String msg = paramsObj.getString("msg"); if (!HttpStatus.IOT_SUCCESS.equals(code)) { - throw new ServiceException(code+"-----"+msg); + throw new ServiceException(code+"-----"+formatMsg(code)); } logger.info("IOT请求调用结果:【{}】",result); /**4.更新数据库*/ return asDeviceMapper.updateAsDevice(asDevice); } + + private String formatMsg(String code) { + if(HttpStatus.ERROR_CODE_DEVICE_NOT_ONLINE.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_NOT_ONLINE_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ALREADY_EXISTS.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_NON_EXISTENT.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_NON_EXISTENT_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_SET_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_SET_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_SET_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_SET_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_GET_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_GET_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_SERVICE_CALL_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_SERVICE_CALL_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_DALETE_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_DALETE_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVIE_NEW_DATA_QUERY_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVIE_NEW_DATA_QUERY_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL.equals(code)){ + return HttpStatus.ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL_MSG; + } + return ""; + } + private String getCommand(AsDevice asDevice) { String regularWateringSwitch = "true".equals(asDevice.getRegularWatering()) ? "1" : "0";//定时浇水开关 @@ -208,7 +261,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** * 批量删除设备列表 - * + * * @param deviceIds 需要删除的设备列表主键 * @return 结果 */ @@ -220,7 +273,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** * 删除设备列表信息 - * + * * @param deviceId 设备列表主键 * @return 结果 */ diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsModelServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsModelServiceImpl.java index 015e098..c2ceeb3 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsModelServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsModelServiceImpl.java @@ -25,7 +25,7 @@ import javax.annotation.Resource; /** * 型号列表Service业务层处理 - * + * * @author qiuzhenzhao * @date 2023-11-11 */ @@ -46,7 +46,7 @@ public class AsModelServiceImpl extends ServiceImpl impl /** * 查询型号列表 - * + * * @param modelId 型号列表主键 * @return 型号列表 */ @@ -58,7 +58,7 @@ public class AsModelServiceImpl extends ServiceImpl impl /** * 查询型号列表列表 - * + * * @param asModel 型号列表 * @return 型号列表 */ @@ -93,7 +93,7 @@ public class AsModelServiceImpl extends ServiceImpl impl /** * 新增型号列表 - * + * * @param asModel 型号列表 * @return 结果 */ @@ -108,7 +108,7 @@ public class AsModelServiceImpl extends ServiceImpl impl /** * 修改型号列表 - * + * * @param asModel 型号列表 * @return 结果 */ @@ -116,12 +116,15 @@ public class AsModelServiceImpl extends ServiceImpl impl public int updateAsModel(AsModel asModel) { asModel.setUpdateTime(DateUtils.getNowDate()); + AsDeviceClassify deviceClassify = classifyMapper.selectAsDeviceClassifyByClassifyId(asModel.getClassifyId()); + String classifyName = deviceClassify.getClassifyName(); + asModel.setClassifyName(classifyName); return asModelMapper.updateAsModel(asModel); } /** * 批量删除型号列表 - * + * * @param modelIds 需要删除的型号列表主键 * @return 结果 */ @@ -133,7 +136,7 @@ public class AsModelServiceImpl extends ServiceImpl impl /** * 删除型号列表信息 - * + * * @param modelId 型号列表主键 * @return 结果 */ diff --git a/AutoSprout-watering/src/main/resources/mapper/article/AsArticleMapper.xml b/AutoSprout-watering/src/main/resources/mapper/article/AsArticleMapper.xml new file mode 100644 index 0000000..42f29a9 --- /dev/null +++ b/AutoSprout-watering/src/main/resources/mapper/article/AsArticleMapper.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + select article_id, classify, dynamic_classify, title, logo, master_picture, tag, is_hot, introduction, content, author, create_by, create_time, update_by, update_time, remark from as_article + + + + + + + + + insert into as_article + + article_id, + classify, + dynamic_classify, + title, + logo, + master_picture, + tag, + is_hot, + introduction, + content, + author, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{articleId}, + #{classify}, + #{dynamicClassify}, + #{title}, + #{logo}, + #{masterPicture}, + #{tag}, + #{isHot}, + #{introduction}, + #{content}, + #{author}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update as_article + + classify = #{classify}, + dynamic_classify = #{dynamicClassify}, + title = #{title}, + logo = #{logo}, + master_picture = #{masterPicture}, + tag = #{tag}, + is_hot = #{isHot}, + introduction = #{introduction}, + content = #{content}, + author = #{author}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where article_id = #{articleId} + + + + delete from as_article where article_id = #{articleId} + + + + delete from as_article where article_id in + + #{articleId} + + + + +