ZhangWenQiang пре 6 година
родитељ
комит
9f6663114a
15 измењених фајлова са 188 додато и 9 уклоњено
  1. 7 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/entity/HlgPayment.java
  2. 2 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/mapper/HlgPaymentDetailMapper.java
  3. 13 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/mapper/xml/HlgPaymentDetailMapper.xml
  4. 4 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/IHlgPaymentDetailService.java
  5. 7 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/impl/HlgPaymentDetailServiceImpl.java
  6. 111 1
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/impl/HlgPaymentServiceImpl.java
  7. 1 1
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/entity/HlgTaxRate.java
  8. 2 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/HlgTaxMapper.java
  9. 3 1
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/HlgTaxRateMapper.java
  10. 11 5
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/xml/HlgTaxMapper.xml
  11. 12 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/xml/HlgTaxRateMapper.xml
  12. 2 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/IHlgTaxRateService.java
  13. 2 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/IHlgTaxService.java
  14. 6 1
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/impl/HlgTaxRateServiceImpl.java
  15. 5 0
      happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/impl/HlgTaxServiceImpl.java

+ 7 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/entity/HlgPayment.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.hlgpayment.entity;
 import java.io.Serializable;
 import java.util.Date;
 import java.math.BigDecimal;
+import java.util.List;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
@@ -142,4 +143,10 @@ public class HlgPayment implements Serializable {
      */
     @TableField(exist = false)
     private HlgAccount hlgAccount;
+
+    /**
+     * 报错list
+     */
+    @TableField(exist = false)
+    private List<HlgPaymentDetail> list;
 }

+ 2 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/mapper/HlgPaymentDetailMapper.java

@@ -18,4 +18,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 public interface HlgPaymentDetailMapper extends BaseMapper<HlgPaymentDetail> {
 
     List<HlgPaymentDetail> findList(Page<HlgPaymentDetail> pageList, @Param("hlgPaymentDetail") HlgPaymentDetail hlgPaymentDetail, @Param(Constants.WRAPPER) QueryWrapper<HlgPaymentDetail> queryWrapper);
+
+    List<HlgPaymentDetail> findMonthListByUserId(@Param("hlgPaymentDetail") HlgPaymentDetail hlgPaymentDetail);
 }

+ 13 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/mapper/xml/HlgPaymentDetailMapper.xml

@@ -174,4 +174,17 @@
 		WHERE id = #{id}
 	</update>
 
+	<!--该付款明细用户本月累计已打款-->
+	<select id="findMonthListByUserId" resultType="org.jeecg.modules.hlgpayment.entity.HlgPaymentDetail">
+		SELECT
+		<include refid="hlgPaymentDetailColumns"/>
+		FROM hlg_payment_detail a
+		<include refid="hlgPaymentDetailJoins"/>
+		<where>
+			a.user_id = #{hlgPaymentDetail.userId}
+			and DATE_FORMAT(a.payment_time, '%Y%m') = DATE_FORMAT( CURDATE( ) , '%Y%m' )
+			and (a.status = 1 or a.status = 2)
+		</where>
+	</select>
+
 </mapper>

+ 4 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/IHlgPaymentDetailService.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.jeecg.modules.hlgpayment.entity.HlgPaymentDetail;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: 付款明细表
  * @Author: jeecg-boot
@@ -14,4 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IHlgPaymentDetailService extends IService<HlgPaymentDetail> {
 
     Page<HlgPaymentDetail> pageList(Page<HlgPaymentDetail> page, HlgPaymentDetail hlgPaymentDetail, QueryWrapper<HlgPaymentDetail> queryWrapper);
+
+    List<HlgPaymentDetail> findMonthListByUserId(HlgPaymentDetail hlgPaymentDetail);
 }

+ 7 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/impl/HlgPaymentDetailServiceImpl.java

