diff --git a/lc123/cloud/app/api/controller/SupplierControl.java b/lc123/cloud/app/api/controller/SupplierControl.java new file mode 100644 index 0000000..f5e2527 --- /dev/null +++ b/lc123/cloud/app/api/controller/SupplierControl.java @@ -0,0 +1,382 @@ +package tqq9.lc123.cloud.app.api.controller; + +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.OperateOption; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.operate.result.IOperateInfo; +import kd.bos.entity.operate.result.OperationResult; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; +import kd.bos.openapi.common.custom.annotation.ApiController; +import kd.bos.openapi.common.custom.annotation.ApiPostMapping; +import kd.bos.openapi.common.custom.annotation.ApiRequestBody; +import kd.bos.openapi.common.custom.annotation.ApiResponseBody; +import kd.bos.openapi.common.result.CustomApiResult; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.operation.OperationServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.bos.util.StringUtils; +import scala.Dynamic; +import tqq9.lc123.cloud.app.api.model.SupplierModel; +import tqq9.lc123.cloud.app.api.utils.ApiResultExt; +import tqq9.lc123.cloud.app.api.utils.AttachmentFileUtil; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.*; + +//非采供应商 +@ApiController(value = "SupplierControl", desc = "泛微非采购供应商导入") +public class SupplierControl implements Serializable { + private final static Log logger = LogFactory.getLog(SupplierControl.class); + + @ApiPostMapping(value = "/FWSupplierImport", desc = "泛微非采购供应商导入") + public CustomApiResult<@ApiResponseBody("返回参数") ApiResultExt> fWSupplierImport + (@NotNull @Valid @ApiRequestBody(value = "入参") SupplierModel supplier) { + ApiResultExt resultExt = new ApiResultExt(); + List results = new ArrayList<>(); + ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean(); + ApiResultExt.Error error = new ApiResultExt.Error(); + ArrayList rowMsg = new ArrayList<>(); + JSONObject keys = new JSONObject(); + boolean billStatus = true; + + List data = supplier.getData(); + if (null != data && data.size() > 0) { + for (int i = 0; i < data.size(); i++) { + SupplierModel.DataBean dataBean = data.get(i); + String creator_number = dataBean.getCreator_number(); + DynamicObject creator = null; + if (StringUtils.isEmpty(creator_number)) { + rowMsg.add("供应商创建人工号字段【creator_number】为空"); + billStatus = false; + } else { + creator = BusinessDataServiceHelper.loadSingle("bos_user", + new QFilter[]{new QFilter("number", QCP.equals, creator_number)}); + if (null==creator){ + rowMsg.add("根据创建人工号【"+creator_number+"】在金蝶系统中没有查询到对应的人员信息"); + billStatus = false; + } + } + Date createtime = dataBean.getCreatetime(); + if (null == createtime) { + rowMsg.add("供应商创建日期字段【createtime】为空"); + billStatus = false; + } + String number = dataBean.getNumber(); + if (StringUtils.isEmpty(number)) { + rowMsg.add("供应商编号字段【number】为空"); + billStatus = false; + } else { + keys.put("number", number); + } + String name = dataBean.getName(); + if (StringUtils.isEmpty(name)) { + rowMsg.add("供应商名称字段【name】为空"); + billStatus = false; + } + String simplename = dataBean.getSimplename(); + String tqq9_combofield3_jyzt = dataBean.getTqq9_combofield3_jyzt(); + Date tqq9_datefield5_clrq = dataBean.getTqq9_datefield5_clrq(); + String tqq9_textfield210 = dataBean.getTqq9_textfield210(); + String tqq9_textareafield_jyfw = dataBean.getTqq9_textareafield_jyfw(); + String tqq9_textfield3_zczb1 = dataBean.getTqq9_textfield3_zczb1(); + String tqq9_textfield4_zs1 = dataBean.getTqq9_textfield4_zs1(); + String societycreditcode = dataBean.getSocietycreditcode(); + String tqq9_usagescenarios = dataBean.getTqq9_usagescenarios(); + String tqq9_basedatafield1_name = dataBean.getTqq9_basedatafield1_name(); + DynamicObject tqq9_basedatafield1 = null; + if (StringUtils.isNotEmpty(tqq9_basedatafield1_name)) { + tqq9_basedatafield1 = BusinessDataServiceHelper.loadSingle("bd_country", + new QFilter[]{new QFilter("name", QCP.equals, tqq9_basedatafield1_name)}); + } + List entry_bank = dataBean.getEntry_bank(); + if (null == entry_bank || entry_bank.size() == 0) { + rowMsg.add("供应商银行信息分录为空"); + billStatus = false; + } else { + Boolean isdefault_bank = false; + for (int j = 0; j < entry_bank.size(); j++) { + SupplierModel.DataBean.BankBean bankBean = entry_bank.get(j); + String bank_number = bankBean.getBank_number(); + if (StringUtils.isEmpty(bank_number)) { + rowMsg.add("供应商开户银行.编码(行号)字段【bank_number】为空"); + billStatus = false; + } + isdefault_bank = bankBean.getIsdefault_bank(); + String accountname = bankBean.getAccountname(); + if (StringUtils.isEmpty(accountname)) { + rowMsg.add("供应商银行信息分录.收款方名称字段【accountname】为空"); + billStatus = false; + } + String bankaccount = bankBean.getBankaccount(); + if (StringUtils.isEmpty(bankaccount)) { + rowMsg.add("供应商银行信息分录.银行账号字段【bankaccount】为空"); + billStatus = false; + } + Integer seq = bankBean.getSeq(); + } + if (!isdefault_bank) { + rowMsg.add("供应商银行信息分录要有一行默认的银行账号"); + billStatus = false; + } + } + List entry_linkman = dataBean.getEntry_linkman(); + if (null == entry_linkman || entry_linkman.size() == 0) { + rowMsg.add("供应商联系人分录为空"); + billStatus = false; + } else { + for (int k = 0; k < entry_linkman.size(); k++) { + SupplierModel.DataBean.LinkmanBean linkmanBean = entry_linkman.get(k); + String contactperson = linkmanBean.getContactperson(); + if (StringUtils.isEmpty(contactperson)) { + rowMsg.add("供应商联系人分录.联系人字段【contactperson】为空"); + billStatus = false; + } + Integer seq = linkmanBean.getSeq(); + String mobile = linkmanBean.getMobile(); + if (StringUtils.isEmpty(mobile)) { + rowMsg.add("供应商联系人分录.手机字段【mobile】为空"); + billStatus = false; + } + String phone = linkmanBean.getPhone(); + String tqq9_textfield_xxdz = linkmanBean.getTqq9_textfield_xxdz(); + if (StringUtils.isEmpty(tqq9_textfield_xxdz)) { + rowMsg.add("供应商联系人分录.详细地址字段【tqq9_textfield_xxdz】为空"); + billStatus = false; + } + } + } + List attachment = dataBean.getAttachment(); + if (null != attachment && attachment.size() > 0) { + for (SupplierModel.DataBean.AttachmentBean attachmentBean : attachment) { + String attachmentName = attachmentBean.getAttachmentName(); + if (StringUtils.isEmpty(attachmentName)) { + rowMsg.add("供应商附件名称为空"); + billStatus = false; + } + String attachmentUrl = attachmentBean.getAttachmentUrl(); + if (StringUtils.isEmpty(attachmentUrl)) { + rowMsg.add("供应商附件地址为空"); + billStatus = false; + } + + } + } + resultBean.setBillIndex(0); + resultBean.setKeys(keys); + resultBean.setNumber(number); + if (!billStatus) { + //出现错误后返回 + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("bd_supplier"); + resultBean.setId(""); + resultBean.setBillStatus(billStatus); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + } else { + DynamicObject bd_supplier = BusinessDataServiceHelper.newDynamicObject("bd_supplier"); + bd_supplier.set("number", number); + bd_supplier.set("name", name); + bd_supplier.set("simplename", simplename); + bd_supplier.set("tqq9_combofield3_jyzt", tqq9_combofield3_jyzt); + bd_supplier.set("tqq9_basedatafield1", tqq9_basedatafield1); + bd_supplier.set("creator", creator); + bd_supplier.set("createtime",createtime); + bd_supplier.set("societycreditcode",societycreditcode); + bd_supplier.set("tqq9_usagescenarios",tqq9_usagescenarios); + bd_supplier.set("tqq9_datefield5_clrq",tqq9_datefield5_clrq); + bd_supplier.set("tqq9_textfield210",tqq9_textfield210); + bd_supplier.set("tqq9_textareafield_jyfw",tqq9_textareafield_jyfw); + bd_supplier.set("tqq9_textfield3_zczb1",tqq9_textfield3_zczb1); + bd_supplier.set("tqq9_textfield4_zs1",tqq9_textfield4_zs1); + DynamicObjectCollection entry_linkman1 = bd_supplier.getDynamicObjectCollection("entry_linkman"); + for (SupplierModel.DataBean.LinkmanBean linkmanBean : entry_linkman) { + DynamicObject dynamicObject = entry_linkman1.addNew(); + dynamicObject.set("contactperson",linkmanBean.getContactperson()); + dynamicObject.set("phone",linkmanBean.getPhone()); + dynamicObject.set("mobile",linkmanBean.getMobile()); + dynamicObject.set("tqq9_textfield_xxdz",linkmanBean.getTqq9_textfield_xxdz()); + dynamicObject.set("seq",linkmanBean.getSeq()); + } + DynamicObjectCollection entry_bank1 = bd_supplier.getDynamicObjectCollection("entry_bank"); + for (SupplierModel.DataBean.BankBean bankBean : entry_bank) { + DynamicObject dynamicObject = entry_bank1.addNew(); + dynamicObject.set("seq",bankBean.getSeq()); + dynamicObject.set("accountname",bankBean.getAccountname()); + String bank_number = bankBean.getBank_number(); + DynamicObject bank = BusinessDataServiceHelper.loadSingle("bd_bebank", + new QFilter[]{new QFilter("union_number", QCP.equals, bank_number)}); + dynamicObject.set("bank",bank); + dynamicObject.set("bankaccount",bankBean.getBankaccount()); + dynamicObject.set("isdefault_bank",bankBean.getIsdefault_bank()); + DynamicObject currency = BusinessDataServiceHelper.loadSingle("bd_currency", + new QFilter[]{new QFilter("number", QCP.equals, "CNY")}); + dynamicObject.set("currency",currency); + } + + //供应商状态——正常 + QFilter q3 = new QFilter("number", "=", "ZCGYS"); + DynamicObject bd_supplierstatus = BusinessDataServiceHelper.loadSingle("bd_supplierstatus", new QFilter[]{q3}); + if (null != bd_supplierstatus) { + bd_supplier.set("supplier_status", bd_supplierstatus);//供应商状态 + } + bd_supplier.set("enable", "1");//使用状态 + bd_supplier.set("status", "C");//数据状态 + bd_supplier.set("ctrlstrategy", "5");//控制策略 + bd_supplier.set("type", "1");//伙伴类型 + bd_supplier.set("bizfunction", ",1,2,3,4,");//业务职能 + + OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bd_supplier", new DynamicObject[]{bd_supplier}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("bd_supplier"); + resultBean.setId(""); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + }else { + bd_supplier.set("masterid", bd_supplier.getPkValue()); + SaveServiceHelper.save(new DynamicObject[]{bd_supplier}); + + //循环遍历每个附件内容 + if (null!=attachment && attachment.size() > 0) { + // 单个附件面板中所有附件的信息 + List> attachments = new ArrayList>(); + // 单个附件的信息 + Map attachmentInfo = null; + + StringBuffer uid = new StringBuffer(); + uid.append("rc-upload-").append(new Date().getTime()).append("-"); + int index = (int) (1 + Math.random() * 10); + //循环附件参数 + for (int j = 0; j < attachment.size(); j++) { + SupplierModel.DataBean.AttachmentBean attachmentBean = attachment.get(j); + + String attachementname = attachmentBean.getAttachmentName(); + BigDecimal attachementsize = BigDecimal.ZERO; + String attachementurl = attachmentBean.getAttachmentUrl(); + +// attachmentInfo = new HashMap(); +// attachmentInfo.put("entityNum", "attachmentpanel"); +// attachmentInfo.put("name", attachementname); +// attachmentInfo.put("url", attachementurl); +// attachmentInfo.put("size", attachementsize); +// attachmentInfo.put("uid", uid.toString() + index++); + String uid1 = uid.toString() + index++; +// attachments.add(attachmentInfo); + Map uploadres = null; + try { + uploadres = AttachmentFileUtil.saveUrlFile2Attchment(uid1,"bd_supplier", bd_supplier.getPkValue(), attachementurl, attachementname, attachementsize.toString(), "attachmentpanel"); + }catch (Exception ee1){ + rowMsg.add("第"+(j+1)+"条附件信息处理错误,上传失败!The No."+j+1+" attachment information processing error."); + break; + } + if(uploadres.get("isSuccess")!="true"){ + rowMsg.add("第"+(j+1)+"条附件信息处理错误,上传失败!The No."+j+1+" attachment information processing error."); + break; + } + } + } + + + //供应商分类标准页签 + DynamicObject bd_suppliergroupdetails = BusinessDataServiceHelper.newDynamicObject("bd_suppliergroupdetail"); + QFilter q4 = new QFilter("number", "=", "JBFLBZ"); + //供应商分类标准 + DynamicObject bd_suppliergroupstandard = BusinessDataServiceHelper.loadSingle("bd_suppliergroupstandard", new QFilter[]{q4}); + if (null != bd_suppliergroupstandard) { + bd_suppliergroupdetails.set("standard", bd_suppliergroupstandard);//分录标准 + } + QFilter q2 = new QFilter("number", "=", "001"); + DynamicObject bd_suppliergroup = BusinessDataServiceHelper.loadSingle("bd_suppliergroup", new QFilter[]{q2}); + if (null != bd_suppliergroup) { + bd_suppliergroupdetails.set("group", bd_suppliergroup);//分类 + } + bd_suppliergroupdetails.set("supplier", bd_supplier); +// bd_suppliergroupdetails.set("createorg", org); 需要创建组织 + + SaveServiceHelper.save(new DynamicObject[]{bd_suppliergroupdetails}); + + operationResult = OperationServiceHelper.executeOperate("submit", "bd_supplier", new DynamicObject[]{bd_supplier}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("bd_supplier"); + resultBean.setId(bd_supplier.getString("id")); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + }else { + operationResult = OperationServiceHelper.executeOperate("audit", "bd_supplier", new DynamicObject[]{bd_supplier}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("bd_supplier"); + resultBean.setId(bd_supplier.getString("id")); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + }else { + resultBean.setId(bd_supplier.getString("id")); + resultBean.setBillStatus(true); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + } + } + } + resultExt.setResult(results); + return CustomApiResult.success(resultExt); + + + } + } + } else { + rowMsg.add("供应商信息为空"); + billStatus = false; + } + if (!billStatus) { + //出现错误后返回 + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("bd_supplier"); + resultBean.setId(""); + resultBean.setBillStatus(billStatus); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + } + + resultExt.setResult(results); + return CustomApiResult.success(resultExt); + } +} diff --git a/lc123/cloud/app/api/model/SupplierModel.java b/lc123/cloud/app/api/model/SupplierModel.java new file mode 100644 index 0000000..f7597fa --- /dev/null +++ b/lc123/cloud/app/api/model/SupplierModel.java @@ -0,0 +1,355 @@ +package tqq9.lc123.cloud.app.api.model; + +import kd.bos.openapi.common.custom.annotation.ApiModel; +import kd.bos.openapi.common.custom.annotation.ApiParam; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@ApiModel +public class SupplierModel implements Serializable { + + @ApiParam(value = "单据集合", example = "") + private List data; + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + @ApiModel + public static class DataBean implements Serializable { + + @ApiParam(value = "经营状态", example = "A", required = false, position = 1) + private String tqq9_combofield3_jyzt; + + @ApiParam(value = "国家.名称", example = "J296I", required = false, position = 2) + private String tqq9_basedatafield1_name; + + @ApiParam(value = "创建人.工号", example = "qlteK", required = true, position = 3) + private String creator_number; + + @ApiParam(value = "创建时间", example = "2025-11-12 10:30:13", required = true, position = 4) + private Date createtime; + + @ApiParam(value = "成立日期", example = "2025-11-12", required = false, position = 5) + private Date tqq9_datefield5_clrq; + + @ApiParam(value = "法定代表人", example = "e5qo5", required = false, position = 6) + private String tqq9_textfield210; + + @ApiParam(value = "经营范围", example = "yNv5N", required = false, position = 7) + private String tqq9_textareafield_jyfw; + + @ApiParam(value = "注册资本", example = "lTc3V", required = false, position = 8) + private String tqq9_textfield3_zczb1; + + @ApiParam(value = "住所", example = "yhULb", required = false, position = 9) + private String tqq9_textfield4_zs1; + + @ApiParam(value = "供应商编号", example = "jCWlN", required = true, position = 10) + private String number; + + @ApiParam(value = "供应商名称", example = "YBeZa", required = true, position = 11) + private String name; + + @ApiParam(value = "供应商简称", example = "PvxKu", required = false, position = 12) + private String simplename; + + @ApiParam(value = "统一社会信用代码", example = "hTqsT", required = false, position = 13) + private String societycreditcode; + + @ApiParam(value = "供应商用途类型", example = "0", required = false, position = 14) + private String tqq9_usagescenarios; + + @ApiParam(value = "银行信息分录", example = "",required = true,position = 15) + private List entry_bank; + + @ApiParam(value = "附件", example = "",required = false,position = 16) + private List attachment; + + @ApiParam(value = "联系人分录", example = "",required = true,position = 17) + private List entry_linkman; + + public String getTqq9_combofield3_jyzt() { + return tqq9_combofield3_jyzt; + } + + public void setTqq9_combofield3_jyzt(String tqq9_combofield3_jyzt) { + this.tqq9_combofield3_jyzt = tqq9_combofield3_jyzt; + } + + public String getTqq9_basedatafield1_name() { + return tqq9_basedatafield1_name; + } + + public void setTqq9_basedatafield1_name(String tqq9_basedatafield1_name) { + this.tqq9_basedatafield1_name = tqq9_basedatafield1_name; + } + + public String getCreator_number() { + return creator_number; + } + + public void setCreator_number(String creator_number) { + this.creator_number = creator_number; + } + + public Date getCreatetime() { + return createtime; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getTqq9_datefield5_clrq() { + return tqq9_datefield5_clrq; + } + + public void setTqq9_datefield5_clrq(Date tqq9_datefield5_clrq) { + this.tqq9_datefield5_clrq = tqq9_datefield5_clrq; + } + + public String getTqq9_textfield210() { + return tqq9_textfield210; + } + + public void setTqq9_textfield210(String tqq9_textfield210) { + this.tqq9_textfield210 = tqq9_textfield210; + } + + public String getTqq9_textareafield_jyfw() { + return tqq9_textareafield_jyfw; + } + + public void setTqq9_textareafield_jyfw(String tqq9_textareafield_jyfw) { + this.tqq9_textareafield_jyfw = tqq9_textareafield_jyfw; + } + + public String getTqq9_textfield3_zczb1() { + return tqq9_textfield3_zczb1; + } + + public void setTqq9_textfield3_zczb1(String tqq9_textfield3_zczb1) { + this.tqq9_textfield3_zczb1 = tqq9_textfield3_zczb1; + } + + public String getTqq9_textfield4_zs1() { + return tqq9_textfield4_zs1; + } + + public void setTqq9_textfield4_zs1(String tqq9_textfield4_zs1) { + this.tqq9_textfield4_zs1 = tqq9_textfield4_zs1; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSimplename() { + return simplename; + } + + public void setSimplename(String simplename) { + this.simplename = simplename; + } + + public String getSocietycreditcode() { + return societycreditcode; + } + + public void setSocietycreditcode(String societycreditcode) { + this.societycreditcode = societycreditcode; + } + + public String getTqq9_usagescenarios() { + return tqq9_usagescenarios; + } + + public void setTqq9_usagescenarios(String tqq9_usagescenarios) { + this.tqq9_usagescenarios = tqq9_usagescenarios; + } + + public List getEntry_bank() { + return entry_bank; + } + + public void setEntry_bank(List entry_bank) { + this.entry_bank = entry_bank; + } + + public List getAttachment() { + return attachment; + } + + public void setAttachment(List attachment) { + this.attachment = attachment; + } + + public List getEntry_linkman() { + return entry_linkman; + } + + public void setEntry_linkman(List entry_linkman) { + this.entry_linkman = entry_linkman; + } + + @ApiModel + public static class BankBean implements Serializable { + @ApiParam(value = "银行信息分录.银行账号", example = "vdHNW",required = true,position = 1) + private String bankaccount; + + @ApiParam(value = "银行信息分录.收款方名称,", example = "GPy7s",required = true,position = 2) + private String accountname; + + @ApiParam(value = "银行信息分录.默认", example = "0",required = true,position = 3) + private Boolean isdefault_bank; + + @ApiParam(value = "银行信息分录.分录行号", example = "44",required = true,position = 4) + private Integer seq; + + @ApiParam(value = "开户银行.编码(行号)-联行号", example = "GPy7s",required = true,position = 5) + private String bank_number; + + public String getBankaccount() { + return bankaccount; + } + + public void setBankaccount(String bankaccount) { + this.bankaccount = bankaccount; + } + + public String getAccountname() { + return accountname; + } + + public void setAccountname(String accountname) { + this.accountname = accountname; + } + + public Boolean getIsdefault_bank() { + return isdefault_bank; + } + + public void setIsdefault_bank(Boolean isdefault_bank) { + this.isdefault_bank = isdefault_bank; + } + + public Integer getSeq() { + return seq; + } + + public void setSeq(Integer seq) { + this.seq = seq; + } + + public String getBank_number() { + return bank_number; + } + + public void setBank_number(String bank_number) { + this.bank_number = bank_number; + } + } + @ApiModel + public static class AttachmentBean implements Serializable { + @ApiParam(value = "附件.附件名称", example = "50Kr3",required = true,position = 1) + private String attachmentName; + + @ApiParam(value = "附件.附件地址", example = "hsUsx",required = false,position = 2) + private String attachmentUrl; + + public String getAttachmentName() { + return attachmentName; + } + + public void setAttachmentName(String attachmentName) { + this.attachmentName = attachmentName; + } + + public String getAttachmentUrl() { + return attachmentUrl; + } + + public void setAttachmentUrl(String attachmentUrl) { + this.attachmentUrl = attachmentUrl; + } + } + + @ApiModel + public static class LinkmanBean implements Serializable { + @ApiParam(value = "联系人分录.分录行号", example = "44",required = true,position = 1) + private Integer seq; + + @ApiParam(value = "联系人分录.联系人", example = "GPy7s",required = true,position = 2) + private String contactperson; + + @ApiParam(value = "联系人分录.联系电话", example = "0",required = false,position = 3) + private String phone; + + @ApiParam(value = "联系人分录.手机", example = "GPy7s",required = true,position = 4) + private String mobile; + + @ApiParam(value = "联系人分录.详细地址", example = "GPy7s",required = true,position = 5) + private String tqq9_textfield_xxdz; + + public Integer getSeq() { + return seq; + } + + public void setSeq(Integer seq) { + this.seq = seq; + } + + public String getContactperson() { + return contactperson; + } + + public void setContactperson(String contactperson) { + this.contactperson = contactperson; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getTqq9_textfield_xxdz() { + return tqq9_textfield_xxdz; + } + + public void setTqq9_textfield_xxdz(String tqq9_textfield_xxdz) { + this.tqq9_textfield_xxdz = tqq9_textfield_xxdz; + } + } + + } +} diff --git a/lc123/cloud/app/api/utils/AttachmentFileUtil.java b/lc123/cloud/app/api/utils/AttachmentFileUtil.java new file mode 100644 index 0000000..aae2873 --- /dev/null +++ b/lc123/cloud/app/api/utils/AttachmentFileUtil.java @@ -0,0 +1,313 @@ +package tqq9.lc123.cloud.app.api.utils; + +import com.kingdee.bos.qinglightapp.util.SslUtils; +import kd.bos.cache.CacheFactory; +import kd.bos.cache.TempFileCache; +import kd.bos.context.RequestContext; +import kd.bos.entity.MainEntityType; +import kd.bos.fileservice.FileItem; +import kd.bos.fileservice.FileService; +import kd.bos.fileservice.FileServiceFactory; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; +import kd.bos.servicehelper.AttachmentServiceHelper; +import kd.bos.servicehelper.MetadataServiceHelper; +import kd.bos.util.FileNameUtils; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.text.DecimalFormat; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author lxl + */ +public class AttachmentFileUtil { + + private final static Log logger = LogFactory.getLog(AttachmentFileUtil.class); + /** + * @param entity 目标单据实体标识 + * @param pk 目标数据id + * @param fileUrl 待存入文件的url + * @param fileName 带存入文件名称 + * @param fileSize 带存入文件大小 + * @param attachKey 附件面板标识 + * @throws IOException + */ + public static Map saveUrlFile2Attchment(String uid1,String entity, Object pk, String fileUrl, String fileName,String fileSize, String attachKey){ + List> attachments = new ArrayList<>(); + Map attachItem = new HashMap<>(); + Map result = new HashMap<>(); + attachItem.put("name", fileName); + attachItem.put("uid", uid1); + InputStream inputStream = null; + HttpURLConnection conn = null; + String tempUrl = null; + try { +// 连接url并 获取输入流 +// fileUrl = URLEncoder.encode(fileUrl,"UTF-8"); +// fileUrl = java.net.URLDecoder.decode(fileUrl, "UTF-8"); + fileUrl = encode(fileUrl,"UTF-8"); + logger.info("fileUrl:" + fileUrl); + URL url = new URL(fileUrl); + //忽略证书 + SslUtils.ignoreSsl(); + conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(25*1000); + conn.setReadTimeout(25*1000); + conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); + conn.setInstanceFollowRedirects(false); + inputStream = conn.getInputStream(); + logger.info("inputStream -- size:"+inputStream.available()); + System.out.println("inputStream:"+inputStream); +// inputStream = getInputStreamFromURL(fileUrl); + attachItem.put("size", getFileSizeByUrl(fileUrl)); +// 苍穹自带 + TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); + tempUrl = cache.saveAsFullUrl((String) attachItem.get("name"), inputStream, 600); + logger.info("tempUrl -- inputStream -- size:" + CacheFactory.getCommonCacheFactory().getTempFileCache().getInputStream(tempUrl).available()); + System.out.println(":tempUrl"+tempUrl); + } catch (Exception e) { + logger.info("附件上传失败,堆栈信息:",e); + result.put("isSuccess", "false"); + result.put("msg", "转文件流异常"+e); + return result; + } finally { + try { + if(inputStream!=null){ + inputStream.close(); + } + } catch (Exception e) { + logger.info("附件上传失败,堆栈信息01:",e); + result.put("isSuccess", "false"); + result.put("msg", "文件流关闭异常:"+e); + conn.disconnect(); + return result; + } + conn.disconnect(); + } + try{ + attachItem.put("lastModified",System.currentTimeMillis()); + MainEntityType dataEntityType = MetadataServiceHelper.getDataEntityType(entity); + String appId = dataEntityType.getAppId(); + + //上传到临时文件服务器 + String actUrl = AttachmentServiceHelper.saveTempToFileService(tempUrl,appId,entity, pk, (String)attachItem.get("name")); + logger.info("actUrl:"+actUrl); + System.out.println("actUrl:"+actUrl); + TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); + InputStream in = cache.getInputStream(tempUrl); + FileService service = FileServiceFactory.getAttachmentFileService(); + RequestContext requestContext = RequestContext.get(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + String pathParam = FileNameUtils.getAttachmentFileName(requestContext.getTenantId(), + requestContext.getAccountId(), uuid, fileName); + System.out.println("pathParam"+pathParam); + FileItem fileItem = new FileItem(fileName, pathParam, in); + + //从临时上传至 文件服务器 + String downUrl =service.upload(fileItem); + logger.info("downUrl:"+downUrl); + System.out.println("downUrl:"+downUrl); + + attachItem.put("url", actUrl); + attachments.add(attachItem); + // 绑定单据 + AttachmentServiceHelper.upload(entity, pk, attachKey, attachments); + + }catch(Exception e1){ + logger.info("附件上传失败,堆栈信息e1:",e1); + result.put("isSuccess", "false"); + result.put("msg", "上传服务器异常:"+e1); + return result; + } + result.put("isSuccess", "true"); + result.put("msg", "附件上传成功"); + return result; + } + + public static String ioPost(String tempUrl,String fileName,String entity,String size,String attachKey,Object pk){ + List> attachments = new ArrayList<>(); + Map attachItem = new HashMap<>(); + try{ + MainEntityType dataEntityType = MetadataServiceHelper.getDataEntityType(entity); + String appId = dataEntityType.getAppId(); + + //上传到临时文件服务器 + System.out.println(tempUrl); + String actUrl = AttachmentServiceHelper.saveTempToFileService(tempUrl,appId,entity, pk,fileName); + System.out.println("actUrl:"+actUrl); + TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); + InputStream in = cache.getInputStream(tempUrl); + FileService service = FileServiceFactory.getAttachmentFileService(); + RequestContext requestContext = RequestContext.get(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + String pathParam = FileNameUtils.getAttachmentFileName(requestContext.getTenantId(), + requestContext.getAccountId(), uuid, fileName); + System.out.println("pathParam:"+pathParam); + FileItem fileItem = new FileItem(fileName, pathParam, in); + + //从临时上传至 文件服务器 + String downUrl =service.upload(fileItem); + System.out.println("downUrl:"+downUrl); + + attachItem.put("name", fileName); + attachItem.put("size", size); + attachItem.put("lastModified",System.currentTimeMillis()); + attachItem.put("url", actUrl); + + attachments.add(attachItem); + // 绑定单据 + AttachmentServiceHelper.upload(entity, pk, attachKey, attachments); + }catch (Exception e){ + System.out.println(e); + return e.toString(); + } + return "ss"; + } + + /** + * 根据地址获得数据的字节流并转换成大小 + * @param strUrl 网络连接地址 + * @return + */ + public static int getFileSizeByUrl(String strUrl){ + InputStream inStream=null; + ByteArrayOutputStream outStream=null; + int size = 0; + try { + URL url = new URL(strUrl); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(5 * 1000); + inStream = conn.getInputStream(); + + outStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len = 0; + while( (len=inStream.read(buffer)) != -1 ){ + outStream.write(buffer, 0, len); + } + byte[] bt = outStream.toByteArray(); + + if(null != bt && bt.length > 0){ + DecimalFormat df = new DecimalFormat("#"); + size = Integer.parseInt(df.format((double) bt.length)); + + System.out.println("文件大小=:" + size); + }else{ + System.out.println("没有从该连接获得内容"); + } + inStream.close(); + outStream.close(); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try{ + if(inStream !=null){ + inStream.close(); + } + if(outStream !=null){ + outStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return size; + } + + private static InputStream getInputStreamFromURL(String urlString) throws IOException { + URL url = null; + try { + url = new URL(urlString); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + //设置超时间为3秒 + conn.setConnectTimeout(3*1000); + //防止屏蔽程序抓取而返回403错误 + conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); + //得到输入流 + return conn.getInputStream(); + } catch (Exception e) { + System.out.println(e); + } + return null; + } + + /** + * 处理url里的中文 + * @param url + * @return + */ + private static String zhPattern = "[\\u4e00-\\u9fa5]"; + + /** + * 替换字符串卷 + * + * @param str 被替换的字符串 + * @param charset 字符集 + * @return 替换好的 + * @throws UnsupportedEncodingException 不支持的字符集 + */ + public static String encode(String str, String charset) throws UnsupportedEncodingException { + Pattern p = Pattern.compile(zhPattern); + Matcher m = p.matcher(str); + StringBuffer b = new StringBuffer(); + while (m.find()) { + m.appendReplacement(b, URLEncoder.encode(m.group(0), charset)); + } + m.appendTail(b); + return b.toString(); + } + + public static void downloadFile(String fileUrl, String saveDir) throws IOException { + URL url = new URL(fileUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + String fileName = ""; + String disposition = connection.getHeaderField("Content-Disposition"); + String contentType = connection.getContentType(); + + if (disposition != null) { + int index = disposition.indexOf("filename="); + if (index > 0) { + fileName = disposition.substring(index + 10, disposition.length() - 1); + } + } else { fileUrl= URLDecoder.decode(fileUrl);//前面中文encode了,这里decode才能保持原文件名 + fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1); + } + + InputStream inputStream = connection.getInputStream(); + File saveFile=new File(saveDir); + if(!saveFile.exists()){ + saveFile.mkdirs(); + } + String saveFilePath = saveDir + File.separator + fileName; + + FileOutputStream outputStream = new FileOutputStream(saveFilePath); + + int bytesRead; + byte[] buffer = new byte[1024]; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + outputStream.close(); + inputStream.close(); + System.out.println(saveDir+"文件下载完成"); + } else { + System.out.println("文件下载失败,错误码:" + responseCode+";错误文件为"+saveDir); + } + connection.disconnect(); + } + +}