业务账号的状态维护

1、业务账号状态分3种,分别是开通、暂停、删除,其基本操作和账务账号一致。重点关注的是它和账务账号状态的关系。
2、账务账号与业务账号状态的关系
    1)暂停账务账号,同时暂停其下属的所有业务账号
    2)删除账务账号,同时删除其下属的所有
    3)开通业务账号时,校验其对应的账务账号是否处于开通态,若不是,则不允许开通。

DAO:

public void pause(Integer id) throws DAOException {
	if(id==null){
		return;
	}
	String sql = "update service set status='1', pause_date=sysdate where id=?";
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, id);
		ps.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("暂停业务账号失败", e);
	} finally{
		DBUtil.close();
	}
}

public void pauseByAccount(Integer accountId) throws DAOException {
	if(accountId==null){
		return;
	}
	
	String sql = "update service set status='1', pause_date=sysdate where account_id=?";
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, accountId);
		ps.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("根据账务账号暂停业务账号失败",e);
	} finally{
		DBUtil.close();
	}
	
	
}

public void delete(Integer id) throws DAOException {
	if(id==null){
		return;
	}
	
	String sql = "update service set status='2', close_date=sysdate where id=?";
	
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, id);
		ps.executeQuery();
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("删除业务账号失败",e);
	} finally{
		DBUtil.close();
	}
}

public void deleteByAccount(Integer accountId) throws DAOException {
	if(accountId == null){
		return;
	}
	
	String sql = "update service set status='2', close_date=sysdate where account_id=?";
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, accountId);
		ps.executeQuery();
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("根据账务账号删除业务账号失败",e);
	} finally{
		DBUtil.close();
	}
	
}

public void start(Integer id) throws DAOException {
	if(id == null){
		return;
	}
	String sql = "update service set status='0', pause_date=null where id=?";
	Connection con = DBUtil.getConnection();
	
	try {
			PreparedStatement ps = con.prepareStatement(sql);
			con.prepareStatement(sql);
			ps.setObject(1, id);
			ps.executeUpdate();
				
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("开通业务账号失败",e);
	} finally{
		DBUtil.close();
	}
}

public boolean checkAccount(Integer id) throws DAOException {
	if(id==null){
		return false;
	}
	String sql = "select status from account where id in ("+
				"select account_id from service where id=?)";
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, id);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			String status = rs.getString(1);
			if(status.equals("0")){
				return true;
			}else{
				return false;
			}
		}
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("根据业务账号校验账务账号失败",e);
	} finally{
		DBUtil.close();
	}
	
	return false;
}

Action:

public class PauseServiceAction {
	
	public String execute(){
		IServiceDAO dao = DAOFactory.getServiceDAO();
		
		try {
			
			dao.pause(id);
			info.put("message", "暂停业务账号成功");
		} catch (DAOException e) {
			info.put("message", "暂停业务账号失败");
			e.printStackTrace();
			
		}
		
		return "success";
	}
	
	//input
	private Integer id;
	//output
	private Map<String, Object> info = new HashMap<String, Object>();

	public Map<String, Object> getInfo() {
		return info;
	}

	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
}

public class DeleteServiceAction {
	
	public String execute(){
		IServiceDAO dao = DAOFactory.getServiceDAO();
		
		try {
			dao.delete(id);
			info.put("success", true);
			info.put("message", "删除业务账号成功");
		} catch (DAOException e) {
			e.printStackTrace();
			info.put("success", false);
			info.put("message", "删除业务账号失败");
		}
		
		return "success";
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Map<String, Object> getInfo() {
		return info;
	}
	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}
	//input
	private Integer id;
	//output
	private Map<String,Object> info = new HashMap<String, Object>();
}

public class StartServiceAction {
	
	
	public String execute(){
		IServiceDAO dao = DAOFactory.getServiceDAO();
		try {
			if(dao.checkAccount(id)){
				dao.start(id);
				info.put("success", true);
				info.put("message", "开通业务账号成功");
			}else{
				info.put("success", false);
				info.put("message", "开通业务账号失败");
			}
			
		} catch (DAOException e) {
			e.printStackTrace();
			info.put("success", false);
			info.put("message", "开通业务账号失败");
		}
		
		return "success";
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Map<String, Object> getInfo() {
		return info;
	}
	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}
	//input
	private Integer id;
	//output
	private Map<String, Object> info = new HashMap<String, Object>();
}


