人员统计,工资统计

This commit is contained in:
方亮 2025-10-10 18:04:48 +08:00
parent e02d9aa490
commit 62878ff94d
11 changed files with 508 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package com.bonus.bmw.controller;
import com.bonus.bmw.domain.vo.ProStatisticsPo;
import com.bonus.bmw.service.SalaryStatisticsService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.InnerAuth;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 工资统计
* @author fly
*/
@RestController
@RequestMapping("/salaryStatistics")
public class SalaryStatisticsController extends BaseController {
/**
* 服务对象
*/
@Autowired
private SalaryStatisticsService service;
/**
* 人员统计
* @param o
* @return
*/
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth(isUser = false), requiresPermissions = @RequiresPermissions("salary:statistics:query"))
@GetMapping("/getSalaryStatisticsTable")
@SysLog(title = "工资统计", businessType = OperaType.QUERY, logType = 0, module = "工资统计->工资统计", details = "工资统计")
public AjaxResult getProStatisticsTable(ProStatisticsPo o) {
try {
Map<String, Object> list = service.getSalaryStatisticsTable(o);
return AjaxResult.success(list);
} catch (Exception e) {
logger.error(e.toString(), e);
}
return AjaxResult.error("查询失败");
}
}

View File

@ -0,0 +1,53 @@
package com.bonus.bmw.controller;
import com.bonus.bmw.domain.po.HomePagePo;
import com.bonus.bmw.domain.vo.HomePageSubProVo;
import com.bonus.bmw.service.WorkerStatisticsService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.InnerAuth;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* 人员统计
* @author fly
*/
@RestController
@RequestMapping("/workerStatistics")
public class WorkerStatisticsController extends BaseController {
/**
* 服务对象
*/
@Autowired
private WorkerStatisticsService service;
/**
* 人员统计
* @param o
* @return
*/
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth(isUser = false), requiresPermissions = @RequiresPermissions("worker:statistics:query"))
@GetMapping("/getWorkerStatisticsTable")
@SysLog(title = "人员统计", businessType = OperaType.QUERY, logType = 0, module = "人员统计->人员统计", details = "人员统计")
public TableDataInfo getWorkerStatisticsTable(HomePagePo o) {
try {
startPage();
List<HomePageSubProVo> list = service.getWorkerStatisticsTable(o);
return getDataTable(list);
} catch (Exception e) {
logger.error(e.toString(), e);
}
return getDataTableError(new ArrayList<>());
}
}

View File

@ -0,0 +1,22 @@
package com.bonus.bmw.domain.vo;
import lombok.Data;
@Data
public class SalaryStatisticsVo {
private Integer proId;
private String proName;
private Integer subCompanyId;
private String subCompanyName;
private Integer companyId;
private String companyName;
private String month;
private String proNum;
private Integer subNum;
private Double netSalary;
private String subName;
private Double allSalary;
private Integer subId;
}

View File

@ -0,0 +1,21 @@
package com.bonus.bmw.mapper;
import com.bonus.bmw.domain.vo.SalaryStatisticsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SalaryStatisticsMapper {
List<SalaryStatisticsVo> getSalaryStatisticsTable(@Param("year") String year, @Param("list") List<String> list);
List<SalaryStatisticsVo> getSalaryStatisticsSubComTable(@Param("year") String year, @Param("list") List<String> list);
List<SalaryStatisticsVo> getSalaryStatisticsComTable(@Param("year") String year, @Param("list") List<String> list);
List<SalaryStatisticsVo> salaryStatisticsSubTable(@Param("year") String year, @Param("list") List<String> list);
}

View File

@ -0,0 +1,16 @@
package com.bonus.bmw.mapper;
import com.bonus.bmw.domain.po.HomePagePo;
import com.bonus.bmw.domain.vo.HomePageSubProVo;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface WorkerStatisticsMapper {
List<HomePageSubProVo> getWorkerStatisticsTable(HomePagePo o);
}

View File

@ -0,0 +1,16 @@
package com.bonus.bmw.service;
import com.bonus.bmw.domain.vo.ProStatisticsPo;
import java.util.Map;
public interface SalaryStatisticsService {
/**
* 获取工程统计
* @param o
* @return
*/
Map<String, Object> getSalaryStatisticsTable(ProStatisticsPo o);
}

