/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.mapper;

import com.ifish.bean.Tbl_User;
import org.apache.ibatis.annotations.Param;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author Administrator
 */
public class Tbl_User_MapperSql {

    public String updateUser(@Param("user") Tbl_User user) {
        StringBuilder sb = new StringBuilder();

        sb.append("Update tbl_User SET ");
        if (user.getNickName() != null && StringUtils.isNotBlank(user.getNickName())) {
            sb.append("nick_name = #{user.nickName}, ");
        }
        if (user.getUserPassword() != null && StringUtils.isNotBlank(user.getUserPassword())) {
            sb.append("user_password = #{user.userPassword}, ");
        }
        if (user.getPhoneNumber() != null && StringUtils.isNotBlank(user.getPhoneNumber())) {
            sb.append("phone_number = #{user.phoneNumber}, ");
        }
        if (user.getUserEmail() != null && StringUtils.isNotBlank(user.getUserEmail())) {
            sb.append("user_email = #{user.userEmail}, ");
        }
//        if (user.getUserType() != null && StringUtils.isNotBlank(user.getUserType())) {
//            sb.append("user_type = #{user.userType}, ");
//        }
        if (user.getUserImg() != null && StringUtils.isNotBlank(user.getUserImg())) {
            sb.append("user_img = #{user.userImg}, ");
        }
        if (user.getUserSex() != null && StringUtils.isNotBlank(user.getUserSex())) {
            sb.append("user_sex = #{user.userSex}, ");
        }
        if (user.getLoginTime() != null) {
            sb.append("login_time = #{user.loginTime}, ");
        }
        //注册时间不予修改
        if (user.getLoginType() != null && StringUtils.isNotBlank(user.getLoginType())) {
            sb.append("login_type = #{user.loginType}, ");
        }
        if (user.getRemarks() != null && StringUtils.isNotBlank(user.getRemarks())) {
            sb.append("remarks = #{user.remarks}, ");
        }
        if (user.getAddress() != null && StringUtils.isNotBlank(user.getAddress())) {
            sb.append("address = #{user.address}, ");
        }
        if (user.getP2pverifyCode1() != null && StringUtils.isNotBlank(user.getP2pverifyCode1())) {
            sb.append("p2pverify_code1 = #{user.p2pverifyCode1}, ");
        }
        if (user.getP2pverifyCode2() != null && StringUtils.isNotBlank(user.getP2pverifyCode2())) {
            sb.append("p2pverify_code2 = #{user.p2pverifyCode2}, ");
        }
        if (user.getGwellUserid() != null && StringUtils.isNotBlank(user.getGwellUserid())) {
            sb.append("gwell_userid = #{user.gwellUserid}, ");
        }
        if (user.getIsRegisterGwell() != null && StringUtils.isNotBlank(user.getIsRegisterGwell())) {
            sb.append("is_register_gwell = #{user.isRegisterGwell}, ");
        }
        if (user.getJiguangUserid() != null && StringUtils.isNotBlank(user.getJiguangUserid())) {
            sb.append("jiguang_userID = #{user.jiguangUserid}, ");
        }
        if (user.getLatitude() != null && user.getLatitude() > 0) {
            sb.append("latitude = #{user.latitude}, ");
        }
        if (user.getLongitude() != null && user.getLongitude() > 0) {
            sb.append("longitude = #{iser.longitude}, ");
        }
        sb.append("update_time = NOW() ");
        sb.append(" WHERE user_id = #{user.userId}");
        return sb.toString();
    }

    /**
     * 游客注册接口
     *
     * @param user
     * @return
     */
    public String registerUserByTourist(@Param("user") Tbl_User user) {
        StringBuilder sb = new StringBuilder();

        sb.append("INSERT tbl_user (user_type,token) value ('0',#{user.token})");

        return sb.toString();
    }
}
