ly 1 سال پیش
والد
کامیت
9d0ba3e5bb

+ 164 - 3
src/main/java/cn/ezhizao/project/business/socialSecurity/controller/SocialSecurityDeclareController.java

@@ -11,9 +11,15 @@ import cn.ezhizao.project.business.company.domain.BizCompany;
 import cn.ezhizao.project.business.company.service.IBizCompanyService;
 import cn.ezhizao.project.business.deduction.domain.BizDeduction;
 import cn.ezhizao.project.business.deduction.service.IBizDeductionService;
+import cn.ezhizao.project.business.housingFund.domain.BizHousingFundConfirmDetail;
+import cn.ezhizao.project.business.housingFund.domain.BizHousingFundConfirmDetailEmployee;
+import cn.ezhizao.project.business.housingFund.domain.vo.EmployeeExcel;
+import cn.ezhizao.project.business.housingFund.domain.vo.HousingFundEmployeeVo;
 import cn.ezhizao.project.business.reportTaxIsZero.domain.BizFinancialReportTaxDetail;
 import cn.ezhizao.project.business.socialSecurity.domain.*;
 import cn.ezhizao.project.business.socialSecurity.domain.vo.SocialSecurityDetailVo;
+import cn.ezhizao.project.business.socialSecurity.domain.vo.SocialSecurityEmployeeExcel;
+import cn.ezhizao.project.business.socialSecurity.domain.vo.SocialSecurityEmployeeVo;
 import cn.ezhizao.project.business.socialSecurity.service.IBizSocialSecurityConfirmDetailEmployeeService;
 import cn.ezhizao.project.business.socialSecurity.service.IBizSocialSecurityConfirmDetailService;
 import cn.ezhizao.project.business.socialSecurity.service.IBizSocialSecurityDeclareDetailService;
@@ -24,18 +30,29 @@ import cn.ezhizao.project.system.domain.SysFileStorage;
 import cn.ezhizao.project.system.domain.SysUser;
 import cn.ezhizao.project.system.mapper.SysUserMapper;
 import cn.ezhizao.project.system.service.ISysFileStorageService;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.metadata.fill.FillConfig;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.catalina.security.SecurityUtil;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.net.URLEncoder;
 import java.time.LocalDate;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 
@@ -128,6 +145,145 @@ public class SocialSecurityDeclareController extends BaseController {
         return getDataTable(list);
     }
 
+    @PostMapping("/exportDetail")
+    public void exportDetail(HttpServletResponse response, SocialSecurityEmployeeVo vo) throws Exception {
+        OutputStream out = null;
+        BufferedOutputStream bos = null;
+        List<BizSocialSecurityConfirmDetailEmployee> employees = new ArrayList<>();
+        List<SocialSecurityEmployeeExcel> employeeExcels = new ArrayList<>();
+        try {
+            ClassPathResource classPathResource = new ClassPathResource("importTemplate/社保明细模板 .xlsx");
+            InputStream inputStream = classPathResource.getInputStream();
+            response.setContentType("application/vnd.ms-excel");
+            response.setCharacterEncoding("utf-8");
+            String fileName = URLEncoder.encode("社保模板.xls", "utf-8");
+            response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "ISO-8859-1"));
+
+            out = response.getOutputStream();
+            bos = new BufferedOutputStream(out);
+
+            //读取Excel
+            ExcelWriter excelWriter = EasyExcel.write(bos).withTemplate(inputStream).build();
+            WriteSheet writeSheet = EasyExcel.writerSheet().build();
+
+            FillConfig fillConfig = FillConfig.builder()
+                    // 开启填充换行
+                    .forceNewRow(true)
+                    .build();
+            // 直接写入Excel数据
+            List<SocialSecurityEmployeeExcel> list = getList(vo, employees, employeeExcels);
+            HashMap<String, Object> map = new HashMap<>();
+            String titleName = vo.getYear() + "年" + vo.getMonth() + "月" + "社保明细";
+            AtomicReference<BigDecimal>[] totals = new AtomicReference[17];
+            // 初始化数组
+            for (int i = 0; i < totals.length; i++) {
+                totals[i] = new AtomicReference<>(BigDecimal.ZERO);
+            }
+            // 处理列表并更新每个 AtomicReference
+            list.forEach(item -> {
+                totals[0].updateAndGet(v -> v.add(item.getBasePayment()));
+                totals[1].updateAndGet(v -> v.add(item.getMmBasePayment()));
+                totals[2].updateAndGet(v -> v.add(item.getHeatingPayment()));
+                totals[3].updateAndGet(v -> v.add(item.getCompanyBirth()));
+                totals[4].updateAndGet(v -> v.add(item.getCompanyLargeMedical()));
+                totals[5].updateAndGet(v -> v.add(item.getCompanyMedical()));
+                totals[6].updateAndGet(v -> v.add(item.getCompanyElderly()));
+                totals[7].updateAndGet(v -> v.add(item.getCompanyUnemployment()));
+                totals[8].updateAndGet(v -> v.add(item.getCompanyInjury()));
+                totals[9].updateAndGet(v -> v.add(item.getHeatingPayment()));
+                totals[10].updateAndGet(v -> v.add(item.getCompanyCount()));
+                totals[11].updateAndGet(v -> v.add(item.getOneSelfLargeMedical()));
+                totals[12].updateAndGet(v -> v.add(item.getOneSelfElderly()));
+                totals[13].updateAndGet(v -> v.add(item.getOneSelfUnemployment()));
+                totals[14].updateAndGet(v -> v.add(item.getOneSelfEMedical()));
+                totals[15].updateAndGet(v -> v.add(item.getOneSelfCount()));
+                totals[16].updateAndGet(v -> v.add(item.getTotalAmount()));
+            });
+            // 将结果放入 map 中
+            map.put("titleName", titleName);
+            for (int i = 0; i < totals.length; i++) {
+                map.put("total" + (i + 1), totals[i].get());
+            }
+            excelWriter.fill(list, fillConfig, writeSheet);
+            excelWriter.fill(map, fillConfig, writeSheet);
+            excelWriter.finish();
+            bos.flush();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            bos.close();
+        }
+
+    }
+
+    private List<SocialSecurityEmployeeExcel> getList(SocialSecurityEmployeeVo vo, List<BizSocialSecurityConfirmDetailEmployee> employees, List<SocialSecurityEmployeeExcel> employeeExcels) {
+        BizSocialSecurityConfirmDetail detail = socialSecurityConfirmDetailService
+                .query().eq("company_id", vo.getCompanyId())
+                .eq("year", vo.getYear())
+                .eq("month", vo.getMonth())
+                .eq("deleted", 0).one();
+
+        if (detail != null) {
+            employees = socialSecurityConfirmDetailEmployeeService.query()
+                    .eq("social_security_confirm_detail_id", detail.getId())
+                    .eq("deleted", 0)
+                    .ne("change_status", 2)
+                    .list();
+        }
+        //0.05%
+        BigDecimal zeroPointZeroFiveDecimal = new BigDecimal("0.0005");
+        //0.2%
+        BigDecimal ZeroPointTwoDecimal = new BigDecimal("0.002");
+        //0.5%
+        BigDecimal halfOneDecimal = new BigDecimal("0.005");
+        //1%
+        BigDecimal onePercent = new BigDecimal("0.01");
+        //2%
+        BigDecimal twoPercent = new BigDecimal("0.02");
+        //8%
+        BigDecimal eightDecimal = new BigDecimal("0.08");
+        //16%
+        BigDecimal sixteenPercent = new BigDecimal("0.16");
+        if (!CollectionUtils.isEmpty(employees)) {
+            for (int i = 0; i < employees.size(); i++) {
+                BizSocialSecurityConfirmDetailEmployee employee = employees.get(i);
+                SocialSecurityEmployeeExcel item = new SocialSecurityEmployeeExcel();
+                item.setIndex(i + 1);
+                item.setName(employee.getEmployeeName());
+                item.setBasePayment(employee.getCardinalNumber());
+                item.setMmBasePayment(employee.getMedicalCardinalNumber());
+                item.setHeatingPayment(employee.getHeatingFee());
+                item.setCompanyBirth(this.multiplication(employee.getMedicalCardinalNumber(), onePercent));
+                item.setCompanyLargeMedical((this.multiplication(employee.getMedicalCardinalNumber(), ZeroPointTwoDecimal)));
+
+                item.setCompanyMedical(this.multiplication(employee.getMedicalCardinalNumber(), eightDecimal));
+                item.setCompanyElderly(this.multiplication(employee.getCardinalNumber(), sixteenPercent));
+                item.setCompanyUnemployment(this.multiplication(employee.getCardinalNumber(), halfOneDecimal));
+                if (vo.getRadio() != null) {
+                    item.setCompanyInjury(this.multiplication(employee.getCardinalNumber(), vo.getRadio().divide(BigDecimal.valueOf(100))));
+                } else {
+                    item.setCompanyInjury(BigDecimal.ZERO);
+                }
+                item.setCompanyHeat(this.multiplication(employee.getHeatingFee(), onePercent));
+                item.setCompanyCount(
+                        item.getCompanyBirth().add(item.getCompanyLargeMedical()).add(item.getCompanyMedical())
+                                .add(item.getCompanyElderly()).add(item.getCompanyUnemployment()).add(item.getCompanyInjury()).add(item.getCompanyHeat())
+                );
+                item.setOneSelfLargeMedical(this.multiplication(employee.getMedicalCardinalNumber(), zeroPointZeroFiveDecimal));
+                item.setOneSelfElderly(this.multiplication(employee.getCardinalNumber(), eightDecimal));
+                item.setOneSelfUnemployment(this.multiplication(employee.getCardinalNumber(), halfOneDecimal));
+                item.setOneSelfEMedical(this.multiplication(employee.getMedicalCardinalNumber(), twoPercent));
+                item.setOneSelfCount(
+                        item.getOneSelfLargeMedical().add(item.getOneSelfElderly()).add(item.getOneSelfUnemployment()).add(item.getOneSelfEMedical())
+                );
+                item.setTotalAmount(item.getCompanyCount().add(item.getOneSelfCount()));
+                employeeExcels.add(item);
+            }
+        }
+        return employeeExcels;
+    }
+
     /**
      * 导出列表
      */
