/**
* 文件：ValidCodeServiceImpl.java
* 版本：1.0.0
* 日期：
* Copyright &reg; 
* All right reserved.
*/

package com.mortals.xhx.base.system.valid.service.impl;

import com.mortals.framework.common.code.ValidCodeType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.SecurityCode;
import com.mortals.xhx.base.system.valid.dao.ValidCodeDao;
import com.mortals.xhx.base.system.valid.model.ValidCodeEntity;
import com.mortals.xhx.base.system.valid.model.ValidCodeQuery;
import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import org.springframework.stereotype.Service;

import java.util.Calendar;

/**
 * <p>Title: 验证码信息</p>
 * <p>Description: ValidCodeServiceImpl service接口 </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 * @author 
 * @version 1.0.0
 */
@Service("validCodeService")
public class ValidCodeServiceImpl extends AbstractCRUDServiceImpl<ValidCodeDao,ValidCodeEntity,Long> implements ValidCodeService {

    @Override
    public String createImageValidCode(String sessionId, String ip) throws AppException {
        String code = SecurityCode.getSecurityCode();
        Calendar cal = Calendar.getInstance();
        ValidCodeEntity entity = new ValidCodeEntity();
        entity.setType(ValidCodeType.IMAGE.getValue());
        entity.setCode(code);
        entity.setSessionId(sessionId);
        entity.setIp(ip);
        entity.setCreateTime(cal.getTime());
        cal.add(Calendar.MINUTE, 10);
        entity.setLapseTime(cal.getTime());
        dao.insert(entity);
        return code;
    }

    @Override
    public boolean doCheckImageValidCode(String sessionId, String ip, String code) throws AppException {
        ValidCodeQuery condition = new ValidCodeQuery();
        condition.setSessionId(sessionId);
        condition.setCode(code);
        int result = dao.delete(condition);
        return result > 0;
    }

    @Override
    public boolean createSmsValidCode(String sessionId, String ip, String mobile) throws AppException {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean doCheckSmsValidCode(String sessionId, String ip, String mobile, String code) throws AppException {
        // TODO Auto-generated method stub
        return false;
    }
	
}