//Acount的Action
public class PauseAccountAction {
	
	public String execute(){
		IAccountDAO dao = DAOFactory.getAccountDAO();
		IServiceDAO daoservice = DAOFactory.getServiceDAO();
		try {
			dao.pause(id);
			daoservice.pauseByAccount(id);
			info.put("success", true);
			info.put("message", "暂停号成功");
		} catch (DAOException e) {
			e.printStackTrace();
			info.put("success", false);
			info.put("message", "系统发生异常");
		}
		
		return "success";
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Map<String, Object> getInfo() {
		return info;
	}
	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}
	//input
	private Integer id;
	//output
	private Map<String, Object> info = new HashMap<String,Object>();
}

public class DeleteAccountAction {
	
	public String execute(){
		
		IAccountDAO accdao = DAOFactory.getAccountDAO();
		IServiceDAO serdao = DAOFactory.getServiceDAO();
		try {
			accdao.delete(id);
			serdao.deleteByAccount(id);
			info.put("message", true);
			info.put("message", "删除账务账号成功");
		} catch (DAOException e) {
			e.printStackTrace();
			info.put("message", false);
			info.put("message", "系统发生错误");
		}
		return "success";
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Map<String, Object> getInfo() {
		return info;
	}
	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}
	//input
	private Integer id;
	//output
	private Map<String, Object> info = new HashMap<String, Object>();
}



struts.xml

<!-- 暂停业务账号Action -->
<action name="pauseService" class="netctoss.action.service.PauseServiceAction">
	<result name="success" type="json">
		<param name="root">info</param>
	</result>
</action>
<!-- 删除业务账号Action -->
<action name="deleteService" class="netctoss.action.service.DeleteServiceAction">
	<result name="success" type="json">
		<param name="root">info</param>
	</result>
</action>
<!-- 开通业务账号Action -->
<action name="startService" class="netctoss.action.service.StartServiceAction">
	<result name="success" type="json">
		<param name="root">info</param>
	</result>
</action>

Jsp:

<s:if test="status==0">
		<input type="button" value="暂停" class="btn_pause" οnclick="pauseService(<s:property value="id"/>);" />
	</s:if>
	<s:else>
	<input type="button" value="开通" class="btn_start" οnclick="startService(<s:property value="id"/>);" />
    </s:else>
    <input type="button" value="修改" class="btn_modify" οnclick="" />
    <input type="button" value="删除" class="btn_delete" οnclick="deleteService(<s:property value="id"/>);" />

    //暂停
    function pauseService(id){
	var r = window.confirm("确定要暂停此业务账号吗?");
	if(!r){
		return;
	}
	
	$.post(
		"pauseService",
		{"id":id},
		function(data){
			var info = data;
			$("#operate_msg").text(info.message);
			$("#operate_result_info").show();
			setTimeout(function(){
				toPage($("#page").val());
				},1000);
		}
	);
    }
    
    //分页查询,隐藏框设置为用户选中的页
    function toPage(currPage){
	document.getElementById("page").value = currPage;
	document.forms[0].submit();
    }
    
    //删除
    function deleteService(id){
	var r = window.confirm("确定要删除业务账号吗?");
	if(!r){
		return;
	}
	$.post(
		"deleteService",
		{"id":id},
		function(data){
			var info = data;
			$("#operate_msg").text(info.message);
			$("#operate_result_info").show();
			setTimeout(function(){
				toPage($("#page").val());
			}, 1000);
		}
	);
    }

    
    //开通
    function startService(id){
	var r = window.confirm("确定开通业务账号吗?");
	if(!r){
		return;
	}
	
	$.post(
		"startService",
		{"id":id},
		function(data){
			var info = data;
			$("#operate_msg").text(info.message);
			$("#operate_result_info").show();
			setTimeout(function(){
				toPage($("#page"));
			},1000);
		}
	);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值