ezhizao_zx hai 1 ano
pai
achega
ea2ee52ddf

+ 104 - 71
src/main/java/cn/ezhizao/project/business/deduct/controller/BizDeductController.java

@@ -8,6 +8,7 @@ import java.util.stream.Collectors;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.ezhizao.common.utils.DateUtils;
 import cn.ezhizao.project.business.company.domain.BizCompany;
 import cn.ezhizao.project.business.company.service.IBizCompanyService;
 import cn.ezhizao.project.business.deposit.domain.BizDeposit;
@@ -36,6 +37,7 @@ import cn.ezhizao.project.business.workOrder.service.IBizWorkOrderRecordService;
 import cn.ezhizao.project.business.workOrder.service.IBizWorkOrderService;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
@@ -64,8 +66,7 @@ import cn.ezhizao.framework.web.page.TableDataInfo;
  */
 @RestController
 @RequestMapping("/business/deduct")
-public class BizDeductController extends BaseController
-{
+public class BizDeductController extends BaseController {
     @Resource
     private IBizDeductService bizDeductService;
     @Resource
@@ -100,18 +101,17 @@ public class BizDeductController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:deduct:list')")
     @GetMapping("/list")
-    public TableDataInfo list(BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public TableDataInfo list(BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(bizDeduct);
         startPage();
         startOrderBy();
         List<BizDeduct> list = bizDeductService.getList(bizDeduct);
         return getDataTable(list);
     }
+
     @PreAuthorize("@ss.hasPermi('business:deduct:list')")
     @GetMapping("/getEntrustOrder/{id}")
-    public AjaxResult getEntrustOrder(@PathVariable("id") Long id) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult getEntrustOrder(@PathVariable("id") Long id) throws NoSuchFieldException, IllegalAccessException {
         BizEntrustOrder bizEntrustOrder = bizEntrustOrderService.getById(id);
         return success(bizEntrustOrder);
     }
@@ -122,8 +122,7 @@ public class BizDeductController extends BaseController
     @PreAuthorize("@ss.hasPermi('business:deduct:export')")
     @Log(title = "扣款记录", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public void export(HttpServletResponse response, BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(bizDeduct);
         List<BizDeduct> list = bizDeductService.getList(bizDeduct);
         ExcelUtil<BizDeduct> util = new ExcelUtil<BizDeduct>(BizDeduct.class);
@@ -135,8 +134,7 @@ public class BizDeductController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:deduct:info')")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
         BizDeduct conditions = new BizDeduct();
         conditions.setId(id);
         BizDeduct deduct = bizDeductService.getList(conditions).stream().findFirst().orElse(null);
@@ -160,20 +158,19 @@ public class BizDeductController extends BaseController
     }
 
 
-
-
     /**
      * 获取扣款记录详细信息
      */
     @PreAuthorize("@ss.hasPermi('business:deduct:add')")
     @GetMapping(value = "/gen")
-    public AjaxResult genInfo(BizDeduct conditions)
-    {
+    public AjaxResult genInfo(BizDeduct conditions) {
         // 获取主表
         BizDeduct bizDeduct = new BizDeduct();
         bizDeduct.setEntrustOrderId(conditions.getEntrustOrderId());
-        bizDeduct.setMonth(DateTime.of(conditions.getCurrentDate()).toString("MM"));
-        bizDeduct.setYear(DateTime.of(conditions.getCurrentDate()).toString("yyyy"));
+        bizDeduct.setMonth(DateTime.of(conditions.getStartMonth()).toString("MM"));
+        bizDeduct.setYear(DateTime.of(conditions.getStartMonth()).toString("yyyy"));
+        bizDeduct.setStartMonth(conditions.getStartMonth());
+        bizDeduct.setEndMonth(conditions.getEndMonth());
         bizDeduct.setStatementDate(DateTime.now().toJdkDate());
 
         BizEntrustOrder entrustCondition = new BizEntrustOrder();
@@ -188,6 +185,8 @@ public class BizDeductController extends BaseController
         bizDeduct.setFromTenantId(bizEntrustOrder.getFromTenantId());
         bizDeduct.setContactCompany(bizEntrustOrder.getContactCompany());
         bizDeduct.setSigningSubject(bizEntrustOrder.getSigningSubject());
+        bizDeduct.setStartMonth(conditions.getStartMonth());
+        bizDeduct.setEndMonth(conditions.getEndMonth());
         // 上期余额
         BizDeposit totalCondition = new BizDeposit();
         totalCondition.setEntrustOrderId(bizEntrustOrder.getId());
@@ -201,21 +200,29 @@ public class BizDeductController extends BaseController
         BizEntrust entrustLoopCondition = new BizEntrust();
         entrustLoopCondition.setToTenantId(bizEntrustOrder.getTenantId());
         entrustLoopCondition.setFromTenantId(bizEntrustOrder.getFromTenantId());
-        entrustLoopCondition.setWorkMonth(DateTime.of(conditions.getCurrentDate()).toSqlDate());
+//        entrustLoopCondition.setWorkMonth(DateTime.of(conditions.getCurrentDate()).toSqlDate());
+        entrustLoopCondition.setWorkMonthFrom(DateTime.of(conditions.getStartMonth()).toSqlDate());
+        entrustLoopCondition.setWorkMonthTo(DateTime.of(conditions.getEndMonth()).toSqlDate());
         entrustLoopCondition.setType(1);
         List<BizEntrust> loopEntrust = entrustService.getList(entrustLoopCondition);
         List<BizStatementAccountLoop> loops = new ArrayList<>();
         BizFinancialKeepAccountDetail keepAccountCondition = new BizFinancialKeepAccountDetail();
-        keepAccountCondition.setYear(DateTime.of(bizDeduct.getCurrentDate()).offset(DateField.MONTH, -1).toString("yyyy"));
-        keepAccountCondition.setMonth(DateTime.of(bizDeduct.getCurrentDate()).offset(DateField.MONTH, -1).toString("MM"));
+//        keepAccountCondition.setYear(DateTime.of(bizDeduct.getCurrentDate()).offset(DateField.MONTH, -1).toString("yyyy"));
+//        keepAccountCondition.setMonth(DateTime.of(bizDeduct.getCurrentDate()).offset(DateField.MONTH, -1).toString("MM"));
+        keepAccountCondition.setStartMonth(DateTime.of(conditions.getStartMonth()).toSqlDate());
+        keepAccountCondition.setEndMonth(DateTime.of(conditions.getEndMonth()).toSqlDate());
         List<BizFinancialKeepAccountDetail> keepAccountDetails = keepAccountDetailService.getList(keepAccountCondition);
         BizHousingFundConfirmDetail housingFundCondition = new BizHousingFundConfirmDetail();
-        housingFundCondition.setYear(DateTime.of(bizDeduct.getCurrentDate()).toString("yyyy"));
-        housingFundCondition.setMonth(DateTime.of(bizDeduct.getCurrentDate()).toString("MM"));
+//        housingFundCondition.setYear(DateTime.of(bizDeduct.getCurrentDate()).toString("yyyy"));
+//        housingFundCondition.setMonth(DateTime.of(bizDeduct.getCurrentDate()).toString("MM"));
+        housingFundCondition.setStartMonth(DateTime.of(conditions.getStartMonth()).toSqlDate());
+        housingFundCondition.setEndMonth(DateTime.of(conditions.getEndMonth()).toSqlDate());
         List<BizHousingFundConfirmDetail> housingFundConfirmDetails = bizHousingFundConfirmDetailService.getListByBean(housingFundCondition);
         BizSocialSecurityConfirmDetail socialSecurityConditions = new BizSocialSecurityConfirmDetail();
-        housingFundCondition.setYear(DateTime.of(bizDeduct.getCurrentDate()).toString("yyyy"));
-        housingFundCondition.setMonth(DateTime.of(bizDeduct.getCurrentDate()).toString("MM"));
+//        socialSecurityConditions.setYear(DateTime.of(bizDeduct.getCurrentDate()).toString("yyyy"));
+//        socialSecurityConditions.setMonth(DateTime.of(bizDeduct.getCurrentDate()).toString("MM"));
+        socialSecurityConditions.setStartMonth(DateTime.of(conditions.getStartMonth()).toSqlDate());
+        socialSecurityConditions.setEndMonth(DateTime.of(conditions.getEndMonth()).toSqlDate());
         List<BizSocialSecurityConfirmDetail> socialSecurityConfirmDetails = bizSocialSecurityConfirmDetailService.getListByBean(socialSecurityConditions);
         BizCompany companyCondition = new BizCompany();
         companyCondition.setIds(loopEntrust.stream().map(BizEntrust::getCompanyId).collect(Collectors.toList()));
@@ -225,32 +232,64 @@ public class BizDeductController extends BaseController
         } else {
             companies = new ArrayList<>();
         }
-        companies.forEach(l ->{
-            BizStatementAccountLoop item = new BizStatementAccountLoop();
-            item.setEntrustOrderId(bizDeduct.getEntrustOrderId());
-            item.setSocialCreditCode(l.getSocialCreditCode());
-            item.setCompanyId(l.getId());
-            item.setCompanyName(l.getName());
-            item.setProvince(l.getProvince());
-            item.setCity(l.getCity());
-            item.setDistrict(l.getDistrict());
-            BizFinancialKeepAccountDetail keepAccountDetail = keepAccountDetails.stream().filter(v -> v.getCompanyId().equals(l.getId())).findFirst().orElse(null);
-            item.setCumulativeIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null);
-            item.setQuotaAmount(l.getQuotaAmount());
-            item.setCollectionMethod(l.getCollectionMethod());
-            item.setTaxType(l.getTaxType());
-            item.setIsTax(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(1L)) ? 1 : 0);
-            item.setIsHousingFund(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(3L)) ? 1 : 0);
-            item.setIsSocialSecurity(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(2L)) ? 1 : 0);
-            item.setActuallyAnnualIncome(getAnnualIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null));
-            BizSocialSecurityConfirmDetail socialSecurityConfirmDetail = socialSecurityConfirmDetails.stream().filter(v -> v.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
-            item.setChangedSocialSecurity(socialSecurityConfirmDetail == null ? 0 : socialSecurityConfirmDetail.getIsChanged());
-
-            BizHousingFundConfirmDetail housingFundConfirmDetail = housingFundConfirmDetails.stream().filter(v -> v.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
-            item.setChangedHousingFund(housingFundConfirmDetail == null ? 0 : housingFundConfirmDetail.getIsChanged());
-            item.setAnnualIncome(l.getAnnualIncome());
-            loops.add(item);
+        List<String> months = loopEntrust.stream().map(v -> DateTime.of(v.getWorkMonth()).toString("yyyy-MM-dd")).distinct().sorted().collect(Collectors.toList());
+        List<BizCompany> finalCompanies = companies;
+        months.forEach(l -> {
+            List<BizEntrust> monthEntrust = loopEntrust.stream().filter(v -> DateTime.of(v.getWorkMonth()).toString("yyyy-MM-dd").equals(l)).collect(Collectors.toList());
+            finalCompanies.stream().filter(v -> monthEntrust.stream().anyMatch(e -> e.getCompanyId().equals(v.getId()))).forEach(v -> {
+                BizStatementAccountLoop item = new BizStatementAccountLoop();
+                item.setEntrustOrderId(bizDeduct.getEntrustOrderId());
+                item.setSocialCreditCode(v.getSocialCreditCode());
+                item.setCompanyId(v.getId());
+                item.setCompanyName(v.getName());
+                item.setProvince(v.getProvince());
+                item.setCity(v.getCity());
+                item.setDistrict(v.getDistrict());
+                item.setWorkMonth(DateTime.of(l, "yyyy-MM-dd").toSqlDate());
+                BizFinancialKeepAccountDetail keepAccountDetail = keepAccountDetails.stream().filter(e -> e.getCompanyId().equals(v.getId())).findFirst().orElse(null);
+                item.setCumulativeIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null);
+                item.setQuotaAmount(v.getQuotaAmount());
+                item.setCollectionMethod(v.getCollectionMethod());
+                item.setTaxType(v.getTaxType());
+                item.setIsTax(monthEntrust.stream().anyMatch(e -> e.getCompanyId().equals(v.getId()) && e.getTaskTypeId().equals(1L)) ? 1 : 0);
+                item.setIsHousingFund(monthEntrust.stream().anyMatch(e -> e.getCompanyId().equals(v.getId()) && e.getTaskTypeId().equals(3L)) ? 1 : 0);
+                item.setIsSocialSecurity(monthEntrust.stream().anyMatch(e -> e.getCompanyId().equals(v.getId()) && e.getTaskTypeId().equals(2L)) ? 1 : 0);
+                item.setActuallyAnnualIncome(getAnnualIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null));
+                BizSocialSecurityConfirmDetail socialSecurityConfirmDetail = socialSecurityConfirmDetails.stream().filter(e -> e.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
+                item.setChangedSocialSecurity(socialSecurityConfirmDetail == null ? 0 : socialSecurityConfirmDetail.getIsChanged());
+
+                BizHousingFundConfirmDetail housingFundConfirmDetail = housingFundConfirmDetails.stream().filter(e -> e.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
+                item.setChangedHousingFund(housingFundConfirmDetail == null ? 0 : housingFundConfirmDetail.getIsChanged());
+                item.setAnnualIncome(v.getAnnualIncome());
+                loops.add(item);
+            });
         });
+//        companies.forEach(l -> {
+//            BizStatementAccountLoop item = new BizStatementAccountLoop();
+//            item.setEntrustOrderId(bizDeduct.getEntrustOrderId());
+//            item.setSocialCreditCode(l.getSocialCreditCode());
+//            item.setCompanyId(l.getId());
+//            item.setCompanyName(l.getName());
+//            item.setProvince(l.getProvince());
+//            item.setCity(l.getCity());
+//            item.setDistrict(l.getDistrict());
+//            BizFinancialKeepAccountDetail keepAccountDetail = keepAccountDetails.stream().filter(v -> v.getCompanyId().equals(l.getId())).findFirst().orElse(null);
+//            item.setCumulativeIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null);
+//            item.setQuotaAmount(l.getQuotaAmount());
+//            item.setCollectionMethod(l.getCollectionMethod());
+//            item.setTaxType(l.getTaxType());
+//            item.setIsTax(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(1L)) ? 1 : 0);
+//            item.setIsHousingFund(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(3L)) ? 1 : 0);
+//            item.setIsSocialSecurity(loopEntrust.stream().anyMatch(v -> v.getCompanyId().equals(l.getId()) && v.getTaskTypeId().equals(2L)) ? 1 : 0);
+//            item.setActuallyAnnualIncome(getAnnualIncome(keepAccountDetail != null ? keepAccountDetail.getCurrentYearIncome() : null));
+//            BizSocialSecurityConfirmDetail socialSecurityConfirmDetail = socialSecurityConfirmDetails.stream().filter(v -> v.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
+//            item.setChangedSocialSecurity(socialSecurityConfirmDetail == null ? 0 : socialSecurityConfirmDetail.getIsChanged());
+//
+//            BizHousingFundConfirmDetail housingFundConfirmDetail = housingFundConfirmDetails.stream().filter(v -> v.getCompanyId().equals(item.getCompanyId())).findFirst().orElse(null);
+//            item.setChangedHousingFund(housingFundConfirmDetail == null ? 0 : housingFundConfirmDetail.getIsChanged());
+//            item.setAnnualIncome(l.getAnnualIncome());
+//            loops.add(item);
+//        });
 
         // 获取单次从表
         BizEntrust entrustOnceCondition = new BizEntrust();
@@ -273,7 +312,7 @@ public class BizDeductController extends BaseController
         recordCondition.setWorkOrderIds(workOrders.stream().map(BizWorkOrder::getId).collect(Collectors.toList()));
         List<BizWorkOrderRecord> records = workOrderRecordService.getList(recordCondition);
         onceEntrust.forEach(l -> {
-            BizWorkOrderRecord record = records.stream().filter(v -> v.getWorkOrderId().equals(l.getWorkOrderId()) && v.getFromId().equals(0L) && v.getStatus().equals(3) && (DateTime.of(v.getCreateTime()).toString("yyyy-MM-01").equals(DateTime.of(conditions.getCurrentDate()).toString("yyyy-MM-01")))).findFirst().orElse(null);
+            BizWorkOrderRecord record = records.stream().filter(v -> v.getWorkOrderId().equals(l.getWorkOrderId()) && v.getFromId().equals(0L) && v.getStatus().equals(3) && v.getCreateTime().compareTo(conditions.getStartMonth()) >= 0 && v.getCreateTime().compareTo(DateUtil.endOfMonth(conditions.getEndMonth())) <= 0).findFirst().orElse(null);
             if (record != null) {
                 BizStatementAccountOnce item = new BizStatementAccountOnce();
                 item.setEntrustOrderId(bizDeduct.getEntrustOrderId());
@@ -299,7 +338,7 @@ public class BizDeductController extends BaseController
         });
 
         // 获取汇总
-        List<BizStatementAccount> accounts ;
+        List<BizStatementAccount> accounts;
         accounts = getStatementAccount(onceList, loops, bizDeduct);
         bizDeduct.setCollect(accounts);
         bizDeduct.setLoopList(loops);
@@ -316,7 +355,7 @@ public class BizDeductController extends BaseController
     private List<BizStatementAccount> getStatementAccount(List<BizStatementAccountOnce> onceList, List<BizStatementAccountLoop> loops, BizDeduct bizDeduct) {
         List<BizStatementAccount> accounts = new ArrayList<>();
         BizEntrustPrice priceCondition = new BizEntrustPrice();
-        priceCondition.setFromTenantId(bizDeduct.getFromTenantId());
+//        priceCondition.setFromTenantId(bizDeduct.getFromTenantId());
         priceCondition.setToTenantId(bizDeduct.getTenantId());
         List<BizEntrustPrice> prices = entrustPriceService.getList(priceCondition);
         List<BizEntrustPrice> oncePrices = entrustPriceService.query().gt("task_type_id", 4).list();
@@ -489,18 +528,19 @@ public class BizDeductController extends BaseController
     private String getAnnualIncome(BigDecimal currentYearIncome) {
         if (currentYearIncome == null || currentYearIncome.compareTo(BigDecimal.ZERO) == 0) {
             return "0";
-        } else if (currentYearIncome.compareTo(BigDecimal.ZERO) > 0 && currentYearIncome.compareTo(BigDecimal.valueOf(2000000)) <= 0 ) {
+        } else if (currentYearIncome.compareTo(BigDecimal.ZERO) > 0 && currentYearIncome.compareTo(BigDecimal.valueOf(2000000)) <= 0) {
             return "0~200万元";
         } else if (currentYearIncome.compareTo(BigDecimal.valueOf(2000000)) > 0 && currentYearIncome.compareTo(BigDecimal.valueOf(5000000)) <= 0) {
             return "200~500万元";
         } else if (currentYearIncome.compareTo(BigDecimal.valueOf(5000000)) > 0 && currentYearIncome.compareTo(BigDecimal.valueOf(10000000)) <= 0) {
             return "500~1000万元";
-        } else if (currentYearIncome.compareTo(BigDecimal.valueOf(10000000)) > 0 ) {
+        } else if (currentYearIncome.compareTo(BigDecimal.valueOf(10000000)) > 0) {
             return "1000万元以上";
         } else {
             return "";
         }
     }
+
     /**
      * 新增扣款记录
      */
@@ -508,8 +548,7 @@ public class BizDeductController extends BaseController
     @Log(title = "扣款记录", businessType = BusinessType.INSERT)
     @Transactional(rollbackFor = Exception.class)
     @PostMapping
-    public AjaxResult add(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult add(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         boolean status = bizDeductService.save(bizDeduct);
         bizDeduct.getCollect().forEach(l -> {
             l.setDeductId(bizDeduct.getId());
@@ -539,8 +578,7 @@ public class BizDeductController extends BaseController
     @Log(title = "扣款记录", businessType = BusinessType.UPDATE)
     @Transactional(rollbackFor = Exception.class)
     @PutMapping
-    public AjaxResult edit(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult edit(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         boolean status = bizDeductService.updateById(bizDeduct);
         bizDeduct.getCollect().forEach(l -> {
             l.setDeductId(bizDeduct.getId());
@@ -577,9 +615,8 @@ public class BizDeductController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:deduct:remove')")
     @Log(title = "扣款记录", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable List<Long> ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable List<Long> ids) {
         QueryWrapper<BizStatementAccount> removeQuery = new QueryWrapper<>();
         removeQuery.in("deduct_id", ids);
         QueryWrapper<BizStatementAccountLoop> removeLoopQuery = new QueryWrapper<>();
@@ -599,8 +636,7 @@ public class BizDeductController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:deduct:query')")
     @GetMapping(value = "/checkStatementAccount/{entrustOrderId}")
-    public AjaxResult checkStatementAccount(@PathVariable Long entrustOrderId)
-    {
+    public AjaxResult checkStatementAccount(@PathVariable Long entrustOrderId) {
         // 判断最后一个对账单是哪个月的
         BizDeduct deduct = bizDeductService.query().eq("entrust_order_id", entrustOrderId).orderByDesc("year", "month").last("limit 1").one();
         DateTime prev = DateTime.now().offsetNew(DateField.MONTH, -1);
@@ -616,7 +652,7 @@ public class BizDeductController extends BaseController
             return error("本月已对账,无法对下月进行对账。");
         } else {
             // 其他 对最后一个对账单的下个月进行对账
-            DateTime then = DateTime.of(deduct.getYear() + "-" + deduct.getMonth() + "-01","yyyy-MM-dd").offsetNew(DateField.MONTH, 1);
+            DateTime then = DateTime.of(deduct.getYear() + "-" + deduct.getMonth() + "-01", "yyyy-MM-dd").offsetNew(DateField.MONTH, 1);
             return success(then.toString("yyyy-MM-01"));
         }
     }
@@ -628,8 +664,7 @@ public class BizDeductController extends BaseController
     @Log(title = "扣款记录", businessType = BusinessType.INSERT)
     @Transactional(rollbackFor = Exception.class)
     @PostMapping("/confirm")
-    public AjaxResult confirmDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult confirmDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         bizDeduct.setStatus(1);
         boolean status = bizDeductService.updateById(bizDeduct);
         // 扣款
@@ -637,7 +672,7 @@ public class BizDeductController extends BaseController
         BigDecimal amount = bizDeduct.getAmount();
         int index = 0;
         while (amount.compareTo(BigDecimal.ZERO) > 0) {
-            if (deposits.get(index).getRemainAmount().compareTo(amount) > 0){
+            if (deposits.get(index).getRemainAmount().compareTo(amount) > 0) {
                 BigDecimal remain = deposits.get(index).getRemainAmount().subtract(amount).setScale(2, RoundingMode.HALF_UP);
                 amount = BigDecimal.ZERO;
                 deposits.get(index).setRemainAmount(remain);
@@ -651,12 +686,11 @@ public class BizDeductController extends BaseController
         return toAjax(status);
     }
 
-    @PreAuthorize("@ss.hasPermi('business:deduct:reject')")
+    @PreAuthorize("@ss.hasAnyPermi('business:deduct:reject,business:deduct:confirm')")
     @Log(title = "扣款记录", businessType = BusinessType.INSERT)
     @Transactional(rollbackFor = Exception.class)
     @PostMapping("/reject")
-    public AjaxResult rejectDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult rejectDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         bizDeduct.setStatus(4);
         boolean status = bizDeductService.updateById(bizDeduct);
         return toAjax(status);
@@ -666,8 +700,7 @@ public class BizDeductController extends BaseController
     @Log(title = "扣款记录", businessType = BusinessType.INSERT)
     @Transactional(rollbackFor = Exception.class)
     @PostMapping("/verify")
-    public AjaxResult verifyDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult verifyDeduct(@RequestBody BizDeduct bizDeduct) throws NoSuchFieldException, IllegalAccessException {
         bizDeduct.setStatus(2);
         // 到存款记录中扣款
         boolean status = bizDeductService.updateById(bizDeduct);

+ 4 - 0
src/main/java/cn/ezhizao/project/business/deduct/domain/BizDeduct.java

@@ -93,6 +93,10 @@ public class BizDeduct extends BaseEntity
     @TableField(exist = false)
     @JsonFormat(pattern = "yyyy-MM-dd")
     private Date currentDate;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date startMonth;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date endMonth;
 
     @TableField(exist = false)
     private List<BizStatementAccountOnce> onceList;

+ 5 - 0
src/main/java/cn/ezhizao/project/business/entrust/domain/BizEntrust.java

@@ -78,4 +78,9 @@ public class BizEntrust extends BaseEntity
     @TableField(exist = false)
     private String taskTypeDetailName;
 
+    @TableField(exist = false)
+    private Date workMonthFrom;
+    @TableField(exist = false)
+    private Date workMonthTo;
+
 }

+ 55 - 18
src/main/java/cn/ezhizao/project/business/entrustOrder/controller/BizEntrustOrderController.java

@@ -1,13 +1,19 @@
 package cn.ezhizao.project.business.entrustOrder.controller;
 
 import java.util.List;
+import java.util.stream.Collectors;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 
 import cn.ezhizao.common.utils.SecurityUtils;
 import cn.ezhizao.common.utils.StringUtils;
+import cn.ezhizao.project.business.deduct.domain.BizDeduct;
+import cn.ezhizao.project.business.deduct.service.IBizDeductService;
+import cn.ezhizao.project.business.entrust.domain.BizEntrust;
+import cn.ezhizao.project.business.entrust.service.IBizEntrustService;
 import cn.ezhizao.project.tenant.domain.Tenant;
 import cn.ezhizao.project.tenant.service.ITenantService;
+import cn.hutool.core.date.DateTime;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -34,20 +40,22 @@ import cn.ezhizao.framework.web.page.TableDataInfo;
  */
 @RestController
 @RequestMapping("/business/entrustOrder")
-public class BizEntrustOrderController extends BaseController
-{
+public class BizEntrustOrderController extends BaseController {
     @Resource
     private IBizEntrustOrderService bizEntrustOrderService;
     @Resource
+    private IBizEntrustService entrustService;
+    @Resource
     private ITenantService tenantService;
+    @Resource
+    private IBizDeductService bizDeductService;
 
     /**
      * 查询委托签约合同列表
      */
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:list')")
     @GetMapping("/list")
-    public TableDataInfo list(BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException
-    {
+    public TableDataInfo list(BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(bizEntrustOrder);
         startPage();
         startOrderBy();
@@ -70,14 +78,14 @@ public class BizEntrustOrderController extends BaseController
         bizEntrustOrder.setStatus(2);
         return toAjax(bizEntrustOrderService.updateById(bizEntrustOrder));
     }
+
     /**
      * 导出委托签约合同列表
      */
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:export')")
     @Log(title = "委托签约合同", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException
-    {
+    public void export(HttpServletResponse response, BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(bizEntrustOrder);
         List<BizEntrustOrder> list = bizEntrustOrderService.getList(bizEntrustOrder);
         ExcelUtil<BizEntrustOrder> util = new ExcelUtil<BizEntrustOrder>(BizEntrustOrder.class);
@@ -89,8 +97,7 @@ public class BizEntrustOrderController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:query')")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
         BizEntrustOrder condition = new BizEntrustOrder();
         condition.setId(id);
         BizEntrustOrder item = bizEntrustOrderService.getList(condition).stream().findFirst().orElse(null);
@@ -103,8 +110,25 @@ public class BizEntrustOrderController extends BaseController
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:add')")
     @Log(title = "委托签约合同", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult add(@RequestBody BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException {
+        /* 校验是否存在同家公司未完结的合同*/
+        //空对象
+        BizEntrustOrder order = new BizEntrustOrder();
+        //往来单位赋值
+        order.setFromTenantId(bizEntrustOrder.getFromTenantId());
+        //查询是否存在相同的往来单位
+        List<BizEntrustOrder> list = bizEntrustOrderService.getList(order);
+        //存在相同的往来单位
+        if (list.size() > 0) {
+            for (BizEntrustOrder item : list) {
+                //判断合同是否完结
+                if (item.getStatus() != 2) {
+
+                    return AjaxResult.error("不能新建同家公司新合同");
+                }
+            }
+        }
+
         return toAjax(bizEntrustOrderService.save(bizEntrustOrder));
     }
 
@@ -114,8 +138,7 @@ public class BizEntrustOrderController extends BaseController
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:edit')")
     @Log(title = "委托签约合同", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException
-    {
+    public AjaxResult edit(@RequestBody BizEntrustOrder bizEntrustOrder) throws NoSuchFieldException, IllegalAccessException {
         return toAjax(bizEntrustOrderService.updateById(bizEntrustOrder));
     }
 
@@ -124,22 +147,36 @@ public class BizEntrustOrderController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('business:entrustOrder:remove')")
     @Log(title = "委托签约合同", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable List<Long> ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable List<Long> ids) {
         return toAjax(bizEntrustOrderService.removeBatchByIds(ids));
     }
 
     @PreAuthorize("@ss.hasAnyPermi('business:entrustOrder:add,business:entrustOrder:edit')")
     @GetMapping("/listTenant")
-    public TableDataInfo listTenant(Tenant tenant)
-    {
+    public TableDataInfo listTenant(Tenant tenant) {
         startPage();
-        if(StringUtils.isNotBlank(tenant.getOperateType())){
+        if (StringUtils.isNotBlank(tenant.getOperateType())) {
             tenant.setUserId(SecurityUtils.getUserId());
         }
         List<Tenant> list = tenantService.getList(tenant);
         return getDataTable(list);
     }
 
+    @PreAuthorize("@ss.hasAnyPermi('business:entrustOrder:add')")
+    @GetMapping("/getMonths/{entrustOrderId}")
+    public AjaxResult getMonths(@PathVariable Long entrustOrderId) {
+        // 根据Tenant获取没有对账的委托月
+        // BizDeduct deduct = bizDeductService.query().eq("entrust_order_id", entrustOrderId).orderByDesc("year", "month").last("limit 1").one();
+        BizEntrustOrder entrustOrder = bizEntrustOrderService.getById(entrustOrderId);
+        // 所有委托月
+        List<BizEntrust> entrust = entrustService.query().eq("from_tenant_id", entrustOrder.getFromTenantId()).eq("to_tenant_id", entrustOrder.getTenantId()).list();
+        List<BizDeduct> deducts = bizDeductService.query().eq("from_tenant_id", entrustOrder.getFromTenantId()).eq("tenant_id", entrustOrder.getTenantId()).list();
+        entrust = entrust.stream().filter(v -> v.getWorkMonth() != null &&
+                deducts.stream().noneMatch(e -> v.getWorkMonth().compareTo(e.getStartMonth()) >= 0 && v.getWorkMonth().compareTo(e.getEndMonth()) <= 0)
+        ).collect(Collectors.toList());
+        List<String> months = entrust.stream().map(v -> DateTime.of(v.getWorkMonth()).toString("yyyy-MM-dd")).distinct().sorted().collect(Collectors.toList());
+        return success(months);
+    }
+
 }

+ 6 - 0
src/main/java/cn/ezhizao/project/business/housingFund/domain/BizHousingFundConfirmDetail.java

@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -68,4 +69,9 @@ public class BizHousingFundConfirmDetail extends BaseEntity implements Serializa
 
     @ApiModelProperty("是否变更")
     private Integer isChanged;
+
+    @TableField(exist = false)
+    private Date startMonth;
+    @TableField(exist = false)
+    private Date endMonth;
 }

+ 7 - 0
src/main/java/cn/ezhizao/project/business/keepAccounts/domain/BizFinancialKeepAccountDetail.java

@@ -10,6 +10,7 @@ import lombok.experimental.Accessors;
 
 import java.math.BigDecimal;
 import java.sql.Timestamp;
+import java.util.Date;
 import java.util.List;
 
 @EqualsAndHashCode(callSuper = true)
@@ -55,4 +56,10 @@ public class BizFinancialKeepAccountDetail extends BaseEntity {
 
     @TableField(exist = false)
     private BigDecimal previousAnnualLosses;
+
+    @TableField(exist = false)
+    private Date startMonth;
+    @TableField(exist = false)
+    private Date endMonth;
+
 }

+ 6 - 0
src/main/java/cn/ezhizao/project/business/socialSecurity/domain/BizSocialSecurityConfirmDetail.java

@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -72,4 +73,9 @@ public class BizSocialSecurityConfirmDetail extends BaseEntity implements Serial
 
     @ApiModelProperty("是否变更")
     private Integer isChanged;
+
+    @TableField(exist = false)
+    private Date startMonth;
+    @TableField(exist = false)
+    private Date endMonth;
 }

+ 5 - 0
src/main/java/cn/ezhizao/project/business/statementAccount/domain/BizStatementAccountLoop.java

@@ -1,10 +1,12 @@
 package cn.ezhizao.project.business.statementAccount.domain;
 
 import java.math.BigDecimal;
+import java.sql.Date;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import cn.ezhizao.framework.web.domain.BaseEntity;
+import io.swagger.annotations.Api;
 import lombok.Data;
 import io.swagger.annotations.ApiModelProperty;
 import cn.ezhizao.framework.aspectj.lang.annotation.Excel;
@@ -128,4 +130,7 @@ public class BizStatementAccountLoop extends BaseEntity
 
     @TableField(exist = false)
     private String taskTypeName;
+
+    @ApiModelProperty(value = "工作月")
+    private Date workMonth;
 }

+ 1 - 1
src/main/java/cn/ezhizao/project/business/workOrder/controller/WorkOrderOnceController.java

@@ -72,7 +72,7 @@ public class WorkOrderOnceController extends BaseController {
     /**
      * 查询工单信息列表
      */
-    @PreAuthorize("@ss.hasPermi('business:entrust:workOrder:next:list')")
+    @PreAuthorize("@ss.hasPermi('business:entrust:workOrder:once:list')")
     @GetMapping("/listForFactory")
     public TableDataInfo listForFactory(BizWorkOrder bizWorkOrder) throws NoSuchFieldException, IllegalAccessException
     {

+ 4 - 0
src/main/java/cn/ezhizao/project/business/workOrder/domain/BizWorkOrderDetail.java

@@ -33,6 +33,10 @@ public class BizWorkOrderDetail extends BaseEntity
     @ApiModelProperty("合同明细外键")
     private Long contractDetailId;
 
+    /** 任务外键 */
+    @ApiModelProperty(value = "${comment}")
+    private Long taskTypeId;
+
     /** 购买月数 */
     @Excel(name = "购买月数")
     @ApiModelProperty(value = "购买月数")

+ 1 - 0
src/main/resources/mybatis/business/BizEntrustMapper.xml

@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
             <if test="fromTenantId != null "> AND t1.from_tenant_id = #{fromTenantId}</if>
             <if test="workMonth != null "> AND t1.work_month = #{workMonth}</if>
+            <if test="workMonthFrom != null and workMonthTo != null"> and t1.work_month between #{workMonthFrom} and #{workMonthTo}</if>
             <if test="currentMonth != null "> AND t1.current_month = #{currentMonth}</if>
             <if test="toTenantId != null "> AND t1.to_tenant_id = #{toTenantId}</if>
             <if test="workOrderId != null "> AND t1.work_order_id = #{workOrderId}</if>

+ 6 - 0
src/main/resources/mybatis/business/BizFinancialKeepAccountDetailMapper.xml

@@ -31,6 +31,12 @@
         <if test="year != null and year != ''">
             AND t1.year = #{year}
         </if>
+        <if test="month != null and month != ''">
+            AND t1.month = #{month}
+        </if>
+        <if test="startMonth != null and endMonth != null">
+            AND STR_TO_DATE(concat(t1.year, '-', t1.month, '-01'), '%Y-%m-%d') between #{startMonth} and #{endMonth}
+        </if>
         <if test="mainIds != null and mainIds.size > 0">
             AND t1.financial_keep_account_id in
             <foreach collection="mainIds" index="index" item="item" separator=","  open="(" close=")">

+ 3 - 0
src/main/resources/mybatis/business/BizHousingFundConfirmDetailMapper.xml

@@ -57,6 +57,9 @@
             <if test="verifyContent != null  and verifyContent != '' ">
                 t1.verify_content = #{verifyContent} AND
             </if>
+            <if test="startMonth != null and endMonth != null">
+                STR_TO_DATE(concat(t1.year, '-', t1.month, '-01'), '%Y-%m-%d') between #{startMonth} and #{endMonth} AND
+            </if>
         </trim>
     </sql>
 

+ 3 - 0
src/main/resources/mybatis/business/BizSocialSecurityConfirmDetailMapper.xml

@@ -58,6 +58,9 @@
             <if test="verifyContent != null  and verifyContent != '' ">
                 t1.verify_content = #{verifyContent} AND
             </if>
+            <if test="startMonth != null and endMonth != null">
+                STR_TO_DATE(concat(t1.year, '-', t1.month, '-01'), '%Y-%m-%d') between #{startMonth} and #{endMonth} AND
+            </if>
         </trim>
     </sql>
 

+ 1 - 1
src/main/resources/mybatis/business/BizWorkOrderMapper.xml

@@ -39,7 +39,7 @@
             <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
             <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
             <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
-            <if test="currentMonth != null"> AND #{currentMonth} &gt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.start_month,interval 1 month) else t1.start_month end) and #{currentMonth} &lt;= (case when t1.end_month = 0 then #{currentMonth} when t1.task_type_id = 1 then DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)</if>
+            <if test="currentMonth != null"> AND t1.start_month != 0 AND #{currentMonth} &gt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.start_month,interval 1 month) else t1.start_month end) and #{currentMonth} &lt;= (case when t1.end_month = 0 then #{currentMonth} when t1.task_type_id = 1 then DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)</if>
             <if test="toTenantId != null and currentMonth != null">
                 AND exists (select 1 from biz_entrust t6 where t6.deleted = 0 and t6.to_tenant_id = #{toTenantId} and t6.work_month = #{currentMonth} and t1.id = t6.work_order_id )
             </if>