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"); String devId = jsonContent.getString("dev_id");
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId);
if(deviceEntity == null){ if(deviceEntity == null){
log.error("设备已删除"); // log.error("设备已删除");
return; return;
} }
@ -264,7 +264,7 @@ public class DeviceApiServiceImpl implements DeviceApiService {
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId);
if(deviceEntity == null){ if(deviceEntity == null){
log.error("设备已删除"); // log.error("设备已删除");
return; return;
} }
SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper<SysDeviceEntity>() SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper<SysDeviceEntity>()
@ -369,7 +369,7 @@ public class DeviceApiServiceImpl implements DeviceApiService {
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
if(deviceEntity == null){ if(deviceEntity == null){
log.error("设备已删除"); // log.error("设备已删除");
return; return;
} }
@ -457,7 +457,7 @@ public class DeviceApiServiceImpl implements DeviceApiService {
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
if(deviceEntity == null){ if(deviceEntity == null){
log.error("设备已删除"); // log.error("设备已删除");
return; return;
} }
@ -514,7 +514,7 @@ public class DeviceApiServiceImpl implements DeviceApiService {
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
if(deviceEntity == null){ if(deviceEntity == null){
log.error("设备已删除"); // log.error("设备已删除");
return; return;
} }

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; 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.nettyapi.service.ServerApiService;
import net.shapelight.modules.sys.entity.SysDeviceEntity; import net.shapelight.modules.sys.entity.SysDeviceEntity;
import net.shapelight.modules.sys.service.SysDeviceService; 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.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -35,6 +38,10 @@ public class SysDeviceController {
@Autowired @Autowired
private ServerApiService serverApiService; private ServerApiService serverApiService;
@Autowired
private TenDeviceService tenDeviceService;
/** /**
* 列表 * 列表
*/ */
@ -78,7 +85,13 @@ public class SysDeviceController {
if (StringUtils.isEmpty(sysDevice.getSn())) if (StringUtils.isEmpty(sysDevice.getSn()))
return R.error("设备sn不能为空"); return R.error("设备sn不能为空");
sysDevice.setSn(sysDevice.getSn().trim()); 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(); return R.ok();
} }
@ -125,6 +138,15 @@ public class SysDeviceController {
@ApiOperation(value = "删除") @ApiOperation(value = "删除")
public R delete(@RequestBody Long[] deviceIds){ 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)); sysDeviceService.removeByIds(Arrays.asList(deviceIds));
return R.ok(); return R.ok();

View File

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

View File

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

View File

@ -31,19 +31,24 @@ public class TenPersonSyncServiceImpl implements TenPersonSyncService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insert(TenPersonSyncEntity tenLicenseEntity) { public int insert(TenPersonSyncEntity tenPersonSyncEntity) {
TenPersonSyncEntity entity = this.findByDeviceIdAndPersonId(tenLicenseEntity.getDeviceId(), TenPersonSyncEntity entity = this.findByDeviceIdAndPersonId(tenPersonSyncEntity.getDeviceId(),
tenLicenseEntity.getPersonId(), tenPersonSyncEntity.getPersonId(),
tenLicenseEntity.getTenantId()); tenPersonSyncEntity.getTenantId());
if(entity==null){ if(entity==null){
return tenPersonSyncDao.insert(tenLicenseEntity); return tenPersonSyncDao.insert(tenPersonSyncEntity);
}else{ }else{
entity.setLastUpdateTime(tenLicenseEntity.getLastUpdateTime()); entity.setLastUpdateTime(tenPersonSyncEntity.getLastUpdateTime());
entity.setState(tenLicenseEntity.getState()); entity.setState(tenPersonSyncEntity.getState());
return tenPersonSyncDao.updateById(entity); return tenPersonSyncDao.updateById(entity);
} }
} }
@Override
public int insertBatch(List<TenPersonSyncEntity> list,Long tenantId) {
return tenPersonSyncDao.insertBatch(list,tenantId);
}
@Override @Override
public int updateById(TenPersonSyncEntity entity) { public int updateById(TenPersonSyncEntity entity) {
return tenPersonSyncDao.updateById(entity); return tenPersonSyncDao.updateById(entity);

View File

@ -340,6 +340,10 @@ public class TenRecordServiceImpl implements TenRecordService {
for (TenRecordEntity rec : page.getRecords()) { for (TenRecordEntity rec : page.getRecords()) {
TenDeviceEntity dev = tenDeviceService.findBySn(rec.getDeviceSn()); TenDeviceEntity dev = tenDeviceService.findBySn(rec.getDeviceSn());
if(dev==null){
rec.setDeviceName("");
rec.setGateFlag(1);
}
rec.setDeviceName(dev.getName()); rec.setDeviceName(dev.getName());
rec.setGateFlag(dev.getGateFlag()); rec.setGateFlag(dev.getGateFlag());
TenPersonEntity person = tenPersonService.getById(rec.getPersonId(), rec.getCellId()); TenPersonEntity person = tenPersonService.getById(rec.getPersonId(), rec.getCellId());

View File

@ -211,8 +211,8 @@ public class XaApi {
e.printStackTrace(); e.printStackTrace();
} }
// String s = httpPOSTJson(apiUrl,b,"SYFW","SYFW",appid,appsecret); String s = httpPOSTJson(apiUrl,b,"SYFW","SYFW",appid,appsecret,"202104140001");
// System.out.println(s); System.out.println(s);
} }
@ -308,8 +308,8 @@ public class XaApi {
e.printStackTrace(); e.printStackTrace();
} }
// String s = httpPOSTJson(apiUrl,b,"SYRK","SYRK",appid,appsecret); String s = httpPOSTJson(apiUrl,b,"SYRK","SYRK",appid,appsecret,"202104140001");
// System.out.println(s); System.out.println(s);
} }
@ -319,16 +319,16 @@ public class XaApi {
* appsecret: 22971647780410956329716477804109 * appsecret: 22971647780410956329716477804109
* xqid: 610113600000000004538 * xqid: 610113600000000004538
*/ */
// String appid = "1297164778041095"; String appid = "1297164778041095";
// String appsecret = "22971647780410956329716477804109"; String appsecret = "22971647780410956329716477804109";
// String xqid = "610113600000000004538"; String xqid = "610113600000000004538";
// String address = getAddress(xqid,appid,appsecret); String address = getAddress(xqid,appid,appsecret);
// System.out.println(address); System.out.println(address);
//6.2 获取数据对接接口--------------------------------------------------------------------------- //6.2 获取数据对接接口---------------------------------------------------------------------------
// String apiUrl = getFwikUrl(appid, appsecret); String apiUrl = getFwikUrl(appid, appsecret);
// System.out.println(apiUrl); System.out.println(apiUrl);
//6.1 获取标准地址接口--------------------------------------------------------------------------- //6.1 获取标准地址接口---------------------------------------------------------------------------
// String address = getAddress(xqid, appid, appsecret); // String address = getAddress(xqid, appid, appsecret);
// System.out.println(address); // System.out.println(address);

View File

@ -3,7 +3,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
druid: druid:
driver-class-name: com.mysql.cj.jdbc.Driver 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 username: user
password: user@server001 password: user@server001
initial-size: 10 initial-size: 10

View File

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