需求:用户在登录NC系统时 可以进行手机短信提醒
手机号用户可以自己进行维护。
思路:NC65有一个个性化中心 里面有个邮箱绑定功能
因而可以根据邮箱绑定的功能 添加一个手机号绑定功能
效果如下:
系统案例
手机号案例:
具体步骤:
1、寻找邮箱绑定源码 登录集团账号 找到邮箱绑定的注册类
nc.individuation.defaultData.MailBingPage(可以去studio去搜索找到在哪个模块下)
2、在studio下搜索编译后的文件 找到对应的.class文件
3、模仿邮箱绑定的功能 调整为手机号绑定功能
源码如下:
package nc.individuation.defaultData;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import nc.bs.framework.common.NCLocator;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.individuation.property.pub.AbstractIndividuationPage;
import nc.itf.fdgyl.IFdDBService;
import nc.ui.pub.beans.UILabel;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UIPasswordField;
import nc.ui.pub.beans.UITextField;
import nc.ui.tools.query.PubTools;
import nc.vo.pub.BusinessException;
import nc.vo.sm.UserVO;
import com.borland.jbcl.layout.VerticalFlowLayout;
public class MobileBingPage extends AbstractIndividuationPage implements nc.pubitf.setting.defaultdata.IUAPDefaultSettingConst, nc.individuation.property.pub.IExceptionHandler {
private static final long serialVersionUID = 1L;
private UILabel mobilePromptUL;
private UserVO currentUser;
private UITextField mobileTfd;
private UIPanel mobilePanel;
private UILabel mobileUL;
private UILabel promotUL1;
private UILabel promotUL2;
private UIPanel up1;
private UIPanel up2;
private String mobileValue;
private UIPanel pwdPanel;
private UILabel pwdPromptUL;
private UIPasswordField pwdTfd;
private String password;
public MobileBingPage()
{
this.currentUser = WorkbenchEnvironment.getInstance().getLoginUser();
initUI();
}
private void initUI() {
setLayout(new VerticalFlowLayout());
createElementDiff();
initMobilePanel();
initPwdPanel();
initPromotPanel();
add(new UIPanel());
add(this.up1);
add(this.up2);
add(new UIPanel());
add(this.mobilePanel);
// add(this.pwdPanel);
}
private void createElementDiff()
{
this.mobilePromptUL = new UILabel();
this.mobilePromptUL.setPreferredSize(new Dimension(80, 20));
this.mobilePromptUL.setHorizontalAlignment(4);
if (this.currentUser.getUser_note() == null) {
// this.promotUL1 = new UILabel("为了你的账户安全,请绑定手机号。绑定时需要提供系统密码以确定身份");
this.promotUL1 = new UILabel("为了你的账户安全,请绑定手机号。");
this.mobileUL = new UILabel();
this.promotUL2 = new UILabel("");
this.mobilePromptUL.setText("手机号");
}
else {
this.promotUL1 = new UILabel("您已成功绑定手机号:");
this.mobileUL = new UILabel(this.currentUser.getUser_note());
// this.promotUL2 = new UILabel("输入新手机号可以更改绑定手机号。更改手机号时需要您提供系统登录密码以确定您的身份。");
this.promotUL2 = new UILabel("输入新手机号可以更改绑定手机号。");
this.mobilePromptUL.setText("新手机号");
}
this.mobileUL.setFont(new Font("宋体", 1, 12));
}
private void initMobilePanel()
{
this.mobilePanel = new UIPanel();
this.mobilePanel.setOpaque(false);
this.mobilePanel.setLayout(new FlowLayout(3, 40, 5));
this.mobileTfd = new UITextField();
this.mobileTfd.setPreferredSize(new Dimension(200, 20));
this.mobilePanel.add(this.mobilePromptUL);
this.mobilePanel.add(this.mobileTfd);
}
private void initPwdPanel()
{
this.pwdPanel = new UIPanel();
this.pwdPanel.setOpaque(false);
this.pwdPanel.setLayout(new FlowLayout(3, 40, 5));
this.pwdPromptUL = new UILabel();
this.pwdPromptUL.setText("系统登录密码");
this.pwdPromptUL.setPreferredSize(new Dimension(80, 20));
this.pwdPromptUL.setHorizontalAlignment(4);
this.pwdPanel.add(this.pwdPromptUL);
this.pwdTfd = new UIPasswordField();
this.pwdTfd.setPreferredSize(new Dimension(200, 20));
this.pwdPanel.add(this.pwdTfd);
}
private void initPromotPanel()
{
this.up1 = new UIPanel();
this.up1.setLayout(new FlowLayout(3, 20, 0));
this.up2 = new UIPanel();
this.up2.setLayout(new FlowLayout(3, 20, 0));
this.up1.add(this.promotUL1);
this.up1.add(this.mobileUL);
this.up2.add(this.promotUL2);
}
/**
* 应用
*/
public void onApply()throws Exception
{
getViewValues();
validateInput();
doUpdateMobile();
}
public void onOK()throws Exception
{
if (isEditStatus()) {
onApply();
}
else
super.onCancel();
}
private boolean isEditStatus()
{
boolean isEditing = true;
if ("".equals(this.mobileTfd.getText().trim()))
{
isEditing = false;
}
return isEditing;
}
private void getViewValues()
{
this.mobileValue = this.mobileTfd.getText();
this.password = new String(this.pwdTfd.getPassword());
}
private boolean validateMobileForm(String mobile)
{
boolean flag = false;
try {
String check = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(mobile);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
private void validateInput() throws BusinessException
{
if (!validateMobileForm(this.mobileValue))
throw new BusinessException("手机号格式错误!请检查!");
}
private void doUpdateMobile()throws BusinessException
{
updateMobile();
updateView();
this.currentUser.setUser_note(this.mobileValue);
}
private void updateMobile() throws BusinessException
{
Properties p = PubTools.getParameterInfo();
String design = p.getProperty("design");
StringBuffer sbup = new StringBuffer();
String sql = " update sm_user set user_note ='"+this.mobileValue+"' where user_code = '"+currentUser.getUser_code()+"';";
sbup.append(sql);
try {
this.getFdDBService().updateDatas(sbup,design);
} catch (BusinessException e) {
e.printStackTrace();
}
}
public IFdDBService getFdDBService() {
IFdDBService fddbService = NCLocator.getInstance().lookup(
IFdDBService.class);
return fddbService;
}
private void updateView()
{
this.mobileUL.setText(this.mobileValue);
this.mobilePromptUL.setText("新手机号");
this.promotUL1.setText("您已成功绑定手机号:");
this.promotUL2.setText("输入新手机号可以更改绑定手机号。");
this.mobileTfd.setText(null);
this.pwdTfd.setText(null);
}
@Override
public String getDescription() {
return "绑定手机号可用于登录时提示手机短消息,增加您账户的安全性。";
}
@Override
public String getTitle() {
return "手机号绑定";
}
@Override
public void handleException(Throwable arg0) {
// TODO 自动生成的方法存根
}
}
4、把新增的类注册到个性化中心下
5、重启服务器 (注:新增类 个性化中心 注册后 一定要重启服务器才生效)
6、手机号的存放的位置 用户的备注字段
效果图:
7、测试功能
总结: studio调试的时候 是立即生效的 但是打补丁到nchome下modules后 一定要重启服务器才生效