/*
 * 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.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;

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

    public String updateUser(@Param("user") 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.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.getSignature() != null && StringUtils.isNotBlank(user.getSignature())) {
            sb.append("signature = #{user.signature}, ");
        }
        if (user.getPhoneType() != null && StringUtils.isNotBlank(user.getPhoneType())) {
            sb.append("phone_type = #{user.phoneType}, ");
        }
        if (user.getUpdateTime() != null) {
            sb.append("update_time = #{user.updateTime}, ");
        }
        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.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.isRegisterNetease}, ");
        }
        if (user.getUserType() != null && StringUtils.isNotBlank(user.getUserType())) {
            sb.append("user_type = #{user.userType}, ");
        }
        if (user.getShopsUserId() != null && user.getShopsUserId() > 0) {
            sb.append("shops_user_id = #{user.shopsUserId}, ");
        }
        if (user.getNeteaseToken() != null && StringUtils.isNotBlank(user.getNeteaseToken())) {
            sb.append("netease_token = #{user.neteaseToken}, ");
        }
        if (user.getIsRegisterNetease() != null && StringUtils.isNotBlank(user.getIsRegisterNetease())) {
            sb.append("is_register_netease = #{user.isRegisterNetease}, ");
        }
        if (user.getLatitude() != null && user.getLatitude() > 0) {
            sb.append("latitude = #{user.latitude}, ");
        }
        if (user.getLongitude() != null && user.getLongitude() > 0) {
            sb.append("latitude = #{iser.latitude}, ");
        }
        if (sb.lastIndexOf(",") == sb.length() - 1) {
            sb.deleteCharAt(sb.length() - 1);
        }
        sb.append(" WHERE user_id = #{user.userId}");
        return sb.toString();
    }

}