View File

@ -0,0 +1,17 @@
package com.bonus.bmw.service;
import com.bonus.bmw.domain.po.HomePagePo;
import com.bonus.bmw.domain.vo.HomePageSubProVo;
import java.util.List;
public interface WorkerStatisticsService {
/**
* 获取工程统计
* @param o
* @return
*/
List<HomePageSubProVo> getWorkerStatisticsTable(HomePagePo o);
}

View File

@ -0,0 +1,127 @@
package com.bonus.bmw.service.impl;
import com.bonus.bmw.domain.vo.ProStatisticsPo;
import com.bonus.bmw.domain.vo.SalaryStatisticsVo;
import com.bonus.bmw.mapper.SalaryStatisticsMapper;
import com.bonus.bmw.service.SalaryStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class SalaryStatisticsServiceImpl implements SalaryStatisticsService {
@Autowired
private SalaryStatisticsMapper mapper;
@Override
public Map<String, Object> getSalaryStatisticsTable(ProStatisticsPo o) {
List<String> listMonth = new ArrayList<>();
if(o.getMonth() != null){
String[] split = o.getMonth().split(",");
listMonth.addAll(Arrays.asList(split));
}
List<SalaryStatisticsVo> salaryStatisticsTable = mapper.getSalaryStatisticsTable(o.getYear(),listMonth);
List<SalaryStatisticsVo> salaryStatisticsTable2 = mapper.getSalaryStatisticsTable(null,null);
// 创建以 proId 为键的映射表用于快速查找
Map<Integer, SalaryStatisticsVo> proTable2Map = new HashMap<>();
if (salaryStatisticsTable2 != null) {
for (SalaryStatisticsVo vo2 : salaryStatisticsTable2) {
if (vo2.getProId() != null) {
proTable2Map.put(vo2.getProId(), vo2);
}
}
}
// salaryStatisticsTable2 中的 netSalary 根据 proId 匹配存入 salaryStatisticsTable allSalary
if (salaryStatisticsTable != null && !proTable2Map.isEmpty()) {
for (SalaryStatisticsVo vo1 : salaryStatisticsTable) {
if (vo1.getProId() != null) {
SalaryStatisticsVo matchedVo = proTable2Map.get(vo1.getProId());
if (matchedVo != null && matchedVo.getNetSalary() != null) {
vo1.setAllSalary(matchedVo.getNetSalary());
}
}
}
}
List<SalaryStatisticsVo> salaryStatisticsSubComTable = mapper.getSalaryStatisticsSubComTable(o.getYear(),listMonth);
List<SalaryStatisticsVo> salaryStatisticsSubComTable2 = mapper.getSalaryStatisticsTable(null,null);
// 创建以 proId 为键的映射表用于快速查找
Map<Integer, SalaryStatisticsVo> subComTable2Map = new HashMap<>();
if (salaryStatisticsSubComTable2 != null) {
for (SalaryStatisticsVo vo2 : salaryStatisticsSubComTable2) {
if (vo2.getSubCompanyId() != null) {
subComTable2Map.put(vo2.getSubCompanyId(), vo2);
}
}
}
// salaryStatisticsSubComTable2 中的 netSalary 根据 proId 匹配存入 salaryStatisticsTable allSalary
if (salaryStatisticsSubComTable != null && !subComTable2Map.isEmpty()) {
for (SalaryStatisticsVo vo1 : salaryStatisticsSubComTable) {
if (vo1.getSubCompanyId() != null) {
SalaryStatisticsVo matchedVo = subComTable2Map.get(vo1.getSubCompanyId());
if (matchedVo != null && matchedVo.getNetSalary() != null) {
vo1.setAllSalary(matchedVo.getNetSalary());
}
}
}
}
List<SalaryStatisticsVo> salaryStatisticsComTable = mapper.getSalaryStatisticsComTable(o.getYear(),listMonth);
List<SalaryStatisticsVo> salaryStatisticsComTable2 = mapper.getSalaryStatisticsTable(null,null);
// 创建以 proId 为键的映射表用于快速查找
Map<Integer, SalaryStatisticsVo> comTable2Map = new HashMap<>();
if (salaryStatisticsComTable2 != null) {
for (SalaryStatisticsVo vo2 : salaryStatisticsComTable2) {
if (vo2.getCompanyId() != null) {
comTable2Map.put(vo2.getCompanyId(), vo2);
}
}
}
// salaryStatisticsSubComTable2 中的 netSalary 根据 proId 匹配存入 salaryStatisticsTable allSalary
if (salaryStatisticsComTable != null && !comTable2Map.isEmpty()) {
for (SalaryStatisticsVo vo1 : salaryStatisticsComTable) {
if (vo1.getCompanyId() != null) {
SalaryStatisticsVo matchedVo = comTable2Map.get(vo1.getCompanyId());
if (matchedVo != null && matchedVo.getNetSalary() != null) {
vo1.setAllSalary(matchedVo.getNetSalary());
}
}
}
}
List<SalaryStatisticsVo> salaryStatisticsSubTable = mapper.salaryStatisticsSubTable(o.getYear(),listMonth);
List<SalaryStatisticsVo> salaryStatisticsSubTable2 = mapper.getSalaryStatisticsTable(null,null);
// 创建以 proId 为键的映射表用于快速查找
Map<Integer, SalaryStatisticsVo> subTable2Map = new HashMap<>();
if (salaryStatisticsSubTable2 != null) {
for (SalaryStatisticsVo vo2 : salaryStatisticsSubTable2) {
if (vo2.getSubId() != null) {
subTable2Map.put(vo2.getSubId(), vo2);
}
}
}
// salaryStatisticsSubTable2 中的 netSalary 根据 proId 匹配存入 salaryStatisticsTable allSalary
if (salaryStatisticsSubTable != null && !subTable2Map.isEmpty()) {
for (SalaryStatisticsVo vo1 : salaryStatisticsSubTable) {
if (vo1.getSubId() != null) {
SalaryStatisticsVo matchedVo = subTable2Map.get(vo1.getSubId());
if (matchedVo != null && matchedVo.getNetSalary() != null) {
vo1.setAllSalary(matchedVo.getNetSalary());
}
}
}
}
Map<String, Object> map = new HashMap<>();
map.put("工程", salaryStatisticsTable);
map.put("分公司", salaryStatisticsSubComTable);
map.put("公司", salaryStatisticsComTable);
map.put("分包", salaryStatisticsSubTable);
return map;
}
}

