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.Api1212;
|
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.Api1212;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.view.repository.Api1212Rep;
|
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.List;
|
|
/**
|
* 客户信息
|
*
|
* @author Andy
|
*/
|
@Slf4j
|
@Component
|
public class Api1212PR {
|
|
@Autowired
|
private Api1212Rep apiRepository;
|
@Autowired
|
private ApiCommonService apiCommonService;
|
@Autowired
|
private ApiPushManager apiPushManager;
|
|
/**
|
* api1212PR#pageList
|
*
|
* @return
|
*/
|
@DataProvider
|
public void pageList(Page<Api1212> page, ApiParam param) {
|
|
//多参数分页查询
|
Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, Api1212.SORT_PROP);
|
|
if (null == param) {
|
org.springframework.data.domain.Page<Api1212> japPage = apiRepository.findAll(pageable);
|
page.setEntityCount((int) japPage.getTotalElements());
|
page.setEntities(japPage.getContent());
|
|
return;
|
}
|
|
Specification<Api1212> specification = new Specification<Api1212>() {
|
private static final long serialVersionUID = 1L;
|
|
public Predicate toPredicate(Root<Api1212> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
List<Predicate> predicates = new ArrayList<>(); //所有的断言
|
|
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.get("zhgxsj"), ContextUtil.getCurZero(param.getStart()));
|
predicates.add(predicate3);
|
}
|
|
if (null != param.getEnd()) {
|
Predicate predicate4 = cb.lessThan(root.get("zhgxsj"), ContextUtil.getNextZero(param.getEnd()));
|
predicates.add(predicate4);
|
}
|
return cb.and(predicates.toArray(new Predicate[0]));
|
}
|
};
|
|
log.debug("---------分页参数查询----------{}", param.toString());
|
org.springframework.data.domain.Page<Api1212> japPage = apiRepository.findAll(specification, pageable);
|
page.setEntityCount((int) japPage.getTotalElements());
|
page.setEntities(japPage.getContent());
|
}
|
|
|
/**
|
* api1212PR#updateSave
|
*
|
* @param entity
|
*/
|
@DataResolver
|
public void updateSave(Api1212 entity) {
|
|
if (StringUtils.isEmpty(entity.getCzbz())) {
|
entity.setCzbz(Constant.CZBZ_I);
|
}
|
|
//手动将doradoEntity对象转换为标准Bean对象
|
Api1212 data = new Api1212();
|
BeanUtils.copyProperties(entity, data);
|
|
apiRepository.save(data);
|
}
|
|
|
/**
|
* api1212PR#delData
|
*
|
* @param data
|
*/
|
@Expose
|
public String delData(Api1212 data) {
|
if(null == data) return "无数据执行";
|
apiRepository.deleteById(data.getId());
|
|
return null;
|
}
|
|
/**
|
* 更新删除标记 api1212PR#delUpdate
|
*
|
* @param entity
|
*/
|
@Expose
|
public String delUpdate(Api1212 entity) {
|
if(null == entity) return "无数据执行";
|
|
entity.setCzbz(Constant.CZBZ_D);
|
|
Api1212 data = new Api1212();
|
BeanUtils.copyProperties(entity, data);
|
|
apiRepository.save(data);
|
|
return null;
|
}
|
|
/**
|
* api1212PR#pushData
|
*
|
* @param items
|
*/
|
@Expose
|
public String pushData(List<Api1212> items) {
|
ResponseDto responseDto;
|
String result = "";
|
Api1212 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_1212);
|
|
|
//获取实现接口
|
ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol());
|
if (null == apiService) return "系统没有当前推送协议配置,执行失败";
|
|
for (Api1212 data : items) {
|
d = new Api1212();
|
BeanUtils.copyProperties(data, d);
|
responseDto = apiService.pushData(param, apiConf, d);
|
result += responseDto.toString();
|
if (responseDto.getSuccess() == 0) {
|
//todo 代表上传成功 ,后期需要保存日志
|
if ("i".equals(d.getCzbz())) {
|
apiRepository.updateStatus(d.getId(), Constant.CZBZ_U);
|
}
|
}
|
}
|
return result;
|
}
|
|
}
|