From 8a7797cf8ba37fa1beec625209a6964a3668b994 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期二, 23 一月 2024 18:18:33 +0800
Subject: [PATCH] 111

---
 server/service/src/main/java/com/doumee/service/business/TaxesService.java                   |   11 ++
 server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java |   61 ++++++++++++
 server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java           |    7 +
 server/service/src/main/java/com/doumee/dao/business/model/Taxes.java                        |    6 
 server/service/src/main/java/com/doumee/dao/business/dto/EntrustInvoicingDTO.java            |   32 ++++++
 server/service/src/main/java/com/doumee/service/business/impl/TaxesServiceImpl.java          |  115 +++++++++++++++++++++++
 server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java               |   12 ++
 server/service/src/main/java/com/doumee/dao/business/join/TaxesJoinMapper.java               |    1 
 server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java          |    2 
 server/company/src/main/java/com/doumee/api/business/TaxesController.java                    |   30 ++++-
 server/service/src/main/java/com/doumee/dao/business/dto/InsuranceApplyQueryDTO.java         |   12 ++
 server/service/src/main/java/com/doumee/dao/business/join/TaxDetailJoinMapper.java           |    2 
 12 files changed, 281 insertions(+), 10 deletions(-)

diff --git a/server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java b/server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java
index 593bf81..ce47e32 100644
--- a/server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java
+++ b/server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java
@@ -76,6 +76,13 @@
         return ApiResponse.success(insuranceApplyService.findPage(pageWrap));
     }
 
+    @ApiOperation("鍒楄〃")
+    @PostMapping("/findListByDTO")
+    @RequiresPermissions("business:insuranceapply:query")
+    public ApiResponse<List<InsuranceApply>> findListByDTO (@RequestBody InsuranceApplyQueryDTO insuranceApplyQueryDTO) {
+        return ApiResponse.success(insuranceApplyService.findListByDTO(insuranceApplyQueryDTO));
+    }
+
     @ApiOperation("瀵煎嚭Excel")
     @PostMapping("/exportExcel")
     @RequiresPermissions("business:insuranceapply:exportExcel")
diff --git a/server/company/src/main/java/com/doumee/api/business/TaxesController.java b/server/company/src/main/java/com/doumee/api/business/TaxesController.java
index f3a3665..8ac43c2 100644
--- a/server/company/src/main/java/com/doumee/api/business/TaxesController.java
+++ b/server/company/src/main/java/com/doumee/api/business/TaxesController.java
@@ -3,14 +3,20 @@
 import com.doumee.api.BaseController;
 import com.doumee.core.annotation.excel.ExcelExporter;
 import com.doumee.core.annotation.pr.PreventRepeat;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.ApiResponse;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.model.PageData;
+import com.doumee.core.utils.Constants;
+import com.doumee.dao.business.dto.EntrustInvoicingDTO;
 import com.doumee.dao.business.model.Taxes;
 import com.doumee.service.business.TaxesService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.apache.shiro.authz.annotation.RequiresPermissions;    
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
@@ -71,7 +77,7 @@
     @PostMapping("/page")
     @RequiresPermissions("business:taxes:query")
     public ApiResponse<PageData<Taxes>> findPage (@RequestBody PageWrap<Taxes> pageWrap) {
-        return ApiResponse.success(taxesService.findPage(pageWrap));
+        return ApiResponse.success(taxesService.findPageForCompany(pageWrap));
     }
 
     @ApiOperation("瀵煎嚭Excel")
@@ -81,10 +87,22 @@
         ExcelExporter.build(Taxes.class).export(taxesService.findPage(pageWrap).getRecords(), "鍙戠エ淇℃伅琛�", response);
     }
 
-    @ApiOperation("鏍规嵁ID鏌ヨ")
-    @GetMapping("/{id}")
+    @ApiOperation("鑾峰彇浼佷笟淇℃伅")
+    @GetMapping("/getCompanyDetail")
     @RequiresPermissions("business:taxes:query")
