|  |  |  | 
|---|
|  |  |  | 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.data.ApiParam; | 
|---|
|  |  |  | import com.fzzy.api.data.PushProtocol; | 
|---|
|  |  |  | import com.fzzy.api.service.ApiCommonService; | 
|---|
|  |  |  | import com.fzzy.api.service.ApiPushManager; | 
|---|
|  |  |  | import com.fzzy.api.service.ApiRemoteService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.fzzy.api.entity.ApiConfs; | 
|---|
|  |  |  | import com.fzzy.api.utils.ContextUtil; | 
|---|
|  |  |  | import com.fzzy.api.view.repository.Api1109Rep; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 sun.misc.BASE64Encoder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.persistence.criteria.CriteriaBuilder; | 
|---|
|  |  |  | import javax.persistence.criteria.CriteriaQuery; | 
|---|
|  |  |  | import javax.persistence.criteria.Predicate; | 
|---|
|  |  |  | import javax.persistence.criteria.Root; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @DataProvider | 
|---|
|  |  |  | public List<Api1109> listAll() { | 
|---|
|  |  |  | return api1109Rep.findAll(); | 
|---|
|  |  |  | public void listAll(Page<Api1109> page, ApiParam param) { | 
|---|
|  |  |  | //多参数分页查询 | 
|---|
|  |  |  | Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, Api1109.SORT_PROP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null == param) { | 
|---|
|  |  |  | org.springframework.data.domain.Page<Api1109> japPage = api1109Rep.findAll(pageable); | 
|---|
|  |  |  | page.setEntityCount((int) japPage.getTotalElements()); | 
|---|
|  |  |  | page.setEntities(japPage.getContent()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Specification<Api1109> specification = new Specification<Api1109>() { | 
|---|
|  |  |  | private static final long serialVersionUID = 1L; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Predicate toPredicate(Root<Api1109> 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("zhgxsj"), ContextUtil.getCurZero(param.getStart())); | 
|---|
|  |  |  | predicates.add(predicate3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null != param.getEnd()) { | 
|---|
|  |  |  | Predicate predicate4 = cb.lessThan(root.<Date>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<Api1109> japPage = api1109Rep.findAll(specification, pageable); | 
|---|
|  |  |  | page.setEntityCount((int) japPage.getTotalElements()); | 
|---|
|  |  |  | page.setEntities(japPage.getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * 更新删除标记 api1109PR#delUpdate | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param entity | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Expose | 
|---|
|  |  |  | public String pushData(List<Api1109> items) { | 
|---|
|  |  |  | ResponseDto responseDto; | 
|---|
|  |  |  | String result = ""; | 
|---|
|  |  |  | Api1109 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_1109); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取实现接口 | 
|---|
|  |  |  | ApiRemoteService apiRemoteService = apiPushManager.getApiRemoteService(param.getPushProtocol()); | 
|---|
|  |  |  | ApiRemoteService apiRemoteService = apiPushManager.getApiRemoteService(apiConf.getPushProtocol()); | 
|---|
|  |  |  | if (null == apiRemoteService) return "系统没有当前推送协议配置,执行失败"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return pushDataSingle(items,apiRemoteService,apiConf); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 单条数据json推送 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param items | 
|---|
|  |  |  | * @param apiRemoteService | 
|---|
|  |  |  | * @param apiConf | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String pushDataSingle(List<Api1109> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { | 
|---|
|  |  |  | ResponseDto responseDto; | 
|---|
|  |  |  | String result = ""; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装参数 | 
|---|
|  |  |  | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1109); | 
|---|
|  |  |  | Api1109 d; | 
|---|
|  |  |  | for (Api1109 data : items) { | 
|---|
|  |  |  | d = new Api1109(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data, d); | 
|---|
|  |  |  | 
|---|
|  |  |  | result += responseDto.toString(); | 
|---|
|  |  |  | if (responseDto.getSuccess() == 0) { | 
|---|
|  |  |  | if (Constant.CZBZ_I.equals(d.getCzbz())) { | 
|---|
|  |  |  | api1109Rep.updateStatus(data.getKqdm(), Constant.CZBZ_U); | 
|---|
|  |  |  | api1109Rep.updateStatus(data.getId(), Constant.CZBZ_U); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 多条数据json推送 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param items | 
|---|
|  |  |  | * @param apiRemoteService | 
|---|
|  |  |  | * @param apiConf | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String pushDataList(List<Api1109> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装参数 | 
|---|
|  |  |  | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1109); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //推送,数据为集合形式 | 
|---|
|  |  |  | ResponseDto responseDto = apiRemoteService.pushData(param, apiConf, items); | 
|---|
|  |  |  | if (responseDto.getSuccess() == 0) { | 
|---|
|  |  |  | //推送成功,更新数据上传状态 | 
|---|
|  |  |  | for (Api1109 data : items) { | 
|---|
|  |  |  | if (Constant.CZBZ_I.equals(data.getCzbz())) { | 
|---|
|  |  |  | //更新状态 | 
|---|
|  |  |  | api1109Rep.updateStatus(data.getId(), Constant.CZBZ_U); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return responseDto.toString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * imgFile 图片本地存储路径 | 
|---|