| | |
| | | package com.fzzy.otherview.gd2022.pr; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.Constant; |
| | | import com.fzzy.api.data.ApiParam; |
| | | import com.fzzy.api.dto.ResponseDto; |
| | | import com.fzzy.api.entity.ApiConfs; |
| | | import com.fzzy.api.entity.ApiInfoData; |
| | | import com.fzzy.api.service.ApiCommonService; |
| | | import com.fzzy.api.service.ApiPushManager; |
| | | import com.fzzy.api.service.ApiRemoteService; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.view.repository.ApiInfoDataRep; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1023; |
| | | import com.fzzy.push.gd2022.ApiCodeConstant; |
| | | import org.apache.commons.lang.StringUtils; |
| | | 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.*; |
| | | |
| | | /** |
| | | * 广东省接口-1023 熏蒸备案 |
| | |
| | | * @author czt |
| | | * @date 2023/8/17 |
| | | */ |
| | | @Component |
| | | @Component(value = "gDApi1023PR") |
| | | public class GDApi1023PR { |
| | | |
| | | @Autowired |
| | | private ApiCommonService apiCommonService; |
| | | @Autowired |
| | | private ApiPushManager apiPushManager; |
| | | @Autowired |
| | | private ApiInfoDataRep apiInfoDataRep; |
| | | |
| | | /** |
| | | * 获取熏蒸备案主表信息 |
| | | * gDApi1023PR#listData |
| | | * |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public void listData(Page<Gd2022Api1023> page, ApiParam param) { |
| | | |
| | | Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, "updateTime"); |
| | | |
| | | Specification specification = new Specification<ApiInfoData>() { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Override |
| | | public Predicate toPredicate(Root<ApiInfoData> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { |
| | | List<Predicate> predicates = new ArrayList<>(); //所有的断言 |
| | | Predicate predicate = criteriaBuilder.equal(root.get("inteId"), ApiCodeConstant.API_1023); |
| | | predicates.add(predicate); |
| | | if (null != param) { |
| | | if (StringUtils.isNotBlank(param.getKqdm())) { |
| | | Predicate predicate1 = criteriaBuilder.equal(root.get("kqdm"), param.getKqdm()); |
| | | predicates.add(predicate1); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(param.getCzbz())) { |
| | | Predicate predicate2 = criteriaBuilder.equal(root.get("czbz"), param.getCzbz()); |
| | | predicates.add(predicate2); |
| | | } |
| | | if (null != param.getStart()) { |
| | | Predicate predicate3 = criteriaBuilder.greaterThan(root.get("updateTime"), ContextUtil.getCurZero(param.getStart())); |
| | | predicates.add(predicate3); |
| | | } |
| | | |
| | | if (null != param.getEnd()) { |
| | | Predicate predicate4 = criteriaBuilder.lessThan(root.get("updateTime"), ContextUtil.getNextZero(param.getEnd())); |
| | | predicates.add(predicate4); |
| | | } |
| | | } |
| | | return criteriaBuilder.and(predicates.toArray(new Predicate[0])); |
| | | } |
| | | }; |
| | | org.springframework.data.domain.Page<ApiInfoData> japPage = apiInfoDataRep.findAll(specification, pageable); |
| | | page.setEntityCount((int) japPage.getTotalElements()); |
| | | List<Gd2022Api1023> list = new ArrayList<>(); |
| | | Gd2022Api1023 GD2022Api1023; |
| | | for (ApiInfoData infoData : japPage.getContent()) { |
| | | GD2022Api1023 = JSONObject.parseObject(infoData.getData(), Gd2022Api1023.class); |
| | | list.add(GD2022Api1023); |
| | | } |
| | | page.setEntities(list); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * gDApi1023PR#saveData |
| | | */ |
| | | @DataResolver |
| | | public void saveData(Gd2022Api1023 data) { |
| | | ApiInfoData infoData; |
| | | List<ApiInfoData> apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), data.getKqdm()); |
| | | if (apiInfoList.size() != 0) { |
| | | infoData = apiInfoList.get(0); |
| | | infoData.setData(JSON.toJSONString(data)); |
| | | } else { |
| | | infoData = new ApiInfoData(); |
| | | infoData.setId(data.getXzbm()); |
| | | infoData.setKqdm(data.getKqdm()); |
| | | infoData.setInteId(ApiCodeConstant.API_1023); |
| | | infoData.setUpdateTime(new Date()); |
| | | infoData.setDataId(data.getXzbm()); |
| | | infoData.setData(JSON.toJSONString(data)); |
| | | infoData.setCzbz(Constant.CZBZ_I); |
| | | infoData.setRemarks("备注信息"); |
| | | } |
| | | apiInfoDataRep.save(infoData); |
| | | } |
| | | |
| | | /** |
| | | * gDApi1023PR#delData |
| | | */ |
| | | @Expose |
| | | public void delData(Gd2022Api1023 data) { |
| | | List<ApiInfoData> apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), data.getKqdm()); |
| | | apiInfoDataRep.deleteById(apiInfoList.get(0).getId()); |
| | | } |
| | | |
| | | /** |
| | | * gDApi1023PR#delUpdate |
| | | */ |
| | | @Expose |
| | | public String delUpdate(Gd2022Api1023 data) { |
| | | if (null == data) { |
| | | return "无数据执行"; |
| | | } |
| | | List<ApiInfoData> apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), data.getKqdm()); |
| | | data.setCzbz(Constant.CZBZ_D); |
| | | apiInfoDataRep.updateStatus(apiInfoList.get(0).getId(), JSON.toJSONString(data), Constant.CZBZ_D); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * gDApi1023PR#pushData |
| | | * |
| | | * @param items |
| | | * @return |
| | | */ |
| | | @Expose |
| | | public String pushData(List<Gd2022Api1023> items) { |
| | | ResponseDto responseDto; |
| | | String result = ""; |
| | | |
| | | String kqdm = items.get(0).getKqdm(); |
| | | ApiConfs apiConf = apiCommonService.getConf(kqdm); |
| | | |
| | | if (null == apiConf) { |
| | | return "系统没有获取到当前库区配置信息,执行失败"; |
| | | } |
| | | |
| | | //封装参数 |
| | | ApiParam param = new ApiParam(apiConf, "21", ApiCodeConstant.API_1023); |
| | | |
| | | //获取实现接口 |
| | | ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol()); |
| | | if (null == apiService) { |
| | | return "系统没有当前推送协议配置,执行失败"; |
| | | } |
| | | |
| | | ApiInfoData infoData; |
| | | for (Gd2022Api1023 data : items) { |
| | | //推送,数据为集合形式 |
| | | responseDto = apiService.pushData(param, apiConf, data); |
| | | if (responseDto.getSuccess() == 0) { |
| | | if (Constant.CZBZ_I.equals(data.getCzbz())) { |
| | | //推送成功,更新数据上传状态 |
| | | List<ApiInfoData> apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), data.getKqdm()); |
| | | data.setCzbz(Constant.CZBZ_U); |
| | | infoData = apiInfoList.get(0); |
| | | infoData.setUpdateTime(new Date()); |
| | | infoData.setCzbz(Constant.CZBZ_U); |
| | | infoData.setData(JSON.toJSONString(data)); |
| | | apiInfoDataRep.save(infoData); |
| | | } |
| | | } |
| | | result += responseDto.toString(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | } |