1.post
function deleCustomsVender(cvId) {
var url = "$popSellerAdminModule.getTarget("/customs/shop/customs_deleCustomsVender.action?_charset_=utf-8")";
if(confirm("确定要解除海关对该拍卖店铺的管理授权?解除后该店铺将不受海关账号控制。")) {
jQuery.post(url
,{
"customsVenderId":cvId
} , function (data) {
if(data!="false"){
alert("解除授权成功!");
$("#deleCustomsVender_"+cvId).hide();
}else {
alert("解除授权失败,请稍后再试");
}
}, 'text');
}
}
function operateOpenStatus(openStatus,customsId) {
var url = "$popSellerAdminModule.getTarget("/customs/customs_operateOpenStatus.action?_charset_=utf-8")";
var msg = "";
if (openStatus == 1) {
msg = "停用海关不会自动停用关联的店铺,关联店铺需要单独处理,确定要停用该海关吗?";
} else if (openStatus == 2) {
msg = "确定启用该海关账号?";
}
if(confirm(msg)) {
jQuery.post(url
,{
"customsId":customsId,
"openStatus":openStatus
} , function (data) {
if(data!="false"){
alert("操作成功!");
window.location.reload(true);
}else {
alert("操作失败,请稍后再试");
}
}, 'text');
}
}
protected javax.servlet.http.HttpServletResponse response;
@HrmPrivilege(code = HrmPurviewConstants.POP_MAN_CUSTOMS_ACCOUNT_MANAGE_ADD)
public void deleCustomsAccount() throws IOException {
String pin = WebHelper.getPin();
if (StringUtils.isNotBlank(pin)){
response.getWriter().write(customsService.deleCustomsAccountByAccountId(accountId)==0?"false":pin);
}else{
response.getWriter().write("false");
}
}
2.ajax
jQuery("#shopform1").validate({
rules: {
"customsFormBean.customsName": {
required: true,
zh_CnLength:100
//maxlength: 50
},
"customsFormBean.licenseNo": {
//required: true,
validLicenseNo:true,
maxlength: 50
},
"customsFormBean.principal":{
required: true
},
"customsFormBean.remark": {
zh_CnLength:200
}
},
messages: {
"customsFormBean.customsName": {
required: "请输入海关名称"
},
"customsFormBean.licenseNo": {
// required: "请输入营业执照编号",
validLicenseNo:"请输入正确的营业执照编号"
},
"customsFormBean.principal":{
required: "请选择招商人员"
}
},
submitHandler: function (form) {
var customsName = jQuery("[name='customsFormBean.customsName']").val();
var licenseNo = jQuery("[name='customsFormBean.licenseNo']").val();
var principal = jQuery("[name='customsFormBean.principal']").val();
var customsId = jQuery("[name='customsId']").val();
var remark = jQuery("[name='customsFormBean.remark']").val();
jQuery.blockUI({message:'提交中,请稍候...'});
jQuery.ajax({
type: "POST",
dataType: "json",
url: '$popSellerAdminModule.getTarget("/json/updateCustoms/doUpdateCustoms.action?_charset_=utf-8")',
data: {"customsFormBean.customsName": customsName, "customsFormBean.licenseNo": licenseNo,
"customsFormBean.principal": principal, "customsId": customsId,
"customsFormBean.remark":remark
},
success: function (data) {
jQuery.unblockUI();
if(data.succeed) {
alert("修改成功!");
window.location.reload(true);
}else{
alert(data.errorContent)
}
},
error:function(data){
jQuery.unblockUI();
alert("修改失败!");
}
});
}
});
===============================================================
jQuery(document).ready(function() {
jQuery("#edit1").click(function() {
jQuery('#div1').attr('class', 'hide');
jQuery('#shopform1').attr('class', '');
});
/**
* 计算含有中文的字符串长度
*/
jQuery.validator.addMethod("zh_CnLength",function(value,element,param){
value = value.replace(/(^\s*)|(\s*$)/g, "");
String.prototype.getBytes = function() {
var cArr = this.match(/[^\x00-\xff]/ig);
return this.length + (cArr == null ? 0 : cArr.length);
}
var length = value.getBytes();
if(length>param){
return false;
}
return true;
},"请输入一个长度最多是 {0} 的字符串,一个中文算两个长度");
/**
* 自定义验证营业执照编号
*/
jQuery.validator.addMethod("validLicenseNo", function (value, element) {
var pattern = new RegExp("^[0-9]{15}$");
return this.optional(element) || (pattern.test(value));
},"请输入正确的营业执照编号");
jQuery("#shopform1").validate({
rules: {
"customsFormBean.customsName": {
required: true,
zh_CnLength:100
//maxlength: 50
},
"customsFormBean.licenseNo": {
//required: true,
validLicenseNo:true,
maxlength: 50
},
"customsFormBean.principal":{
required: true
},
"customsFormBean.remark": {
zh_CnLength:200
}
},
messages: {
"customsFormBean.customsName": {
required: "请输入海关名称"
},
"customsFormBean.licenseNo": {
// required: "请输入营业执照编号",
validLicenseNo:"请输入正确的营业执照编号"
},
"customsFormBean.principal":{
required: "请选择招商人员"
}
},
submitHandler: function (form) {
var customsName = jQuery("[name='customsFormBean.customsName']").val();
var licenseNo = jQuery("[name='customsFormBean.licenseNo']").val();
var principal = jQuery("[name='customsFormBean.principal']").val();
var customsId = jQuery("[name='customsId']").val();
var remark = jQuery("[name='customsFormBean.remark']").val();
jQuery.blockUI({message:'提交中,请稍候...'});
jQuery.ajax({
type: "POST",
dataType: "json",
url: '$popSellerAdminModule.getTarget("/json/updateCustoms/doUpdateCustoms.action?_charset_=utf-8")',
data: {"customsFormBean.customsName": customsName, "customsFormBean.licenseNo": licenseNo,
"customsFormBean.principal": principal, "customsId": customsId,
"customsFormBean.remark":remark
},
success: function (data) {
jQuery.unblockUI();
if(data.succeed) {
alert("修改成功!");
window.location.reload(true);
}else{
alert(data.errorContent)
}
},
error:function(data){
jQuery.unblockUI();
alert("修改失败!");
}
});
}
});
});
<package name="jsonAddCustoms" namespace="/json/addCustoms" extends="json-protected-default">
<action name="*" method="{1}" class="com.jd.pop.customs.web.action.CustomsAction">
<result name="doAddCustoms" type="json">
<param name="ignoreHierarchy">true</param>
<param name="excludeNullProperties">true</param>
<param name="root">baseOperateJson</param>
</result>
</action>
</package>
<!-- 处理json方法中需要获取到当前登录,则用此package-->
<package name="json-protected-default" extends="illegalBase">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
<package name="illegalBase" extends="struts-default">
<result-types>
<result-type name="velocity" class="com.jd.common.struts.velocity.VelocityLayoutResult" default="true" />
</result-types>
<interceptors>
<interceptor name="monitoring" class="net.bull.javamelody.StrutsInterceptor"/>
<interceptor name="loginContext" class="com.jd.pop.admin.web.interceptor.AdminLoginContextInterceptor"/>
<interceptor-stack name="strutsDefaultStack">
<interceptor-ref name="monitoring"/>
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="i18n" />
<interceptor-ref name="prepare" />
<interceptor-ref name="chain" />
<interceptor-ref name="debugging" />
<interceptor-ref name="scopedModelDriven" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="fileUpload">
<param name="maximumSize">4194304</param><!--单个文件最大4M-->
<param name="allowedTypes">image/x-png,image/png,image/gif,image/jpeg,image/jpg,image/pjpeg,application/x-shockwave-flash,application/octet-stream,application/vnd.ms-excel,application/msword,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/zip</param>
<param name="allowedExtensions">jpg,jpeg,png,gif,txt,swf,xls,xlsx,doc,docx,zip,pdf</param>
</interceptor-ref>
<interceptor-ref name="checkbox" />
<interceptor-ref name="multiselect" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="actionMappingParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*,.*\\u0023.*</param>
</interceptor-ref>
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
<interceptor-stack name="illegalInterceptor">
<interceptor-ref name="strutsDefaultStack" />
<interceptor-ref name="loginContext" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="illegalInterceptor" />
<global-results>
<result name="exception">/WEB-INF/vm/error.vm</result>
<result name="input">/WEB-INF/vm/paramError.vm</result>
<result name="error">/WEB-INF/vm/error.vm</result>
<result name="illegal">/WEB-INF/vm/illegal.vm</result>
<result name="login_error">/WEB-INF/vm/loginerror.vm</result>
<result name="login" type="redirect">${loginUrl}</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>
</package>
private BaseOperateJson baseOperateJson;
public BaseOperateJson getBaseOperateJson() {
return baseOperateJson;
}
public void setBaseOperateJson(BaseOperateJson baseOperateJson) {
this.baseOperateJson = baseOperateJson;
}
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import java.io.Serializable;
/**
* BaseOperateJson
* @author @shaodong
*/
@SuppressWarnings("unused")
public class BaseOperateJson implements Serializable{
private boolean succeed;
private String errorCode;
private String errorContent;
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorContent() {
return errorContent;
}
public void setErrorContent(String errorContent) {
this.errorContent = errorContent;
}
public boolean isSucceed() {
return succeed;
}
public void setSucceed(boolean succeed) {
this.succeed = succeed;
}
public BaseOperateJson() {}
public BaseOperateJson(boolean succeed, String errorCode, String errorContent) {
this.succeed = succeed;
this.errorCode = errorCode;
this.errorContent = errorContent;
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
@HrmPrivilege(code = HrmPurviewConstants.POP_MAN_CUSTOMS_MANAGE_DO_UPDATE)
public String doUpdateCustoms(){
baseOperateJson = new BaseOperateJson();
try{
Result result = customsService.updateCustoms(customsFormBean, customsId);
if(result.getSuccess()){
baseOperateJson.setSucceed(true);
String customsId=String.valueOf(result.get("customsId"));
baseOperateJson.setErrorCode(customsId);
}else{
baseOperateJson.setSucceed(false);
String errorCode=result.getResultCode();
baseOperateJson.setErrorCode(errorCode);
baseOperateJson.setErrorContent(getText(errorCode));
log.error(CustomsAction.class.getSimpleName()+"修改海关信息失败"+baseOperateJson+getText(errorCode));
}
}catch (Exception ex){
baseOperateJson.setSucceed(false);
String errorCode= ResultCode.SYSTEM_ERROR;
baseOperateJson.setErrorCode(errorCode);
baseOperateJson.setErrorContent(getText(errorCode));
log.error(CustomsAction.class.getSimpleName()+"修改海关信息失败"+baseOperateJson,ex);
}
return "doUpdateCustoms";
}
@HrmPrivilege(code = HrmPurviewConstants.POP_MAN_CUSTOMS_MANAGE_ADD)
public String doAddCustoms() {
baseOperateJson = new BaseOperateJson();
try{
Result result = customsService.createCustoms(customsFormBean);
if(result.getSuccess()){
baseOperateJson.setSucceed(true);
String customsId=String.valueOf(result.get("customsId"));
baseOperateJson.setErrorCode(customsId);
}else{
baseOperateJson.setSucceed(false);
String errorCode=result.getResultCode();
baseOperateJson.setErrorCode(errorCode);
baseOperateJson.setErrorContent(getText(errorCode));
log.error(CustomsAction.class.getSimpleName()+"创建海关失败"+baseOperateJson+getText(errorCode));
}
}catch (Exception ex){
baseOperateJson.setSucceed(false);
String errorCode= ResultCode.SYSTEM_ERROR;
baseOperateJson.setErrorCode(errorCode);
baseOperateJson.setErrorContent(getText(errorCode));
log.error(CustomsAction.class.getSimpleName()+"创建海关失败"+baseOperateJson,ex);
}
return "doAddCustoms";
}