@@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.util.List;
+
 /**
  * @Description: 付款明细表
  * @Author: jeecg-boot
@@ -22,4 +24,9 @@ public class HlgPaymentDetailServiceImpl extends ServiceImpl<HlgPaymentDetailMap
     public Page<HlgPaymentDetail> pageList(Page<HlgPaymentDetail> pageList, HlgPaymentDetail hlgPaymentDetail, QueryWrapper<HlgPaymentDetail> queryWrapper) {
         return pageList.setRecords(baseMapper.findList(pageList, hlgPaymentDetail, queryWrapper));
     }
+
+    @Override
+    public List<HlgPaymentDetail> findMonthListByUserId(HlgPaymentDetail hlgPaymentDetail) {
+        return baseMapper.findMonthListByUserId(hlgPaymentDetail);
+    }
 }

+ 111 - 1
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgpayment/service/impl/HlgPaymentServiceImpl.java

@@ -1,19 +1,28 @@
 package org.jeecg.modules.hlgpayment.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.StringUtils;
+import org.jeecg.common.util.businessAccountUtils;
 import org.jeecg.modules.hlgcompany.entity.HlgCompany;
 import org.jeecg.modules.hlgcompany.entity.HlgCompanySubcontractor;
 import org.jeecg.modules.hlgcompany.service.IHlgCompanyService;
 import org.jeecg.modules.hlgcompany.service.IHlgCompanySubcontractorService;
 import org.jeecg.modules.hlgpayment.entity.HlgPayment;
+import org.jeecg.modules.hlgpayment.entity.HlgPaymentDetail;
 import org.jeecg.modules.hlgpayment.mapper.HlgPaymentMapper;
+import org.jeecg.modules.hlgpayment.service.IHlgPaymentDetailService;
 import org.jeecg.modules.hlgpayment.service.IHlgPaymentService;
 import org.jeecg.modules.hlgplatform.entity.HlgPlatform;
 import org.jeecg.modules.hlgplatform.entity.HlgPlatformSubcontractor;
 import org.jeecg.modules.hlgplatform.service.IHlgPlatformService;
 import org.jeecg.modules.hlgplatform.service.IHlgPlatformSubcontractorService;
+import org.jeecg.modules.hlgtax.entity.HlgTax;
+import org.jeecg.modules.hlgtax.entity.HlgTaxRate;
+import org.jeecg.modules.hlgtax.service.IHlgTaxRateService;
+import org.jeecg.modules.hlgtax.service.IHlgTaxService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -21,6 +30,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.util.List;
 
 /**
  * @Description: 付款信息表
@@ -39,6 +50,12 @@ public class HlgPaymentServiceImpl extends ServiceImpl<HlgPaymentMapper, HlgPaym
     private IHlgCompanyService hlgCompanyService;
     @Autowired
     private IHlgPlatformService hlgPlatformService;
+    @Autowired
+    private IHlgPaymentDetailService hlgPaymentDetailService;
+    @Autowired
+    private IHlgTaxRateService hlgTaxRateService;
+    @Autowired
+    private IHlgTaxService hlgTaxService;
 
     @Override
     public Page<HlgPayment> pageList(Page<HlgPayment> pageList, HlgPayment hlgPayment, QueryWrapper<HlgPayment> queryWrapper) {
@@ -98,9 +115,102 @@ public class HlgPaymentServiceImpl extends ServiceImpl<HlgPaymentMapper, HlgPaym
                 result.error500("余额不足,请充值");
                 return result;
             }
+            /**
+             * 开始复核
+             */
+            //通过paymentId查询该付款单所有明细
+            QueryWrapper<HlgPaymentDetail> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("payment_id", hlgPayment.getId());
+            List<HlgPaymentDetail> hlgPaymentDetailList = hlgPaymentDetailService.list(queryWrapper);
+            //总付款金额
+            Double totalPayment = 0.00;
+            //未找到税率区间的用户集合
+            String users = "";
+            //超过第一级税率区间的用户集合
+            String usersFirst = "";
+            for (HlgPaymentDetail hlgPaymentDetail : hlgPaymentDetailList) {
+                /**
+                 * 计算个人所得税
+                 */
+                //1.该付款明细用户本月累计已打款(包含:1:付款中 2:付款成功)
+                List<HlgPaymentDetail> userList = hlgPaymentDetailService.findMonthListByUserId(hlgPaymentDetail);
+                //已付总额
+                Double totalOldPayment = 0.00;
+                //已付总税额
+                Double totalOldTaxFee = 0.00;
+                for (int j = 0; j < userList.size(); j++) {
+                    HlgPaymentDetail hlgPaymentDetail1 = userList.get(j);
+                    //已付总额
+                    totalOldPayment = businessAccountUtils.add(totalOldPayment, hlgPaymentDetail1.getPayment());
+                    //已付总税额
+                    totalOldTaxFee = businessAccountUtils.add(totalOldTaxFee, hlgPaymentDetail1.getTaxFee());
+                }
+                //该用户本月累计付款
+                Double currentTotalPayment = businessAccountUtils.add(totalOldPayment, hlgPaymentDetail.getPayment());
+                //查询当前付款的服务商的税务信息
+                HlgTax hlgTax = hlgTaxService.getBySubId(hlgPayment.getSubcontractorId());
+                //查询当前付款所处的税率区间
+                HlgTaxRate hlgTaxRate = hlgTaxRateService.getByTaxFee(hlgPayment.getSubcontractorId(), currentTotalPayment);
+                if (hlgTaxRate != null) {
+                    //超过第一级税率区间的用户
+                    if (hlgTaxRate.getStartInterval() != 0) {
+                        if (StringUtils.isBlank(usersFirst)) {
+                            usersFirst = hlgPaymentDetail.getUserName();
+                        }
+                        hlgPayment.getList().add(hlgPaymentDetail);
+                    } else {
+                        //开始算税
+                        hlgPaymentDetail.setTaxRate(hlgTaxRate.getRate());
+                        hlgPaymentDetail.setTaxType(hlgTax.getTaxType());
+                        //本月总税额
+                        Double currentTaxFee = 0.00;
+                        //0:应付计税 1:实付计税
+                        if (hlgTax.getTaxType() == 0) {
+                            //本月总税额=[本月总金额/(1-tax_rate*0.01)]*(tax_rate*0.01)
+                            currentTaxFee = businessAccountUtils.mul(businessAccountUtils.div(currentTotalPayment, businessAccountUtils.sub(1, hlgTaxRate.getRate() * 0.01)), hlgTaxRate.getRate() * 0.01);
+                        } else if (hlgTax.getTaxType() == 1) {
+                            //本月总税额=本月总金额*tax_rate*0.01
+                            currentTaxFee = businessAccountUtils.mul(currentTotalPayment, hlgTaxRate.getRate() * 0.01);
+                        }
+                        //本次应缴税额,四舍五入俩位小数
+                        hlgPaymentDetail.setTaxFee(businessAccountUtils.round(businessAccountUtils.sub(currentTaxFee, totalOldTaxFee), 2));
+                        hlgPaymentDetailService.updateById(hlgPaymentDetail);
+                        //付款总额
+                        totalPayment = businessAccountUtils.add(totalPayment, hlgPaymentDetail.getPayment());
+                    }
+                } else {
+                    //查不到该用户所处的税率区间
+                    if (StringUtils.isBlank(users)) {
+                        users = hlgPaymentDetail.getUserName();
+                    }
+                    hlgPayment.getList().add(hlgPaymentDetail);
+                }
+            }
+            //判断是否有用户付款时找不到税率区间
+            if (StringUtils.isNotBlank(users) && hlgPayment.getList() != null && hlgPayment.getList().size() > 0) {
+                result.error500("当月累计金额找不到配置的税率");
+                result.setResult(hlgPayment);
+                return result;
+            }
+            //判断是否有用户超过第一级税率
+            if (StringUtils.isNotBlank(usersFirst) && hlgPayment.getList() != null && hlgPayment.getList().size() > 0) {
+                result.error500("超出第一级税率");
+                result.setResult(hlgPayment);
+                return result;
+            }
 