View File

@ -0,0 +1,24 @@
package com.bonus.bmw.service.impl;
import com.bonus.bmw.domain.po.HomePagePo;
import com.bonus.bmw.domain.vo.HomePageSubProVo;
import com.bonus.bmw.mapper.WorkerStatisticsMapper;
import com.bonus.bmw.service.WorkerStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class WorkerStatisticsServiceImpl implements WorkerStatisticsService {
@Autowired
private WorkerStatisticsMapper mapper;
@Override
public List<HomePageSubProVo> getWorkerStatisticsTable(HomePagePo o) {
return mapper.getWorkerStatisticsTable(o);
}
}

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.bmw.mapper.SalaryStatisticsMapper">
<resultMap id="BaseResultMap" type="com.bonus.bmw.domain.vo.HomePageVo">
<result column="mainProNum" property="mainProNum" />
<result column="proNum" property="proNum" />
<result column="yellowNum" property="yellowNum"/>
<result column="yellowThanSevenDayNum" property="yellowThanSevenDayNum"/>
</resultMap>
<select id="getSalaryStatisticsTable" resultType="com.bonus.bmw.domain.vo.SalaryStatisticsVo">
SELECT
pp.id as proId,
pp.pro_name,
psc.id as subCompanyId,
psc.sub_company_name,
pc.id as companyId,
pc.company_name as companyName,
1 AS proNum,
sum(sub_num) as subNum,
sum(net_salary) as netSalary
FROM
tb_pro_month_table tpmt
LEFT JOIN pm_project pp ON pp.id = tpmt.pro_id
LEFT JOIN pm_sub_company psc ON psc.id = pp.sub_com_id
LEFT JOIN pm_company pc ON pc.id = psc.com_id
WHERE
`status` = 2
<if test="year != null">
AND locate(#{year},table_month)
</if>
<if test="list != null">
AND table_month in
<foreach collection="list" item="it" separator="," open="(" close=")">
#{it}
</foreach>
</if>
group by tpmt.pro_id
</select>
<select id="getSalaryStatisticsSubComTable" resultType="com.bonus.bmw.domain.vo.SalaryStatisticsVo">
SELECT
psc.id as subCompanyId,
psc.sub_company_name,
pc.id as companyId,
pc.company_name as companyName,
1 AS proNum,
sum(sub_num) as subNum,
sum(net_salary) as netSalary
FROM
tb_pro_month_table tpmt
LEFT JOIN pm_project pp ON pp.id = tpmt.pro_id
LEFT JOIN pm_sub_company psc ON psc.id = pp.sub_com_id
LEFT JOIN pm_company pc ON pc.id = psc.com_id
WHERE
`status` = 2
<if test="year != null">
AND locate(#{year},table_month)
</if>
<if test="list != null">
AND table_month in
<foreach collection="list" item="it" separator="," open="(" close=")">
#{it}
</foreach>
</if>
group by psc.id
</select>
<select id="getSalaryStatisticsComTable" resultType="com.bonus.bmw.domain.vo.SalaryStatisticsVo">
SELECT
pc.id as companyId,
pc.company_name as companyName,
1 AS proNum,
sum(sub_num) as subNum,
sum(net_salary) as netSalary
FROM
tb_pro_month_table tpmt
LEFT JOIN pm_project pp ON pp.id = tpmt.pro_id
LEFT JOIN pm_sub_company psc ON psc.id = pp.sub_com_id
LEFT JOIN pm_company pc ON pc.id = psc.com_id
WHERE
`status` = 2
<if test="year != null">
AND locate(#{year},table_month)
</if>
<if test="list != null">
AND table_month in
<foreach collection="list" item="it" separator="," open="(" close=")">
#{it}
</foreach>
</if>
group by pc.id
</select>
<select id="salaryStatisticsSubTable" resultType="com.bonus.bmw.domain.vo.SalaryStatisticsVo">
SELECT
tpmtr.sub_id,
tpmtr.sub_name,
count(DISTINCT tpmtr.pro_id) AS proNum,
SUM(net_salary) AS netSalary
FROM
tb_pro_month_table_roster tpmtr
LEFT JOIN tb_pro_month_table tpmt ON tpmt.id = tpmtr.month_id
WHERE
tpmt.`status` = 2
<if test="year != null">
AND locate(#{year},tpmtr.month)
</if>
<if test="list != null">
AND tpmtr.month in
<foreach collection="list" item="it" separator="," open="(" close=")">
#{it}
</foreach>
</if>
GROUP BY
tpmtr.sub_id
</select>
</mapper>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.bmw.mapper.WorkerStatisticsMapper">
<resultMap id="BaseResultMap" type="com.bonus.bmw.domain.vo.HomePageVo">
<result column="mainProNum" property="mainProNum" />
<result column="proNum" property="proNum" />
<result column="yellowNum" property="yellowNum"/>
<result column="yellowThanSevenDayNum" property="yellowThanSevenDayNum"/>
</resultMap>
<select id="getWorkerStatisticsTable" resultType="com.bonus.bmw.domain.vo.HomePageSubProVo">
SELECT
pw.id AS worker_id,
pw.id_number,
pw.phone,
bwem.post_name,
proNum,
subNum,
teamNum
FROM
pm_worker pw
LEFT JOIN bm_worker_ein_msg bwem ON pw.id = bwem.worker_id
AND bwem.is_active = 1
LEFT JOIN (
SELECT
worker_id,
COUNT(DISTINCT pro_id) AS proNum,
COUNT(DISTINCT sub_id) AS subNum,
COUNT(DISTINCT team_Id) AS teamNum
FROM
bm_worker_ein_pro_record
GROUP BY
worker_id
) bb ON pw.id = bb.worker_id
WHERE
pw.is_active = 1
<if test="proName != null">
AND locate(#{workerName},pw.name)
</if>
</select>
</mapper>