只是个人笔记:他人勿扰
按钮
前端的按钮:
<a href="#" class="btn btn-default" onclick="btnWrite()" title="${text('写入EAS')}"><i class="fa fa-filter"></i> ${text('写入EAS')}</a>
中间复选框点击按钮实现功能
{header:'${text("操作")}', name:'actions', 50, sortable:false, title:false, formatter: function(val, obj, row, act){ var actions = []; <% if(hasPermi('supplier:vendor:edit')){ %> actions.push('<a href="${ctx}/supplier/vendor/write?id='+row.id+'" class="btnList" title="${text("写入供应商")}" data-confirm="${text("确认要写入EAS吗?")}"><i class="glyphicon glyphicon-ok"></i></a> '); <% } %> return actions.join(''); }},
点击按钮实现功能进入到Controller层
function btnWrite(){ var rowId = $('#dataGrid').dataGrid('getSelectRow'); if (rowId == null) { js.showMessage('只能选中一行数据!'); return; } js.confirm('确认提交吗?', '${ctx}/supplier/vendor/write', {id: rowId}, function(data){ js.showMessage(data.message); $('#dataGrid').dataGrid('refresh'); $('#dataGridSub').dataGrid('refresh'); }, 'json', true, '正在写入...'); }
进入到controller层的代码:
在写入上面还需要导入service的方法
@Autowired
private VendorService vendorService;
插入contorllet层
@RequiresPermissions("supplier:vendor:edit") @RequestMapping(value = "write") @ResponseBody @RepeatSubmit public String write(Vendor vendor) { try { vendorService.write(vendor); } catch (RemoteException | ServiceException e) { e.printStackTrace(); return renderResult(Global.FALSE, text("供应商写入EAS失败!")); } return renderResult(Global.TRUE, text("供应商写入EAS成功!")); }
正常是直接service.它的方法名就可以,因为这个项目他有回滚事件,所以它必须要抛异常,所以try catch.
进入到service层:
它需要导入个EAS这个接口直接导入就好了
@Autowired
private EasService easService;
下面是对接EAS接口的代码了
@Transactional(readOnly=false, rollbackFor = Exception.class) public void write(Vendor vendor) throws RemoteException, ServiceException { Result sendSupplierInfo = easService.sendSupplierInfo(vendor.getCvencode(), vendor.getCvenname(), "", vendor.getCvenabbname(), vendor.getCvenaddress(),vendor.getCvenlperson()); if(sendSupplierInfo.isFlag()) { vendor.setIsup("Y"); this.update(vendor); }else { throw new BaseException(sendSupplierInfo.getMessage()); } }