Browse Source

* ~~报销信息添加备注:用于记录~~
* ~~报销的时候,展示剩余报销天数~~
* ~~开票日期没能导入(bug)~~
* ~~补差不记录到报销额度计算中~~
* ~~业务编号导入时,判断业务编号是否存在,如果存在,则将对应的发票存入以前的业务编号~~
* ~~业务编码可选择 临时立项号,~~
* ~~兴光会计,业务编码自动生成~~
* ~~根据开票时间进行筛选(立项号可重复,但同年份不可重复,需合并)~~
* ~~选择发票信息添加收入筛选~~
* ~~添加购方企业名称筛选项~~

user5 2 years ago
parent
commit
4e3c60d691
17 changed files with 566 additions and 121 deletions
  1. 1 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/controller/AccountantReimbursementSysController.java
  2. 1 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/domain/dto/AccountantReimbursementBusinessDTO.java
  3. 24 7
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/domain/dto/AccountantReimbursementDTO.java
  4. 23 2
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/AccountantReimbursementSysMapper.java
  5. 5 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/xml/AccountantReimbursementBusinessMapper.xml
  6. 53 3
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/xml/AccountantReimbursementSysMapper.xml
  7. 39 9
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/service/impl/AccountantReimbursementBusinessServiceImpl.java
  8. 117 38
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/service/impl/AccountantReimbursementSysServiceImpl.java
  9. 1 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/controller/ReimbursementSysController.java
  10. 1 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/domain/dto/ReimbursementBusinessDTO.java
  11. 27 7
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/domain/dto/ReimbursementDTO.java
  12. 22 2
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/ReimbursementSysMapper.java
  13. 5 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/xml/ReimbursementBusinessMapper.xml
  14. 69 5
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/xml/ReimbursementSysMapper.xml
  15. 40 8
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/service/impl/ReimbursementBusinessServiceImpl.java
  16. 110 36
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/service/impl/ReimbursementSysServiceImpl.java
  17. 28 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/utils/PublicUtil.java

+ 1 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/controller/AccountantReimbursementSysController.java