-        }
+            //四舍五入,保留俩位小数
+            DecimalFormat df = new DecimalFormat("#.00");
+            String totalPaymenStr = df.format(totalPayment);
 
+            //银行业务接口(代发工资)
+//            JSONObject jsonObjectBody = PayCommon.DCAGPOPR(hwPaymentDetailList, totalPaymenStr);
+
+
+        } else {
+            updateById(hlgPayment);
+            result.success("复核不通过");
+        }
         return result;
     }
 

+ 1 - 1
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/entity/HlgTaxRate.java

@@ -37,5 +37,5 @@ public class HlgTaxRate implements Serializable {
 	private Integer endInterval;
 	/**税率(例如0.06)*/
 	@Excel(name = "税率(例如0.06)", width = 15)
-	private BigDecimal rate;
+	private Double rate;
 }

+ 2 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/HlgTaxMapper.java

@@ -18,4 +18,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 public interface HlgTaxMapper extends BaseMapper<HlgTax> {
 
     List<HlgTax> findList(Page<HlgTax> pageList,@Param("hlgTax") HlgTax hlgTax,@Param(Constants.WRAPPER) QueryWrapper<HlgTax> queryWrapper);
+
+    HlgTax getBySubId(@Param("subcontractorId") Integer subcontractorId);
 }

