diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java index 849e9cc..8efef18 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java @@ -218,7 +218,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { String devId = jsonContent.getString("dev_id"); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId); if(deviceEntity == null){ - log.error("设备已删除"); +// log.error("设备已删除"); return; } @@ -264,7 +264,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId); if(deviceEntity == null){ - log.error("设备已删除"); +// log.error("设备已删除"); return; } SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper() @@ -369,7 +369,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); if(deviceEntity == null){ - log.error("设备已删除"); +// log.error("设备已删除"); return; } @@ -457,7 +457,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); if(deviceEntity == null){ - log.error("设备已删除"); +// log.error("设备已删除"); return; } @@ -514,7 +514,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); if(deviceEntity == null){ - log.error("设备已删除"); +// log.error("设备已删除"); return; } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java index 465dd30..f898bdb 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -12,6 +13,8 @@ import net.shapelight.common.utils.StringUtils; import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.entity.SysDeviceEntity; import net.shapelight.modules.sys.service.SysDeviceService; +import net.shapelight.modules.ten.entity.TenDeviceEntity; +import net.shapelight.modules.ten.service.TenDeviceService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -35,6 +38,10 @@ public class SysDeviceController { @Autowired private ServerApiService serverApiService; + @Autowired + private TenDeviceService tenDeviceService; + + /** * 列表 */ @@ -78,7 +85,13 @@ public class SysDeviceController { if (StringUtils.isEmpty(sysDevice.getSn())) return R.error("设备sn不能为空"); sysDevice.setSn(sysDevice.getSn().trim()); - this.sysDeviceService.save(sysDevice); + SysDeviceEntity entity = sysDeviceService.getOne(new QueryWrapper() + .eq("sn",sysDevice.getSn())); + if (entity!=null){ + return R.error("设备sn已存在"); + } + sysDeviceService.save(sysDevice); +// sysDeviceService.createTenPersonSyncBySn(sysDevice.getSn()); return R.ok(); } @@ -125,6 +138,15 @@ public class SysDeviceController { @ApiOperation(value = "删除") public R delete(@RequestBody Long[] deviceIds){ + + //删除同步人员 + for(Long devId: deviceIds){ + TenDeviceEntity deviceEntity = tenDeviceService.getById(devId); + if(deviceEntity!=null){ + return R.error("设备已绑定运营商正在使用,请联系运营商先删除"); + } + } + sysDeviceService.removeByIds(Arrays.asList(deviceIds)); return R.ok(); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java index 0b9d0cf..717b8ed 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java @@ -19,6 +19,7 @@ public interface TenPersonSyncDao { List getDeviceAllPersonIdUpdateTime(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); int insert(TenPersonSyncEntity tenLicenseEntity); + int insertBatch(@Param("list")List list,@Param("tenantId")Long tenantId); int updateById(TenPersonSyncEntity entity); void removeByDeviceId(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java index eb721c9..1a59ff4 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java @@ -19,6 +19,7 @@ public interface TenPersonSyncService { List getDeviceAllPersonIdUpdateTime(Long deviceId,Long tenantId); int insert(TenPersonSyncEntity tenLicenseEntity); + int insertBatch(List list,Long tenantId); int updateById(TenPersonSyncEntity entity); void removeByDeviceId(Long deviceId, Long tenantId); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java index 8d1ccbe..0344610 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java @@ -333,6 +333,9 @@ public class TenDeviceServiceImpl extends ServiceImpl sList = new ArrayList<>(); + //1.删除设备关联的人 + //2.批量添加 + List saveList = new ArrayList<>(); for(TenPersonIdUpdateAllVo vo:list){ TenPersonSyncEntity entity = new TenPersonSyncEntity(); entity.setDeviceId(deviceEntity.getDeviceId()); @@ -342,8 +345,13 @@ public class TenDeviceServiceImpl extends ServiceImpl0){ + tenPersonSyncService.insertBatch(saveList,deviceEntity.getTenantId()); + } + // tenPersonSyncService.saveBatch(sList); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java index dbe8d9d..4377f7d 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java @@ -31,19 +31,24 @@ public class TenPersonSyncServiceImpl implements TenPersonSyncService { @Override @Transactional(rollbackFor = Exception.class) - public int insert(TenPersonSyncEntity tenLicenseEntity) { - TenPersonSyncEntity entity = this.findByDeviceIdAndPersonId(tenLicenseEntity.getDeviceId(), - tenLicenseEntity.getPersonId(), - tenLicenseEntity.getTenantId()); + public int insert(TenPersonSyncEntity tenPersonSyncEntity) { + TenPersonSyncEntity entity = this.findByDeviceIdAndPersonId(tenPersonSyncEntity.getDeviceId(), + tenPersonSyncEntity.getPersonId(), + tenPersonSyncEntity.getTenantId()); if(entity==null){ - return tenPersonSyncDao.insert(tenLicenseEntity); + return tenPersonSyncDao.insert(tenPersonSyncEntity); }else{ - entity.setLastUpdateTime(tenLicenseEntity.getLastUpdateTime()); - entity.setState(tenLicenseEntity.getState()); + entity.setLastUpdateTime(tenPersonSyncEntity.getLastUpdateTime()); + entity.setState(tenPersonSyncEntity.getState()); return tenPersonSyncDao.updateById(entity); } } + @Override + public int insertBatch(List list,Long tenantId) { + return tenPersonSyncDao.insertBatch(list,tenantId); + } + @Override public int updateById(TenPersonSyncEntity entity) { return tenPersonSyncDao.updateById(entity); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java index 23e6813..29b37c1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java @@ -340,6 +340,10 @@ public class TenRecordServiceImpl implements TenRecordService { for (TenRecordEntity rec : page.getRecords()) { TenDeviceEntity dev = tenDeviceService.findBySn(rec.getDeviceSn()); + if(dev==null){ + rec.setDeviceName(""); + rec.setGateFlag(1); + } rec.setDeviceName(dev.getName()); rec.setGateFlag(dev.getGateFlag()); TenPersonEntity person = tenPersonService.getById(rec.getPersonId(), rec.getCellId()); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java b/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java index bf54354..93ae02d 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java @@ -211,8 +211,8 @@ public class XaApi { e.printStackTrace(); } -// String s = httpPOSTJson(apiUrl,b,"SYFW","SYFW",appid,appsecret); -// System.out.println(s); + String s = httpPOSTJson(apiUrl,b,"SYFW","SYFW",appid,appsecret,"202104140001"); + System.out.println(s); } @@ -308,8 +308,8 @@ public class XaApi { e.printStackTrace(); } -// String s = httpPOSTJson(apiUrl,b,"SYRK","SYRK",appid,appsecret); -// System.out.println(s); + String s = httpPOSTJson(apiUrl,b,"SYRK","SYRK",appid,appsecret,"202104140001"); + System.out.println(s); } @@ -319,16 +319,16 @@ public class XaApi { * appsecret: 22971647780410956329716477804109 * xqid: 610113600000000004538 */ -// String appid = "1297164778041095"; -// String appsecret = "22971647780410956329716477804109"; -// String xqid = "610113600000000004538"; -// String address = getAddress(xqid,appid,appsecret); -// System.out.println(address); + String appid = "1297164778041095"; + String appsecret = "22971647780410956329716477804109"; + String xqid = "610113600000000004538"; + String address = getAddress(xqid,appid,appsecret); + System.out.println(address); //6.2 获取数据对接接口--------------------------------------------------------------------------- -// String apiUrl = getFwikUrl(appid, appsecret); -// System.out.println(apiUrl); + String apiUrl = getFwikUrl(appid, appsecret); + System.out.println(apiUrl); //6.1 获取标准地址接口--------------------------------------------------------------------------- // String address = getAddress(xqid, appid, appsecret); // System.out.println(address); diff --git a/shapelight-admin/src/main/resources/application-dev.yml b/shapelight-admin/src/main/resources/application-dev.yml index 3beb63d..47aa778 100644 --- a/shapelight-admin/src/main/resources/application-dev.yml +++ b/shapelight-admin/src/main/resources/application-dev.yml @@ -3,7 +3,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.50.232:3306/cell_db_tcp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.50.232:3306/cell_db_tcp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true username: user password: user@server001 initial-size: 10 diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml index e3a506f..534b3d2 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml @@ -3,7 +3,7 @@ - + @@ -20,6 +20,25 @@ + + INSERT INTO ten_person_sync_${tenantId} + (device_id, + device_sn, + person_id, + state, + last_update_time, + tenant_id) + VALUES + + #{item.deviceId}, + #{item.deviceSn}, + #{item.personId}, + #{item.state}, + #{item.lastUpdateTime}, + #{item.tenantId} + + + insert into ten_person_sync_${tenantId} @@ -100,7 +119,6 @@ - select device_sn as deviceSn,group_concat(person_id,"_",last_update_time separator ",") as plist - from ten_person_sync_${tenantId} where 1= 1 + from ten_person_sync_${tenantId} where 1= 1 and person_id in