AppVersionDaoImpl.java 2.81 KB
package com.zteits.pay.dao.impl;

import java.util.Date;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.pay.param.AppVersionQueryForPageReq;
import com.zteits.pay.dao.AppVersionDao;
import com.zteits.pay.domain.AppVersion;
import com.zteits.pay.domain.AppVersionExample;
import com.zteits.pay.domain.AppVersionExample.Criteria;
import com.zteits.pay.mapper.AppVersionMapper;
import com.zteits.pay.mapper.smapper.AppVersionSMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppVersionDaoImpl implements AppVersionDao {

    @Autowired
    private AppVersionSMapper appVersionSMapper;

    @Autowired
    private AppVersionMapper appVersionMapper;

    @Override
    public AppVersion checkVersionByAppType(Integer appType) {
        return appVersionSMapper.checkVersionByAppType(appType);
    }

    @Override
    public int saveAppVersion(AppVersion appVersion) {

        AppVersionExample example = new AppVersionExample();
        example.createCriteria().andAppTypeEqualTo(appVersion.getAppType());

        AppVersion updateVersion = new AppVersion();
        updateVersion.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
        updateVersion.setModfiyDate(new Date());
        updateVersion.setModfiyEmpid(appVersion.getCreateEmpid());
        appVersionMapper.updateByExampleSelective(updateVersion, example);

        return appVersionMapper.insertSelective(appVersion);
    }

    @Override
    public int updateAppVersionById(AppVersion appVersion) {

        if (null == appVersion.getId()) {
            throw new BizException(ErrorType.PARAMM_NULL, "主键ID");
        }

        appVersion.setModfiyDate(new Date());

        return appVersionMapper.updateByPrimaryKeySelective(appVersion);
    }

    @Override
    public PageInfo<AppVersion> queryAppVersionForPage(AppVersionQueryForPageReq req) {

        AppVersionExample example = new AppVersionExample();
        example.setOrderByClause(" create_date desc");
        Criteria sql = example.createCriteria().andAppTypeIn(req.getAppTypes());

        if (null != req.getCreateDateStart()) {
            sql.andCreateDateGreaterThanOrEqualTo(req.getCreateDateStart());
        }

        if (null != req.getCreateDateEnd()) {
            sql.andCreateDateLessThanOrEqualTo(req.getCreateDateEnd());
        }

        PageHelper.startPage(req.getBaseRequest().getPageNum(), req.getBaseRequest().getPageSize());
        List<AppVersion> list = appVersionMapper.selectByExample(example);

        return new PageInfo<>(list);
    }

}