package io.hmit.modules.appointment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.sm.SMUtil;
import io.hmit.modules.appointment.dao.AppointmentOrderDao;
import io.hmit.modules.appointment.dto.AppointmentOrderDTO;
import io.hmit.modules.appointment.entity.AppointmentOrderEntity;
import io.hmit.modules.appointment.service.AppointmentOrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 预约订单表
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-02-13
 */
@Service
public class AppointmentOrderServiceImpl extends CrudServiceImpl<AppointmentOrderDao, AppointmentOrderEntity, AppointmentOrderDTO> implements AppointmentOrderService {

    @Override
    public QueryWrapper<AppointmentOrderEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String status = null !=params.get("status")?params.get("status").toString():"";

        QueryWrapper<AppointmentOrderEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(status), "status", status);

        return wrapper;
    }


    /**
     * <h2>对原始数据进行加密，请勿执行</h2>
     */
    @Override
    public void encryptOneTime() {
        List<AppointmentOrderEntity> appointmentList =
                baseDao.selectList(new QueryWrapper<AppointmentOrderEntity>().isNotNull("appointment_phone"));
        for (AppointmentOrderEntity appointmentOrderEntity : appointmentList) {
            appointmentOrderEntity.setAppointmentPhone(SMUtil.SM4Encrypt(appointmentOrderEntity.getAppointmentPhone()));
            appointmentOrderEntity.setAppointmentIdCard(SMUtil.SM4Encrypt(appointmentOrderEntity.getAppointmentIdCard()));
            baseDao.updateById(appointmentOrderEntity);
        }
    }
}
