diff --git a/AutoSprout-admin/src/main/java/com/ruoyi/web/controller/system/AsUserCollectionController.java b/AutoSprout-admin/src/main/java/com/ruoyi/web/controller/system/AsUserCollectionController.java index 9a28d8a..f6f91bf 100644 --- a/AutoSprout-admin/src/main/java/com/ruoyi/web/controller/system/AsUserCollectionController.java +++ b/AutoSprout-admin/src/main/java/com/ruoyi/web/controller/system/AsUserCollectionController.java @@ -1,11 +1,17 @@ package com.ruoyi.web.controller.system; import java.util.List; +import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.core.domain.entity.AsUser; +import com.ruoyi.device.domain.AsPlant; import com.ruoyi.device.domain.AsUserCollection; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.device.service.IAsPlantService; import com.ruoyi.device.service.IAsUserCollectionService; +import com.ruoyi.device.service.IAsUserService; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -35,6 +41,12 @@ public class AsUserCollectionController extends BaseController @Autowired private IAsUserCollectionService asUserCollectionService; + @Resource + private IAsUserService asUserService; + + @Resource + private IAsPlantService asPlantService; + /** * 查询用户收藏列表 */ @@ -44,6 +56,16 @@ public class AsUserCollectionController extends BaseController { startPage(); List list = asUserCollectionService.selectAsUserCollectionList(asUserCollection); + for (AsUserCollection asUserCollection1:list) { + AsUser asUser = asUserService.selectUserById(asUserCollection1.getUserId()); + if(ObjectUtils.isNotEmpty(asUser)){ + asUserCollection1.setUserName(asUser.getUserName()); + } + AsPlant asPlant = asPlantService.selectAsPlantByPlantId(asUserCollection1.getPlantId()); + if(ObjectUtils.isNotEmpty(asPlant)){ + asUserCollection1.setPlantName(asPlant.getPlantName()); + } + } return getDataTable(list); } @@ -78,7 +100,8 @@ public class AsUserCollectionController extends BaseController @PostMapping public AjaxResult add(@RequestBody AsUserCollection asUserCollection) { - return toAjax(asUserCollectionService.insertAsUserCollection(asUserCollection)); + Long aLong = asUserCollectionService.insertAsUserCollection(asUserCollection); + return success(aLong); } /** diff --git a/AutoSprout-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java b/AutoSprout-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java index 5954f13..dbb0c78 100644 --- a/AutoSprout-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java +++ b/AutoSprout-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java @@ -31,7 +31,7 @@ public class AccessTokenUtil { String accessToken = wxMaService.getAccessToken(); cachedToken = accessToken; // 更新 token 过期时间 - tokenExpirationTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(7200L); + tokenExpirationTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3600L); return cachedToken; } return cachedToken; diff --git a/AutoSprout-ui/src/views/plant/plant/index.vue b/AutoSprout-ui/src/views/plant/plant/index.vue index db29491..bccff8c 100644 --- a/AutoSprout-ui/src/views/plant/plant/index.vue +++ b/AutoSprout-ui/src/views/plant/plant/index.vue @@ -177,8 +177,8 @@ - - + + - - + + - - - + + + + + + + + + + + + + + + + + + beamIds; @@ -70,6 +74,10 @@ public class AsPlant extends BaseEntity @Excel(name = "功能") private String func; + /** 功能 */ + @Excel(name = "功能") + private String funcStr; + /** 功能 */ @Excel(name = "功能") private List funcs; @@ -78,6 +86,10 @@ public class AsPlant extends BaseEntity @Excel(name = "适合的空间") private String fitSpace; + /** 适合的空间 */ + @Excel(name = "适合的空间") + private String fitSpaceStr; + /** 适合的空间ids */ @Excel(name = "适合的空间ids") private List fitSpaces; @@ -86,6 +98,10 @@ public class AsPlant extends BaseEntity @Excel(name = "水分要求") private String moisture; + /** 水分要求 */ + @Excel(name = "水分要求") + private String moistureStr; + /** 水分要求ids */ @Excel(name = "水分要求ids") private List moistures; diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsUserCollection.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsUserCollection.java index ad1fdc9..5198877 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsUserCollection.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/domain/AsUserCollection.java @@ -22,10 +22,18 @@ public class AsUserCollection extends BaseEntity @Excel(name = "用户") private Long userId; + /** 用户名 */ + @Excel(name = "用户名") + private String userName; + /** 植物id */ @Excel(name = "植物id") private Long plantId; + /** 植物名 */ + @Excel(name = "植物名") + private String plantName; + /** 植物对象 */ @Excel(name = "植物对象") private AsPlant plant; diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsUserCollectionService.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsUserCollectionService.java index 0d76a40..2c3cbed 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsUserCollectionService.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/IAsUserCollectionService.java @@ -34,7 +34,7 @@ public interface IAsUserCollectionService * @param asUserCollection 用户收藏 * @return 结果 */ - public int insertAsUserCollection(AsUserCollection asUserCollection); + public Long insertAsUserCollection(AsUserCollection asUserCollection); /** * 修改用户收藏 diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantIdentifyLogServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantIdentifyLogServiceImpl.java index 307b85c..dd112bc 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantIdentifyLogServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantIdentifyLogServiceImpl.java @@ -7,6 +7,7 @@ import java.util.List; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.device.domain.vo.IdentifyRes; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.device.mapper.AsPlantIdentifyLogMapper; @@ -50,12 +51,14 @@ public class AsPlantIdentifyLogServiceImpl implements IAsPlantIdentifyLogService for (AsPlantIdentifyLog log:asPlantIdentifyLogs ) { String response = log.getResponse(); IdentifyRes identifyRes = JSONObject.parseObject(response, IdentifyRes.class); - StringBuilder s = new StringBuilder(); - for (IdentifyRes.PlantItem item : identifyRes.getResult()) { - BigDecimal b = item.getScore().multiply(new BigDecimal(100)).setScale(1, RoundingMode.HALF_UP); - s.append(item.getName()).append(":").append(b).append("%,"); + if(ObjectUtils.isNotEmpty(identifyRes.getResult())){ + StringBuilder s = new StringBuilder(); + for (IdentifyRes.PlantItem item : identifyRes.getResult()) { + BigDecimal b = item.getScore().multiply(new BigDecimal(100)).setScale(1, RoundingMode.HALF_UP); + s.append(item.getName()).append(":").append(b).append("%,"); + } + log.setResponse(s.toString()); } - log.setResponse(s.toString()); } return asPlantIdentifyLogs; } diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantServiceImpl.java index 329f35d..ea2b89e 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsPlantServiceImpl.java @@ -47,10 +47,16 @@ public class AsPlantServiceImpl extends ServiceImpl impl public AsPlant selectAsPlantByPlantId(Long plantId) { AsPlant asPlant = asPlantMapper.selectAsPlantByPlantId(plantId); - showBeam(asPlant); - showFunc(asPlant); - showFitSpace(asPlant); - showMoisture(asPlant); + if(ObjectUtils.isNotEmpty(asPlant)){ + showBeam(asPlant); + showFunc(asPlant); + showFitSpace(asPlant); + showMoisture(asPlant); + handleBeam(asPlant); + handleFuns(asPlant); + handleFitSpace(asPlant); + handleMoisture(asPlant); + } return asPlant; } @@ -141,7 +147,7 @@ public class AsPlantServiceImpl extends ServiceImpl impl sb.append(","); } } - asPlant1.setBeam(sb.toString()); + asPlant1.setBeamStr(sb.toString()); } } /** 处理功能数据*/ @@ -159,7 +165,7 @@ public class AsPlantServiceImpl extends ServiceImpl impl sb.append(","); } } - asPlant1.setFunc(sb.toString()); + asPlant1.setFuncStr(sb.toString()); } } /** 适合的空间*/ @@ -177,7 +183,7 @@ public class AsPlantServiceImpl extends ServiceImpl impl sb.append(","); } } - asPlant1.setFitSpace(sb.toString()); + asPlant1.setFitSpaceStr(sb.toString()); } } /** 水分要求*/ @@ -195,7 +201,7 @@ public class AsPlantServiceImpl extends ServiceImpl impl sb.append(","); } } - asPlant1.setMoisture(sb.toString()); + asPlant1.setMoistureStr(sb.toString()); } } diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsUserCollectionServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsUserCollectionServiceImpl.java index 2692a34..8977f62 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsUserCollectionServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsUserCollectionServiceImpl.java @@ -61,10 +61,11 @@ public class AsUserCollectionServiceImpl implements IAsUserCollectionService * @return 结果 */ @Override - public int insertAsUserCollection(AsUserCollection asUserCollection) + public Long insertAsUserCollection(AsUserCollection asUserCollection) { asUserCollection.setCreateTime(DateUtils.getNowDate()); - return asUserCollectionMapper.insertAsUserCollection(asUserCollection); + asUserCollectionMapper.insertAsUserCollection(asUserCollection); + return asUserCollection.getCollectionId(); } /**