| | |
| | | package com.fzzy.otherview.sh2023.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.Api1204; |
| | | 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.otherview.whhpjl.WhjlConstant; |
| | | import com.fzzy.otherview.whhpjl.dto.WhjlApi1101; |
| | | import com.fzzy.push.sh2023.SH2023Constant; |
| | | import com.fzzy.push.sh2023.dto.SH2023Api2101; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateFormatUtils; |
| | | 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; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 上海市接口-2101 检斤单 |
| | |
| | | * @author czt |
| | | * @date 2023/8/17 |
| | | */ |
| | | @Component |
| | | @Component(value = "sHApi2101PR") |
| | | public class SHApi2101PR { |
| | | |
| | | @Autowired |
| | | private ApiInfoDataRep apiInfoDataRep; |
| | | @Autowired |
| | | private ApiCommonService apiCommonService; |
| | | @Autowired |
| | | private ApiPushManager apiPushManager; |
| | | |
| | | /** |
| | | * 获取信息 |
| | | * sHApi2101PR#listData |
| | | * |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public void listData(Page<SH2023Api2101> 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"), SH2023Constant.SH_2023_API_CODE_2101); |
| | | 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<SH2023Api2101> list = new ArrayList<>(); |
| | | SH2023Api2101 sh2023Api2101; |
| | | for (ApiInfoData infoData : japPage.getContent()) { |
| | | sh2023Api2101 = JSONObject.parseObject(infoData.getData(), SH2023Api2101.class); |
| | | list.add(sh2023Api2101); |
| | | } |
| | | page.setEntities(list); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * sHApi2101PR#saveData |
| | | */ |
| | | @DataResolver |
| | | public void saveData(SH2023Api2101 data) { |
| | | if (null == data.getPch() || data.getPch() == "") { |
| | | data.setPch(data.getHwdm() + DateFormatUtils.format(data.getJjrq(), "yyyy")); |
| | | } |
| | | ApiInfoData infoData = new ApiInfoData(); |
| | | infoData.setId(data.getJjdh()); |
| | | infoData.setKqdm(data.getKqdm()); |
| | | infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2101); |
| | | infoData.setUpdateTime(new Date()); |
| | | infoData.setDataId(data.getJjdh()); |
| | | infoData.setData(JSON.toJSONString(data)); |
| | | infoData.setCzbz(data.getCzbz()); |
| | | infoData.setRemarks("备注信息"); |
| | | |
| | | apiInfoDataRep.save(infoData); |
| | | } |
| | | |
| | | /** |
| | | * sHApi2101PR#delData |
| | | */ |
| | | @Expose |
| | | public void delData(SH2023Api2101 data) { |
| | | apiInfoDataRep.deleteById(data.getJjdh()); |
| | | } |
| | | |
| | | /** |
| | | * sHApi2101PR#delUpdate |
| | | */ |
| | | @Expose |
| | | public String delUpdate(SH2023Api2101 entity) { |
| | | if (null == entity) { |
| | | return "无数据执行"; |
| | | } |
| | | entity.setCzbz(Constant.CZBZ_D); |
| | | apiInfoDataRep.updateStatus(entity.getJjdh(), JSON.toJSONString(entity), Constant.CZBZ_D); |
| | | return null; |
| | | } |
| | | |
| | | @Expose |
| | | public String pushData(List<SH2023Api2101> 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", SH2023Constant.SH_2023_API_CODE_2101); |
| | | |
| | | //获取实现接口 |
| | | ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol()); |
| | | if (null == apiService) { |
| | | return "系统没有当前推送协议配置,执行失败"; |
| | | } |
| | | |
| | | //推送,数据为集合形式 |
| | | responseDto = apiService.pushData(param, apiConf, items); |
| | | if (responseDto.getSuccess() == 0) { |
| | | //推送成功,更新数据上传状态 |
| | | |
| | | ApiInfoData infoData; |
| | | for (SH2023Api2101 data : items) { |
| | | if (Constant.CZBZ_I.equals(data.getCzbz())) { |
| | | |
| | | infoData = new ApiInfoData(); |
| | | infoData.setId(data.getBizId()); |
| | | infoData.setKqdm(data.getKqdm()); |
| | | infoData.setInteType("21"); |
| | | infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2101); |
| | | infoData.setUpdateTime(new Date()); |
| | | infoData.setDataId(data.getBizId()); |
| | | |
| | | data.setCzbz(Constant.CZBZ_U); |
| | | infoData.setCzbz(Constant.CZBZ_U); |
| | | infoData.setData(JSON.toJSONString(data)); |
| | | |
| | | apiInfoDataRep.save(infoData); |
| | | } |
| | | } |
| | | result += responseDto.toString(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | } |