package com.fzzy.api.view.pr;
|
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.bstek.dorado.data.provider.Page;
|
import com.fzzy.api.entity.Api1308;
|
import com.fzzy.api.entity.ApiConfs;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.service.ApiPushManager;
|
import com.fzzy.api.service.ApiRemoteService;
|
import com.fzzy.push.gb2022.GBApiRemoteService;
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.data.ApiParam;
|
import com.fzzy.api.dto.ResponseDto;
|
import com.fzzy.api.entity.Api1308;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.view.repository.Api1308Rep;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Component;
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Root;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 视频监控异常事件告警基本信息
|
*
|
* @author chen
|
*/
|
@Slf4j
|
@Component
|
public class Api1308PR {
|
|
@Autowired
|
private Api1308Rep api1308Rep;
|
@Autowired
|
private ApiCommonService apiCommonService;
|
@Autowired
|
private ApiPushManager apiPushManager;
|
|
/**
|
* api1308PR#pageList
|
*
|
* @return
|
*/
|
@SuppressWarnings("serial")
|
@DataProvider
|
public void pageList(Page<Api1308> page, final ApiParam param) {
|
|
//多参数分页查询
|
Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, "gjsj");
|
|
if (null == param) {
|
org.springframework.data.domain.Page<Api1308> japPage = api1308Rep.findAll(pageable);
|
page.setEntityCount((int) japPage.getTotalElements());
|
page.setEntities(japPage.getContent());
|
|
return;
|
}
|
|
Specification<Api1308> specification = new Specification<Api1308>() {
|
public Predicate toPredicate(Root<Api1308> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
|
|
if (StringUtils.isNotBlank(param.getKqdm())) {
|
Predicate predicate1 = cb.equal(root.get("kqdm"), param.getKqdm());
|
predicates.add(predicate1);
|
}
|
|
if (StringUtils.isNotBlank(param.getCzbz())) {
|
Predicate predicate2 = cb.equal(root.get("czbz"),param.getCzbz());
|
predicates.add(predicate2);
|
}
|
if (null != param.getStart()) {
|
Predicate predicate3 = cb.greaterThan(root.<Date>get("gjsj"), ContextUtil.getCurZero(param.getStart()));
|
predicates.add(predicate3);
|
}
|
|
if (null != param.getEnd()) {
|
Predicate predicate4 = cb.lessThan(root.<Date>get("gjsj"), ContextUtil.getNextZero(param.getEnd()));
|
predicates.add(predicate4);
|
}
|
return cb.and(predicates.toArray(new Predicate[0]));
|
}
|
};
|
|
log.debug("---------分页参数查询----------{}", param.toString());
|
org.springframework.data.domain.Page<Api1308> japPage = api1308Rep.findAll(specification, pageable);
|
page.setEntityCount((int) japPage.getTotalElements());
|
page.setEntities(japPage.getContent());
|
}
|
|
|
/**
|
* api1308PR#updateSave
|
*
|
* @param entity
|
*/
|
@DataResolver
|
public void updateSave(Api1308 entity) {
|
|
//手动将doradoEntity对象转换为标准Bean对象
|
Api1308 data = new Api1308();
|
BeanUtils.copyProperties(entity, data);
|
if(StringUtils.isEmpty(data.getId())){
|
data.setId(ContextUtil.getUUID());
|
}
|
api1308Rep.save(data);
|
}
|
|
|
/**
|
* api1308PR#delData
|
*
|
* @param data
|
*/
|
@Expose
|
public String delData(Api1308 data) {
|
|
api1308Rep.deleteById(data.getId());
|
|
return null;
|
}
|
|
/**
|
*
|
* 更新删除标记 api1308PR#delUpdate
|
*
|
* @param entity
|
*/
|
@Expose
|
public String delUpdate(Api1308 entity) {
|
|
entity.setCzbz(Constant.CZBZ_D);
|
|
Api1308 data = new Api1308();
|
BeanUtils.copyProperties(entity, data);
|
|
api1308Rep.save(data);
|
|
return null;
|
}
|
|
/**
|
* api1308PR#pushData
|
*
|
* @param items
|
*/
|
@Expose
|
public String pushData(List<Api1308> items) {
|
ResponseDto responseDto;
|
String result = "";
|
Api1308 d;
|
String kqdm = items.get(0).getKqdm();
|
ApiConfs apiConf = apiCommonService.getConf(kqdm);
|
|
if (null == apiConf) return "系统没有获取到当前库区配置信息,执行失败";
|
|
//封装参数
|
ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1308);
|
|
|
//获取实现接口
|
ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol());
|
if (null == apiService) return "系统没有当前推送协议配置,执行失败";
|
|
for (Api1308 data : items) {
|
d = new Api1308();
|
BeanUtils.copyProperties(data, d);
|
responseDto = apiService.pushData(param, apiConf, d);
|
result += responseDto.toString();
|
if (responseDto.getSuccess() == 0) {
|
//todo 代表上传成功 ,后期需要保存日志
|
if("i".equals(d.getCzbz())){
|
d.setCzbz("u");
|
api1308Rep.save(d);
|
}
|
}
|
}
|
return result;
|
}
|
|
}
|