1.定义多个对象包装类
注意:要实现序列化接口!!!
publishProductKeyInfoList
factorVoList
serverVoList
bankVoList
以上四个类对象 为 jsonData 的键,一定要对应上,具体看后面前端代码。
public class PublishProductKeyVo implements Serializable {
private List<PublishProductKeyInfo> publishProductKeyInfoList;
private List<FactorVo> factorVoList;
private List<ServerVo> serverVoList;
private List<BankVo> bankVoList;
public List<BankVo> getBankVoList() {
return bankVoList;
}
public void setBankVoList(List<BankVo> bankVoList) {
this.bankVoList = bankVoList;
}
public List<PublishProductKeyInfo> getPublishProductKeyInfoList() {
return publishProductKeyInfoList;
}
public void setPublishProductKeyInfoList(List<PublishProductKeyInfo> publishProductKeyInfoList) {
this.publishProductKeyInfoList = publishProductKeyInfoList;
}
public List<FactorVo> getFactorVoList() {
return factorVoList;
}
public void setFactorVoList(List<FactorVo> factorVoList) {
this.factorVoList = factorVoList;
}
public List<ServerVo> getServerVoList() {
return serverVoList;
}
public void setServerVoList(List<ServerVo> serverVoList) {
this.serverVoList = serverVoList;
}
@Override
public String toString() {
return "PublishProductKeyVo{" +
"publishProductKeyInfoList=" + publishProductKeyInfoList +
", factorVoList=" + factorVoList +
", serverVoList=" + serverVoList +
'}';
}
2.前端代码
注意:ajax里的 contentType : "application/json;charset=UTF-8",一点要写!!
/**
* 发行
*/
InputInfoDlg.addSubmit = function() {
var inputInfoFormvalue = document.getElementById("inputInfoForm");
var bankInfoFormvalue = document.getElementById("bankInfoForm");
if(inputInfoFormvalue!= null && inputInfoFormvalue.id == 'inputInfoForm'){
if (!this.validate()) {
return;
}
}
if(bankInfoFormvalue!= null && bankInfoFormvalue.id == 'bankInfoForm'){
if (!this.validate2()) {
return;
}
}
var tr = $("#licenseTable tr"); // 获取table中每一行内容
var serverresult = []; // 数组
for (var i = 0; i < tr.length; i++) {// 遍历表格中每一行的内容
var tds = $(tr[i]).find("td");
if (tds.length > 0) {
serverresult.push({
"No" :$(tds[0]).context.innerHTML,
"serverName" : $(tds[1]).find("input").val(),
"startType" : $(tds[2]).find("select").val(),
"distributionAuthNum" : $(tds[3]).find("input").val(),
})
}
}
var tr = $("#modelTable tr"); // 获取table中每一行内容
var modelresult = []; // 数组
for (var i = 0; i < tr.length; i++) {// 遍历表格中每一行的内容
var tds = $(tr[i]).find("td");
if (tds.length > 0) {
modelresult.push({
"No" :$(tds[0]).context.innerHTML,
"factor" : $(tds[1]).find("input").val(),
"model" : $(tds[2]).find("input").val()
})
}
}
var inputInfo = [];
inputInfo.push({
"ourCompany" : $('input[name="inlineRadioOptions"]:checked ').val(),
"contractType" : $('input[name="inlineRadioOptions1"]:checked ').val(),
"company" : $('#company').val(),
"payCompany": $('#payCompany').val(),
"payDepartment" :$("#payDepartment").val(),
"signingTime" : $('#signingTime').val(),
"projectName" :$("#projectName").val(),
"authTotalNum" :$("#authTotalNum").val(),
"productId" :$("#productId").val(),
"priceType" :$('input[name="inlineRadioOptions2"]:checked ').val(),
"specialPrice" : $("#specialpricetext").val(),
"startupUpdateTime" :$("#startupUpdateTime").val(),
"serverName" :$("#serverName").val(),
"startType" :$("#startType").val(),
"distributionAuthNum" :$("#distributionAuthNum").val(),
"factor" :$("#factor").val(),
"payType" :$('input[name="inlineRadioOptions3"]:checked ').val(),//支付区分
"settlementType" :$('input[name="inlineRadioOptions2"]:checked ').val(),
"payDimension" :$('input[name="inlineRadioOptions4"]:checked ').val(),//支付维度
"payTime" :$("#payTime").val()//支付日
});
var bankArr = [];
var bankjsonstr = $('#bankinfo').val();
if(bankjsonstr == ""){
bankArr = [];
}else{
bankArr =JSON.parse(bankjsonstr);
}
var jsonData = { // json数据 此处键名称 需要跟 序列化对象PublishProductKeyVo里的的属性名一致
"serverVoList" : serverresult,
"factorVoList" : modelresult,
"publishProductKeyInfoList":inputInfo,
"bankVoList" : bankArr
}
$.ajax({
type : "post",
url : Feng.ctxPath +"/input/getTableData",
contentType : "application/json;charset=UTF-8",
data : JSON.stringify(jsonData),// 将json数据转化为字符串
success : function(data) {
Feng.success("凳行成功!");
//重定向
window.location.replace(Feng.ctxPath +"/license")
}
});
};
3.Controller接收
注意:要加@RequestBody 注解,且为POST 方法。
@Controller
@RequestMapping("/input")
public class PublishProductKeyController extends BaseController {
@Permission(Const.ADMIN_NAME)
@BussinessLog(value = "license凳行", businessType = BizLogType.BUSSINESS)
@Transactional
@ResponseBody
@RequestMapping(value = "/getTableData", method = RequestMethod.POST)
public String getTableData(@RequestBody PublishProductKeyVo publishProductKeyVo) {
List<PublishProductKeyInfo> publishProductKeyInfoList = publishProductKeyVo.getPublishProductKeyInfoList();
for (PublishProductKeyInfo info : publishProductKeyInfoList) {
//处理数据 (不添加行情况)
this.ourCompany = info.getOurCompany();
this.contractNo = getContractNo();
/*--------------------------合约信息-------------------------------------*/
Contract contract = new Contract();
contract.setContractNo(contractNo);
contract.setStatus(ContractStatus.SIGINING.getCode());//默认签约中
contract.setOurCompany(info.getOurCompany());
contract.setContractType(info.getContractType());
//首先查询是否有这个公司
String company = customerService.selectCompanyByCompanyName(info.getCompany());
if (ToolUtil.isNotEmpty(company)) {
//公司名不为空 说明有这个公司并且 名字正确
//根据签约公司名找到 customer表 的签约公司code company_code
Object companycode = customerService.selectCompanyCodeByCompany(info.getCompany());
contract.setCompanyCode((Integer) companycode);
} else {
throw new ServiceException(BizExceptionEnum.NO_THIS_COMPANY);
}
int payCompanyCode = customerService.selectPayCompanyCodeByCompany(info.getPayCompany());
contract.setPayCompanyCode(payCompanyCode);
contract.setPayDepartmentCode(Integer.parseInt(info.getPayDepartment()));//部门对应部门code 没毛病
contract.setProjectName(info.getProjectName());
if (ToolUtil.isNotEmpty(info.getSigningTime())) {
contract.setSigningTime(DateTimeUtil.strToDate(info.getSigningTime()));//合约日
}
contract.setStatus(ContractStatus.SIGINING.getCode());//签约中
if (info.getStartType() == 0) {
contract.setHotServerNum(info.getDistributionAuthNum()); //serverI hot
}
if (info.getStartType() == 1) {
contract.setColdServerNum(info.getDistributionAuthNum());
}
int hotTotalNum =0;
int coldToalNum =0;
for (ServerVo serverVo : publishProductKeyVo.getServerVoList()) {
if (serverVo.getStartType() == 0) {
hotTotalNum += serverVo.getDistributionAuthNum();
contract.setHotServerNum(hotTotalNum); //serverI hot
}
if (serverVo.getStartType() == 1) {
coldToalNum += serverVo.getDistributionAuthNum();
contract.setColdServerNum(coldToalNum);
}
}
contract.setTotalAuthNum(hotTotalNum + coldToalNum);
//添加合约时 根据合约公司查出客户id
int customerId = customerService.selectCustomerIdByCompany(info.getCompany());
if (ToolUtil.isEmpty(customerId)) {
throw new ServiceException(BizExceptionEnum.NO_THIS_CUSTOMER);
}
contract.setPayType(info.getPayType());
contract.setPayDimension(info.getPayDimension());
contract.setSettlementType(info.getSettlementType());
contract.setPayTime(info.getPayTime());
contract.setCustomerId(customerId);
contract.setCreateTime(new Date());
contract.insert();
/*-----------------------------------------------------------*/
//不加行情况 list为1条数据
List<FactorVo> factorList = publishProductKeyVo.getFactorVoList();
String tips = "";
List<ServerVo> serverList = publishProductKeyVo.getServerVoList();
String secendtips = "";
int addOrReduceTotal =0 ;
/*发现表有多行的话 发现表有多行的话 发现表有多行的话 发现表有多行的话 发现表有多行的话*/
for (ServerVo serverVo : serverList) {
if (serverList.size() >= 1) {
/*---------------------------license信息------------------------------------*/
this.license = new License();
license.setContractNo(contractNo);
license.setServerName(serverVo.getServerName());
//重新生成productKey
String newproductKey = ProductKeyGenerateUtil.getProductKey();
this.newproductKey = newproductKey;
license.setProductKey(newproductKey);
license.setPassword(PasswordGenerateUtil.GeneratePassword());
if (ToolUtil.isNotEmpty(info.getStartupUpdateTime())) {
license.setStartupUpdateTime(DateTimeUtil.strToDate(info.getStartupUpdateTime()));
}
license.setStartType(serverVo.getStartType());
//端末分配台数 初始化为0 当客户认证完成后 将增减预定数 加在这里 增减预定数变为 0
license.setAuthNum(0);
//增减预定台数
license.setAddOrReduceNum(serverVo.getDistributionAuthNum());
//用端末分配的台数总和 更新履历表数量
addOrReduceTotal += serverVo.getDistributionAuthNum();
//swing生成license默认信息
license.setmBindPort(-1);
license.setmAssignerLimit(2);
license.setmCountRemain(5);
//这里为端末分配台数
//TODO 端末分配台数 + 增减预定台数
license.setmHtLicense(serverVo.getDistributionAuthNum());
license.setmHywayserverLimit(100);
license.setmServeripEditRemain(5);
license.setmActive("false");
license.setmClusterLevel("Level 2");
//判断合约类型,如果是普通合约,DateValid 为空字符串,认证的时候判断如果为使用合约,DateValid 为认证时间延后一个月
//这里直接给空
license.setmDateValid("");
license.setmLicenseClass("Main License");
license.setmLicenseId("0000000000000001");
license.setmLicenseType("Executive");
license.setmServerIp("255.255.255.255");
license.setmServerType("WiFi@Hyway");
license.setmMacAddrList("00:00:00:00:00:00");
license.setmUsername("SNJP");
license.setCreatetime(new Date());
license.insert();
secendtips += "[" +
"No:" + serverVo.getNo()
+ ",サーバー名:" + serverVo.getServerName()
+ ",プロダクトキー:" + newproductKey
+ ",割当端末台数:" + serverVo.getDistributionAuthNum()
+ ",認証日:" + ""
+ ']' + " ";
}
}
for (FactorVo factorVo : factorList) {
if (factorList.size() >= 1) {
//厂家备注写履历 备注1
tips += "[" +
"No:" + factorVo.getNo() +
",factor:" + factorVo.getFactor() +
",model:" + factorVo.getModel() +
']' + " ";
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------合约变更履历信息------------------------------------*/
RevisionHistory history = new RevisionHistory();
//判断合约类型 如果为试用合约 就不做履历 0:普通 1:试用
if(info.getContractType() == 0){
history.setContractNo(contractNo);
int num = historyService.selectNumByContractNo(contractNo);
if (ToolUtil.isEmpty(num)) {
num = 0;
}
history.setNum(num + 1);
//根据商品ID 商品表单的 productID
String productId = productService.selectproductIdByProductId(info.getProductId().trim());
if (ToolUtil.isEmpty(productId)) {
throw new ServiceException(BizExceptionEnum.NO_THIS_PRODUCT);
}
history.setProductId(productId);
history.setPriceType(info.getPriceType());
//特殊单价如果不为空 可set特殊单价的值
if (ToolUtil.isNotEmpty(info.getSpecialPrice())) {
history.setSpecialPrice(info.getSpecialPrice());
}
history.setApplyTime(DateTimeUtil.strToDate(info.getSigningTime()));//合约申请日
if (ToolUtil.isNotEmpty(info.getStartupUpdateTime())) {
history.setStartupUpdateTime(DateTimeUtil.strToDate(info.getStartupUpdateTime()));//启动变更预定日
}
history.setAuthStatus(AuthStatus.UNAUTH.getCode());//未认证
/*剪切代码到history上*/
history.setTips(tips);
history.setAuthNum(addOrReduceTotal);
history.setSecendTips(secendtips);
history.setCreatetime(new Date());
history.insert();
}
Account account = new Account();
List<BankVo> bankVoList = publishProductKeyVo.getBankVoList();
if(bankVoList.size() > 0){
for (BankVo bankVo : bankVoList) {
account.setContractNo(contractNo);
account.setAccount(bankVo.getAccount());
account.setBankType(bankVo.getBankType());
account.setAccountAlias(bankVo.getAccountAlias());
account.setAccountName(bankVo.getAccountName());
account.setBankNum(bankVo.getBankNum());
account.setBankName(bankVo.getBankName());
account.setBranchName(bankVo.getBranchName());
account.setBranchNum(bankVo.getBranchNum());
//判断银行类型 选中是否设置存款类型的值
if(bankVo.getBankType() == 0){
//非邮政银行
account.setDepositType(bankVo.getDepositType().toString());
}
if(bankVo.getBankType() == 1){
//如果是邮政银行 存款类型为空
account.setDepositType("");
}
int bnum = accountService.selectNumByContractNo(contractNo);
if (ToolUtil.isEmpty(bnum)) {
bnum = 0;
}
account.setNum(bnum + 1);
account.setTips(bankVo.getTips());
account.setBankType(bankVo.getBankType());
}
//开始日为 合约表里的 signing_time
String signing_time = contractService.selectSigningTimeByContractNo(contractNo);
String time = signing_time.replace(".0", "");
account.setBeginTime(DateTimeUtil.strToDate(time));
account.setCreateTime(new Date());
account.insert();
}
}
return REDIRECT + "/license";
}
}