|
@@ -0,0 +1,342 @@
|
|
|
|
+package nc.mc.br.plugin;
|
|
|
|
+
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.io.StringWriter;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import org.jeecg.common.util.GetDataUtil;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+
|
|
|
|
+import nc.bs.framework.common.NCLocator;
|
|
|
|
+import nc.bs.pub.taskcenter.BgWorkingContext;
|
|
|
|
+import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
|
|
|
|
+import nc.itf.gl.pub.IFreevaluePub;
|
|
|
|
+import nc.itf.mc.IEteamsService;
|
|
|
|
+import nc.vo.bd.b04.DeptdocVO;
|
|
|
|
+import nc.vo.gl.pubvoucher.DetailVO;
|
|
|
|
+import nc.vo.gl.pubvoucher.VoucherVO;
|
|
|
|
+import nc.vo.glcom.ass.AssVO;
|
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
|
+import nc.vo.pub.VOStatus;
|
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
|
+import nc.vo.pub.lang.UFDate;
|
|
|
|
+import nc.vo.pub.lang.UFDouble;
|
|
|
|
+import u8c.log.NcLog;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 安装队进度款
|
|
|
|
+ * @author
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+public class InstallTeamProgressPaymentPlugin implements IBackgroundWorkPlugin{
|
|
|
|
+
|
|
|
|
+ public String id = "&id=926089863630626869";
|
|
|
|
+ private IEteamsService service = NCLocator.getInstance().lookup(IEteamsService.class);
|
|
|
|
+ private IFreevaluePub freepub = NCLocator.getInstance().lookup(IFreevaluePub.class);
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String executeTask(BgWorkingContext arg0) throws BusinessException {
|
|
|
|
+ try {
|
|
|
|
+ String code = service.getCode();
|
|
|
|
+ String token = service.getToken(code);
|
|
|
|
+ JSONArray alldata = service.getAllId(id,token);
|
|
|
|
+ List<String> ids = new ArrayList<String>();
|
|
|
|
+ List<String> serNums = new ArrayList<String>();
|
|
|
|
+ for (int i = 0; i < alldata.size(); i++) {
|
|
|
|
+ JSONObject json = JSONObject.parseObject(alldata.getString(i));
|
|
|
|
+ ids.add("&id="+json.getString("id"));
|
|
|
|
+ serNums.add(json.getString("serNum"));
|
|
|
|
+ }
|
|
|
|
+ String serNum = null;
|
|
|
|
+ Map<String,String> map = GetDataUtil.getVoucher(serNums);
|
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
|
|
+ try {
|
|
|
|
+ JSONObject json = service.getInfoByID(token, ids.get(i));
|
|
|
|
+ //如果有匹配值表示在NC存在该凭证,跳过这条数据的保存
|
|
|
|
+ serNum = json.getJSONObject("flowRequest").getString("serNum");
|
|
|
|
+ String currentNode = json.getJSONObject("flowRequest").getString("currentNode");
|
|
|
|
+ if(map.get(serNum) != null || !"结束节点".equals(currentNode)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ saveVoucher(json);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
|
+ // 获取详细信息
|
|
|
|
+ String msg = stringWriter.getBuffer().toString();
|
|
|
|
+ NcLog.info("安装队进度款生成凭证失败,单号:"+serNum+"\n"+msg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
|
+ // 获取详细信息
|
|
|
|
+ String msg = stringWriter.getBuffer().toString();
|
|
|
|
+ NcLog.info("安装队进度款生成凭证失败"+"\n"+msg);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证保存方法
|
|
|
|
+ * @param createStrJs
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private void saveVoucher(JSONObject createStrJs) throws Exception{
|
|
|
|
+ VoucherVO newvo = interfaceService(createStrJs);
|
|
|
|
+ service.saveVoucher_RequiresNew(newvo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 拼装凭证vo
|
|
|
|
+ * @param map
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public VoucherVO interfaceService(JSONObject map) throws Exception {
|
|
|
|
+ //组装凭证VO
|
|
|
|
+ VoucherVO voucher = new VoucherVO();
|
|
|
|
+ //主表凭证
|
|
|
|
+ setVoucher(map,voucher);
|
|
|
|
+ //凭证分录VOs
|
|
|
|
+ setDetail(map,voucher);
|
|
|
|
+ //回写表头金额
|
|
|
|
+ sumAmount(voucher);
|
|
|
|
+ voucher.setExplanation(voucher.getDetails()[0].getExplanation());
|
|
|
|
+ return voucher;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证主表
|
|
|
|
+ * @param map
|
|
|
|
+ * @param obj
|
|
|
|
+ * @param voucher
|
|
|
|
+ * @throws BusinessException
|
|
|
|
+ */
|
|
|
|
+ private void setVoucher(JSONObject json,VoucherVO voucher) throws Exception {
|
|
|
|
+ JSONObject formData = json.getJSONObject("formData");
|
|
|
|
+ JSONObject dataDetails = formData.getJSONObject("dataDetails");
|
|
|
|
+ //制单人
|
|
|
|
+ voucher.setPk_prepared(GetDataUtil.getUserid("15800802186"));
|
|
|
|
+ //凭证类别
|
|
|
|
+ voucher.setPk_vouchertype(GetDataUtil.getVoucherType("付款凭证"));
|
|
|
|
+ //公司
|
|
|
|
+ voucher.setPk_corp(GetDataUtil.getCorpPK("1001"));
|
|
|
|
+
|
|
|
|
+ UFDate createTime = new UFDate(formData.getDate("createTime"));
|
|
|
|
+ //会计年度
|
|
|
|
+ voucher.setYear(String.valueOf(createTime.getYear()));
|
|
|
|
+ //会计期间
|
|
|
|
+ voucher.setPeriod(String.valueOf(createTime).substring(5,7));
|
|
|
|
+ //制单日期
|
|
|
|
+ voucher.setPrepareddate(createTime);
|
|
|
|
+ //记账人
|
|
|
|
+ voucher.setPk_manager("N/A");
|
|
|
|
+ //签字标识
|
|
|
|
+ voucher.setSignflag(UFBoolean.TRUE);
|
|
|
|
+ //分录增删标志
|
|
|
|
+ voucher.setDetailmodflag(UFBoolean.TRUE);
|
|
|
|
+ //作废标识
|
|
|
|
+ voucher.setDiscardflag(UFBoolean.FALSE);
|
|
|
|
+ //制单系统
|
|
|
|
+ voucher.setPk_system("GL");
|
|
|
|
+ //凭证类型
|
|
|
|
+ voucher.setVoucherkind(0);
|
|
|
|
+ //借方合计
|
|
|
|
+ voucher.setTotaldebit(new UFDouble(dataDetails.getString("合同总价")));
|
|
|
|
+ //贷方合计
|
|
|
|
+ voucher.setTotalcredit(new UFDouble(dataDetails.getString("合同总价")));
|
|
|
|
+ //泛微唯一标识
|
|
|
|
+ voucher.setFree2(dataDetails.getString("自动编号"));
|
|
|
|
+ String pk_glorg = GetDataUtil.getGlorg("1001");
|
|
|
|
+ //主体
|
|
|
|
+ voucher.setPk_glorg(pk_glorg);
|
|
|
|
+ // 主体帐簿
|
|
|
|
+ voucher.setPk_glorgbook(GetDataUtil.getGlorgbook(pk_glorg));
|
|
|
|
+ voucher.setIsdifflag(UFBoolean.FALSE);
|
|
|
|
+ voucher.setStatus(VOStatus.NEW);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证分录
|
|
|
|
+ * @param map
|
|
|
|
+ * @param obj
|
|
|
|
+ * @param voucher
|
|
|
|
+ * @throws BusinessException
|
|
|
|
+ * @throws SQLException
|
|
|
|
+ */
|
|
|
|
+ private void setDetail(JSONObject map, VoucherVO voucher) throws Exception {
|
|
|
|
+ JSONObject formData = map.getJSONObject("formData");
|
|
|
|
+ JSONObject dataDetails = formData.getJSONObject("dataDetails");
|
|
|
|
+ String money = dataDetails.getString("合同总价");
|
|
|
|
+ String costName = dataDetails.getString("费用名称");
|
|
|
|
+ JSONArray datas = new JSONArray();
|
|
|
|
+ String pk_accsubj = GetDataUtil.getAccSubject("560201",voucher.getPk_glorgbook());//科目主键
|
|
|
|
+ String pk_currtype = GetDataUtil.getCurrType("CNY");
|
|
|
|
+ String deptName = dataDetails.getString("部门");
|
|
|
|
+ DeptdocVO deptdocVO = GetDataUtil.getDept(deptName, voucher.getPk_corp());
|
|
|
|
+ AssVO jobAssVO = getPubAssid("部门档案",deptdocVO,voucher.getPk_corp());
|
|
|
|
+ // 将formData中的每个键值对转换为JSONArray的元素
|
|
|
|
+// for (String key : money.keySet()) {
|
|
|
|
+// JSONObject jsonObject = new JSONObject();
|
|
|
|
+// jsonObject.put("money", money.get(key));
|
|
|
|
+// jsonObject.put("costName", "付款审批单(财务)生成凭证");
|
|
|
|
+// jsonObject.put("pk_accsubj", pk_accsubj);
|
|
|
|
+// jsonObject.put("pk_currtype", pk_currtype);
|
|
|
|
+// datas.add(jsonObject);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ /*************数据格式不一样 没有资金明细******************/
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("money",money);
|
|
|
|
+ jsonObject.put("costName", "安装队进度款生成凭证");
|
|
|
|
+ jsonObject.put("pk_accsubj", pk_accsubj);
|
|
|
|
+ jsonObject.put("pk_currtype", pk_currtype);
|
|
|
|
+ datas.add(jsonObject);
|
|
|
|
+
|
|
|
|
+ List<DetailVO> details = new ArrayList<DetailVO>();
|
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
|
+ JSONObject data = datas.getJSONObject(i);
|
|
|
|
+ //一条数据生成一借一贷
|
|
|
|
+ //借方分录
|
|
|
|
+ setDebitVO(details, voucher,data,map,jobAssVO);
|
|
|
|
+ //贷方分录
|
|
|
|
+ setCreditVO(details, voucher, data,map,jobAssVO);
|
|
|
|
+ }
|
|
|
|
+ DetailVO[] detailVOs = new DetailVO[details.size()];
|
|
|
|
+ details.toArray(detailVOs);
|
|
|
|
+ voucher.setDetails(detailVOs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证分录借方
|
|
|
|
+ * @param details
|
|
|
|
+ * @param voucher
|
|
|
|
+ * @param data
|
|
|
|
+ * @param map
|
|
|
|
+ * @throws BusinessException
|
|
|
|
+ * @throws SQLException
|
|
|
|
+ */
|
|
|
|
+ private void setDebitVO(List<DetailVO> details, VoucherVO voucher, JSONObject data, JSONObject map ,AssVO jobAssVO) throws Exception {
|
|
|
|
+ DetailVO vo = new DetailVO();
|
|
|
|
+ List<AssVO> listAss = new ArrayList<AssVO>();
|
|
|
|
+
|
|
|
|
+ listAss.add(jobAssVO);
|
|
|
|
+ AssVO[] assVOs = new AssVO[listAss.size()];
|
|
|
|
+ listAss.toArray(assVOs);
|
|
|
|
+ vo.setAssid(freepub.getAssID(assVOs, true));
|
|
|
|
+ vo.setPk_accsubj(data.getString("pk_accsubj"));//会计科目
|
|
|
|
+ vo.setCreditamount(UFDouble.ZERO_DBL);//贷方
|
|
|
|
+ vo.setCreditquantity(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setDebitamount(new UFDouble(data.getString("money")));//借方
|
|
|
|
+ vo.setDirection("D");//方向
|
|
|
|
+ vo.setDiscardflag(UFBoolean.FALSE);
|
|
|
|
+ vo.setExcrate1(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setExcrate2(UFDouble.ONE_DBL);
|
|
|
|
+ vo.setExplanation(data.getString("costName"));//摘要
|
|
|
|
+ vo.setFraccreditamount(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setFracdebitamount(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setLocalcreditamount(UFDouble.ZERO_DBL);//全局贷方
|
|
|
|
+ vo.setLocaldebitamount(new UFDouble(data.getString("money")));//借方
|
|
|
|
+ vo.setPeriod(voucher.getPeriod());//会计期间
|
|
|
|
+ vo.setPk_corp(voucher.getPk_corp());
|
|
|
|
+ vo.setPk_currtype(data.getString("pk_currtype"));//币种
|
|
|
|
+ vo.setPk_glbook(voucher.getPk_glbook());
|
|
|
|
+ vo.setPk_glorg(voucher.getPk_glorg());
|
|
|
|
+ vo.setPk_glorgbook(voucher.getPk_glorgbook());
|
|
|
|
+ vo.setPk_manager(voucher.getPk_manager());
|
|
|
|
+ vo.setPk_system(voucher.getPk_system());
|
|
|
|
+ vo.setPk_vouchertype(voucher.getPk_vouchertype());//凭证类型
|
|
|
|
+ vo.setPrepareddate(voucher.getPrepareddate());
|
|
|
|
+ vo.setYear(voucher.getYear());
|
|
|
|
+ details.add(vo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证分录贷方
|
|
|
|
+ * @param details
|
|
|
|
+ * @param voucher
|
|
|
|
+ * @param data
|
|
|
|
+ * @param map
|
|
|
|
+ * @throws BusinessException
|
|
|
|
+ */
|
|
|
|
+ private void setCreditVO( List<DetailVO> details,VoucherVO voucher, JSONObject data, JSONObject map, AssVO jobAssVO) throws Exception {
|
|
|
|
+ DetailVO vo = new DetailVO();
|
|
|
|
+ List<AssVO> listAss = new ArrayList<AssVO>();
|
|
|
|
+ listAss.add(jobAssVO);
|
|
|
|
+ AssVO[] assVOs = new AssVO[listAss.size()];
|
|
|
|
+ listAss.toArray(assVOs);
|
|
|
|
+ vo.setAssid(freepub.getAssID(assVOs, true));
|
|
|
|
+ vo.setPk_accsubj(data.getString("pk_accsubj"));//会计科目
|
|
|
|
+ vo.setCreditamount(new UFDouble(data.getString("money")));//贷方
|
|
|
|
+ vo.setDebitamount(UFDouble.ZERO_DBL);//借方
|
|
|
|
+ vo.setDirection("C");//方向
|
|
|
|
+ vo.setDiscardflag(UFBoolean.FALSE);
|
|
|
|
+ vo.setExcrate1(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setExcrate2(UFDouble.ONE_DBL);
|
|
|
|
+ vo.setExplanation(data.getString("costName"));//摘要
|
|
|
|
+ vo.setFraccreditamount(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setFracdebitamount(UFDouble.ZERO_DBL);
|
|
|
|
+ vo.setLocalcreditamount(new UFDouble(data.getString("money")));//全局贷方
|
|
|
|
+ vo.setLocaldebitamount(UFDouble.ZERO_DBL);//借方
|
|
|
|
+ vo.setPeriod(voucher.getPeriod());//会计期间
|
|
|
|
+ vo.setPk_corp(voucher.getPk_corp());
|
|
|
|
+ vo.setPk_currtype(data.getString("pk_currtype"));//币种
|
|
|
|
+ vo.setPk_glbook(voucher.getPk_glbook());
|
|
|
|
+ vo.setPk_glorg(voucher.getPk_glorg());
|
|
|
|
+ vo.setPk_glorgbook(voucher.getPk_glorgbook());
|
|
|
|
+ vo.setPk_manager(voucher.getPk_manager());
|
|
|
|
+ vo.setPk_system(voucher.getPk_system());
|
|
|
|
+ vo.setPk_vouchertype(voucher.getPk_vouchertype());//凭证类型
|
|
|
|
+ vo.setPrepareddate(voucher.getPrepareddate());
|
|
|
|
+ vo.setYear(voucher.getYear());
|
|
|
|
+ details.add(vo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 凭证分录生成后需要把原币金额回写到表头金额
|
|
|
|
+ * @param voucher
|
|
|
|
+ */
|
|
|
|
+ private void sumAmount(VoucherVO voucher) {
|
|
|
|
+ UFDouble amount1 = new UFDouble(0);
|
|
|
|
+ UFDouble amount2 = new UFDouble(0);
|
|
|
|
+ DetailVO[] vos = voucher.getDetails();
|
|
|
|
+ for(DetailVO vo : vos){
|
|
|
|
+ amount1 = amount1.add(vo.getCreditamount());
|
|
|
|
+ amount2 = amount2.add(vo.getDebitamount());
|
|
|
|
+ }
|
|
|
|
+ voucher.setTotalcredit(amount1);// 贷方合计
|
|
|
|
+ voucher.setTotaldebit(amount2);// 借方合计
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通用辅助核算
|
|
|
|
+ * @param pk_bdinfo
|
|
|
|
+ * @throws SQLException
|
|
|
|
+ */
|
|
|
|
+ private AssVO getPubAssid(String checktype,DeptdocVO deptdocVO,String pk_corp) throws Exception {
|
|
|
|
+ List<AssVO> list = new ArrayList<AssVO>();
|
|
|
|
+ AssVO vo = new AssVO();
|
|
|
|
+ vo.setChecktypecode(deptdocVO.getDeptcode());
|
|
|
|
+ vo.setChecktypename(checktype);
|
|
|
|
+ vo.setPk_Checktype(GetDataUtil.getBdpkByBdInfo(checktype));
|
|
|
|
+ vo.setPk_Checkvalue(deptdocVO.getPrimaryKey());
|
|
|
|
+ vo.setCheckvaluecode(deptdocVO.getDeptcode());
|
|
|
|
+ vo.setCheckvaluename(deptdocVO.getDeptname());
|
|
|
|
+ vo.setUserData(true);
|
|
|
|
+ list.add(vo);
|
|
|
|
+ AssVO[] assVOs = new AssVO[list.size()];
|
|
|
|
+ list.toArray(assVOs);
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|