@@ -239,6 +395,7 @@ public class SocialSecurityDeclareController extends BaseController {
                 List<SysFileStorage> reportFiles = fileStorageService.query().eq("master_table_name", "biz_social_security_declare_detail").eq("master_id", detail.getId()).eq("type", "reportFile").list();
                 reportFiles.forEach(l -> l.setId(null));
                 condition.setReportFiles(reportFiles);
+                condition.setInjuryRadio(detail.getInjuryRadio());
             } else {
                 condition.setEvidenceFiles(new ArrayList<>());
                 condition.setReportFiles(new ArrayList<>());
@@ -402,9 +559,13 @@ public class SocialSecurityDeclareController extends BaseController {
                 vo.setCompanyBirth(this.multiplication(employee.getMedicalCardinalNumber(), onePercent));
                 vo.setCompanyLargeMedical(this.multiplication(employee.getMedicalCardinalNumber(), ZeroPointTwoDecimal));
                 vo.setCompanyMedical(this.multiplication(employee.getMedicalCardinalNumber(), eightDecimal));
-                vo.setCompanyElderly(this.multiplication(employee.getMedicalCardinalNumber(), sixteenPercent));
+                vo.setCompanyElderly(this.multiplication(employee.getCardinalNumber(), sixteenPercent));
                 vo.setCompanyUnemployment(this.multiplication(employee.getCardinalNumber(), halfOneDecimal));
-                vo.setCompanyInjury(this.multiplication(employee.getCardinalNumber(), detail.getInjuryRadio().divide(BigDecimal.valueOf(100))));
+                if (detail.getInjuryRadio() != null) {
+                    vo.setCompanyInjury(this.multiplication(employee.getCardinalNumber(), detail.getInjuryRadio().divide(BigDecimal.valueOf(100))));
+                } else {
+                    vo.setCompanyInjury(BigDecimal.ZERO);
+                }
                 vo.setCompanyHeat(this.multiplication(employee.getHeatingFee(), onePercent));
                 vo.setCompanyCount(
                         vo.getCompanyBirth().add(vo.getCompanyLargeMedical()).add(vo.getCompanyMedical())
@@ -428,7 +589,7 @@ public class SocialSecurityDeclareController extends BaseController {
 
     public BigDecimal multiplication(BigDecimal a, BigDecimal b) {
 
-        return a.multiply(b).setScale(2, BigDecimal.ROUND_DOWN);
+        return a.multiply(b).setScale(2, BigDecimal.ROUND_HALF_UP);
     }
 
 

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

@@ -80,7 +80,6 @@ public class BizSocialSecurityConfirmDetail extends BaseEntity implements Serial
     private Integer isChanged;
     @ApiModelProperty("审核人")
     private Date verifierTime;
-
     @TableField(exist = false)
     private BigDecimal injuryRadio;
 }

+ 3 - 0
src/main/java/cn/ezhizao/project/business/socialSecurity/domain/BizSocialSecurityDeclareDetail.java

@@ -113,4 +113,7 @@ public class BizSocialSecurityDeclareDetail extends BaseEntity implements Serial
     @TableField(exist = false)
     private List<Long> mainIds;
 
+
+    private BigDecimal injuryRadio;
+
 }

+ 40 - 0
src/main/java/cn/ezhizao/project/business/socialSecurity/domain/vo/SocialSecurityEmployeeExcel.java

@@ -0,0 +1,40 @@
+package cn.ezhizao.project.business.socialSecurity.domain.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class SocialSecurityEmployeeExcel {
+    private Integer index;
+    private String name;
+    private BigDecimal basePayment;
+    /**
+     * 医疗基数
+     */
+    private BigDecimal mmBasePayment;
+    /**
+     * 采暖基数
+     */
+    private BigDecimal heatingPayment;
+    /**
+     * 生育保险公司
+     */
+    private BigDecimal companyBirth;
+    private BigDecimal companyLargeMedical;
+    private BigDecimal companyMedical;
+    /**
+     * 养老
+     */
+    private BigDecimal companyElderly;
+    private BigDecimal companyUnemployment;
+    private BigDecimal companyInjury;
+    private BigDecimal companyHeat;
+    private BigDecimal companyCount;
+    private BigDecimal oneSelfLargeMedical;
+    private BigDecimal oneSelfElderly;
+    private BigDecimal oneSelfUnemployment;
+    private BigDecimal oneSelfEMedical;
+    private BigDecimal oneSelfCount;
+    private BigDecimal totalAmount;
+}

+ 18 - 0
src/main/java/cn/ezhizao/project/business/socialSecurity/domain/vo/SocialSecurityEmployeeVo.java

@@ -0,0 +1,18 @@
+package cn.ezhizao.project.business.socialSecurity.domain.vo;
+
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class SocialSecurityEmployeeVo {
+    private String companyId;
+
+    private String year;
+
+    private String month;
+
+    private BigDecimal radio;
+
+}

BIN
src/main/resources/importTemplate/社保明细模板 .xlsx