|
@@ -1,6 +1,7 @@
|
|
|
package com.webchat.pay.service;
|
|
|
|
|
|
|
|
|
+import com.webchat.common.bean.APIPageResponseBean;
|
|
|
import com.webchat.common.constants.WebConstant;
|
|
|
import com.webchat.common.enums.CommonStatusEnum;
|
|
|
import com.webchat.common.enums.RedisKeyEnum;
|
|
@@ -13,13 +14,22 @@ import com.webchat.domain.vo.response.payment.AppBaseResponseVO;
|
|
|
import com.webchat.domain.vo.response.payment.CreateAppResponseVO;
|
|
|
import com.webchat.pay.repository.dao.IAppDAO;
|
|
|
import com.webchat.pay.repository.entity.AppEntity;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class PaymentAppService {
|
|
|
|
|
@@ -110,6 +120,61 @@ public class PaymentAppService {
|
|
|
return createAppResponseVO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 发布应用
|
|
|
+ * @param appId
|
|
|
+ */
|
|
|
+ public void publishApp(Long appId) {
|
|
|
+
|
|
|
+ this.updateAppStatus(appId, CommonStatusEnum.PUBLISHED);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 删除应用
|
|
|
+ * @param appId
|
|
|
+ */
|
|
|
+ public void deleteApp(Long appId) {
|
|
|
+
|
|
|
+ this.updateAppStatus(appId, CommonStatusEnum.DELETED);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAppStatus(Long appId, CommonStatusEnum status) {
|
|
|
+ AppEntity appEntity = appDAO.findById(appId).orElse(null);
|
|
|
+ Assert.notNull(appEntity, "状态修改失败: 应用不存在");
|
|
|
+ appEntity.setStatus(status.getStatusCode());
|
|
|
+ appDAO.save(appEntity);
|
|
|
+
|
|
|
+ this.refreshAppInfoCache(appEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询应用列表
|
|
|
+ *
|
|
|
+ * @param keywords
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public APIPageResponseBean<AppBaseResponseVO> page(String keywords, Integer pageNo, Integer pageSize) {
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(Sort.Direction.DESC, "id"));
|
|
|
+ List<Integer> statusList = new ArrayList<>();
|
|
|
+ statusList.add(CommonStatusEnum.NEW.getStatusCode());
|
|
|
+ statusList.add(CommonStatusEnum.PUBLISHED.getStatusCode());
|
|
|
+
|
|
|
+ Page<AppEntity> appEntities;
|
|
|
+ if (StringUtils.isBlank(keywords)) {
|
|
|
+ appEntities = appDAO.findAllByStatusIn(statusList, pageable);
|
|
|
+ } else {
|
|
|
+ appEntities = appDAO.findAllByNameLikeAndStatusIn("%" + keywords + "%", statusList, pageable);
|
|
|
+ }
|
|
|
+ List<AppBaseResponseVO> vos = new ArrayList<>();
|
|
|
+ if (appEntities != null && CollectionUtils.isNotEmpty(appEntities.getContent())) {
|
|
|
+ vos = appEntities.getContent().stream().map(this::covertResponseVo).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return APIPageResponseBean.success(pageNo, pageSize, appEntities.getTotalElements(), vos);
|
|
|
+ }
|
|
|
+
|
|
|
private AppBaseResponseVO covertResponseVo(AppEntity appEntity) {
|
|
|
AppBaseResponseVO response = new AppBaseResponseVO();
|
|
|
BeanUtils.copyProperties(appEntity, response);
|
|
@@ -194,7 +259,8 @@ public class PaymentAppService {
|
|
|
appEntity = new AppEntity();
|
|
|
appEntity.setAdmin(createAppRequest.getUserId());
|
|
|
appEntity.setCreateBy(createAppRequest.getUserId());
|
|
|
- appEntity.setStatus(CommonStatusEnum.NEW.getStatusCode());
|
|
|
+
|
|
|
+ appEntity.setStatus(CommonStatusEnum.PUBLISHED.getStatusCode());
|
|
|
}
|
|
|
appEntity.setLogo(createAppRequest.getLogo());
|
|
|
appEntity.setName(createAppRequest.getName());
|