-    public ApiResponse findById(@PathVariable Integer id) {
-        return ApiResponse.success(taxesService.findById(id));
+    public ApiResponse getCompanyDetail() {
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(!loginUserInfo.getType().equals(Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闈炰紒涓氱被鐢ㄦ埛鏃犳硶杩涜璇ユ搷浣�");
+        }
+        return ApiResponse.success(taxesService.findById(loginUserInfo.getCompanyId()));
     }
+
+    @ApiOperation("鎻愪氦濮旀墭鎶曟姤寮�绁�")
+    @PostMapping("/entrustInvoicing")
+    public ApiResponse entrustInvoicing(@RequestBody EntrustInvoicingDTO entrustInvoicingDTOs) {
+        taxesService.entrustInvoicing(entrustInvoicingDTOs);
+        return ApiResponse.success(null);
+    }
+
 }
diff --git a/server/service/src/main/java/com/doumee/dao/business/dto/EntrustInvoicingDTO.java b/server/service/src/main/java/com/doumee/dao/business/dto/EntrustInvoicingDTO.java
new file mode 100644
index 0000000..64df936
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/dao/business/dto/EntrustInvoicingDTO.java
@@ -0,0 +1,32 @@
+package com.doumee.dao.business.dto;
+
+import com.doumee.dao.business.model.TaxDetial;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @Author : Rk
+ * @create 2024/1/23 16:01
+ */
+@Data
+public class EntrustInvoicingDTO {
+
+    @ApiModelProperty(value = "寮�绁ㄩ噾棰�")
+    private BigDecimal invoicingMoney;
+
+    @ApiModelProperty(value = "鎺ユ敹鏂瑰紡 0鐢靛瓙鍙戠エ 1绾歌川鍙戠エ")
+    private Integer type;
+
+    @ApiModelProperty(value = "鍙戠エ鎺ユ敹鍦板潃")
+    private String address;
+
+    @ApiModelProperty(value = "鎶曚繚涓婚敭鍒楄〃" ,notes = "insuranceApplyId 銆� fee  銆乤pplyCode  ")
+    private List<TaxDetial> taxDetialList;
+
+
+}
diff --git a/server/service/src/main/java/com/doumee/dao/business/dto/InsuranceApplyQueryDTO.java b/server/service/src/main/java/com/doumee/dao/business/dto/InsuranceApplyQueryDTO.java
index 36e3e76..32aa81d 100644
--- a/server/service/src/main/java/com/doumee/dao/business/dto/InsuranceApplyQueryDTO.java
+++ b/server/service/src/main/java/com/doumee/dao/business/dto/InsuranceApplyQueryDTO.java
@@ -8,8 +8,10 @@
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * @author RenKang
@@ -35,13 +37,23 @@
     @ApiModelProperty(value = "鍗曞彿")
     private String code;
 
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
     @ApiModelProperty(value = "鎻愪氦鏃ユ湡寮�濮�")
     private Date createTimeS;
 
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
     @ApiModelProperty(value = "鎻愪氦鏃ユ湡缁撴潫")
     private Date createTimeE;
 
     @ApiModelProperty(value = "鐘舵�� 0寰呭鏍� 1骞冲彴閫�鍥炰繚鍗曪紙宸查��鍥烇級 2宸蹭笂浼犱唬绛剧敵璇疯〃寰呬紒涓氱绔狅紙寰呯缃诧級  3宸茬绔犲緟涓婁紶淇濋櫓鍗曪紙寰呭嚭鍗曪級 4淇濆崟鍑哄叿澶辫触閫�鍥烇紙宸查��鍥烇級 5宸蹭笂浼犱繚鍗曪紙淇濋殰涓級6浼佷笟鐢宠閫�鍥炰腑 7骞冲彴鍚屾剰閫�鍥烇紙宸查��鍥烇級 8浼佷笟鍏抽棴  锛堝凡鍏抽棴锛�", example = "1")
     private Integer status;
 
+    @ApiModelProperty(value = "绫诲瀷 0鐩翠繚 1濮旀墭鎶曚繚")
+    private Integer type;
+
+    @ApiModelProperty(value = "涓婚敭鍒楄〃")
+    private List<Integer> ids;
+
 }
diff --git a/server/service/src/main/java/com/doumee/dao/business/join/TaxDetailJoinMapper.java b/server/service/src/main/java/com/doumee/dao/business/join/TaxDetailJoinMapper.java
index b34c4ce..24901c3 100644
--- a/server/service/src/main/java/com/doumee/dao/business/join/TaxDetailJoinMapper.java
+++ b/server/service/src/main/java/com/doumee/dao/business/join/TaxDetailJoinMapper.java
@@ -1,5 +1,6 @@
 package com.doumee.dao.business.join;
 
+import com.doumee.dao.business.model.CompanySolution;
 import com.doumee.dao.business.model.TaxDetial;
 import com.doumee.dao.business.model.Taxes;
 import com.github.yulichang.base.mapper.MPJJoinMapper;
@@ -12,4 +13,5 @@
  */
 public interface TaxDetailJoinMapper extends MPJJoinMapper<TaxDetial> {
 
+    void insertBatchSomeColumn(List<TaxDetial> taxDetialList);
 }
diff --git a/server/service/src/main/java/com/doumee/dao/business/join/TaxesJoinMapper.java b/server/service/src/main/java/com/doumee/dao/business/join/TaxesJoinMapper.java
index c5a3c0f..e29bb4f 100644
--- a/server/service/src/main/java/com/doumee/dao/business/join/TaxesJoinMapper.java
+++ b/server/service/src/main/java/com/doumee/dao/business/join/TaxesJoinMapper.java
@@ -11,5 +11,4 @@
  * @date 2024/01/16 10:03
  */
 public interface TaxesJoinMapper extends MPJJoinMapper<Taxes> {
-    void insertBatchSomeColumn(List<Taxes> list);
 }
diff --git a/server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java b/server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java
index 3ea5d97..8dc48f3 100644
--- a/server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java
+++ b/server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java
@@ -10,6 +10,7 @@
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -133,6 +134,17 @@
     @TableField(exist = false)
     private Integer insureNum;
 
+    @ApiModelProperty(value = "寮�绁ㄩ噾棰�")
+    @TableField(exist = false)
+    private BigDecimal taxesMoney;
+
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
+    @ApiModelProperty(value = "鏈�鍚庝竴娆″紑绁ㄦ椂闂�")
+    @TableField(exist = false)
+    private Date taxesLast;
+
+
     @ApiModelProperty(value = "鏈嶅姟澶╂暟")
     @TableField(exist = false)
     private Integer serviceDays;
diff --git a/server/service/src/main/java/com/doumee/dao/business/model/Taxes.java b/server/service/src/main/java/com/doumee/dao/business/model/Taxes.java
index e02dcd8..fe5f9fe 100644
--- a/server/service/src/main/java/com/doumee/dao/business/model/Taxes.java
+++ b/server/service/src/main/java/com/doumee/dao/business/model/Taxes.java
@@ -61,7 +61,7 @@
     private String remark;
 
     @ApiModelProperty(value = "鐘舵�� 0寰呭鐞� 1宸插紑绁� 2骞冲彴鎾ゅ洖 3宸插啿绾�", example = "1")
-    @ExcelColumn(name="鐘舵�� 0寰呭鐞� 1宸插紑绁� 2骞冲彴鎾ゅ洖3宸插啿绾�")
+    @ExcelColumn(name="鐘舵�� 0寰呭鐞� 1宸插紑绁� 2骞冲彴鎾ゅ洖 3宸插啿绾�")
     private Integer status;
 
     @ApiModelProperty(value = "浼佷笟缂栫爜锛堝叧鑱攃ompany锛�", example = "1")
@@ -121,7 +121,6 @@
 
     @ApiModelProperty(value = "骞冲彴鎾ゅ洖鏃堕棿")
     @ExcelColumn(name="骞冲彴鎾ゅ洖鏃堕棿")
-
     private Date cancelDate;
 
     @ApiModelProperty(value = "鎾ゅ洖澶囨敞")
@@ -143,6 +142,9 @@
     @ExcelColumn(name="鍐茬孩鎿嶄綔浜哄憳缂栫爜")
     private Integer  delUserId;
 
+    @ApiModelProperty(value = "鍗曟嵁鐢宠缂栫爜锛堝叧鑱攊nsurance_apply锛�", example = "1")
+    @ExcelColumn(name="鍗曟嵁鐢宠缂栫爜锛堝叧鑱攊nsurance_apply锛�")
+    private Integer insuranceApplyId;
 
     @ApiModelProperty(value = "鐢宠浜�")
     @TableField(exist = false)
diff --git a/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java b/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
index 855388f..244bb25 100644
--- a/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
+++ b/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
@@ -113,5 +113,7 @@
 
      InsuranceApply  findDetailForExport(InsuranceApply model);
 
