Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
		
						commit
						f8b1191489
					
				| 
						 | 
				
			
			@ -0,0 +1,92 @@
 | 
			
		|||
package zcgj.zcdev.zcdev.fs.plugin.form;
 | 
			
		||||
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObject;
 | 
			
		||||
import kd.bos.form.control.events.ItemClickEvent;
 | 
			
		||||
import kd.bos.list.plugin.AbstractListPlugin;
 | 
			
		||||
import kd.bos.orm.query.QCP;
 | 
			
		||||
import kd.bos.orm.query.QFilter;
 | 
			
		||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.fi.gl.servicehelper.BalanceQueryParam;
 | 
			
		||||
import kd.fi.gl.servicehelper.BanlanceServiceHelper;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 核算维度余额取数表(矿山二开)
 | 
			
		||||
 */
 | 
			
		||||
public class AssistbalancePlugin extends AbstractListPlugin implements Plugin  {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static String ksNumberTop = "10006431"; //矿山总部组织编码
 | 
			
		||||
    @Override
 | 
			
		||||
    public void itemClick(ItemClickEvent evt) {
 | 
			
		||||
        super.itemClick(evt);
 | 
			
		||||
        String itemKey = evt.getItemKey();
 | 
			
		||||
        if("zcgj_gatdata".equals(itemKey)) {
 | 
			
		||||
            BalanceQueryParam balanceQueryParam = new BalanceQueryParam();
 | 
			
		||||
            String[] selectorsArray = new String[]{"beginlocal", "endlocal",  "yeardebitfor","yearcreditfor","debitlocal","creditlocal"};
 | 
			
		||||
            Arrays.asList(selectorsArray).forEach(balanceQueryParam::addSelector);
 | 
			
		||||
 | 
			
		||||
            QFilter filterOrgId = new QFilter("number", QCP.equals,"100002");//主账簿
 | 
			
		||||
            DynamicObject accountbookstype = BusinessDataServiceHelper.loadSingle("bd_accountbookstype", "id,number", new QFilter[]{filterOrgId});
 | 
			
		||||
            balanceQueryParam.setBookTypeId(accountbookstype.getLong("id"));
 | 
			
		||||
 | 
			
		||||
            QFilter filterperiod = new QFilter("number", QCP.equals,"202501");//期间
 | 
			
		||||
            DynamicObject period = BusinessDataServiceHelper.loadSingle("bd_period", "id,number", new QFilter[]{filterperiod});
 | 
			
		||||
            balanceQueryParam.setPeriodId(period.getLong("id"));
 | 
			
		||||
 | 
			
		||||
            QFilter filtercurrency= new QFilter("number", QCP.equals,"CNY");//币别
 | 
			
		||||
            DynamicObject currency = BusinessDataServiceHelper.loadSingle("bd_currency", "id,number", new QFilter[]{filtercurrency});
 | 
			
		||||
            balanceQueryParam.setCurrencyId(currency.getLong("id"));
 | 
			
		||||
 | 
			
		||||
            QFilter filteraccount= new QFilter("number", QCP.equals,"112204");//会计科目
 | 
			
		||||
            DynamicObject account = BusinessDataServiceHelper.loadSingle("bd_accountview", "id,number", new QFilter[]{filteraccount});
 | 
			
		||||
 | 
			
		||||
            List<Map<String, Long>> paramMap = new ArrayList<>();
 | 
			
		||||
            Map<String, Long> map = new HashMap<>();
 | 
			
		||||
            map.put("0001",0L);
 | 
			
		||||
            paramMap.add(map);
 | 
			
		||||
            balanceQueryParam.setAccountAssgrp(account.getLong("id"),paramMap);
 | 
			
		||||
            balanceQueryParam.addGroupBy("0001");
 | 
			
		||||
            balanceQueryParam.addGroupBy("account");
 | 
			
		||||
            for (Long orgId : getKsOrg()) {
 | 
			
		||||
                balanceQueryParam.setOrgId(orgId);
 | 
			
		||||
                List<Map<String, Object>> balance = BanlanceServiceHelper.getBalance(balanceQueryParam);
 | 
			
		||||
                System.out.println();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            System.out.println();
 | 
			
		||||
            System.out.println();
 | 
			
		||||
            //balanceQueryParam.setAccountAssgrp();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            /*
 | 
			
		||||
            private long orgId;
 | 
			
		||||
            private long bookTypeId; ..
 | 
			
		||||
            private long periodId;
 | 
			
		||||
            private long currencyId;
 | 
			
		||||
            private Map<Long, List<Map<String, Long>>> accountAssgrp = new HashMap();
 | 
			
		||||
            private List<String> groupBys = new ArrayList();
 | 
			
		||||
            private boolean isSubstractPL = false;*/
 | 
			
		||||
            //BanlanceServiceHelper.getBalance(balanceQueryParam);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Set<Long> getKsOrg(){
 | 
			
		||||
        QFilter filterOrgId = new QFilter("number", QCP.equals,ksNumberTop);//中材矿山建设有限公司
 | 
			
		||||
        DynamicObject adminOrg = BusinessDataServiceHelper.loadSingle("bos_org", "number,name,fullname", new QFilter[]{filterOrgId});
 | 
			
		||||
        long orgId = adminOrg.getLong("id");
 | 
			
		||||
        List<Long> orgIds = new ArrayList<>(1);
 | 
			
		||||
        //orgIds.add(1692204547985902592L);
 | 
			
		||||
        orgIds.add(orgId);
 | 
			
		||||
        List<Long> subOrgIds = OrgUnitServiceHelper.getAllSubordinateOrgs(1L, orgIds, true);
 | 
			
		||||
        return subOrgIds.stream().collect(Collectors.toSet());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package zcgj.zcdev.zcdev.pr.plugin.form;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.excel.util.StringUtils;
 | 
			
		||||
import com.greenpineyu.fel.common.NumberUtil;
 | 
			
		||||
import kd.bos.coderule.api.CodeRuleInfo;
 | 
			
		||||
import kd.bos.coderule.service.cache.CodeRuleCache;
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +8,8 @@ import kd.bos.dataentity.entity.DynamicObject;
 | 
			
		|||
import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
			
		||||
import kd.bos.entity.datamodel.ListSelectedRow;
 | 
			
		||||
import kd.bos.entity.datamodel.ListSelectedRowCollection;
 | 
			
		||||
import kd.bos.entity.operate.result.IOperateInfo;
 | 
			
		||||
import kd.bos.entity.operate.result.OperateErrorInfo;
 | 
			
		||||
import kd.bos.entity.operate.result.OperationResult;
 | 
			
		||||
import kd.bos.form.IFormView;
 | 
			
		||||
import kd.bos.form.control.events.BeforeItemClickEvent;
 | 
			
		||||
| 
						 | 
				
			
			@ -20,9 +23,11 @@ import kd.bos.orm.ORM;
 | 
			
		|||
import kd.bos.orm.query.QCP;
 | 
			
		||||
import kd.bos.orm.query.QFilter;
 | 
			
		||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.QueryServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.fi.gl.util.DateUtil;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +40,7 @@ import java.time.YearMonth;
 | 
			
		|||
import java.time.format.DateTimeFormatter;
 | 
			
		||||
import java.time.format.DateTimeParseException;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,6 +57,17 @@ public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugi
 | 
			
		|||
        super.itemClick(evt);
 | 
			
		||||
        String itemKey = evt.getItemKey();
 | 
			
		||||
        if (itemKey.equals("zcgj_idle")){//闲置
 | 
			
		||||
            Set<Long> setIds = getSelectOrderIds(this.getSelectedRows());
 | 
			
		||||
            DynamicObject[] equipments = BusinessDataServiceHelper.load("eceq_equipment_card", "billno,billname,equipstatus", new QFilter[]{new QFilter("id", "in", setIds)});
 | 
			
		||||
            for (DynamicObject equipment : equipments) {
 | 
			
		||||
                equipment.set("equipstatus","FREE");
 | 
			
		||||
            }
 | 
			
		||||
            Object[] save = SaveServiceHelper.save(equipments);
 | 
			
		||||
            System.out.println();
 | 
			
		||||
            this.getView().showMessage("闲置成功!");
 | 
			
		||||
            IFormView view = this.getView();
 | 
			
		||||
            view.invokeOperation("refresh");
 | 
			
		||||
        } else if (itemKey.equals("zcgj_asset")) {//同步资产卡片
 | 
			
		||||
            Set<String> strings = new HashSet();
 | 
			
		||||
            DynamicObject[] equipmenttype = BusinessDataServiceHelper.load("zcgj_equipmenttype", "number,zcgj_assetcat",new QFilter[]{new QFilter("zcgj_assetcat.number", QCP.is_notnull,"" )});
 | 
			
		||||
            for (DynamicObject dynamicObject : equipmenttype) {
 | 
			
		||||
| 
						 | 
				
			
			@ -59,11 +76,24 @@ public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugi
 | 
			
		|||
                    strings.add(number) ;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            QFilter filterOrgId = new QFilter("number", QCP.equals,"10006431");//中材矿山建设有限公司
 | 
			
		||||
            DynamicObject adminOrg = BusinessDataServiceHelper.loadSingle("bos_org", "number,name,fullname", new QFilter[]{filterOrgId});
 | 
			
		||||
            long orgId = adminOrg.getLong("id");
 | 
			
		||||
            List<Long> orgIds = new ArrayList<>(1);
 | 
			
		||||
            //orgIds.add(1692204547985902592L);
 | 
			
		||||
            orgIds.add(orgId);
 | 
			
		||||
            List<Long> subOrgIds = OrgUnitServiceHelper.getAllSubordinateOrgs(1L, orgIds, true);
 | 
			
		||||
            Set<Long> orgSer = subOrgIds.stream().collect(Collectors.toSet());
 | 
			
		||||
            Set<String> orgcset = new HashSet();
 | 
			
		||||
            for (Long l : orgSer) {
 | 
			
		||||
                orgcset.add(l.toString());
 | 
			
		||||
            }
 | 
			
		||||
            QFilter qFilter = new QFilter("assetcat.number", QCP.in, strings);
 | 
			
		||||
            qFilter.and(new QFilter("assetunit.fullname", QCP.like, "中材矿山")) ;
 | 
			
		||||
            QFilter qFilter2 = new QFilter("assetunit.id", QCP.in, orgSer);
 | 
			
		||||
            DynamicObject[] realcards = BusinessDataServiceHelper.load("fa_asset_card", "zcgj_costcenter,headusedept,finentry,assetcat,number,assetname,model,realaccountdate," +
 | 
			
		||||
                    "assetunit,supplier,zcgj_platenumber,unit,zcgj_manufacturer,zcgj_prodate,storeplace,creator,createtime,modifier,modifytime,auditdate,auditor,finentry.fin_originalval,finentry.fin_preresidualval,finentry.fin_depredamount,finentry.fin_preusingamount,finentry.fin_accumdepre,finentry.fin_networth", new QFilter[]{qFilter});
 | 
			
		||||
                    "assetunit,supplier,zcgj_platenumber,unit,zcgj_manufacturer,zcgj_prodate,storeplace,creator,createtime,modifier,modifytime,auditdate,auditor,finentry.fin_originalval,finentry.fin_preresidualval,finentry.fin_depredamount,finentry.fin_preusingamount,finentry.fin_accumdepre,finentry.fin_networth", new QFilter[]{qFilter,qFilter2});
 | 
			
		||||
            log.info("同步的实物数量有"+realcards.length);
 | 
			
		||||
            String operationResultErrorInfos = null;
 | 
			
		||||
            for (DynamicObject realcard : realcards) {
 | 
			
		||||
                String number = realcard.getString("number");//资产编码
 | 
			
		||||
//                DynamicObject assetcat = realcard.getDynamicObject("assetcat");//资产类别
 | 
			
		||||
| 
						 | 
				
			
			@ -110,6 +140,7 @@ public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugi
 | 
			
		|||
                }else{
 | 
			
		||||
                    equipmentcard.set("number",getCodeRule(equipmentcard,"53BT+ZJB86=L"));//设备编号
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                equipmentcard.set("billno",timeText);//单据编号
 | 
			
		||||
                equipmentcard.set("status","C");//单据状态
 | 
			
		||||
                equipmentcard.set("billstatus","C");//
 | 
			
		||||
| 
						 | 
				
			
			@ -139,32 +170,54 @@ public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugi
 | 
			
		|||
                equipmentcard.set("auditdate",auditdate);//审核日期
 | 
			
		||||
                equipmentcard.set("zcgj_assetnumber",number);//资产编码
 | 
			
		||||
                equipmentcard.set("zcgj_headusedepts",headusedept);//使用部门
 | 
			
		||||
                equipmentcard.set("zcgj_costcenters",zcgj_costcenter);//审核日期
 | 
			
		||||
 | 
			
		||||
                equipmentcard.set("zcgj_costcenters",zcgj_costcenter);//成本中心
 | 
			
		||||
                BigDecimal finOriginalval = BigDecimal.ZERO;
 | 
			
		||||
                BigDecimal fin_preusingamount = BigDecimal.ZERO;
 | 
			
		||||
                BigDecimal fin_depredamount = BigDecimal.ZERO;
 | 
			
		||||
                BigDecimal fin_preresidualval = BigDecimal.ZERO;
 | 
			
		||||
                BigDecimal fin_accumdepre = BigDecimal.ZERO;
 | 
			
		||||
                BigDecimal fin_networth = BigDecimal.ZERO;
 | 
			
		||||
                if(finentrys.size()>0){
 | 
			
		||||
                    DynamicObject finentry = finentrys.get(0);
 | 
			
		||||
                    BigDecimal fin_originalval = finentry.getBigDecimal("fin_originalval");//资产原值
 | 
			
		||||
                    BigDecimal fin_preusingamount = finentry.getBigDecimal("fin_preusingamount");//预计使用月
 | 
			
		||||
                    BigDecimal fin_depredamount = finentry.getBigDecimal("fin_depredamount");//已折旧月
 | 
			
		||||
                    BigDecimal fin_preresidualval = finentry.getBigDecimal("fin_preresidualval");//预计净残值
 | 
			
		||||
                    BigDecimal fin_accumdepre = finentry.getBigDecimal("fin_accumdepre");//累计折旧
 | 
			
		||||
                    BigDecimal fin_networth = finentry.getBigDecimal("fin_networth");//净值
 | 
			
		||||
                    finOriginalval = finentry.getBigDecimal("fin_originalval");//资产原值
 | 
			
		||||
                    fin_preusingamount = finentry.getBigDecimal("fin_preusingamount");//预计使用月
 | 
			
		||||
                    fin_depredamount = finentry.getBigDecimal("fin_depredamount");//已折旧月
 | 
			
		||||
                    fin_preresidualval = finentry.getBigDecimal("fin_preresidualval");//预计净残值
 | 
			
		||||
                    fin_accumdepre = finentry.getBigDecimal("fin_accumdepre");//累计折旧
 | 
			
		||||
                    fin_networth = finentry.getBigDecimal("fin_networth");//净值
 | 
			
		||||
                    equipmentcard.set("zcgj_networth",fin_networth);
 | 
			
		||||
                    equipmentcard.set("zcgj_accumdepre",fin_accumdepre);
 | 
			
		||||
                    equipmentcard.set("zcgj_depredamount",fin_depredamount);
 | 
			
		||||
                    equipmentcard.set("zcgj_preresidualval",fin_preresidualval);
 | 
			
		||||
                    equipmentcard.set("zcgj_preusingamount",fin_preusingamount);
 | 
			
		||||
                    equipmentcard.set("unitprice",fin_originalval);
 | 
			
		||||
                    equipmentcard.set("unitprice",finOriginalval);
 | 
			
		||||
                }
 | 
			
		||||
                if (eceq_equipment_card!=null){
 | 
			
		||||
                    SaveServiceHelper.update(equipmentcard);
 | 
			
		||||
                    System.out.println();
 | 
			
		||||
                }else {
 | 
			
		||||
                    OperationResult result = OperationServiceHelper.executeOperate("save", "eceq_equipment_card", new DynamicObject[]{equipmentcard}, null);
 | 
			
		||||
                    System.out.println();
 | 
			
		||||
                    String operationResultErrorInfo  = getOperationResultErrorInfos(result);
 | 
			
		||||
                    if (!operationResultErrorInfo.isEmpty() && operationResultErrorInfo!=null){
 | 
			
		||||
                        operationResultErrorInfos = operationResultErrorInfo + operationResultErrorInfos;
 | 
			
		||||
                        System.out.println(number+assetname+"报错信息为:"+operationResultErrorInfos);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            this.getView().showMessage("同步操作成功。");
 | 
			
		||||
                DynamicObject eceq_equipment = BusinessDataServiceHelper.loadSingle("eceq_equipinfo", new QFilter[]{new QFilter("zcgj_assetnumber", QCP.equals, number)});
 | 
			
		||||
                if (eceq_equipment != null) {
 | 
			
		||||
                    eceq_equipment.set("zcgj_assetnumber",number);//资产编码
 | 
			
		||||
                    eceq_equipment.set("zcgj_headusedepts",headusedept);//使用部门
 | 
			
		||||
                    eceq_equipment.set("zcgj_costcenters",zcgj_costcenter);//成本中心
 | 
			
		||||
                    eceq_equipment.set("zcgj_networth",fin_networth);
 | 
			
		||||
                    eceq_equipment.set("zcgj_accumdepre",fin_accumdepre);
 | 
			
		||||
                    eceq_equipment.set("zcgj_depredamount",fin_depredamount);
 | 
			
		||||
                    eceq_equipment.set("zcgj_preresidualval",fin_preresidualval);
 | 
			
		||||
                    eceq_equipment.set("zcgj_preusingamount",fin_preusingamount);
 | 
			
		||||
                    eceq_equipment.set("unitprice",finOriginalval);
 | 
			
		||||
                    DynamicObjectCollection entrys = eceq_equipment.getDynamicObjectCollection("zcgj_entryentity");
 | 
			
		||||
                    SaveServiceHelper.save(new DynamicObject[]{eceq_equipment});
 | 
			
		||||
                }
 | 
			
		||||
                System.out.println("总报错信息为:"+operationResultErrorInfos);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -252,15 +305,57 @@ public class EquipmentCardListPlugin extends AbstractListPlugin implements Plugi
 | 
			
		|||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static String getCodeRule(DynamicObject data,String number) {
 | 
			
		||||
        String archivebillno = null;
 | 
			
		||||
        //查找编码规则
 | 
			
		||||
        DynamicObject coderule = BusinessDataServiceHelper.loadSingle("bos_coderule", "id", new QFilter[]{new QFilter("number", QCP.equals, number)});
 | 
			
		||||
        //编码对象
 | 
			
		||||
        if (coderule != null) {
 | 
			
		||||
            CodeRuleInfo codeRule = CodeRuleCache.reloadCodeRuleById(coderule.getString("id"));
 | 
			
		||||
            //生成箱号编码
 | 
			
		||||
            String archivebillno = CodeRuleServiceHelper.getNumber(codeRule, data);
 | 
			
		||||
            archivebillno = CodeRuleServiceHelper.getNumber(codeRule, data);
 | 
			
		||||
        }
 | 
			
		||||
        if(archivebillno.isEmpty() && archivebillno==null){
 | 
			
		||||
 | 
			
		||||
            DynamicObject dynamicObject = BusinessDataServiceHelper.newDynamicObject("eceq_equipment_card");
 | 
			
		||||
            // 调用自动编码规则
 | 
			
		||||
            CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(dynamicObject.getDataEntityType().getName(), dynamicObject, null);
 | 
			
		||||
            // 获取单据编码
 | 
			
		||||
            archivebillno = CodeRuleServiceHelper.getNumber(codeRule, dynamicObject);
 | 
			
		||||
        }
 | 
			
		||||
        log.info("生成的设备编号为"+archivebillno);
 | 
			
		||||
        return archivebillno;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取操作错误信息
 | 
			
		||||
     * @param operationResult
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private String getOperationResultErrorInfos(OperationResult operationResult){
 | 
			
		||||
        if(operationResult.isSuccess()){
 | 
			
		||||
            return StringUtils.EMPTY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo();
 | 
			
		||||
        int size = errorInfos.size() + operationResult.getSuccessPkIds().size();
 | 
			
		||||
        if (size > 1) {
 | 
			
		||||
            StringBuilder stringBuilder = new StringBuilder();
 | 
			
		||||
            int i = 0;
 | 
			
		||||
            for(int len = errorInfos.size(); i < 5 && i < len; ++i) {
 | 
			
		||||
                stringBuilder.append((errorInfos.get(i)).getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            return stringBuilder.toString();
 | 
			
		||||
        } else if (!errorInfos.isEmpty()) {
 | 
			
		||||
            OperateErrorInfo errorInfo = (OperateErrorInfo)errorInfos.get(0);
 | 
			
		||||
            String msg = errorInfo.getMessage() == null ? "" : errorInfo.getMessage();
 | 
			
		||||
            return msg;
 | 
			
		||||
        } else{
 | 
			
		||||
            String msg = operationResult.getMessage() == null ? "" : operationResult.getMessage();
 | 
			
		||||
            return msg;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,14 @@
 | 
			
		|||
package zcgj.zcdev.zcdev.pr.task;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.excel.util.StringUtils;
 | 
			
		||||
import kd.bos.algo.DataSet;
 | 
			
		||||
import kd.bos.coderule.api.CodeRuleInfo;
 | 
			
		||||
import kd.bos.coderule.service.cache.CodeRuleCache;
 | 
			
		||||
import kd.bos.context.RequestContext;
 | 
			
		||||
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.OperateErrorInfo;
 | 
			
		||||
import kd.bos.entity.operate.result.OperationResult;
 | 
			
		||||
import kd.bos.exception.KDException;
 | 
			
		||||
import kd.bos.logging.Log;
 | 
			
		||||
| 
						 | 
				
			
			@ -19,6 +22,7 @@ import kd.bos.servicehelper.QueryServiceHelper;
 | 
			
		|||
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +31,7 @@ import java.time.YearMonth;
 | 
			
		|||
import java.time.format.DateTimeFormatter;
 | 
			
		||||
import java.time.format.DateTimeParseException;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -45,11 +50,24 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
 | 
			
		|||
                strings.add(number) ;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        QFilter filterOrgId = new QFilter("number", QCP.equals,"10006431");//中材矿山建设有限公司
 | 
			
		||||
        DynamicObject adminOrg = BusinessDataServiceHelper.loadSingle("bos_org", "number,name,fullname", new QFilter[]{filterOrgId});
 | 
			
		||||
        long orgId = adminOrg.getLong("id");
 | 
			
		||||
        List<Long> orgIds = new ArrayList<>(1);
 | 
			
		||||
        //orgIds.add(1692204547985902592L);
 | 
			
		||||
        orgIds.add(orgId);
 | 
			
		||||
        List<Long> subOrgIds = OrgUnitServiceHelper.getAllSubordinateOrgs(1L, orgIds, true);
 | 
			
		||||
        Set<Long> orgSer = subOrgIds.stream().collect(Collectors.toSet());
 | 
			
		||||
        Set<String> orgcset = new HashSet();
 | 
			
		||||
        for (Long l : orgSer) {
 | 
			
		||||
            orgcset.add(l.toString());
 | 
			
		||||
        }
 | 
			
		||||
        QFilter qFilter = new QFilter("assetcat.number", QCP.in, strings);
 | 
			
		||||
        qFilter.and(new QFilter("assetunit.fullname", QCP.like, "中材矿山")) ;
 | 
			
		||||
        QFilter qFilter2 = new QFilter("assetunit.id", QCP.in, orgSer);
 | 
			
		||||
        DynamicObject[] realcards = BusinessDataServiceHelper.load("fa_asset_card", "zcgj_costcenter,headusedept,finentry,assetcat,number,assetname,model,realaccountdate," +
 | 
			
		||||
                "assetunit,supplier,zcgj_platenumber,unit,zcgj_manufacturer,zcgj_prodate,storeplace,creator,createtime,modifier,modifytime,auditdate,auditor,finentry.fin_originalval,finentry.fin_preresidualval,finentry.fin_depredamount,finentry.fin_preusingamount,finentry.fin_accumdepre,finentry.fin_networth", new QFilter[]{qFilter});
 | 
			
		||||
                "assetunit,supplier,zcgj_platenumber,unit,zcgj_manufacturer,zcgj_prodate,storeplace,creator,createtime,modifier,modifytime,auditdate,auditor,finentry.fin_originalval,finentry.fin_preresidualval,finentry.fin_depredamount,finentry.fin_preusingamount,finentry.fin_accumdepre,finentry.fin_networth", new QFilter[]{qFilter,qFilter2});
 | 
			
		||||
        log.info("同步的实物数量有"+realcards.length);
 | 
			
		||||
        String operationResultErrorInfos = null;
 | 
			
		||||
        for (DynamicObject realcard : realcards) {
 | 
			
		||||
            String number = realcard.getString("number");//资产编码
 | 
			
		||||
//                DynamicObject assetcat = realcard.getDynamicObject("assetcat");//资产类别
 | 
			
		||||
| 
						 | 
				
			
			@ -126,16 +144,21 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
 | 
			
		|||
            equipmentcard.set("auditdate",auditdate);//审核日期
 | 
			
		||||
            equipmentcard.set("zcgj_assetnumber",number);//资产编码
 | 
			
		||||
            equipmentcard.set("zcgj_headusedepts",headusedept);//使用部门
 | 
			
		||||
            equipmentcard.set("zcgj_costcenters",zcgj_costcenter);//审核日期
 | 
			
		||||
 | 
			
		||||
            equipmentcard.set("zcgj_costcenters",zcgj_costcenter);//成本中心
 | 
			
		||||
            BigDecimal finOriginalval = BigDecimal.ZERO;
 | 
			
		||||
            BigDecimal fin_preusingamount = BigDecimal.ZERO;
 | 
			
		||||
            BigDecimal fin_depredamount = BigDecimal.ZERO;
 | 
			
		||||
            BigDecimal fin_preresidualval = BigDecimal.ZERO;
 | 
			
		||||
            BigDecimal fin_accumdepre = BigDecimal.ZERO;
 | 
			
		||||
            BigDecimal fin_networth = BigDecimal.ZERO;
 | 
			
		||||
            if(finentrys.size()>0){
 | 
			
		||||
                DynamicObject finentry = finentrys.get(0);
 | 
			
		||||
                BigDecimal finOriginalval = finentry.getBigDecimal("fin_originalval");//资产原值
 | 
			
		||||
                BigDecimal fin_preusingamount = finentry.getBigDecimal("fin_preusingamount");//预计使用月
 | 
			
		||||
                BigDecimal fin_depredamount = finentry.getBigDecimal("fin_depredamount");//已折旧月
 | 
			
		||||
                BigDecimal fin_preresidualval = finentry.getBigDecimal("fin_preresidualval");//预计净残值
 | 
			
		||||
                BigDecimal fin_accumdepre = finentry.getBigDecimal("fin_accumdepre");//累计折旧
 | 
			
		||||
                BigDecimal fin_networth = finentry.getBigDecimal("fin_networth");//净值
 | 
			
		||||
                finOriginalval = finentry.getBigDecimal("fin_originalval");//资产原值
 | 
			
		||||
                fin_preusingamount = finentry.getBigDecimal("fin_preusingamount");//预计使用月
 | 
			
		||||
                fin_depredamount = finentry.getBigDecimal("fin_depredamount");//已折旧月
 | 
			
		||||
                fin_preresidualval = finentry.getBigDecimal("fin_preresidualval");//预计净残值
 | 
			
		||||
                fin_accumdepre = finentry.getBigDecimal("fin_accumdepre");//累计折旧
 | 
			
		||||
                fin_networth = finentry.getBigDecimal("fin_networth");//净值
 | 
			
		||||
                equipmentcard.set("zcgj_networth",fin_networth);
 | 
			
		||||
                equipmentcard.set("zcgj_accumdepre",fin_accumdepre);
 | 
			
		||||
                equipmentcard.set("zcgj_depredamount",fin_depredamount);
 | 
			
		||||
| 
						 | 
				
			
			@ -145,13 +168,25 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
 | 
			
		|||
            }
 | 
			
		||||
            if (eceq_equipment_card!=null){
 | 
			
		||||
                SaveServiceHelper.update(equipmentcard);
 | 
			
		||||
                System.out.println();
 | 
			
		||||
            }else {
 | 
			
		||||
                OperationResult result = OperationServiceHelper.executeOperate("save", "eceq_equipment_card", new DynamicObject[]{equipmentcard}, null);
 | 
			
		||||
                System.out.println();
 | 
			
		||||
                String operationResultErrorInfo  = getOperationResultErrorInfos(result);
 | 
			
		||||
                if (!operationResultErrorInfo.isEmpty() && operationResultErrorInfo!=null){
 | 
			
		||||
                    operationResultErrorInfos = operationResultErrorInfo + operationResultErrorInfos;
 | 
			
		||||
                    System.out.println(number+assetname+"报错信息为:"+operationResultErrorInfos);
 | 
			
		||||
                }
 | 
			
		||||
            DynamicObject eceq_equipment = BusinessDataServiceHelper.loadSingle("eceq_equipinfo", new QFilter[]{new QFilter("number", QCP.equals, number)});
 | 
			
		||||
            }
 | 
			
		||||
            DynamicObject eceq_equipment = BusinessDataServiceHelper.loadSingle("eceq_equipinfo", new QFilter[]{new QFilter("zcgj_assetnumber", QCP.equals, number)});
 | 
			
		||||
            if (eceq_equipment != null) {
 | 
			
		||||
                eceq_equipment.set("zcgj_assetnumber",number);//资产编码
 | 
			
		||||
                eceq_equipment.set("zcgj_headusedepts",headusedept);//使用部门
 | 
			
		||||
                eceq_equipment.set("zcgj_costcenters",zcgj_costcenter);//成本中心
 | 
			
		||||
                eceq_equipment.set("zcgj_networth",fin_networth);
 | 
			
		||||
                eceq_equipment.set("zcgj_accumdepre",fin_accumdepre);
 | 
			
		||||
                eceq_equipment.set("zcgj_depredamount",fin_depredamount);
 | 
			
		||||
                eceq_equipment.set("zcgj_preresidualval",fin_preresidualval);
 | 
			
		||||
                eceq_equipment.set("zcgj_preusingamount",fin_preusingamount);
 | 
			
		||||
                eceq_equipment.set("unitprice",finOriginalval);
 | 
			
		||||
                DynamicObjectCollection entrys = eceq_equipment.getDynamicObjectCollection("zcgj_entryentity");
 | 
			
		||||
                QFilter qf = new QFilter("realcard.number", QCP.equals, number);
 | 
			
		||||
//                if (entrys.size() > 0) {//若分录行数大于0 则取上月的
 | 
			
		||||
| 
						 | 
				
			
			@ -198,6 +233,7 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
 | 
			
		|||
                }
 | 
			
		||||
                SaveServiceHelper.save(new DynamicObject[]{eceq_equipment});
 | 
			
		||||
            }
 | 
			
		||||
            System.out.println("总报错信息为:"+operationResultErrorInfos);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -267,17 +303,55 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
 | 
			
		|||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static String getCodeRule(DynamicObject data,String number) {
 | 
			
		||||
        String archivebillno = null;
 | 
			
		||||
        //查找编码规则
 | 
			
		||||
        DynamicObject coderule = BusinessDataServiceHelper.loadSingle("bos_coderule", "id", new QFilter[]{new QFilter("number", QCP.equals, number)});
 | 
			
		||||
        //编码对象
 | 
			
		||||
        if (coderule != null) {
 | 
			
		||||
            CodeRuleInfo codeRule = CodeRuleCache.reloadCodeRuleById(coderule.getString("id"));
 | 
			
		||||
            //生成箱号编码
 | 
			
		||||
            String archivebillno = CodeRuleServiceHelper.getNumber(codeRule, data);
 | 
			
		||||
            archivebillno = CodeRuleServiceHelper.getNumber(codeRule, data);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
        if(archivebillno.isEmpty() && archivebillno==null){
 | 
			
		||||
            DynamicObject dynamicObject = BusinessDataServiceHelper.newDynamicObject("eceq_equipment_card");
 | 
			
		||||
            // 调用自动编码规则
 | 
			
		||||
            CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(dynamicObject.getDataEntityType().getName(), dynamicObject, null);
 | 
			
		||||
            // 获取单据编码
 | 
			
		||||
            archivebillno = CodeRuleServiceHelper.getNumber(codeRule, dynamicObject);
 | 
			
		||||
        }
 | 
			
		||||
        log.info("生成的设备编号为"+archivebillno);
 | 
			
		||||
        return archivebillno;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取操作错误信息
 | 
			
		||||
     * @param operationResult
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private String getOperationResultErrorInfos(OperationResult operationResult){
 | 
			
		||||
        if(operationResult.isSuccess()){
 | 
			
		||||
            return StringUtils.EMPTY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo();
 | 
			
		||||
        int size = errorInfos.size() + operationResult.getSuccessPkIds().size();
 | 
			
		||||
        if (size > 1) {
 | 
			
		||||
            StringBuilder stringBuilder = new StringBuilder();
 | 
			
		||||
            int i = 0;
 | 
			
		||||
            for(int len = errorInfos.size(); i < 5 && i < len; ++i) {
 | 
			
		||||
                stringBuilder.append((errorInfos.get(i)).getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            return stringBuilder.toString();
 | 
			
		||||
        } else if (!errorInfos.isEmpty()) {
 | 
			
		||||
            OperateErrorInfo errorInfo = (OperateErrorInfo)errorInfos.get(0);
 | 
			
		||||
            String msg = errorInfo.getMessage() == null ? "" : errorInfo.getMessage();
 | 
			
		||||
            return msg;
 | 
			
		||||
        } else{
 | 
			
		||||
            String msg = operationResult.getMessage() == null ? "" : operationResult.getMessage();
 | 
			
		||||
            return msg;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//                DynamicObject[] depresplitdetails = BusinessDataServiceHelper.load("fa_depresplitdetail", "billno,period,splitdept,assentry.costcentrer,assentry.splitamount", new QFilter[]{qf});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue