package com.zteits.pay.biz; import com.github.pagehelper.PageInfo; import com.xiaoleilu.hutool.util.BeanUtil; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.bean.PageBean; import com.zteits.clouds.api.apibase.constants.ErrorType; import com.zteits.clouds.api.apibase.exception.BizException; import com.zteits.clouds.api.dto.pay.AppVersionDTO; import com.zteits.clouds.api.dto.pay.param.AppVersionQueryForPageReq; import com.zteits.clouds.api.dto.pay.param.AppVersionRequest; import com.zteits.clouds.api.dto.pay.param.AppVersionSaveReq; import com.zteits.clouds.api.dto.pay.param.AppVersionUpdateByIdReq; import com.zteits.clouds.api.service.pay.AppVersionService; import com.zteits.pay.dao.AppVersionDao; import com.zteits.pay.domain.AppVersion; import com.zteits.pay.pagepager.PageBeanUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @Component public class AppVersionServiceImpl implements AppVersionService { @Autowired private AppVersionDao appVersionDao; @Override public BizResult checkAppVersion(AppVersionRequest appVersionRequest) { AppVersionDTO appVersionDTO = null; AppVersion appVersion = appVersionDao.checkVersionByAppType(Integer.parseInt(appVersionRequest.getAppType())); if (appVersion != null) { appVersionDTO = new AppVersionDTO(); BeanUtil.copyProperties(appVersion, appVersionDTO); } return new BizResult(appVersionDTO); } @Override public BizResult saveAppVersion(AppVersionSaveReq req) { if (null == req.getData()) { throw new BizException(ErrorType.PARAMM_NULL, "待保存数据"); } if (null == req.getData().getAppName()) { throw new BizException(ErrorType.PARAMM_NULL, "APP名称"); } if (null == req.getData().getAppType()) { throw new BizException(ErrorType.PARAMM_NULL, "APP类型"); } if (null == req.getData().getAppUrl()) { throw new BizException(ErrorType.PARAMM_NULL, "APP发布URL"); } if (null == req.getData().getDownType()) { throw new BizException(ErrorType.PARAMM_NULL, "APP更新类型"); } if (null == req.getData().getVersion()) { throw new BizException(ErrorType.PARAMM_NULL, "APP版本号"); } if (null == req.getData().getRemark()) { throw new BizException(ErrorType.PARAMM_NULL, "APP发布内容"); } AppVersion appVersion = new AppVersion(); BeanUtils.copyProperties(req.getData(), appVersion); Integer num = appVersionDao.saveAppVersion(appVersion); return new BizResult<>(num); } @Override public BizResult updateAppVersionById(AppVersionUpdateByIdReq req) { if (null == req.getData()) { throw new BizException(ErrorType.PARAMM_NULL, "待保存数据"); } if (null == req.getData().getId()) { throw new BizException(ErrorType.PARAMM_NULL, "主键ID"); } if (null == req.getData().getAppName()) { throw new BizException(ErrorType.PARAMM_NULL, "APP名称"); } if (null == req.getData().getAppType()) { throw new BizException(ErrorType.PARAMM_NULL, "APP类型"); } if (null == req.getData().getAppUrl()) { throw new BizException(ErrorType.PARAMM_NULL, "APP发布URL"); } if (null == req.getData().getDownType()) { throw new BizException(ErrorType.PARAMM_NULL, "APP更新类型"); } if (null == req.getData().getVersion()) { throw new BizException(ErrorType.PARAMM_NULL, "APP版本号"); } if (null == req.getData().getRemark()) { throw new BizException(ErrorType.PARAMM_NULL, "APP发布内容"); } AppVersion appVersion = new AppVersion(); BeanUtils.copyProperties(req.getData(), appVersion); Integer num = appVersionDao.updateAppVersionById(appVersion); return new BizResult<>(num); } @Override public BizResult> queryAppVersionForPage(AppVersionQueryForPageReq req) { if (CollectionUtils.isEmpty(req.getAppTypes())) { throw new BizException(ErrorType.PARAMM_NULL, "APP类型"); } PageInfo pageInfo = appVersionDao.queryAppVersionForPage(req); PageBean pageBean = new PageBean<>(); PageBeanUtil.copyProperties(pageInfo, pageBean, AppVersionDTO.class); return new BizResult<>(pageBean); } }