1.优化同步人员表以及逻辑

This commit is contained in:
gaoben 2021-04-22 14:34:51 +08:00
parent 6129298f8d
commit 8c3b244542
10 changed files with 88 additions and 29 deletions

View File

@ -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<SysDeviceEntity>()
@ -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;
}

View File

@ -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<SysDeviceEntity>()
.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();

View File

@ -19,6 +19,7 @@ public interface TenPersonSyncDao {
List<TenPersonIdUpdateAllVo> getDeviceAllPersonIdUpdateTime(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId);
int insert(TenPersonSyncEntity tenLicenseEntity);
int insertBatch(@Param("list")List<TenPersonSyncEntity> list,@Param("tenantId")Long tenantId);
int updateById(TenPersonSyncEntity entity);
void removeByDeviceId(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId);

View File

@ -19,6 +19,7 @@ public interface TenPersonSyncService {
List<TenPersonIdUpdateAllVo> getDeviceAllPersonIdUpdateTime(Long deviceId,Long tenantId);
int insert(TenPersonSyncEntity tenLicenseEntity);
int insertBatch(List<TenPersonSyncEntity> list,Long tenantId);
int updateById(TenPersonSyncEntity entity);
void removeByDeviceId(Long deviceId, Long tenantId);

View File

@ -333,6 +333,9 @@ public class TenDeviceServiceImpl extends ServiceImpl<TenDeviceDao, TenDeviceEnt
deviceEntity.getBuildId(),
deviceEntity.getRoomId());
// List<TenPersonSyncEntity> sList = new ArrayList<>();
//1.删除设备关联的人
//2.批量添加
List<TenPersonSyncEntity> saveList = new ArrayList<>();
for(TenPersonIdUpdateAllVo vo:list){
TenPersonSyncEntity entity = new TenPersonSyncEntity();
entity.setDeviceId(deviceEntity.getDeviceId());
@ -342,8 +345,13 @@ public class TenDeviceServiceImpl extends ServiceImpl<TenDeviceDao, TenDeviceEnt
entity.setState(0);
entity.setTenantId(deviceEntity.getTenantId());
// sList.add(entity);
tenPersonSyncService.insert(entity);
saveList.add(entity);
// tenPersonSyncService.insert(entity);
}
if(saveList.size()>0){
tenPersonSyncService.insertBatch(saveList,deviceEntity.getTenantId());
}
// tenPersonSyncService.saveBatch(sList);
}

View File

@ -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<TenPersonSyncEntity> list,Long tenantId) {
return tenPersonSyncDao.insertBatch(list,tenantId);
}
@Override
public int updateById(TenPersonSyncEntity entity) {
return tenPersonSyncDao.updateById(entity);

View File

@ -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());

View File

@ -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);

View File

@ -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

View File

@ -3,7 +3,7 @@
<mapper namespace="net.shapelight.modules.ten.dao.TenPersonSyncDao">
<!-- 可根据自己的需求,是否要使用 -->
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="net.shapelight.modules.ten.entity.TenPersonSyncEntity" id="tenPersonSyncMap">
<result property="personSyncId" column="person_sync_id"/>
<result property="deviceId" column="device_id"/>
@ -20,6 +20,25 @@
</resultMap>
<insert id="insertBatch" parameterType="java.util.List">
INSERT INTO ten_person_sync_${tenantId}
(device_id,
device_sn,
person_id,
state,
last_update_time,
tenant_id)
VALUES
<foreach collection="list" item="item" open="(" close=")" separator="),(">
#{item.deviceId},
#{item.deviceSn},
#{item.personId},
#{item.state},
#{item.lastUpdateTime},
#{item.tenantId}
</foreach>
</insert>
<insert id="insert" parameterType="net.shapelight.modules.ten.entity.TenPersonSyncEntity">
insert into ten_person_sync_${tenantId}
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -100,7 +119,6 @@
</update>
<select id="getDeviceAllPersonIdUpdateTime" resultMap="idupdatetime">
select person_id,last_update_time from ten_person_sync_${tenantId}
where 1=1
@ -142,7 +160,7 @@
<select id="findGroupDevicePersons" resultType="map">
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
<if test="personIds != null">
and person_id in
<foreach item="personId" collection="personIds" open="(" separator="," close=")">