¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.otherview.gd2022.pr; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson2.JSON; |
| | | 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.Api9201; |
| | | 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.api.utils.ContextUtil; |
| | | import com.fzzy.api.view.repository.Api9201Rep; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1023Dtl; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1023People; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1023Way; |
| | | 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; |
| | | |
| | | /** |
| | | * 广ä¸çæ¥å£-9201 çè¸å¤æ¡ |
| | | * |
| | | * @author czt |
| | | * @date 2023/8/17 |
| | | */ |
| | | @Component(value = "gDApi9201PR") |
| | | public class GDApi9201PR { |
| | | |
| | | @Autowired |
| | | private Api9201Rep api9201Rep; |
| | | |
| | | @Autowired |
| | | private ApiCommonService apiCommonService; |
| | | |
| | | @Autowired |
| | | private ApiPushManager apiPushManager; |
| | | |
| | | /** |
| | | * gDApi9201PR#pageList |
| | | * |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public void pageList(Page<Api9201> page, ApiParam param) { |
| | | |
| | | //å¤åæ°å页æ¥è¯¢ |
| | | Pageable pageable = PageRequest.of(page.getPageNo() - 1, page.getPageSize(), Sort.Direction.DESC, "id"); |
| | | |
| | | if (null == param) { |
| | | org.springframework.data.domain.Page<Api9201> japPage = api9201Rep.findAll(pageable); |
| | | page.setEntityCount((int) japPage.getTotalElements()); |
| | | |
| | | for (Api9201 api9201 : japPage.getContent()) { |
| | | api9201.setDtls(JSONArray.parseArray(api9201.getDtl(), Gd2022Api1023Dtl.class)); |
| | | api9201.setPeoples(JSONArray.parseArray(api9201.getPeople(), Gd2022Api1023People.class)); |
| | | api9201.setWays(JSONArray.parseArray(api9201.getWay(), Gd2022Api1023Way.class)); |
| | | } |
| | | page.setEntities(japPage.getContent()); |
| | | |
| | | return; |
| | | } |
| | | |
| | | Specification<Api9201> specification = new Specification<Api9201>() { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public Predicate toPredicate(Root<Api9201> root, CriteriaQuery<?> query, CriteriaBuilder cb) { |
| | | List<Predicate> predicates = new ArrayList<>(); //ææçæè¨ |
| | | |
| | | if (StringUtils.isNotBlank(param.getKqdm())) { |
| | | Predicate predicate1 = cb.equal(root.get("hwdm"), 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("ywrq"), ContextUtil.getCurZero(param.getStart())); |
| | | predicates.add(predicate3); |
| | | } |
| | | |
| | | if (null != param.getEnd()) { |
| | | Predicate predicate4 = cb.lessThan(root.get("ywrq"), ContextUtil.getNextZero(param.getEnd())); |
| | | predicates.add(predicate4); |
| | | } |
| | | return cb.and(predicates.toArray(new Predicate[0])); |
| | | } |
| | | }; |
| | | |
| | | org.springframework.data.domain.Page<Api9201> japPage = api9201Rep.findAll(specification, pageable); |
| | | page.setEntityCount((int) japPage.getTotalElements()); |
| | | for (Api9201 api9201 : japPage.getContent()) { |
| | | api9201.setDtls(JSONArray.parseArray(api9201.getDtl(), Gd2022Api1023Dtl.class)); |
| | | api9201.setPeoples(JSONArray.parseArray(api9201.getPeople(), Gd2022Api1023People.class)); |
| | | api9201.setWays(JSONArray.parseArray(api9201.getWay(), Gd2022Api1023Way.class)); |
| | | } |
| | | page.setEntities(japPage.getContent()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * gDApi9201PR#updateSave |
| | | * |
| | | * @param entity |
| | | */ |
| | | @DataResolver |
| | | public void updateSave(Api9201 entity) { |
| | | |
| | | // æå¨å°doradoEntity对象转æ¢ä¸ºæ åBean对象 |
| | | Api9201 data = new Api9201(); |
| | | BeanUtils.copyProperties(entity, data); |
| | | data.setDtl(JSON.toJSONString(data.getDtls())); |
| | | data.setPeople(JSON.toJSONString(data.getPeoples())); |
| | | data.setWay(JSON.toJSONString(data.getWays())); |
| | | data.setKqdm(data.getKqdm().trim()); |
| | | api9201Rep.save(data); |
| | | } |
| | | |
| | | /** |
| | | * gDApi9201PR#delData |
| | | * |
| | | * @param data |
| | | */ |
| | | @Expose |
| | | public String delData(Api9201 data) { |
| | | |
| | | api9201Rep.deleteById(data.getId()); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°å 餿 è®° gDApi9201PR#delUpdate |
| | | * |
| | | * @param entity |
| | | */ |
| | | @Expose |
| | | public String delUpdate(Api9201 entity) { |
| | | |
| | | entity.setCzbz(Constant.CZBZ_D); |
| | | |
| | | Api9201 data = new Api9201(); |
| | | BeanUtils.copyProperties(entity, data); |
| | | |
| | | api9201Rep.save(data); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * gDApi9201PR#pushData |
| | | * |
| | | * @param items |
| | | */ |
| | | @Expose |
| | | public String pushData(List<Api9201> items) { |
| | | |
| | | //è·åé
ç½® |
| | | String kqdm = items.get(0).getKqdm(); |
| | | ApiConfs apiConf = apiCommonService.getConf(kqdm); |
| | | |
| | | if (null == apiConf) { |
| | | return "ç³»ç»æ²¡æè·åå°å½ååºåºé
置信æ¯ï¼æ§è¡å¤±è´¥"; |
| | | } |
| | | |
| | | //è·åå®ç°æ¥å£ |
| | | 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<Api9201> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { |
| | | ResponseDto responseDto; |
| | | String result = ""; |
| | | |
| | | //å°è£
åæ° |
| | | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_13, Constant.API_CODE_9201); |
| | | |
| | | Api9201 d; |
| | | for (Api9201 data : items) { |
| | | d = new Api9201(); |
| | | BeanUtils.copyProperties(data, d); |
| | | param.setBizId(data.getBizId()); |
| | | responseDto = apiRemoteService.pushData(param, apiConf, d); |
| | | |
| | | result += responseDto.toString(); |
| | | if (responseDto.getSuccess() == 0) { |
| | | if (Constant.CZBZ_I.equals(d.getCzbz())) { |
| | | api9201Rep.updateStatus(data.getDwdm(), Constant.CZBZ_U); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * éå形弿¨é |
| | | * |
| | | * @param items |
| | | * @param apiRemoteService |
| | | * @param apiConf |
| | | * @return |
| | | */ |
| | | private String pushDataList(List<Api9201> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { |
| | | |
| | | //å°è£
åæ° |
| | | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_13, Constant.API_CODE_9201); |
| | | |
| | | |
| | | //æ¨éï¼æ°æ®ä¸ºéåå½¢å¼ |
| | | ResponseDto responseDto = apiRemoteService.pushData(param, apiConf, items); |
| | | if (responseDto.getSuccess() == 0) { |
| | | //æ¨éæåï¼æ´æ°æ°æ®ä¸ä¼ ç¶æ |
| | | for (Api9201 data : items) { |
| | | if (Constant.CZBZ_I.equals(data.getCzbz())) { |
| | | //æ´æ°ç¶æ |
| | | api9201Rep.updateStatus(data.getDwdm(), Constant.CZBZ_U); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return responseDto.toString(); |
| | | } |
| | | |
| | | } |