增加 解锁

master
wanghao 4 weeks ago
parent db2f62ba57
commit fd34ece36f

@ -13,9 +13,9 @@ spring:
slave:
# 从数据源开关/默认关闭
enabled: true
url: jdbc:mysql://1.13.177.47:3306/bg_wheel_chocks?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://119.45.202.115:3306/bg_wheel_chocks?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: Haiwei123456
password: haiwei@123
# 初始连接数
initialSize: 5
# 最小连接池数量

@ -7,9 +7,9 @@ ruoyi:
# 版权年份
copyrightYear: 2025
# 实例演示开关
demoEnabled: true
demoEnabled: false
# 文件路径 示例( Windows配置D:/ruoyi/uploadPathLinux配置 /home/ruoyi/uploadPath
profile: D:/ruoyi/uploadPath
profile: F:/nopower/uploadPath
# 获取ip地址开关
addressEnabled: true

@ -1,8 +1,9 @@
package com.ruoyi.device.service;
import java.util.List;
import com.ruoyi.device.domain.BaseInfo;
import java.util.List;
/**
* Service
*
@ -42,6 +43,7 @@ public interface IBaseInfoService
* @return
*/
public int updateBaseInfo(BaseInfo baseInfo);
public int updateBaseInfoForApi(BaseInfo baseInfo);
/**
*

@ -1,15 +1,15 @@
package com.ruoyi.device.service.impl;
import java.util.List;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.device.domain.BaseType;
import com.ruoyi.device.domain.BaseInfo;
import com.ruoyi.device.mapper.BaseInfoMapper;
import com.ruoyi.device.service.IBaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.device.mapper.BaseInfoMapper;
import com.ruoyi.device.domain.BaseInfo;
import com.ruoyi.device.service.IBaseInfoService;
import com.ruoyi.common.core.text.Convert;
import java.util.List;
/**
* Service
@ -18,8 +18,7 @@ import com.ruoyi.common.core.text.Convert;
* @date 2025-05-19
*/
@Service
public class BaseInfoServiceImpl implements IBaseInfoService
{
public class BaseInfoServiceImpl implements IBaseInfoService {
@Autowired
private BaseInfoMapper baseInfoMapper;
@ -30,8 +29,7 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public BaseInfo selectBaseInfoByObjId(Long objId)
{
public BaseInfo selectBaseInfoByObjId(Long objId) {
return baseInfoMapper.selectBaseInfoByObjId(objId);
}
@ -42,8 +40,7 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public List<BaseInfo> selectBaseInfoList(BaseInfo baseInfo)
{
public List<BaseInfo> selectBaseInfoList(BaseInfo baseInfo) {
return baseInfoMapper.selectBaseInfoList(baseInfo);
}
@ -54,8 +51,7 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public int insertBaseInfo(BaseInfo baseInfo)
{
public int insertBaseInfo(BaseInfo baseInfo) {
baseInfo.setCreateTime(DateUtils.getNowDate());
baseInfo.setCreateBy(ShiroUtils.getLoginName());
return baseInfoMapper.insertBaseInfo(baseInfo);
@ -68,13 +64,18 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public int updateBaseInfo(BaseInfo baseInfo)
{
public int updateBaseInfo(BaseInfo baseInfo) {
baseInfo.setUpdateTime(DateUtils.getNowDate());
baseInfo.setUpdateBy(ShiroUtils.getLoginName());
return baseInfoMapper.updateBaseInfo(baseInfo);
}
@Override
public int updateBaseInfoForApi(BaseInfo baseInfo) {
return baseInfoMapper.updateBaseInfo(baseInfo);
}
/**
*
*
@ -82,8 +83,7 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public int deleteBaseInfoByObjIds(String objIds)
{
public int deleteBaseInfoByObjIds(String objIds) {
return baseInfoMapper.deleteBaseInfoByObjIds(Convert.toStrArray(objIds));
}
@ -94,8 +94,7 @@ public class BaseInfoServiceImpl implements IBaseInfoService
* @return
*/
@Override
public int deleteBaseInfoByObjId(Long objId)
{
public int deleteBaseInfoByObjId(Long objId) {
return baseInfoMapper.deleteBaseInfoByObjId(objId);
}

@ -1,14 +1,13 @@
package com.ruoyi.device.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.device.domain.RecordUse;
import com.ruoyi.device.mapper.RecordUseMapper;
import com.ruoyi.device.service.IRecordUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.device.mapper.RecordUseMapper;
import com.ruoyi.device.domain.RecordUse;
import com.ruoyi.device.service.IRecordUseService;
import com.ruoyi.common.core.text.Convert;
import java.util.List;
/**
* 使Service
@ -55,8 +54,8 @@ public class RecordUseServiceImpl implements IRecordUseService
@Override
public int insertRecordUse(RecordUse recordUse)
{
recordUse.setCreateTime(DateUtils.getNowDate());
recordUse.setCreateBy(ShiroUtils.getLoginName());
// recordUse.setCreateTime(DateUtils.getNowDate());
// recordUse.setCreateBy(ShiroUtils.getLoginName());
return recordUseMapper.insertRecordUse(recordUse);
}

@ -20,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="typeName" column="device_type_name" />
<result property="defaultPrice" column="default_price" />
<result property="defaultTime" column="default_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectBaseInfoVo">
@ -40,7 +41,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
open_password,
dbt.device_type_name,
dbt.default_price,
dbt.default_time
dbt.default_time,
dbt.remark
from device_base_info info
left join device_base_type dbt on info.device_type = dbt.obj_id
</sql>

@ -36,10 +36,10 @@
<div class="form-group">
<label class="col-sm-4 control-label">摆放桩位:</label>
<div class="col-sm-8">
<!-- <input name="locationName" class="form-control" type="text">-->
<select class="form-control" name="locationName" th:with="type=${@lundang.selectLundangBaseStoreList()}">
<option th:each="dict : ${type}" th:text="${dict.storeName}" th:value="${dict.storeName}"></option>
</select>
<input class="form-control" name="locationName" type="text">
<!-- <select class="form-control" name="locationName" th:with="type=${@lundang.selectLundangBaseStoreList()}">-->
<!-- <option th:each="dict : ${type}" th:text="${dict.storeName}" th:value="${dict.storeName}"></option>-->
<!-- </select>-->
</div>

@ -58,10 +58,10 @@
<div class="form-group">
<label class="col-sm-4 control-label">摆放桩位:</label>
<div class="col-sm-8">
<select class="form-control" name="locationName" th:field="*{locationName}" th:with="type=${@lundang.selectLundangBaseStoreList()}">
<option th:each="dict : ${type}" th:text="${dict.storeName}" th:value="${dict.storeName}"></option>
</select>
<input class="form-control" name="locationName" th:field="*{locationName}" type="text">
<!-- <select class="form-control" name="locationName" th:field="*{locationName}" th:with="type=${@lundang.selectLundangBaseStoreList()}">-->
<!-- <option th:each="dict : ${type}" th:text="${dict.storeName}" th:value="${dict.storeName}"></option>-->
<!-- </select>-->
</div>
</div>
</div>

@ -100,6 +100,8 @@
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "使用记录",
sortName: "openTime",
sortOrder: "desc",
columns: [{
checkbox: true
},

@ -1,17 +1,26 @@
package com.ruoyi.pda.controller;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.device.domain.BaseInfo;
import com.ruoyi.device.domain.RecordUse;
import com.ruoyi.device.service.IBaseInfoService;
import com.ruoyi.device.service.IRecordUseService;
import com.ruoyi.pda.domain.MyResult;
import com.ruoyi.pda.service.IPdaApiService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.List;
import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;
@ -24,6 +33,9 @@ public class PdaApiController {
@Autowired
private IBaseInfoService baseInfoService;
@Autowired
private IRecordUseService recordUseService;
@PostMapping("/home/selectDeviceInfo")
public AjaxResult selectDeviceInfo(String code) {
BaseInfo baseInfo = baseInfoService.selectDeviceInfo(code);
@ -37,22 +49,64 @@ public class PdaApiController {
}
public AjaxResult open() throws IOException {
URL url = new URL("https://api.example.com/data");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
@PostMapping("/home/openDeviceLock")
public AjaxResult openDeviceLock(@RequestBody BaseInfo baseInfo) {
String deviceCode = baseInfo.getDeviceCode();
String openPassword = baseInfo.getOpenPassword();
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
// BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
// String inputLine;
// StringBuilder response = new StringBuilder();
// while ((inputLine = in.readLine()) != null) {
// response.append(inputLine);
// }
// in.close();
// System.out.println(response);
}
return success(conn.getInputStream());
ResponseEntity<String> response = null;
try {
RestTemplate restTemplate = new RestTemplate();
// String url = "http://127.0.0.1:7789/devcontrolbusiness/unlock?idStr=" + deviceCode + "&password=" + openPassword;
String url = "http://119.45.202.115:7789/devcontrolbusiness/unlock?idStr=" + deviceCode + "&password=" + openPassword;
// 根据实际情况调整参数值
response = restTemplate.getForEntity(url, String.class);
if (response.getStatusCode().is2xxSuccessful()) {
// {"code":200/500,"isSuc":true,"msg":"开锁指令下发成功,已收到设备回复","buffer":null,"data":null}
MyResult myResult = JSONObject.parseObject(response.getBody(), MyResult.class);
if (myResult.getCode() == 200) {
/**
*
*/
RecordUse recordUse = new RecordUse();
BeanUtils.copyProperties(baseInfo, recordUse);
recordUse.setDeviceId(String.valueOf(baseInfo.getObjId()));//设备ID
recordUse.setDeviceType(baseInfo.getTypeName());//设备类型
recordUse.setChargePrice(baseInfo.getDefaultPrice());//计费价格
recordUse.setUseState("1");
// 获取当前日期和时间
LocalDate now = LocalDate.now();
// 从LocalDate获取YearMonth
YearMonth currentYearMonth = YearMonth.from(now);
// 获取年份和月份
recordUse.setQueryYear(String.valueOf(currentYearMonth.getYear()));
recordUse.setQueryMonth(String.valueOf(currentYearMonth.getMonthValue()));
recordUseService.insertRecordUse(recordUse);
/**
*
*/
BaseInfo updateBaseInfo = new BaseInfo();
updateBaseInfo.setObjId(baseInfo.getObjId());
updateBaseInfo.setUseState("1");
baseInfoService.updateBaseInfoForApi(updateBaseInfo);
return success("开锁成功");
} else {
return error(myResult.getMsg());
}
}
} catch (RestClientException e) {
return error("通讯失败");
}
return success("开锁成功");
}
@PostMapping("/record/selectUseList")
public AjaxResult selectUseList() {
List<RecordUse> list=service.selectUseList();
return success(list);
}
}

@ -0,0 +1,32 @@
package com.ruoyi.pda.domain;
public class MyResult {
private int code;
private String msg;
private Object data;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

@ -1,8 +1,11 @@
package com.ruoyi.pda.mapper;
import com.ruoyi.device.domain.RecordUse;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Repository
public interface PdaApiMapper {
List<RecordUse> selectUseList();
}

@ -1,4 +1,9 @@
package com.ruoyi.pda.service;
import com.ruoyi.device.domain.RecordUse;
import java.util.List;
public interface IPdaApiService {
List<RecordUse> selectUseList();
}

@ -1,12 +1,20 @@
package com.ruoyi.pda.service.impl;
import com.ruoyi.device.domain.RecordUse;
import com.ruoyi.pda.mapper.PdaApiMapper;
import com.ruoyi.pda.service.IPdaApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PdaServiceImpl implements IPdaApiService {
@Autowired
private PdaApiMapper mapper;
@Override
public List<RecordUse> selectUseList() {
return mapper.selectUseList();
}
}

@ -1,5 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.pda.mapper.PdaApiMapper">
<select id="selectUseList" resultMap="com.ruoyi.device.mapper.RecordUseMapper.RecordUseResult">
SELECT
device_code,
device_name,
device_type,
open_time,
close_time,
use_state,
CASE
WHEN use_time = 0 or use_time is null THEN ROUND(TIMESTAMPDIFF(SECOND, open_time, NOW()) / 3600, 2)
ELSE use_time
END as use_time
FROM device_record_use order by open_time desc
</select>
</mapper>

Loading…
Cancel
Save