package cn.huge.module.xylink.service;
|
|
import cn.huge.base.common.exception.ServiceException;
|
import cn.huge.base.common.utils.DateUtils;
|
import cn.huge.base.common.utils.IdUtils;
|
import cn.huge.base.common.utils.ObjectUtils;
|
import cn.huge.module.client.api.impl.UtilsClientImpl;
|
import cn.huge.module.xylink.dao.mapper.XylinkNemoMapper;
|
import cn.huge.module.xylink.domain.po.XylinkNemo;
|
import cn.huge.module.xylink.utils.XylinkUtils;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.xylink.model.NemoDto;
|
import com.xylink.sdk.enterpriseNemo.EnterpriseNemoApi;
|
import com.xylink.util.Result;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.PostConstruct;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @title: 小鱼硬件设备表业务逻辑处理
|
* @Description JPA的单表数据查询以由BaseService完成
|
* @company hugeinfo
|
* @author liyj
|
* @Time 2023-07-25 11:53:49
|
* @version 1.0.0
|
*/
|
@Slf4j
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class XylinkNemoService extends ServiceImpl<XylinkNemoMapper, XylinkNemo>{
|
|
@Autowired
|
private XylinkNemoMapper mapper;
|
|
@Autowired
|
private UtilsClientImpl utilsClient;
|
|
/**
|
* 更新对象
|
* @param entity 对象
|
*/
|
public void updateXylinkNemo(XylinkNemo entity){
|
try{
|
mapper.updateXylinkNemo(entity);
|
}catch (Exception e){
|
log.error("service方法[XylinkNemoService.updateXylinkNemo]调用异常:"+e, e);
|
throw new ServiceException("XylinkNemoService.updateXylinkNemo", e);
|
}
|
}
|
|
/**
|
* 条件更新对象
|
* @param entity 对象
|
* @param terms 条件
|
*/
|
public void updateXylinkNemoTerms(XylinkNemo entity, Map<String, Object> terms){
|
try{
|
mapper.updateXylinkNemoTerms(entity, terms);
|
}catch (Exception e){
|
log.error("service方法[XylinkNemoService.updateXylinkNemoTerms]调用异常:"+e, e);
|
throw new ServiceException("XylinkNemoService.updateXylinkNemoTerms", e);
|
}
|
}
|
|
/**
|
* 根据编号物理删除
|
* @param id 查询条件集合
|
*/
|
public void deleteXylinkNemo(String id){
|
try{
|
mapper.deleteXylinkNemo(id);
|
}catch (Exception e){
|
log.error("service方法[XylinkNemoService.deleteXylinkNemo]调用异常:"+e, e);
|
throw new ServiceException("XylinkNemoService.deleteXylinkNemo", e);
|
}
|
}
|
|
/**
|
* 按条件查询
|
* @param terms 条件
|
* @return List
|
*/
|
public List<XylinkNemo> listTerms(Map<String, Object> terms){
|
return mapper.listTerms(terms);
|
}
|
|
/**
|
* 按条件统计
|
* @param terms 条件
|
* @return long
|
*/
|
public long countTerms(Map<String, Object> terms){
|
return mapper.countTerms(terms);
|
}
|
|
/**
|
* 按条件分页查询
|
* @param page 分页对象
|
* @param terms 条件
|
* @return Page
|
*/
|
public Page<XylinkNemo> pageQuery(PageRequest page, Map<String, Object> terms){
|
long total = mapper.countTerms(terms);
|
List<XylinkNemo> content = mapper.pageTerms(page, terms);
|
return new PageImpl<XylinkNemo>(content, page, total);
|
}
|
|
/**
|
* 新增或更新对象
|
* @param xylinkNemo 实体对象
|
*/
|
public void saveXylinkNemo(XylinkNemo xylinkNemo){
|
try{
|
Date nowDate = DateUtils.getNowDate();
|
// 判断是否新增
|
if (IdUtils.checkNewId(xylinkNemo.getId())){
|
xylinkNemo.setId(utilsClient.getNewTimeId());
|
xylinkNemo.setCreateTime(nowDate);
|
}
|
xylinkNemo.setUpdateTime(nowDate);
|
this.saveOrUpdate(xylinkNemo);
|
}catch (Exception e){
|
log.error("service方法[XylinkNemoService.saveXylinkNemo]调用异常:"+e, e);
|
throw new ServiceException("XylinkNemoService.saveXylinkNemo", e);
|
}
|
}
|
|
/**
|
* 同步小鱼终端设备信息
|
* @throws Exception
|
*/
|
public Result<NemoDto[]> syncNemo() throws Exception{
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date nowDate = new Date();
|
EnterpriseNemoApi enterpriseNemoApi = new EnterpriseNemoApi();
|
Result<NemoDto[]> result = enterpriseNemoApi.getEnterpriseNemos(XylinkUtils.enterpriseId, XylinkUtils.token);
|
NemoDto[] nemoDtos = result.getData();
|
for (NemoDto nemoDto: nemoDtos) {
|
XylinkNemo xylinkNemo = this.getById(nemoDto.getSn());
|
if (ObjectUtils.isEmpty(xylinkNemo)) {
|
xylinkNemo = new XylinkNemo();
|
BeanUtils.copyProperties(nemoDto, xylinkNemo);
|
xylinkNemo.setId(xylinkNemo.getSn());
|
xylinkNemo.setCreateTime(nowDate);
|
// 判断是否到期
|
Date expireTime = sdf.parse(xylinkNemo.getPortExpireTime());
|
if (expireTime.before(nowDate)) {
|
xylinkNemo.setExpireStatus("已到期");
|
} else {
|
Date lastExpireTime = DateUtils.addDay(expireTime, -10);
|
if (lastExpireTime.before(nowDate)) {
|
xylinkNemo.setExpireStatus("将到期");
|
} else {
|
xylinkNemo.setExpireStatus("未到期");
|
}
|
}
|
xylinkNemo.setUpdateTime(nowDate);
|
this.save(xylinkNemo);
|
}else {
|
// 判断是否到期
|
Date expireTime = sdf.parse(xylinkNemo.getPortExpireTime());
|
if (expireTime.before(nowDate)) {
|
xylinkNemo.setExpireStatus("已到期");
|
} else {
|
Date lastExpireTime = DateUtils.addDay(expireTime, -10);
|
if (lastExpireTime.before(nowDate)) {
|
xylinkNemo.setExpireStatus("将到期");
|
} else {
|
xylinkNemo.setExpireStatus("未到期");
|
}
|
}
|
xylinkNemo.setUpdateTime(nowDate);
|
this.updateXylinkNemo(xylinkNemo);
|
}
|
}
|
return result;
|
}catch (Exception e){
|
throw new Exception("处理出错",e);
|
}
|
}
|
|
}
|