+ 3 - 1
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/HlgTaxRateMapper.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 /**
  * @Description: hlg_tax_rate
  * @Author: jeecg-boot
- * @Date:   2020-02-26
+ * @Date: 2020-02-26
  * @Version: V1.0
  */
 public interface HlgTaxRateMapper extends BaseMapper<HlgTaxRate> {
@@ -17,4 +17,6 @@ public interface HlgTaxRateMapper extends BaseMapper<HlgTaxRate> {
     List<HlgTaxRate> getHlgTaxRateList(Integer id);
 
     List<HlgTaxRate> findHlgTaxRateByTaxId(Integer id);
+
+    HlgTaxRate getByTaxFee(@Param("subId") Integer subcontractorId, @Param("totalMoney") double add);
 }

+ 11 - 5
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/xml/HlgTaxMapper.xml

@@ -22,7 +22,7 @@
     </sql>
 
 
-    <select id="get" resultType="org.jeecg.modules.hlgtax.entity.HlgTax" >
+    <select id="get" resultType="org.jeecg.modules.hlgtax.entity.HlgTax">
         SELECT
         <include refid="hlgTaxColumns"/>
         FROM hlg_tax a
@@ -30,15 +30,16 @@
         WHERE a.id = #{id}
     </select>
 
-    <select id="findList" resultType="org.jeecg.modules.hlgtax.entity.HlgTax" >
+    <select id="findList" resultType="org.jeecg.modules.hlgtax.entity.HlgTax">
         SELECT
         <include refid="hlgTaxColumns"/>
-		,(select b.detail from hlg_tax_modify b where b.tax_id=a.id order by b.generate_time desc ,b.id asc limit 1) as "taxDetail"
+        ,(select b.detail from hlg_tax_modify b where b.tax_id=a.id order by b.generate_time desc ,b.id asc limit 1) as
+        "taxDetail"
         FROM hlg_tax a
         <include refid="hlgTaxJoins"/>
         group by a.id
-      order by a.update_time desc ,id asc
-	</select>
+        order by a.update_time desc ,id asc
+    </select>
 
 
     <insert id="saveHlgTax">
@@ -86,4 +87,9 @@
 		WHERE id = #{id}
 	</update>
 
+    <select id="getBySubId" resultType="org.jeecg.modules.hlgtax.entity.HlgTax">
+		select a.*
+		from hlg_tax a
+		where a.subcontractor_id = #{subcontractorId}
+	</select>
 </mapper>

+ 12 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/mapper/xml/HlgTaxRateMapper.xml

@@ -91,4 +91,16 @@
 		<include refid="hlgTaxRateJoins"/>
 		WHERE a.tax_id = #{0}
 	</select>
+
+	<select id="getByTaxFee" resultType="org.jeecg.modules.hlgtax.entity.HlgTaxRate">
+		SELECT
+		<include refid="hlgTaxRateColumns"/>
+		FROM hlg_tax_rate a
+		LEFT JOIN hlg_tax t ON t.id = a.tax_id
+		WHERE
+		t.subcontractor_id = #{subId}
+		and now() between t.start_date and t.end_date
+		and #{totalMoney} &gt;= a.start_interval
+		and #{totalMoney} &lt; a.end_interval
+	</select>
 </mapper>

+ 2 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/IHlgTaxRateService.java

@@ -16,4 +16,6 @@ public interface IHlgTaxRateService extends IService<HlgTaxRate> {
     List<HlgTaxRate> getHlgTaxRateList(Integer id);
 
     List<HlgTaxRate> findHlgTaxRateByTaxId(Integer id);
+
+    HlgTaxRate getByTaxFee(Integer subcontractorId, double add);
 }

+ 2 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/IHlgTaxService.java

@@ -18,4 +18,6 @@ public interface IHlgTaxService extends IService<HlgTax> {
     void saveinfo(HlgTax hlgTax);
 
     boolean updateByIds(HlgTax hlgTax);
+
+    HlgTax getBySubId(Integer subcontractorId);
 }

+ 6 - 1
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/impl/HlgTaxRateServiceImpl.java

@@ -12,7 +12,7 @@ import java.util.List;
 /**
  * @Description: hlg_tax_rate
  * @Author: jeecg-boot
- * @Date:   2020-02-26
+ * @Date: 2020-02-26
  * @Version: V1.0
  */
 @Service
@@ -26,4 +26,9 @@ public class HlgTaxRateServiceImpl extends ServiceImpl<HlgTaxRateMapper, HlgTaxR
     public List<HlgTaxRate> findHlgTaxRateByTaxId(Integer id) {
         return baseMapper.findHlgTaxRateByTaxId(id);
     }
+
+    @Override
+    public HlgTaxRate getByTaxFee(Integer subcontractorId, double add) {
+        return baseMapper.getByTaxFee(subcontractorId, add);
+    }
 }

+ 5 - 0
happy-boot-module-powerjob/src/main/java/org/jeecg/modules/hlgtax/service/impl/HlgTaxServiceImpl.java

@@ -97,4 +97,9 @@ public class HlgTaxServiceImpl extends ServiceImpl<HlgTaxMapper, HlgTax> impleme
         }
         return true;
     }
+
+    @Override
+    public HlgTax getBySubId(Integer subcontractorId) {
+        return baseMapper.getBySubId(subcontractorId);
+    }
 }