@@ -131,7 +131,7 @@ public class AccountantReimbursementSysController {
     @ApiLog("保存业务报销编码")
     @PostMapping("saveBusiness")
     public ResponseEntity saveBusiness(@Valid @RequestBody AccountantReimbursementDTO reimbursementDTO) {
-        if(StringUtils.isBlank(reimbursementDTO.getBusinessCode())){
+        if(!"1".equals(reimbursementDTO.getRandomType()) && StringUtils.isBlank(reimbursementDTO.getBusinessCode())){
             return ResponseEntity.badRequest ().body ("业务编码不可为空,请重新填写!");
         }
         service.saveBusiness(reimbursementDTO);

+ 1 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/domain/dto/AccountantReimbursementBusinessDTO.java

@@ -25,6 +25,7 @@ public class AccountantReimbursementBusinessDTO extends BaseEntity {
     private String reimbursementQuota;  //年报销额度
     private String reimbursementQuotaDay;  //日报销额度
     private String reimbursementDay;  //报销天数
+    private String surplusReimbursementDay;  //剩余报销天数
     private String reimbursementType;  //报销类型(1:正常报销;2:补差)
     private String reimbursementAmount;  //报销额度
     private String remainReimbursementAmount;  //剩余报销额度

+ 24 - 7
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/domain/dto/AccountantReimbursementDTO.java

@@ -32,10 +32,8 @@ public class AccountantReimbursementDTO extends TreeEntity<AccountantReimburseme
     @Excel(name = "购方企业名称")
     private String firmName;        //购方企业名称
 
-    @DateTimeFormat(pattern =  "yyyy-MM-dd")
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    @Excel(name = "开票日期")
-    private Date makeTime;          //开票日期
+    @Excel(name = "开票日期",importFormat = "yyyy-MM-dd",exportFormat = "yyyy-MM-dd")
+    private String makeTime;          //开票日期
     @Excel(name = "商品名称")
     private String name;     //商品名称
     @Excel(name = "金额")
@@ -62,12 +60,31 @@ public class AccountantReimbursementDTO extends TreeEntity<AccountantReimburseme
     private List<String> idList;
     private String businessFlag;    //报销判定条件(1:表示该数据没有业务编码,即没有进行报销;0:表示该数据有业务编码)
     private String batchFlag;    //批量报销状态(1:批量报销)(仅业务表中使用)
+    private String randomType;    //随机状态(1:随机业务编码,0:指定业务编码)(默认为指定业务编码仅业务表中使用)
+    private String year;    //业务编码年份(相同的业务编码根据年份不同生成不同的数据列)(仅业务表中使用)
+    private String randomBusinessCodeIndex;    //随即业务编码序号
 
-    @DateTimeFormat(pattern =  "yyyy-MM-dd")
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    private Date gatheringTime;     //收款日期
+    @Excel(name = "收款日期",importFormat = "yyyy-MM-dd",exportFormat = "yyyy-MM-dd")
+    private String gatheringTime;     //收款日期
 
 
+    /**
+     * 开票开始日期
+     */
+    private Date beginDate;
+    /**
+     * 开票结束日期
+     */
+    private Date endDate;
+    /**
+     * 收入前区间
+     */
+    private String beginIncome;
+    /**
+     * 收入后区间
+     */
+    private String endIncome;
+
     public String getReimbursementType() {
         if(StringUtils.isBlank(this.reimbursementType)){
             this.reimbursementType = "1";

+ 23 - 2
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/AccountantReimbursementSysMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO;
+import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -73,6 +74,13 @@ public interface AccountantReimbursementSysMapper extends BaseMapper<AccountantR
     List<String> selectOldBusinessCode(@Param("businessCodeList") List<String> businessCodeList);
 
     /**
+     * 查询是否存在已有的业务编号信息(业务编码和年份)
+     * @param businessCodeList
+     * @return
+     */
+    List<AccountantReimbursementDTO> selectOldBusinessCodeByInfo(@Param("businessCodeList") List<String> businessCodeList,@Param("year") String year);
+
+    /**
      * 保存业务编号信息
      * @param businessCodeList
      */
@@ -128,10 +136,10 @@ public interface AccountantReimbursementSysMapper extends BaseMapper<AccountantR
 
     /**
      * 根据业务编码查询业务信息
-     * @param businessCode
+     * @param reimbursement
      * @return
      */
-    AccountantReimbursementDTO getInfoByBusinessCode(String businessCode);
+    AccountantReimbursementDTO getInfoByBusinessCode(AccountantReimbursementDTO reimbursement);
 
     /**
      * 批量修改发票信息
@@ -215,4 +223,17 @@ public interface AccountantReimbursementSysMapper extends BaseMapper<AccountantR
      * @param id
      */
     void updateGatheringStatusById(String id);
+
+    /**
+     * 根据该条发票信息查询同业务编号下的没有收款的发票信息
+     * @param reimbursement
+     * @return
+     */
+    List<AccountantReimbursementDTO> getNotGatheringTimeInvoiceBybusinessCodeId(AccountantReimbursementDTO reimbursement);
+
+    /**
+     * 查询最后一个随机业务编码的编码序号
+     * @return
+     */
+    String getLastRandomBusinessCodeIndex(String year);
 }

+ 5 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/xml/AccountantReimbursementBusinessMapper.xml

@@ -12,6 +12,7 @@
 		a.user_id AS "userId",
         a.year AS "year",
         a.reimbursement_quota AS "reimbursementQuota",
+        a.reimbursement_all_day AS "reimbursementAllDay",
         a.reimbursement_quota_day AS "reimbursementQuotaDay",
         su.id as "user.id",
         su.name as "user.name"
@@ -72,12 +73,14 @@
     <select id="getReimbursementMoneyByYear" resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementUserDTO">
         SELECT
             a.year as year,
-            sum(a.reimbursement_amount) as alreadyReimbursementAmount
+            ifnull(sum(a.reimbursement_amount),0) as alreadyReimbursementAmount,
+            ifnull(sum(a.reimbursement_day),0) as alreadyReimbursementDay
         FROM zs_reimbursement_business_accountant_info a
         <where>
             a.del_flag = 0
             and a.user_id = #{userId}
             and a.year in (${year})
+            and a.reimbursement_type = 1
         </where>
         group by a.year
         order by a.year desc
@@ -193,6 +196,7 @@
         where a.del_flag = 0
         and a.user_id= #{userId}
         and a.year = #{year}
+        and a.reimbursement_type = 1
     </select>
 
     <select id="getAlreadyReimbursementQuotaByBusinessCodeId" resultType="java.lang.String">

+ 53 - 3
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/mapper/xml/AccountantReimbursementSysMapper.xml

@@ -27,7 +27,9 @@
         a.business_type AS "businessType",
         a.reimbursement_ratio AS "reimbursementRatio",
         a.reimbursement_status AS "reimbursementStatus",
-        a.batch_flag as "batchFlag"
+        a.batch_flag as "batchFlag",
+        a.year AS "year",
+        a.random_type AS "randomType"
     </sql>
 
     <select id="findList" resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO">
@@ -174,6 +176,22 @@
         </where>
     </select>
 
+    <select id="selectOldBusinessCodeByInfo" resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO">
+        SELECT
+            a.id,a.business_code
+        FROM zs_reimbursement_accountant_info a
+        <where>
+            a.del_flag = 0
+            <if test="businessCodeList.size>0">
+                and a.business_code in
+                <foreach collection="businessCodeList" item="businessCode" separator="," open="(" close=")">
+                    #{businessCode}
+                </foreach>
+            </if>
+            and a.year = #{year}
+        </where>
+    </select>
+
     <insert id="insertBusinessCodeList">
         insert into zs_reimbursement_accountant_info (
           id,
@@ -185,7 +203,8 @@
           del_flag,
           parent_id,
           parent_ids,
-          business_code
+          business_code,
+          year
         )
         values
         <foreach collection="businessCodeList" item="item" separator=",">
@@ -198,7 +217,8 @@
             #{item.delFlag},
             #{item.parentId},
             #{item.parentIds},
-            #{item.businessCode}
+            #{item.businessCode},
+            #{item.year}
             )
         </foreach>
     </insert>
@@ -292,6 +312,12 @@
             update_by = #{updateBy},
             update_date = #{updateDate},
             business_code = #{businessCode}
+            <if test="randomBusinessCodeIndex != null and randomBusinessCodeIndex != ''">
+                ,random_business_code_index = #{randomBusinessCodeIndex}
+            </if>
+            <if test="randomType != null and randomType != ''">
+                ,random_type = #{randomType}
+            </if>
         where
             id = #{id} and del_flag = 0
     </update>
@@ -340,6 +366,8 @@
         <where>
             a.del_flag = 0
             and a.business_code = #{businessCode}
+            and year = #{year}
+            and a.random_type = 0
         </where>
         limit 1;
     </select>
@@ -491,4 +519,26 @@
         set gathering_status = 1
         where id = #{id}
     </update>
+
+
+
+    <select id="getNotGatheringTimeInvoiceBybusinessCodeId" resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO">
+        SELECT
+        <include refid="reimbursementColumns"/>
+        FROM zs_reimbursement_invoice_accountant_info a
+        <where>
+            a.del_flag = 0
+            and parent_id = #{businessCodeId}
+            and gathering_time is null
+        </where>
+        order by a.invoice_number
+    </select>
+
+    <select id="getLastRandomBusinessCodeIndex" resultType="java.lang.String">
+        select ifnull(max(random_business_code_index),0) as randomBusinessCodeIndex
+        from zs_reimbursement_accountant_info
+        <where>
+            year = #{year}
+        </where>
+    </select>
 </mapper>

+ 39 - 9
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/service/impl/AccountantReimbursementBusinessServiceImpl.java

@@ -13,12 +13,12 @@ import com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimburseme
 import com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementUserDTO;
 import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementBusinessMapper;
 import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementSysMapper;
+import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementUserMapper;
 import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementBusinessService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
@@ -39,6 +39,8 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
     private AccountantReimbursementBusinessMapper mapper;
     @Autowired
     private AccountantReimbursementSysMapper reimbursementSysMapper;
+    @Autowired
+    private AccountantReimbursementUserMapper reimbursementUserMapper;
 
 
     @Override
@@ -99,6 +101,21 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
             for (AccountantReimbursementUserDTO info : list) {
                 for (AccountantReimbursementUserDTO yearInfo : reimbursementMoneyByYear) {
                     if(info.getYear().equals(yearInfo.getYear())){
+                        //根据人员和年份查询报销人年度报销天数信息
+                        AccountantReimbursementUserDTO reimbursementUserDTO = new AccountantReimbursementUserDTO();
+                        reimbursementUserDTO.setUserId(reimbursementUser.getUserId());
+                        reimbursementUserDTO.setYear(info.getYear());
+                        AccountantReimbursementUserDTO userInfo = reimbursementUserMapper.queryByUserIdAndYear(reimbursementUserDTO);
+                        if(null != userInfo.getReimbursementAllDay()){
+                            //计算剩余天数
+                            if(StringUtils.isBlank(yearInfo.getAlreadyReimbursementDay())){
+                                yearInfo.setAlreadyReimbursementDay("0");
+                            }
+                            Integer surplusReimbursementDay = userInfo.getReimbursementAllDay() - Integer.parseInt(yearInfo.getAlreadyReimbursementDay());
+                            info.setSurplusReimbursementDay(surplusReimbursementDay.toString());
+                        }else{
+                            info.setSurplusReimbursementDay("");
+                        }
                         //获取当年总报销额度
                         BigDecimal allAlreadyReimbursementQuota = new BigDecimal(info.getReimbursementQuota());
                         //获取当年已报销额度
@@ -109,6 +126,10 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
                         break;
                     }
                 }
+                //如果没有剩余报销天数 则将年报销天数添加到剩余报销天数中
+                if(StringUtils.isBlank(info.getSurplusReimbursementDay())){
+                    info.setSurplusReimbursementDay(info.getReimbursementAllDay().toString());
+                }
             }
 
         }
@@ -152,7 +173,7 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
             map.put("message", "该员工" + reimbursementUser.getYear() + "年度未添加报销信息,无法进行报销");
             return map;
         }
-        //查询该人员该年度已报销额度
+        //查询该人员该年度已报销额度(正常报销额度)
         String alreadyReimbursementQuota = mapper.getAlreadyReimbursementQuotaByUserIdAndYear(reimbursementUser);
         //判断本地报销额度是否超过该年度所剩余报销额度,如果超过,则不允许报销,并抛出。否则进行报销并保存报销数据
         BigDecimal alreadyReimbursementQuotaB = new BigDecimal(alreadyReimbursementQuota);    //已报销额度
@@ -162,16 +183,16 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
             BigDecimal reimbursementDay = new BigDecimal(reimbursementUser.getReimbursementDay());  //报销天数
             reimbursementAmount = reimbursementQuotaDay.multiply(reimbursementDay).setScale(2, BigDecimal.ROUND_HALF_UP);    //报销额度
 
+            //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
+            if(alreadyReimbursementQuotaB.add(reimbursementAmount).compareTo(new BigDecimal(reimbursementUser.getReimbursementQuota())) == 1){
+                map.put("success", false);
+                map.put("message", "本次报销金额已超出当年报销额度所剩余额,无法进行报销");
+                return map;
+            }
         }else{
             reimbursementAmount = new BigDecimal(reimbursementUser.getReimbursementAmount());
         }
 
-        //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
-        if(alreadyReimbursementQuotaB.add(reimbursementAmount).compareTo(new BigDecimal(reimbursementUser.getReimbursementQuota())) == 1){
-            map.put("success", false);
-            map.put("message", "本次报销金额已超出当年报销额度所剩余额,无法进行报销");
-            return map;
-        }
 
         //根据业务id查询已收款的发票信息收款总额
         String getReceiptInvoiceByReimbursementId = reimbursementSysMapper.getReceiptInvoiceIncomeByReimbursementId(reimbursementUser.getBusinessCodeId());
@@ -195,7 +216,7 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
         String gatheringStatus = mapper.getGatheringStatusById(reimbursementUser);
         BigDecimal allAlreadyReimbursementQuota = new BigDecimal(alreadyReimbursementQuotaByBusinessCodeId);    //总报销额度
         //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
-        if(allAlreadyReimbursementQuota.add(reimbursementAmount).compareTo(canReimbursementAmount) == 1){
+        if(allAlreadyReimbursementQuota.add(reimbursementAmount).compareTo(canReimbursementAmount) == 1 && "1".equals(reimbursementUser.getReimbursementType())){
             map.put("success", false);
             map.put("message", "本次报销金额已超出该业务可报销额度所剩余额,无法进行报销");
             return map;
@@ -208,6 +229,15 @@ public class AccountantReimbursementBusinessServiceImpl implements AccountantRei
             mapper.updateReimbursementInfo(reimbursementDTO);
         }
 
+        AccountantReimbursementDTO reimbursement = new AccountantReimbursementDTO();
+        reimbursement.setBusinessCodeId(reimbursementUser.getBusinessCodeId());
+        //根据该条发票信息查询同业务编号下的没有收款的发票信息
+        List<AccountantReimbursementDTO> notGatheringTimeInvoice = reimbursementSysMapper.getNotGatheringTimeInvoiceBybusinessCodeId(reimbursement);
+        if(notGatheringTimeInvoice.size() == 0){
+            //查询该发票信息
+            //如果所有的发票均已收款,则将业务信息添加全部收款状态
+            reimbursementSysMapper.updateGatheringStatusById(reimbursementUser.getBusinessCodeId());
+        }
 
         UserDTO user = UserUtils.get(reimbursementUser.getUserId());
 

+ 117 - 38
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementAccountant/service/impl/AccountantReimbursementSysServiceImpl.java

@@ -9,12 +9,13 @@ import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementSy
 import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementBusinessService;
 import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementSysService;
 import com.jeeplus.test.reimbursementAccountant.utils.MyBeanUtils;
+import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO;
+import com.jeeplus.test.reimbursementsys.utils.PublicUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
 import java.util.*;
 
 /**
@@ -37,13 +38,23 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
     @Override
     public AccountantReimbursementDTO queryBusinessById(String id) {
         //根据发票id查询业务具体信息
-        return mapper.queryBusinessById(id);
+        AccountantReimbursementDTO reimbursementDTO = mapper.queryBusinessById(id);
+        //如果没有随即类型,则将随即类型默认为非随机(即指定业务编码)
+        if(StringUtils.isBlank(reimbursementDTO.getRandomType())){
+            reimbursementDTO.setRandomType("0");
+        }
+        return reimbursementDTO;
     }
 
     @Override
     public AccountantReimbursementDTO queryBusinessByInvoiceId(String id) {
         //根据发票id查询业务具体信息
-        return mapper.queryBusinessByInvoiceId(id);
+        AccountantReimbursementDTO accountantReimbursementDTO = mapper.queryBusinessByInvoiceId(id);
+        //如果没有随即类型,则将随即类型默认为非随机(即指定业务编码)
+        if(StringUtils.isBlank(accountantReimbursementDTO.getRandomType())){
+            accountantReimbursementDTO.setRandomType("0");
+        }
+        return accountantReimbursementDTO;
     }
 
     @Override
@@ -62,7 +73,14 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
     public IPage<AccountantReimbursementDTO> treeData(Page<AccountantReimbursementDTO> page, AccountantReimbursementDTO reimbursement) {
         IPage<AccountantReimbursementDTO> pageList = new Page();
         //如果筛选项含有发票号码,则需先查询对应的发票信息
-        if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) || StringUtils.isNotBlank(reimbursement.getProposer()) || StringUtils.isNotBlank(reimbursement.getPartner())){
+        if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) ||
+                StringUtils.isNotBlank(reimbursement.getProposer()) ||
+                StringUtils.isNotBlank(reimbursement.getPartner()) ||
+                null != reimbursement.getBeginDate() ||
+                null != reimbursement.getEndDate() ||
+                StringUtils.isNotBlank(reimbursement.getBeginIncome()) ||
+                StringUtils.isNotBlank(reimbursement.getEndIncome()) ||
+                StringUtils.isNotBlank(reimbursement.getFirmName())){
             List<AccountantReimbursementDTO> invoiceList =  mapper.getInvoiceList(reimbursement);
             //如果存在发票信息,则根据发票的父节点查询对应的业务信息
             if(invoiceList.size()>0){
@@ -227,16 +245,20 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
             }
         }
 
+        //获取当前年份
+        Calendar date = Calendar.getInstance();
+        String year = String.valueOf(date.get(Calendar.YEAR));
+
         //查询非空的业务编号数据在数据库中是否存在,若存在,返回已存在的业务编号集合
-        List<String> oldBusinessCodeList = mapper.selectOldBusinessCode(businessCodeList);
+        List<AccountantReimbursementDTO> oldBusinessCodeList = mapper.selectOldBusinessCodeByInfo(businessCodeList,year);
         if (oldBusinessCodeList.size()>0){
             //如果数据库已存在部分业务编号信息,则去除该部分的业务编号信息
-            for (String oldBusinessCode: oldBusinessCodeList) {
+            for (AccountantReimbursementDTO oldBusinessCode: oldBusinessCodeList) {
                 Iterator iterator = businessCodeInfoList.iterator();
                 while (iterator.hasNext()) {
                     AccountantReimbursementDTO data = (AccountantReimbursementDTO) iterator.next();
-                    if (oldBusinessCode.equals(data.getBusinessCode())){
-                        iterator.remove();
+                    if (oldBusinessCode.getBusinessCode().equals(data.getBusinessCode())){
+                        data.setId(oldBusinessCode.getId());
                     }
                 }
             }
@@ -245,28 +267,38 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
 
         //将空的业务编号 的信息添加到集合中
         businessCodeInfoList.addAll(businessCodeNullList);
+        List<AccountantReimbursementDTO> newBusinessCodeInfoList = Lists.newArrayList();
+        newBusinessCodeInfoList.addAll(businessCodeInfoList);
+
         //对业务编号的数据进行新增保存
-        for (AccountantReimbursementDTO newBusinessCodeInfo : businessCodeInfoList) {
-            newBusinessCodeInfo.preInsert();
-            newBusinessCodeInfo.setParentId("0");
-            newBusinessCodeInfo.setParentIds("0,");
+        Iterator iterator = businessCodeInfoList.iterator();
+        while (iterator.hasNext()) {
+            AccountantReimbursementDTO data = (AccountantReimbursementDTO) iterator.next();
+            if (StringUtils.isBlank(data.getId())){
+                data.preInsert();
+                data.setParentId("0");
+                data.setParentIds("0,");
+                data.setYear(year);
+                data.setRandomType("0");
+            }else{
+                iterator.remove();
+            }
+        }
+        if(businessCodeInfoList.size()>0){
+            mapper.insertBusinessCodeList(businessCodeInfoList);
         }
-        mapper.insertBusinessCodeList(businessCodeInfoList);
 
 
         //业务编号对应的数据集合
         List<AccountantReimbursementDTO> invoiceInfoList = Lists.newArrayList();
 
-        for (AccountantReimbursementDTO info : businessCodeInfoList) {
+        for (AccountantReimbursementDTO info : newBusinessCodeInfoList) {
             if(StringUtils.isNotBlank(info.getBusinessCode())){
                 //处理业务编号不为空的数据
                 for (String key : businessCodeListMap.keySet()) {
                     if(info.getBusinessCode().equals(key)){
                         List<AccountantReimbursementDTO> infoList = businessCodeListMap.get(key);
                         for (AccountantReimbursementDTO childrenInfo : infoList) {
-                            if(info.getBusinessCode().equals("2021-01768")){
-                                System.out.println("");
-                            }
                             childrenInfo.setParentId(info.getId());
                             String parentIds = "0," + info.getId() + ",";
                             childrenInfo.setParentIds(parentIds);
@@ -299,28 +331,19 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
     @Override
     @Transactional(readOnly = false)
     public void saveBusiness(AccountantReimbursementDTO reimbursement) {
-        //查询该业务编码在数据库中是否存在
-        AccountantReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement.getBusinessCode());
-        if(null != infoByBusinessCode){
-            //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
-            //根据id 查询对应的发票信息
-            List<String> parentIdList = Lists.newArrayList();
-            parentIdList.add(reimbursement.getId());
-            List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
-            if(invoiceByParentIdList.size()>0){
-                List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
-                for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
-                    invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
-                    invoiceInfo.setParentId(infoByBusinessCode.getId());
-                    invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
-                    invoiceInfo.preUpdate();
-                    updateInvoiceData.add(invoiceInfo);
-                }
-                mapper.updateInvoiceList(updateInvoiceData);
+        //获取当前年份
+        Calendar date = Calendar.getInstance();
+        String year = String.valueOf(date.get(Calendar.YEAR));
+        reimbursement.setYear(year);
+
+        if("1".equals(reimbursement.getRandomType())){
+
+            //根据id查询业务信息是否已经是随机生成的业务编码
+            AccountantReimbursementDTO reimbursementInfo = mapper.queryBusinessById(reimbursement.getId());
+            if("1".equals(reimbursementInfo.getRandomType()) || StringUtils.isNotBlank(reimbursementInfo.getBusinessCode())){
+                return;
             }
-            //删除该业务编码信息
-            mapper.deleteBusinessById(reimbursement.getId());
-        }else{
+
             //根据id查询对应发票信息
             List<String> parentIdList = Lists.newArrayList();
             parentIdList.add(reimbursement.getId());
@@ -328,6 +351,22 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
             if(invoiceByParentIdList.size()>0){
                 List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
                 for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                    synchronized (this){
+                        //生成随机业务编号
+                        //查询最后一个业务编号信息
+                        String lastRandomBusinessCodeIndex = mapper.getLastRandomBusinessCodeIndex(year);
+                        if(StringUtils.isBlank(lastRandomBusinessCodeIndex)){
+                            lastRandomBusinessCodeIndex = "0";
+                        }
+                        Integer randomBusinessCodeIndex = Integer.parseInt(lastRandomBusinessCodeIndex) + 1;
+                        reimbursement.setRandomBusinessCodeIndex(randomBusinessCodeIndex.toString());
+                        //将新的序列号进行向左补齐4位
+                        String padLeft = PublicUtil.padLeft(randomBusinessCodeIndex.toString(), 4, '0');
+                        //生成新的随机业务编号
+                        StringBuilder sbCode = new StringBuilder().append(year).append("-kjsj-").append(padLeft);
+                        reimbursement.setBusinessCode(sbCode.toString());
+                    }
+
                     invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
                     invoiceInfo.preUpdate();
                     updateInvoiceData.add(invoiceInfo);
@@ -336,7 +375,47 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
             }
             reimbursement.preUpdate();
             mapper.saveBusiness(reimbursement);
+        }else{
+            //查询该业务编码在数据库中是否存在(当年)
+            AccountantReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement);
+            if(null != infoByBusinessCode){
+                //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
+                //根据id 查询对应的发票信息
+                List<String> parentIdList = Lists.newArrayList();
+                parentIdList.add(reimbursement.getId());
+                List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
+                if(invoiceByParentIdList.size()>0){
+                    List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
+                    for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                        invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
+                        invoiceInfo.setParentId(infoByBusinessCode.getId());
+                        invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
+                        invoiceInfo.preUpdate();
+                        updateInvoiceData.add(invoiceInfo);
+                    }
+                    mapper.updateInvoiceList(updateInvoiceData);
+                }
+                //删除该业务编码信息
+                mapper.deleteBusinessById(reimbursement.getId());
+            }else{
+                //根据id查询对应发票信息
+                List<String> parentIdList = Lists.newArrayList();
+                parentIdList.add(reimbursement.getId());
+                List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
+                if(invoiceByParentIdList.size()>0){
+                    List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
+                    for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                        invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
+                        invoiceInfo.preUpdate();
+                        updateInvoiceData.add(invoiceInfo);
+                    }
+                    mapper.updateInvoiceList(updateInvoiceData);
+                }
+                reimbursement.preUpdate();
+                mapper.saveBusiness(reimbursement);
+            }
         }
+
     }
 
     @Override

+ 1 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/controller/ReimbursementSysController.java

@@ -103,7 +103,7 @@ public class ReimbursementSysController {
     @ApiLog("保存业务报销编码")
     @PostMapping("saveBusiness")
     public ResponseEntity saveBusiness(@Valid @RequestBody ReimbursementDTO reimbursementDTO) {
-        if(StringUtils.isBlank(reimbursementDTO.getBusinessCode())){
+        if(!"1".equals(reimbursementDTO.getRandomType()) && StringUtils.isBlank(reimbursementDTO.getBusinessCode())){
             return ResponseEntity.badRequest ().body ("业务编码不可为空,请重新填写!");
         }
         service.saveBusiness(reimbursementDTO);

+ 1 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/domain/dto/ReimbursementBusinessDTO.java

@@ -25,6 +25,7 @@ public class ReimbursementBusinessDTO extends BaseEntity {
     private String reimbursementQuota;  //年报销额度
     private String reimbursementQuotaDay;  //日报销额度
     private String reimbursementDay;  //报销天数
+    private String surplusReimbursementDay;  //剩余报销天数
     private String reimbursementType;  //报销类型(1:正常报销;2:补差)
     private String reimbursementAmount;  //报销额度
     private String remainReimbursementAmount;  //剩余报销额度

+ 27 - 7
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/domain/dto/ReimbursementDTO.java

@@ -9,6 +9,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import java.time.LocalDate;
 import java.util.Date;
 import java.util.List;
 
@@ -32,10 +33,8 @@ public class ReimbursementDTO extends TreeEntity<ReimbursementDTO> {
     @Excel(name = "购方企业名称")
     private String firmName;        //购方企业名称
 
-    @DateTimeFormat(pattern =  "yyyy-MM-dd")
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    @Excel(name = "开票日期")
-    private Date makeTime;          //开票日期
+    @Excel(name = "开票日期",importFormat = "yyyy-MM-dd",exportFormat = "yyyy-MM-dd")
+    private String makeTime;          //开票日期
     @Excel(name = "商品名称")
     private String name;     //商品名称
     @Excel(name = "金额")
@@ -59,11 +58,32 @@ public class ReimbursementDTO extends TreeEntity<ReimbursementDTO> {
     private String reimbursementType;    //报销比例
     private String gatheringStatus;    //收款状态
     private String reimbursementStatus;    //报销状态
+    private String randomType;    //随机状态(1:随机业务编码,2:指定业务编码)(默认为指定业务编码仅业务表中使用)
+    private String year;    //业务编码年份(相同的业务编码根据年份不同生成不同的数据列)(仅业务表中使用)
+    private String batchFlag;    //批量报销状态(1:批量报销)(仅业务表中使用)
+    private String randomBusinessCodeIndex;    //随即业务编码序号
     private List<String> idList;
 
-    @DateTimeFormat(pattern =  "yyyy-MM-dd")
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    private Date gatheringTime;     //收款日期
+    @Excel(name = "收款日期",importFormat = "yyyy-MM-dd",exportFormat = "yyyy-MM-dd")
+    private String gatheringTime;     //收款日期
+
+
+    /**
+     * 开票开始日期
+     */
+    private Date beginDate;
+    /**
+     * 开票结束日期
+     */
+    private Date endDate;
+    /**
+     * 收入前区间
+     */
+    private String beginIncome;
+    /**
+     * 收入后区间
+     */
+    private String endIncome;
 
 
     public String getReimbursementType() {

+ 22 - 2
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/ReimbursementSysMapper.java

@@ -63,6 +63,13 @@ public interface ReimbursementSysMapper  extends BaseMapper<ReimbursementDTO> {
     List<String> selectOldBusinessCode(@Param("businessCodeList") List<String> businessCodeList);
 
     /**
+     * 查询是否存在已有的业务编号信息(业务编码和年份)
+     * @param businessCodeList
+     * @return
+     */
+    List<ReimbursementDTO> selectOldBusinessCodeByInfo(@Param("businessCodeList") List<String> businessCodeList,@Param("year") String year);
+
+    /**
      * 保存业务编号信息
      * @param businessCodeList
      */
@@ -111,10 +118,10 @@ public interface ReimbursementSysMapper  extends BaseMapper<ReimbursementDTO> {
 
     /**
      * 根据业务编码查询业务信息
-     * @param businessCode
+     * @param reimbursement
      * @return
      */
-    ReimbursementDTO getInfoByBusinessCode(String businessCode);
+    ReimbursementDTO getInfoByBusinessCode(ReimbursementDTO reimbursement);
 
     /**
      * 批量修改发票信息
@@ -166,6 +173,13 @@ public interface ReimbursementSysMapper  extends BaseMapper<ReimbursementDTO> {
      */
     List<ReimbursementDTO> getNotGatheringTimeInvoice(ReimbursementDTO reimbursement);
 
+    /**
+     * 根据该条发票信息查询同业务编号下的没有收款的发票信息
+     * @param reimbursement
+     * @return
+     */
+    List<ReimbursementDTO> getNotGatheringTimeInvoiceBybusinessCodeId(ReimbursementDTO reimbursement);
+
     void updateGatheringTime(@Param("idList") List<String> idList, @Param("reimbursement") ReimbursementDTO reimbursement);
 
     /**
@@ -173,4 +187,10 @@ public interface ReimbursementSysMapper  extends BaseMapper<ReimbursementDTO> {
      * @param id
      */
     void updateGatheringStatusById(String id);
+
+    /**
+     * 查询最后一个随机业务编码的编码序号
+     * @return
+     */
+    String getLastRandomBusinessCodeIndex(String year);
 }

+ 5 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/xml/ReimbursementBusinessMapper.xml

@@ -12,6 +12,7 @@
 		a.user_id AS "userId",
         a.year AS "year",
         a.reimbursement_quota AS "reimbursementQuota",
+        a.reimbursement_all_day AS "reimbursementAllDay",
         a.reimbursement_quota_day AS "reimbursementQuotaDay",
         su.id as "user.id",
         su.name as "user.name"
@@ -72,12 +73,14 @@
     <select id="getReimbursementMoneyByYear" resultType="com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementUserDTO">
         SELECT
             a.year as year,
-            sum(a.reimbursement_amount) as alreadyReimbursementAmount
+            ifnull(sum(a.reimbursement_amount),0) as alreadyReimbursementAmount,
+            ifnull(sum(a.reimbursement_day),0) as alreadyReimbursementDay
         FROM zs_reimbursement_business_info a
         <where>
             a.del_flag = 0
             and a.user_id = #{userId}
             and a.year in (${year})
+            and a.reimbursement_type = 1
         </where>
         group by a.year
         order by a.year desc
@@ -193,6 +196,7 @@
         where a.del_flag = 0
         and a.user_id= #{userId}
         and a.year = #{year}
+        and a.reimbursement_type = 1
     </select>
 
     <select id="getAlreadyReimbursementQuotaByBusinessCodeId" resultType="java.lang.String">

+ 69 - 5
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/mapper/xml/ReimbursementSysMapper.xml

@@ -26,7 +26,10 @@
         a.partner AS "partner",
         a.business_type AS "businessType",
         a.reimbursement_ratio AS "reimbursementRatio",
-        a.reimbursement_status AS "reimbursementStatus"
+        a.reimbursement_status AS "reimbursementStatus",
+        a.batch_flag AS "batchFlag",
+        a.year AS "year",
+        a.random_type AS "randomType"
     </sql>
 
     <select id="queryAllList" resultType="com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO">
@@ -63,6 +66,21 @@
             <if test="partner != null and partner != ''">
                 and a.partner like concat('%',#{partner},'%')
             </if>
+            <if test="firmName != null and firmName != ''">
+                and a.firm_name like concat('%',#{firmName},'%')
+            </if>
+            <if test="beginIncome != null and beginIncome != ''">
+                and a.income >= #{beginIncome}
+            </if>
+            <if test="endIncome != null and endIncome != ''">
+                and a.income &lt;= #{endIncome}
+            </if>
+            <if test="beginDate != null">
+                and a.make_time >= #{beginDate}
+            </if>
+            <if test="endDate != null">
+                and a.make_time &lt;= #{endDate}
+            </if>
         </where>
         order by a.invoice_number
     </select>
@@ -136,6 +154,22 @@
         </where>
     </select>
 
+    <select id="selectOldBusinessCodeByInfo" resultType="com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO">
+        SELECT
+        a.id,a.business_code
+        FROM zs_reimbursement_info a
+        <where>
+            a.del_flag = 0
+            <if test="businessCodeList.size>0">
+                and a.business_code in
+                <foreach collection="businessCodeList" item="businessCode" separator="," open="(" close=")">
+                    #{businessCode}
+                </foreach>
+            </if>
+            and a.year = #{year}
+        </where>
+    </select>
+
     <insert id="insertBusinessCodeList">
         insert into zs_reimbursement_info (
           id,
@@ -147,7 +181,8 @@
           del_flag,
           parent_id,
           parent_ids,
-          business_code
+          business_code,
+          year
         )
         values
         <foreach collection="businessCodeList" item="item" separator=",">
@@ -160,7 +195,8 @@
             #{item.delFlag},
             #{item.parentId},
             #{item.parentIds},
-            #{item.businessCode}
+            #{item.businessCode},
+            #{item.year}
             )
         </foreach>
     </insert>
@@ -244,6 +280,12 @@
             update_by = #{updateBy},
             update_date = #{updateDate},
             business_code = #{businessCode}
+            <if test="randomBusinessCodeIndex != null and randomBusinessCodeIndex != ''">
+                ,random_business_code_index = #{randomBusinessCodeIndex}
+            </if>
+            <if test="randomType != null and randomType != ''">
+                ,random_type = #{randomType}
+            </if>
         where
             id = #{id} and del_flag = 0
     </update>
@@ -280,6 +322,8 @@
         <where>
             a.del_flag = 0
             and a.business_code = #{businessCode}
+            and year = #{year}
+            and a.random_type = 0
         </where>
         limit 1;
     </select>
@@ -384,13 +428,25 @@
         FROM zs_reimbursement_invoice_info a
         <where>
             a.del_flag = 0
-            and business_code = (
-            select business_code from zs_reimbursement_invoice_info where id = #{businessCode}
+            and parent_id = (
+            select parent_id from zs_reimbursement_invoice_info where id = #{id}
             ) and gathering_time is null
         </where>
         order by a.invoice_number
     </select>
 
+    <select id="getNotGatheringTimeInvoiceBybusinessCodeId" resultType="com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO">
+        SELECT
+        <include refid="reimbursementColumns"/>
+        FROM zs_reimbursement_invoice_info a
+        <where>
+            a.del_flag = 0
+            and parent_id = #{businessCodeId}
+            and gathering_time is null
+        </where>
+        order by a.invoice_number
+    </select>
+
     <update id="updateGatheringTime">
         <foreach collection="idList" item="id" index="index" open="" close="" separator=";">
             update zs_reimbursement_invoice_info
@@ -408,4 +464,12 @@
         set gathering_status = 1
         where id = #{id}
     </update>
+
+    <select id="getLastRandomBusinessCodeIndex" resultType="java.lang.String">
+        select ifnull(max(random_business_code_index),0) as randomBusinessCodeIndex
+        from zs_reimbursement_info
+        <where>
+            year = #{year}
+        </where>
+    </select>
 </mapper>

+ 40 - 8
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/service/impl/ReimbursementBusinessServiceImpl.java

@@ -13,6 +13,7 @@ import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO;
 import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementUserDTO;
 import com.jeeplus.test.reimbursementsys.mapper.ReimbursementBusinessMapper;
 import com.jeeplus.test.reimbursementsys.mapper.ReimbursementSysMapper;
+import com.jeeplus.test.reimbursementsys.mapper.ReimbursementUserMapper;
 import com.jeeplus.test.reimbursementsys.service.ReimbursementBusinessService;
 import org.springframework.stereotype.Service;
 
@@ -36,6 +37,8 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
     private ReimbursementBusinessMapper mapper;
     @Resource
     private ReimbursementSysMapper reimbursementSysMapper;
+    @Resource
+    private ReimbursementUserMapper reimbursementUserMapper;
 
 
     @Override
@@ -96,6 +99,21 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
             for (ReimbursementUserDTO info : list) {
                 for (ReimbursementUserDTO yearInfo : reimbursementMoneyByYear) {
                     if(info.getYear().equals(yearInfo.getYear())){
+                        //根据人员和年份查询报销人年度报销天数信息
+                        ReimbursementUserDTO reimbursementUserDTO = new ReimbursementUserDTO();
+                        reimbursementUserDTO.setUserId(reimbursementUser.getUserId());
+                        reimbursementUserDTO.setYear(info.getYear());
+                        ReimbursementUserDTO userInfo = reimbursementUserMapper.queryByUserIdAndYear(reimbursementUserDTO);
+                        if(null != userInfo.getReimbursementAllDay()){
+                            //计算剩余天数
+                            if(StringUtils.isBlank(yearInfo.getAlreadyReimbursementDay())){
+                                yearInfo.setAlreadyReimbursementDay("0");
+                            }
+                            Integer surplusReimbursementDay = userInfo.getReimbursementAllDay() - Integer.parseInt(yearInfo.getAlreadyReimbursementDay());
+                            info.setSurplusReimbursementDay(surplusReimbursementDay.toString());
+                        }else{
+                            info.setSurplusReimbursementDay("");
+                        }
                         //获取当年总报销额度
                         BigDecimal allAlreadyReimbursementQuota = new BigDecimal(info.getReimbursementQuota());
                         //获取当年已报销额度
@@ -106,6 +124,10 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
                         break;
                     }
                 }
+                //如果没有剩余报销天数 则将年报销天数添加到剩余报销天数中
+                if(StringUtils.isBlank(info.getSurplusReimbursementDay())){
+                    info.setSurplusReimbursementDay(info.getReimbursementAllDay().toString());
+                }
             }
 
         }
@@ -148,7 +170,7 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
             map.put("message", "该员工" + reimbursementUser.getYear() + "年度未添加报销信息,无法进行报销");
             return map;
         }
-        //查询该人员该年度已报销额度
+        //查询该人员该年度已报销额度(正常报销额度)
         String alreadyReimbursementQuota = mapper.getAlreadyReimbursementQuotaByUserIdAndYear(reimbursementUser);
         //判断本地报销额度是否超过该年度所剩余报销额度,如果超过,则不允许报销,并抛出。否则进行报销并保存报销数据
         BigDecimal alreadyReimbursementQuotaB = new BigDecimal(alreadyReimbursementQuota);    //已报销额度
@@ -158,16 +180,16 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
             BigDecimal reimbursementDay = new BigDecimal(reimbursementUser.getReimbursementDay());  //报销天数
             reimbursementAmount = reimbursementQuotaDay.multiply(reimbursementDay).setScale(2, BigDecimal.ROUND_HALF_UP);    //报销额度
 
+            //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
+            if(alreadyReimbursementQuotaB.add(reimbursementAmount).compareTo(new BigDecimal(reimbursementUser.getReimbursementQuota())) == 1){
+                map.put("success", false);
+                map.put("message", "本次报销金额已超出当年报销额度所剩余额,无法进行报销");
+                return map;
+            }
         }else{
             reimbursementAmount = new BigDecimal(reimbursementUser.getReimbursementAmount());
         }
 
-        //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
-        if(alreadyReimbursementQuotaB.add(reimbursementAmount).compareTo(new BigDecimal(reimbursementUser.getReimbursementQuota())) == 1){
-            map.put("success", false);
-            map.put("message", "本次报销金额已超出当年报销额度所剩余额,无法进行报销");
-            return map;
-        }
 
         //根据业务id查询已收款的发票信息收款总额
         String getReceiptInvoiceByReimbursementId = reimbursementSysMapper.getReceiptInvoiceIncomeByReimbursementId(reimbursementUser.getBusinessCodeId());
@@ -191,7 +213,7 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
         String gatheringStatus = mapper.getGatheringStatusById(reimbursementUser);
         BigDecimal allAlreadyReimbursementQuota = new BigDecimal(alreadyReimbursementQuotaByBusinessCodeId);    //总报销额度
         //往期加这次的总报销额度和当年的总报销额度进行比较,小于当年报销额度 则个人可以进行报销,否则,无法进行报销
-        if(allAlreadyReimbursementQuota.add(reimbursementAmount).compareTo(canReimbursementAmount) == 1){
+        if(allAlreadyReimbursementQuota.add(reimbursementAmount).compareTo(canReimbursementAmount) == 1 && "1".equals(reimbursementUser.getReimbursementType())){
             map.put("success", false);
             map.put("message", "本次报销金额已超出该业务可报销额度所剩余额,无法进行报销");
             return map;
@@ -204,6 +226,16 @@ public class ReimbursementBusinessServiceImpl implements ReimbursementBusinessSe
             mapper.updateReimbursementInfo(reimbursementDTO);
         }
 
+        ReimbursementDTO reimbursement = new ReimbursementDTO();
+        reimbursement.setBusinessCodeId(reimbursementUser.getBusinessCodeId());
+        //根据该条发票信息查询同业务编号下的没有收款的发票信息
+        List<ReimbursementDTO> notGatheringTimeInvoice = reimbursementSysMapper.getNotGatheringTimeInvoiceBybusinessCodeId(reimbursement);
+        if(notGatheringTimeInvoice.size() == 0){
+            //查询该发票信息
+            //如果所有的发票均已收款,则将业务信息添加全部收款状态
+            reimbursementSysMapper.updateGatheringStatusById(reimbursementUser.getBusinessCodeId());
+        }
+
 
         UserDTO user = UserUtils.get(reimbursementUser.getUserId());
 

+ 110 - 36
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/service/impl/ReimbursementSysServiceImpl.java

@@ -8,6 +8,7 @@ import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO;
 import com.jeeplus.test.reimbursementsys.mapper.ReimbursementSysMapper;
 import com.jeeplus.test.reimbursementsys.service.ReimbursementBusinessService;
 import com.jeeplus.test.reimbursementsys.service.ReimbursementSysService;
+import com.jeeplus.test.reimbursementsys.utils.PublicUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 
@@ -32,7 +33,12 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
 
     @Override
     public ReimbursementDTO queryBusinessById(String id) {
-        return mapper.queryBusinessById(id);
+        ReimbursementDTO reimbursementDTO = mapper.queryBusinessById(id);
+        //如果没有随即类型,则将随即类型默认为非随机(即指定业务编码)
+        if(StringUtils.isBlank(reimbursementDTO.getRandomType())){
+            reimbursementDTO.setRandomType("0");
+        }
+        return reimbursementDTO;
     }
 
     @Override
@@ -45,7 +51,14 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
     public IPage<ReimbursementDTO> treeData(Page<ReimbursementDTO> page, ReimbursementDTO reimbursement) {
         IPage<ReimbursementDTO> pageList = new Page();
         //如果筛选项含有发票号码,则需先查询对应的发票信息
-        if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) || StringUtils.isNotBlank(reimbursement.getProposer()) || StringUtils.isNotBlank(reimbursement.getPartner())){
+        if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) ||
+                StringUtils.isNotBlank(reimbursement.getProposer()) ||
+                StringUtils.isNotBlank(reimbursement.getPartner()) ||
+                null != reimbursement.getBeginDate() ||
+                null != reimbursement.getEndDate() ||
+                StringUtils.isNotBlank(reimbursement.getBeginIncome()) ||
+                StringUtils.isNotBlank(reimbursement.getEndIncome()) ||
+                StringUtils.isNotBlank(reimbursement.getFirmName())){
             List<ReimbursementDTO> invoiceList =  mapper.getInvoiceList(reimbursement);
             //如果存在发票信息,则根据发票的父节点查询对应的业务信息
             if(invoiceList.size()>0){
@@ -195,16 +208,20 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
             }
         }
 
+        //获取当前年份
+        Calendar date = Calendar.getInstance();
+        String year = String.valueOf(date.get(Calendar.YEAR));
+
         //查询非空的业务编号数据在数据库中是否存在,若存在,返回已存在的业务编号集合
-        List<String> oldBusinessCodeList = mapper.selectOldBusinessCode(businessCodeList);
+        List<ReimbursementDTO> oldBusinessCodeList = mapper.selectOldBusinessCodeByInfo(businessCodeList,year);
         if (oldBusinessCodeList.size()>0){
             //如果数据库已存在部分业务编号信息,则去除该部分的业务编号信息
-            for (String oldBusinessCode: oldBusinessCodeList) {
+            for (ReimbursementDTO oldBusinessCode: oldBusinessCodeList) {
                 Iterator iterator = businessCodeInfoList.iterator();
                 while (iterator.hasNext()) {
                     ReimbursementDTO data = (ReimbursementDTO) iterator.next();
-                    if (oldBusinessCode.equals(data.getBusinessCode())){
-                        iterator.remove();
+                    if (oldBusinessCode.getBusinessCode().equals(data.getBusinessCode())){
+                        data.setId(oldBusinessCode.getId());
                     }
                 }
             }
@@ -213,28 +230,38 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
 
         //将空的业务编号 的信息添加到集合中
         businessCodeInfoList.addAll(businessCodeNullList);
+        List<ReimbursementDTO> newBusinessCodeInfoList = Lists.newArrayList();
+        newBusinessCodeInfoList.addAll(businessCodeInfoList);
+
         //对业务编号的数据进行新增保存
-        for (ReimbursementDTO newBusinessCodeInfo : businessCodeInfoList) {
-            newBusinessCodeInfo.preInsert();
-            newBusinessCodeInfo.setParentId("0");
-            newBusinessCodeInfo.setParentIds("0,");
+        Iterator iterator = businessCodeInfoList.iterator();
+        while (iterator.hasNext()) {
+            ReimbursementDTO data = (ReimbursementDTO) iterator.next();
+            if (StringUtils.isBlank(data.getId())){
+                data.preInsert();
+                data.setParentId("0");
+                data.setParentIds("0,");
+                data.setYear(year);
+                data.setRandomType("0");
+            }else{
+                iterator.remove();
+            }
+        }
+        if(businessCodeInfoList.size()>0){
+            mapper.insertBusinessCodeList(businessCodeInfoList);
         }
-        mapper.insertBusinessCodeList(businessCodeInfoList);
 
 
         //业务编号对应的数据集合
         List<ReimbursementDTO> invoiceInfoList = Lists.newArrayList();
 
-        for (ReimbursementDTO info : businessCodeInfoList) {
+        for (ReimbursementDTO info : newBusinessCodeInfoList) {
             if(StringUtils.isNotBlank(info.getBusinessCode())){
                 //处理业务编号不为空的数据
                 for (String key : businessCodeListMap.keySet()) {
                     if(info.getBusinessCode().equals(key)){
                         List<ReimbursementDTO> infoList = businessCodeListMap.get(key);
                         for (ReimbursementDTO childrenInfo : infoList) {
-                            if(info.getBusinessCode().equals("2021-01768")){
-                                System.out.println("");
-                            }
                             childrenInfo.setParentId(info.getId());
                             String parentIds = "0," + info.getId() + ",";
                             childrenInfo.setParentIds(parentIds);
@@ -266,28 +293,18 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
 
     @Override
     public void saveBusiness(ReimbursementDTO reimbursement) {
-        //查询该业务编码在数据库中是否存在
-        ReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement.getBusinessCode());
-        if(null != infoByBusinessCode){
-            //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
-            //根据id 查询对应的发票信息
-            List<String> parentIdList = Lists.newArrayList();
-            parentIdList.add(reimbursement.getId());
-            List<ReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
-            if(invoiceByParentIdList.size()>0){
-                List<ReimbursementDTO> updateInvoiceData = Lists.newArrayList();
-                for (ReimbursementDTO invoiceInfo: invoiceByParentIdList) {
-                    invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
-                    invoiceInfo.setParentId(infoByBusinessCode.getId());
-                    invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
-                    invoiceInfo.preUpdate();
-                    updateInvoiceData.add(invoiceInfo);
-                }
-                mapper.updateInvoiceList(updateInvoiceData);
+        //获取当前年份
+        Calendar date = Calendar.getInstance();
+        String year = String.valueOf(date.get(Calendar.YEAR));
+        reimbursement.setYear(year);
+
+        if("1".equals(reimbursement.getRandomType())){
+            //根据id查询业务信息是否已经是随机生成的业务编码
+            ReimbursementDTO reimbursementInfo = mapper.queryBusinessById(reimbursement.getId());
+            if("1".equals(reimbursementInfo.getRandomType()) || StringUtils.isNotBlank(reimbursementInfo.getBusinessCode())){
+                return;
             }
-            //删除该业务编码信息
-            mapper.deleteBusinessById(reimbursement.getId());
-        }else{
+
             //根据id查询对应发票信息
             List<String> parentIdList = Lists.newArrayList();
             parentIdList.add(reimbursement.getId());
@@ -295,6 +312,22 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
             if(invoiceByParentIdList.size()>0){
                 List<ReimbursementDTO> updateInvoiceData = Lists.newArrayList();
                 for (ReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                    synchronized (this){
+                        //生成随机业务编号
+                        //查询最后一个业务编号信息
+                        String lastRandomBusinessCodeIndex = mapper.getLastRandomBusinessCodeIndex(year);
+                        if(StringUtils.isBlank(lastRandomBusinessCodeIndex)){
+                            lastRandomBusinessCodeIndex = "0";
+                        }
+                        Integer randomBusinessCodeIndex = Integer.parseInt(lastRandomBusinessCodeIndex) + 1;
+                        reimbursement.setRandomBusinessCodeIndex(randomBusinessCodeIndex.toString());
+                        //将新的序列号进行向左补齐4位
+                        String padLeft = PublicUtil.padLeft(randomBusinessCodeIndex.toString(), 4, '0');
+                        //生成新的随机业务编号
+                        StringBuilder sbCode = new StringBuilder().append(year).append("-zssj-").append(padLeft);
+                        reimbursement.setBusinessCode(sbCode.toString());
+                    }
+
                     invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
                     invoiceInfo.preUpdate();
                     updateInvoiceData.add(invoiceInfo);
@@ -303,7 +336,48 @@ public class ReimbursementSysServiceImpl implements ReimbursementSysService {
             }
             reimbursement.preUpdate();
             mapper.saveBusiness(reimbursement);
+
+        }else{
+            //查询该业务编码在数据库中是否存在
+            ReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement);
+            if(null != infoByBusinessCode){
+                //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
+                //根据id 查询对应的发票信息
+                List<String> parentIdList = Lists.newArrayList();
+                parentIdList.add(reimbursement.getId());
+                List<ReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
+                if(invoiceByParentIdList.size()>0){
+                    List<ReimbursementDTO> updateInvoiceData = Lists.newArrayList();
+                    for (ReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                        invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
+                        invoiceInfo.setParentId(infoByBusinessCode.getId());
+                        invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
+                        invoiceInfo.preUpdate();
+                        updateInvoiceData.add(invoiceInfo);
+                    }
+                    mapper.updateInvoiceList(updateInvoiceData);
+                }
+                //删除该业务编码信息
+                mapper.deleteBusinessById(reimbursement.getId());
+            }else{
+                //根据id查询对应发票信息
+                List<String> parentIdList = Lists.newArrayList();
+                parentIdList.add(reimbursement.getId());
+                List<ReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
+                if(invoiceByParentIdList.size()>0){
+                    List<ReimbursementDTO> updateInvoiceData = Lists.newArrayList();
+                    for (ReimbursementDTO invoiceInfo: invoiceByParentIdList) {
+                        invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
+                        invoiceInfo.preUpdate();
+                        updateInvoiceData.add(invoiceInfo);
+                    }
+                    mapper.updateInvoiceList(updateInvoiceData);
+                }
+                reimbursement.preUpdate();
+                mapper.saveBusiness(reimbursement);
+            }
         }
+
     }
     @Override
     public Map<String,Object> saveGatheringTime(ReimbursementDTO reimbursement) {

+ 28 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursementsys/utils/PublicUtil.java

@@ -0,0 +1,28 @@
+package com.jeeplus.test.reimbursementsys.utils;
+
+/**
+ * @author: 徐滕
+ * @version: 2022-06-13 14:50
+ */
+public class PublicUtil {
+    /**
+     * 字符串左补齐方法
+     * @param src 原有字符串
+     * @param len 返回字符串长度
+     * @param ch 需要补齐的字符
+     * @return
+     */
+    public static String padLeft(String src, int len, char ch) {
+        int diff = len - src.length();
+        if (diff <= 0) {
+            return src;
+        }
+
+        char[] charr = new char[len];
+        System.arraycopy(src.toCharArray(), 0, charr, diff, src.length());
+        for (int i = 0; i < diff; i++) {
+            charr[i] = ch;
+        }
+        return new String(charr);
+    }
+}