ysh před 3 roky
rodič
revize
6b4f5b6802

+ 91 - 23
src/main/java/net/chenlin/dp/common/openapi4j/examples/voucher/VoucherAdd.java

@@ -34,16 +34,18 @@ public class VoucherAdd {
      * @param biz_id  唯一来源id
      * @param type 数据源 1昆山,3潍坊
      */
-    public static String addVoucher(Map<String,Object> map,String biz_id,String type) {
+    public static String addVoucher(Map<String,Object> map,String biz_id,String type,String upTime) {
 
         Map<String,Object> jsonBodyMap = new HashMap<>();
         Map<String,Object> voucher = new HashMap<>();//凭证数据详情
         String sqr = map.get("申请人").toString();
-
+        String[] da = upTime.split("-");
         voucher.put("voucher_type","记");//凭证类别
-//        voucher.put("fiscal_year","2021");//凭证所属的会计年度,不填写取当前年
-//        voucher.put("accounting_period","1");//所属的会计期间,不填写取当前月份
-        voucher.put("date", DateUtils.format(new Date()));//制单日期
+        voucher.put("fiscal_year",da[0]);//凭证所属的会计年度,不填写取当前年
+        voucher.put("accounting_period",da[1]);//所属的会计期间,不填写取当前月份
+        voucher.put("date", upTime);//制单日期
+//        voucher.put("date", DateUtils.format(new Date()));//制单日期
+
 //        voucher.put("enter","DingDing_"+map.get("申请人"));//制单人名称
         voucher.put("enter","OA");//制单人名称
 //        voucher.put("cashier",map.get("出纳"));//出纳名称
@@ -152,13 +154,18 @@ public class VoucherAdd {
      * @param biz_id  唯一来源id
      * @param type 数据源 1昆山,3潍坊
      */
-    public static String addVoucherNew(Map<String,Object> map,String biz_id,String type) {
+    public static String addVoucherNew(Map<String,Object> map,String biz_id,String type,String upTime) {
         //1昆山,3潍坊
         Map<String,Object> jsonBodyMap = new HashMap<>();
-        Map<String,Object> voucher = new HashMap<>();//凭证数据详情
 
+        Map<String,Object> voucher = new HashMap<>();//凭证数据详情
+        String[] da = upTime.split("-");
         voucher.put("voucher_type","记");//凭证类别
-        voucher.put("date", DateUtils.format(new Date()));//制单日期
+        voucher.put("fiscal_year",da[0]);//凭证所属的会计年度,不填写取当前年
+        voucher.put("accounting_period",da[1]);//所属的会计期间,不填写取当前月份
+        voucher.put("date", upTime);//制单日期
+//        voucher.put("date", DateUtils.format(new Date()));//制单日期
+
         voucher.put("enter","OA");//制单人名称
 
         BigDecimal allNum = new BigDecimal("0");//总金额(所有未税金额和税额之和,用作贷方金额)
@@ -209,11 +216,14 @@ public class VoucherAdd {
 //                        entryDebitMap.put("account_code",map.get("account_code"));
                         String seCode = getCodeSE(bxKm);
                         entryDebitMap.put("account_code",seCode);
-//
-                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        BigDecimal natural_debit_currency = se.multiply(sl);
+                        natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        System.out.println(natural_debit_currency);
                         if(se.compareTo(new BigDecimal("0")) != 0){
                             entryDebit.add(entryDebitMap);
-                            allNum = allNum.add(se.multiply(sl));
+//                            allNum = allNum.add(se.multiply(sl));
+                            allNum = allNum.add(natural_debit_currency);
                         }
 
                     }
@@ -241,9 +251,13 @@ public class VoucherAdd {
                     entryDebitMap.put("abstract",sqr+"/其他报销/"+bxKm+"/"+mingC);
 //                    entryDebitMap.put("account_code",map.get("account_code"));
                     entryDebitMap.put("account_code",account_code);
-                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                    BigDecimal natural_debit_currency = jinE.multiply(sl);
+                    natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                    entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
                     entryDebit.add(entryDebitMap);
-                    allNum = allNum.add(jinE.multiply(sl));
+                    System.out.println(natural_debit_currency);
+//                    allNum = allNum.add(jinE.multiply(sl));
+                    allNum = allNum.add(natural_debit_currency);
                 }
             }
         }
@@ -290,11 +304,13 @@ public class VoucherAdd {
 //                        entryDebitMap.put("account_code",map.get("account_code"));
                         String seCode = getCodeSE(bxKm);
                         entryDebitMap.put("account_code",seCode);
-//
-                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        BigDecimal natural_debit_currency = se.multiply(sl);
+                        natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
                         if(se.compareTo(new BigDecimal("0")) != 0){
                             entryDebit.add(entryDebitMap);
-                            allNum = allNum.add(se.multiply(sl));
+//                            allNum = allNum.add(se.multiply(sl));
+                            allNum = allNum.add(natural_debit_currency);
                         }
 
                     }else{
@@ -315,7 +331,8 @@ public class VoucherAdd {
                             entryDebitMap.put("account_code",seCode);
                             //当报销科目为火车,飞机时,税率自动计算(税额=未税金额*9%)
                             BigDecimal lv = new BigDecimal("0.09");
-                            BigDecimal multiply = jinE.multiply(lv).multiply(sl);
+                            BigDecimal lv2 = new BigDecimal("1.09");
+                            BigDecimal multiply = jinE.multiply(sl).divide(lv2).multiply(lv);
                             multiply = multiply.setScale(2,BigDecimal.ROUND_HALF_UP);
                             entryDebitMap.put("natural_debit_currency", multiply);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
 
@@ -339,9 +356,19 @@ public class VoucherAdd {
                     entryDebitMap.put("abstract",sqr+"/差旅报销/"+bxKm+"/"+mingC);
 //                    entryDebitMap.put("account_code",map.get("account_code"));
                     entryDebitMap.put("account_code",account_code);
-                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+
+                    BigDecimal natural_debit_currency = new BigDecimal("0");// jinE.multiply(sl);
+                    if("飞机、火车".contains(bxKm)){
+                        BigDecimal lv = new BigDecimal("1.09");
+                        natural_debit_currency = jinE.multiply(sl).divide(lv);
+                    }else{
+                        natural_debit_currency = jinE.multiply(sl);
+                    }
+                    natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                    entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
                     entryDebit.add(entryDebitMap);
-                    allNum = allNum.add(jinE.multiply(sl));
+//                    allNum = allNum.add(jinE.multiply(sl));
+                    allNum = allNum.add(natural_debit_currency);
                 }
             }
         }
@@ -382,12 +409,42 @@ public class VoucherAdd {
                         String seCode = getCodeSE(bxKm);
                         entryDebitMap.put("account_code",seCode);
 //
-                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        BigDecimal natural_debit_currency = se.multiply(sl);
+                        natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
                         if(se.compareTo(new BigDecimal("0")) != 0){
                             entryDebit.add(entryDebitMap);
-                            allNum = allNum.add(se.multiply(sl));
+//                            allNum = allNum.add(se.multiply(sl));
+                            allNum = allNum.add(natural_debit_currency);
                         }
 
+                    }else{
+                        if("高速通行费".contains(bxKm)){
+                            Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                            Map<String,Object> auxiliaryDebit = new HashMap<>();
+                            auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                            auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                            if(map.containsKey("item_class")){
+                                auxiliaryDebit.put("item_class","00");//项目大类
+                                auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                            }
+                            entryDebitMap.put("auxiliary",auxiliaryDebit);
+                            entryDebitMap.put("abstract",sqr+"/私车公用/"+bxKm+"/税额");
+                            String seCode = getCodeSE(bxKm);
+                            entryDebitMap.put("account_code",seCode);
+                            //当报销科目为火车,飞机时,税率自动计算(税额=未税金额*9%)
+                            BigDecimal lv = new BigDecimal("0.03");
+                            BigDecimal lv2 = new BigDecimal("1.03");
+                            BigDecimal multiply = jinE.multiply(sl).divide(lv2).multiply(lv);
+                            multiply = multiply.setScale(2,BigDecimal.ROUND_HALF_UP);
+                            entryDebitMap.put("natural_debit_currency", multiply);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+
+                            entryDebit.add(entryDebitMap);
+                            allNum = allNum.add(multiply);
+
+                        }
                     }
 
                     Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
@@ -404,9 +461,20 @@ public class VoucherAdd {
                     entryDebitMap.put("abstract",sqr+"/私车公用/"+bxKm);
 //                    entryDebitMap.put("account_code",map.get("account_code"));
                     entryDebitMap.put("account_code",account_code);
-                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+
+                    BigDecimal natural_debit_currency = new BigDecimal("0");// jinE.multiply(sl);
+                    if("高速通行费".contains(bxKm)){
+                        BigDecimal lv = new BigDecimal("1.03");
+                        natural_debit_currency = jinE.multiply(sl).divide(lv);
+                    }else{
+                        natural_debit_currency = jinE.multiply(sl);
+                    }
+
+                    natural_debit_currency = natural_debit_currency.setScale(2,BigDecimal.ROUND_HALF_UP);
+                    entryDebitMap.put("natural_debit_currency",natural_debit_currency);//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
                     entryDebit.add(entryDebitMap);
-                    allNum = allNum.add(jinE.multiply(sl));
+//                    allNum = allNum.add(jinE.multiply(sl));
+                    allNum = allNum.add(natural_debit_currency);
                 }
             }
         }

+ 23 - 0
src/main/java/net/chenlin/dp/common/utils/DateUtils.java

@@ -1,5 +1,6 @@
 package net.chenlin.dp.common.utils;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -25,6 +26,28 @@ public class DateUtils {
 		return format(date, DATE_PATTERN);
 	}
 
+	/**
+	 * 校验日期是否非法
+	 * @param str
+	 * @return
+	 */
+	public static boolean isValidDate(String str) {
+		boolean convertSuccess=true;
+		// 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写;
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+		try {
+			// 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期,比如2007/02/29会被接受,并转换成2007/03/01
+			format.setLenient(false);
+			format.parse(str);
+		} catch (ParseException e) {
+			// e.printStackTrace();
+			// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
+			convertSuccess=false;
+		}
+		return convertSuccess;
+	}
+
+
 	public static String format(Date date, String pattern) {
 		if (date != null) {
 			SimpleDateFormat df = new SimpleDateFormat(pattern);

+ 35 - 5
src/main/java/net/chenlin/dp/modules/TaskDemo.java

@@ -2,6 +2,7 @@ package net.chenlin.dp.modules;
 
 import com.mysql.cj.util.StringUtils;
 import com.taobao.api.ApiException;
+import net.chenlin.dp.common.exception.RRException;
 import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
 import net.chenlin.dp.common.support.orm.db.DynamicDataSource;
 import net.chenlin.dp.common.utils.DateUtils;
@@ -12,6 +13,8 @@ import net.chenlin.dp.modules.sys.service.testU8Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 
 
@@ -26,9 +29,18 @@ public class TaskDemo {
     /**
      * 定时任务 银行回单 同步至 u8凭证(江苏)
      */
-    public static void autoReimbursementNew() throws Exception {
+    public static void  autoReimbursementNew(String upTime) throws Exception {
+
+        if(StringUtils.isNullOrEmpty(upTime) || upTime.equals("无")){
+           throw new RRException("参数不能为空");
+        }
+        upTime = upTime.trim();
+        if(DateUtils.isValidDate(upTime)){
+            throw new RRException("日期格式不正确");
+        }
+
         ReimbursementService reimbursementService = new ReimbursementService();
-        reimbursementService.autoReimbursementNew("js");
+        reimbursementService.autoReimbursementNew("js",upTime);
         System.out.println("==================================");
         System.out.println("===========银行回单(江苏) 同步至 u8凭证任务执行 "+ DateUtils.getNowTime()+" ============" );
         System.out.println("==================================");
@@ -37,9 +49,16 @@ public class TaskDemo {
      /**
      * 定时任务 银行回单 同步至 u8凭证(山东)
      */
-    public static void autoReimbursementNewSd() throws Exception {
+    public static void autoReimbursementNewSd(String upTime) throws Exception {
+        if(StringUtils.isNullOrEmpty(upTime) || upTime.equals("无")){
+            throw new RRException("参数不能为空");
+        }
+        upTime = upTime.trim();
+        if(DateUtils.isValidDate(upTime)){
+            throw new RRException("日期格式不正确");
+        }
         ReimbursementService reimbursementService = new ReimbursementService();
-        reimbursementService.autoReimbursementNew("sd");
+        reimbursementService.autoReimbursementNew("sd",upTime);
         System.out.println("==================================");
         System.out.println("===========银行回单(山东) 同步至 u8凭证任务执行 "+ DateUtils.getNowTime()+" ============" );
         System.out.println("==================================");
@@ -263,8 +282,19 @@ public class TaskDemo {
     }
 
 
+    public static void main(String[] args) throws OpenAPIException, ParseException {
+
+        String aa = "2021-11-12";
+
+        String[] aaa = aa.split("-");
+        System.out.println(aaa[0]);
+        System.out.println(aaa[1]);
+        System.out.println(aaa[2]);
+
+//        System.out.println(aa.substring(0,4));
+//        System.out.println("=================================="+DateUtils.isValidDate("2021-11-12"));
+
 
-    public static void main(String[] args) throws OpenAPIException {
 //        SaleOrderService saleOrderService = new SaleOrderService();
 //        saleOrderService.shenghe("","");
 //        autoCallProductIn("");

+ 16 - 14
src/main/java/net/chenlin/dp/modules/api/service/ReimbursementService.java

@@ -162,7 +162,7 @@ public class ReimbursementService {
 //                    System.out.println(map1);
 
                     try {
-                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"其他",type);
+                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"其他",type,"");
                     }catch (Exception e){
                         mess = e.getMessage();
                     }
@@ -194,7 +194,7 @@ public class ReimbursementService {
      * @throws Exception
      * @param st js:江苏,sd:山东
      */
-    public void autoReimbursementNew(String st) throws Exception {
+    public void autoReimbursementNew(String st,String upTime) throws Exception {
 
         DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
         Properties prop = PropUtil.getProperties("/config.properties");
@@ -210,19 +210,19 @@ public class ReimbursementService {
         String work_place = "";//办公地(潍坊对03账套 昆山对01账套)
         String dept_code = ""; //部门编码
         String type = ""; //数据源账套 1昆山,3潍坊
-//        List<SyViewEntity> listId = u8Service.selectView("银行凭证至U8");
+        List<SyViewEntity> listId = u8Service.selectViewBy31("银行凭证至U8");
         if(list.size() > 0){
             outCycle:for(String o:list){
 
-//                if(listId.size() > 0){
-//                    for(SyViewEntity en:listId){
-//                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
-//                            continue outCycle;
-//                        }
-//                    }
-//                }
+                if(listId.size() > 0){
+                    for(SyViewEntity en:listId){
+                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+                            continue outCycle;
+                        }
+                    }
+                }
 
-//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("24715cdf-4389-44b3-a634-5c30871a095b");//
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("57942341-3589-43d3-9984-9a786dc9f97d");//
                 Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);//
 
                 if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
@@ -293,7 +293,7 @@ public class ReimbursementService {
                     map1.put("naturalCurrency",object1.get("申请金额"));
 
                     try {
-                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"备用金",type);
+                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"备用金",type,upTime);
                     }catch (Exception e){
                         mess = e.getMessage();
                     }
@@ -301,7 +301,7 @@ public class ReimbursementService {
                 }else if(map1.get("单据类型").toString().equals("报销申请")){
                     entity.setParType("报销申请至U8");
                     try {
-                        mess = VoucherAdd.addVoucherNew(map1,map.get("business_id").toString()+"报销申请",type);
+                        mess = VoucherAdd.addVoucherNew(map1,map.get("business_id").toString()+"报销申请",type,upTime);
                     }catch (Exception e){
                         mess = e.getMessage();
                     }
@@ -311,6 +311,8 @@ public class ReimbursementService {
                 }
                 entity.setSyMessage(mess);
                 u8Service.saveSyView(entity);
+
+
             }
 
         }
@@ -1229,7 +1231,7 @@ public class ReimbursementService {
     public static void main(String[] args) throws Exception {
 //        autoOABankReceipt();
 //        autoReimbursement();
-//        autoReimbursementNew();
+//        autoReimbursementNew("js");
 //        String aa  = "";
 //        if("12334".contains("1")){
 //            System.out.println("sssssssssss");

+ 2 - 0
src/main/java/net/chenlin/dp/modules/sys/dao/TestU8Mapper.java

@@ -24,6 +24,8 @@ public interface TestU8Mapper extends BaseMapper<SyViewEntity> {
 
 	List<SyViewEntity> selectViewByTrue(String tableType);
 
+	List<SyViewEntity> selectViewBy31(String tableType);
+
 	/**
 	 * 调用存储过程 获取下一个编码
 	 * @param StuNo

+ 6 - 0
src/main/java/net/chenlin/dp/modules/sys/mapper/testU8.xml

@@ -74,6 +74,12 @@
 		and sy_state = "true" and table_type = #{tableType}
 	</select>
 
+	<select id="selectViewBy31" resultType="net.chenlin.dp.modules.sys.entity.SyViewEntity">
+		select oa_Id as oaId from sy_view
+		where DATE_FORMAT(create_time,'%Y-%m-%d') >= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 31 DAY),'%Y-%m-%d')
+		and table_type = #{tableType}
+	</select>
+
 	<insert id="save">
 		INSERT INTO sy_view (
 			oa_id,

+ 4 - 0
src/main/java/net/chenlin/dp/modules/sys/service/impl/testU8ServiceImpl.java

@@ -44,6 +44,10 @@ public class testU8ServiceImpl implements testU8Service {
 	public List<SyViewEntity> selectViewByTrue(String tableType) {
 		return testU8Mapper.selectViewByTrue(tableType);
 	}
+	@Override
+	public List<SyViewEntity> selectViewBy31(String tableType) {
+		return testU8Mapper.selectViewBy31(tableType);
+	}
 
 	@Override
 	public R saveSyView(SyViewEntity area) {

+ 2 - 0
src/main/java/net/chenlin/dp/modules/sys/service/testU8Service.java

@@ -22,6 +22,8 @@ public interface testU8Service {
 
 	public List<SyViewEntity> selectViewByTrue(String tableType);
 
+	public List<SyViewEntity> selectViewBy31(String tableType);
+
 	/**
 	 * 调用存储过程 获取下一个编码
 	 * @param StuNo