+    List<InsuranceApply> findListByDTO(InsuranceApplyQueryDTO model);
+
     Integer editBaoxiandan(InsuranceApply param);
 }
diff --git a/server/service/src/main/java/com/doumee/service/business/TaxesService.java b/server/service/src/main/java/com/doumee/service/business/TaxesService.java
index d22b8b7..4ecd699 100644
--- a/server/service/src/main/java/com/doumee/service/business/TaxesService.java
+++ b/server/service/src/main/java/com/doumee/service/business/TaxesService.java
@@ -2,6 +2,7 @@
 
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.dao.business.dto.EntrustInvoicingDTO;
 import com.doumee.dao.business.model.Taxes;
 import java.util.List;
 
@@ -87,6 +88,7 @@
      */
     PageData<Taxes> findPage(PageWrap<Taxes> pageWrap);
 
+    PageData<Taxes> findPageForCompany(PageWrap<Taxes> pageWrap);
     /**
      * 鏉′欢缁熻
      *
@@ -96,5 +98,14 @@
     long count(Taxes taxes);
 
     void doneApply(Taxes taxes);
+
     void backApply(Taxes taxes);
+
+
+    /**
+     * 濮旀墭鎶曚繚鎻愪氦
+     * @param entrustInvoicingDTO
+     */
+    void entrustInvoicing(EntrustInvoicingDTO entrustInvoicingDTO);
+
 }
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
index 3e0c4ff..636d0e5 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -551,6 +551,10 @@
         queryWrapper.selectAll(InsuranceApply.class);
         queryWrapper.selectAs(Company::getName,InsuranceApply::getCompanyName);
         queryWrapper.selectAs(Solutions::getName,InsuranceApply::getSolutionsName);
+        queryWrapper.select(" ( select sum(td.fee) from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ) as taxesMoney");
+        queryWrapper.select(" ( select td.CREATE_DATE from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id order by td.CREATE_DATE desc limit 1 ) as taxesLast ");
+        queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId);
+        queryWrapper.leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId);
         queryWrapper.eq(InsuranceApply::getIsdeleted,Constants.ZERO);
         //浼佷笟浜哄憳鏌ョ湅鏈紒涓氭暟鎹�
         if(loginUserInfo.getType().equals(Constants.ONE)){
@@ -577,7 +581,9 @@
         if (pageWrap.getModel().getCreateTimeE() != null) {
             queryWrapper.le(InsuranceApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateTimeE()));
         }
-
+        if (pageWrap.getModel().getType() != null) {
+            queryWrapper.eq(Solutions::getType, pageWrap.getModel().getType());
+        }
         if (pageWrap.getModel().getCode() != null) {
             queryWrapper.eq(InsuranceApply::getCode, pageWrap.getModel().getCode());
         }
@@ -596,6 +602,59 @@
     }
 
 
+    @Override
+    public List<InsuranceApply> findListByDTO(InsuranceApplyQueryDTO model) {
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        MPJLambdaWrapper<InsuranceApply> queryWrapper = new MPJLambdaWrapper<>();
+        queryWrapper.selectAll(InsuranceApply.class);
+        queryWrapper.selectAs(Company::getName,InsuranceApply::getCompanyName);
+        queryWrapper.selectAs(Solutions::getName,InsuranceApply::getSolutionsName);
+        queryWrapper.select(" ( select sum(td.fee) from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ) as taxesMoney ");
+        queryWrapper.select(" ( select td.CREATE_DATE from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id order by td.CREATE_DATE desc limit 1 ) as taxesLast ");
+        queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId);
+        queryWrapper.leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId);
+        queryWrapper.eq(InsuranceApply::getIsdeleted,Constants.ZERO);
+        //浼佷笟浜哄憳鏌ョ湅鏈紒涓氭暟鎹�
+        if(loginUserInfo.getType().equals(Constants.ONE)){
+            queryWrapper.eq(InsuranceApply::getCompanyId, loginUserInfo.getCompanyId());
+        }
+        if (model.getSolutionId() != null) {
+            queryWrapper.eq(InsuranceApply::getSolutionId, model.getSolutionId());
+        }
+        if (model.getEndTimeS() != null) {
+            queryWrapper.ge(InsuranceApply::getEndTime, Utils.Date.getStart(model.getEndTimeS()));
+        }
+        if (model.getEndTimeE() != null) {
+            queryWrapper.le(InsuranceApply::getEndTime, Utils.Date.getEnd(model.getEndTimeE()));
+        }
+        if (model.getStartTimeS() != null) {
+            queryWrapper.ge(InsuranceApply::getStartTime, Utils.Date.getStart(model.getStartTimeS()));
+        }
+        if (model.getStartTimeE() != null) {
+            queryWrapper.le(InsuranceApply::getStartTime, Utils.Date.getEnd(model.getStartTimeE()));
+        }
+        if (model.getCreateTimeS() != null) {
+            queryWrapper.ge(InsuranceApply::getCreateDate, Utils.Date.getStart(model.getCreateTimeS()));
+        }
+        if (model.getCreateTimeE() != null) {
+            queryWrapper.le(InsuranceApply::getCreateDate, Utils.Date.getEnd(model.getCreateTimeE()));
+        }
+        if (model.getType() != null) {
+            queryWrapper.eq(Solutions::getType, model.getType());
+        }
+        if (model.getCode() != null) {
+            queryWrapper.eq(InsuranceApply::getCode, model.getCode());
+        }
+        if (model.getStatus() != null) {
+            queryWrapper.eq(InsuranceApply::getStatus, model.getStatus());
+        }
+        if (CollectionUtils.isNotEmpty(model.getIds())) {
+            queryWrapper.in(InsuranceApply::getId, model.getIds());
+        }
+        List<InsuranceApply> list = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class, queryWrapper);
+        return list;
+    }
+
 
     @Override
     public long count(InsuranceApply insuranceApply) {
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/TaxesServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/TaxesServiceImpl.java
index 62e836d..27ae00a 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/TaxesServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/TaxesServiceImpl.java
@@ -8,8 +8,11 @@
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.CompanyMapper;
 import com.doumee.dao.business.TaxDetialMapper;
 import com.doumee.dao.business.TaxesMapper;
+import com.doumee.dao.business.dto.EntrustInvoicingDTO;
+import com.doumee.dao.business.join.InsuranceApplyJoinMapper;
 import com.doumee.dao.business.join.TaxDetailJoinMapper;
 import com.doumee.dao.business.join.TaxesJoinMapper;
 import com.doumee.dao.business.model.*;
@@ -30,6 +33,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 鍙戠エ淇℃伅琛⊿ervice瀹炵幇
@@ -49,6 +53,10 @@
     private TaxDetailJoinMapper taxDetailJoinMapper;
     @Autowired
     private SystemDictDataBiz systemDictDataBiz;
+    @Autowired
+    private CompanyMapper companyMapper;
+    @Autowired
+    private InsuranceApplyJoinMapper insuranceApplyJoinMapper;
 
     @Override
     public Integer create(Taxes taxes) {
@@ -305,4 +313,111 @@
         QueryWrapper<Taxes> wrapper = new QueryWrapper<>(taxes);
         return taxesMapper.selectCount(wrapper);
     }
+
+
+    @Override
+    public PageData<Taxes> findPageForCompany(PageWrap<Taxes> pageWrap) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        IPage<Taxes> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+        MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>();
+        queryWrapper.selectAll(Taxes.class);
+        queryWrapper.selectAs(SystemUser::getRealname,Taxes::getCreatorName);
+        queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Taxes::getCreator);
+        Utils.MP.blankToNull(pageWrap.getModel());
+        queryWrapper.eq(Taxes::getIsdeleted, Constants.ZERO);
+        Taxes queryModel = pageWrap.getModel();
+        if(!user.getType().equals(Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闈炰紒涓氱敤鎴锋棤娉曡繘琛岃涓氬姟鏌ヨ");
+        }
+        if(!Objects.isNull(queryModel)){
+            queryWrapper.ge(pageWrap.getModel().getStartDate() != null,Taxes::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getStartDate()));
+            queryWrapper.le(SignRecord::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate()));
+            queryWrapper.eq(!Objects.isNull(queryModel.getInsuranceApplyId()),Taxes::getInsuranceApplyId,queryModel.getInsuranceApplyId());
+            queryWrapper.eq(!Objects.isNull(queryModel.getStatus()),Taxes::getStatus,queryModel.getStatus());
+        }
+
+        queryWrapper.orderByAsc(Taxes::getCreateDate);
+        PageData<Taxes>  result =PageData.from(taxesJoinMapper.selectJoinPage(page,Taxes.class, queryWrapper));
+        if(result!=null && result.getRecords()!=null){
+            String path =systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.TAXES_FILE).getCode();
+            for(Taxes t : result.getRecords()){
+                if(StringUtils.isNotBlank(t.getImgurl())){
+                    t.setImgurlFull(path + t.getImgurl());
+                }
+            }
+        }
+        return result;
+    }
+
+
+
+
+
+    @Override
+    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
+    public void entrustInvoicing(EntrustInvoicingDTO entrustInvoicingDTO){
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(Objects.isNull(entrustInvoicingDTO)
+            || Objects.isNull(entrustInvoicingDTO.getInvoicingMoney())
+            || Objects.isNull(entrustInvoicingDTO.getType())
+            || Objects.isNull(entrustInvoicingDTO.getTaxDetialList())
+            || StringUtils.isNotBlank(entrustInvoicingDTO.getAddress())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        if(!user.getType().equals(Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闈炰紒涓氱敤鎴锋棤娉曡繘琛岃涓氬姟鏌ヨ");
+        }
+        Company company = companyMapper.selectById(user.getCompanyId());
+        if(Objects.isNull(company)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浼佷笟淇℃伅");
+        }
+        Taxes taxes = new Taxes();
+        taxes.setCreator(user.getId());
+        taxes.setCreateDate(new Date());
+        taxes.setIsdeleted(Constants.ZERO);
+        taxes.setStatus(Constants.ZERO);
+        taxes.setCompanyId(company.getId());
+        taxes.setPrice(entrustInvoicingDTO.getInvoicingMoney());
+        taxes.setType(entrustInvoicingDTO.getType());
+        taxes.setTaxCode(company.getTaxCode());
+        taxes.setTaxAccount(company.getTaxAccount());
+        taxes.setTaxAddr(company.getTaxAddr());
+        taxes.setAddr(entrustInvoicingDTO.getAddress());
+        taxes.setCompanyName(company.getName());
+        taxes.setApplyType(Constants.ZERO);
+        taxesMapper.insert(taxes);
+
+        List<TaxDetial> taxDetialList = entrustInvoicingDTO.getTaxDetialList();
+        for (TaxDetial taxDetial:taxDetialList) {
+            if(Objects.isNull(taxDetial)
+                    || Objects.isNull(taxDetial.getInsuranceApplyId())
+                    || Objects.isNull(taxDetial.getFee())
+            ){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST);
+            }
+            //鏌ヨ姣忎釜淇濆崟涓嬪彲浠ユ姇淇濈殑閲戦
+            InsuranceApply insuranceApply = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,new MPJLambdaWrapper<InsuranceApply>()
+                    .selectAll(InsuranceApply.class)
+                    .select(" ( select sum(td.fee) from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ) as taxesMoney ")
+                    .eq(InsuranceApply::getId,taxDetial.getInsuranceApplyId())
+            );
+            if(Objects.isNull(insuranceApply)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"淇濆崟鍙枫��"+taxDetial.getApplyCode()+"銆戞湭鏌ヨ鍒颁繚鍗曚俊鎭�");
+            }
+            if(insuranceApply.getCurrentFee().subtract(insuranceApply.getTaxesMoney()).compareTo(taxDetial.getFee())!=Constants.ZERO){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"淇濆崟鍙枫��"+taxDetial.getApplyCode()+"銆戝彲鎶ラ攢閲戦閿欒銆�"+insuranceApply.getCurrentFee().subtract(insuranceApply.getTaxesMoney())+"銆�");
+            }
+            taxDetial.setCreator(user.getId());
+            taxDetial.setCreateDate(new Date());
+            taxDetial.setIsdeleted(Constants.ZERO);
+            taxDetial.setTaxId(taxes.getId());
+            taxDetial.setTotalFee(insuranceApply.getCurrentFee());
+            taxDetial.setType(Constants.ZERO);
+        }
+        taxDetailJoinMapper.insertBatchSomeColumn(taxDetialList);
+    }
+
+
+
 }

--
Gitblit v1.9.3