Commit ea4234ab authored by fangxinjiang's avatar fangxinjiang

DTC 平均工资接口

parent 32ffaee2
......@@ -25,7 +25,7 @@ import java.math.BigDecimal;
*/
@Getter
@Setter
@TableName("t_min_salary")
@TableName("t_average_salary")
@Tag(name = "前12月平均工资")
public class TAverageSalary implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -50,7 +50,7 @@ public class TAverageSalary implements Serializable {
@ExcelAttribute(name = "应发薪酬")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty("应发薪酬")
private BigDecimal relaySalary;
private BigDecimal averageSalary;
/**
* 结算月
......
package com.yifu.cloud.plus.v1.yifu.salary.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 前12月平均工资(MVP-TDC接口)
* 保留上月与本月,删除上上月数据,用以比对差异部分,推送到TDC
*
* @author hgw
* @date 2023-6-19 15:54:50
*/
@Data
public class TAverageSalaryVo implements Serializable {
/**
* 身份证号
*/
@ExcelAttribute(name = "身份证号", maxLength = 25)
@Length(max = 25, message = "身份证号不能超过25个字符")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty("身份证号")
private String empIdcard;
/**
* 应发薪酬(劳务费、稿酬)
*/
@ExcelAttribute(name = "应发薪酬")
@HeadFontStyle(fontHeightInPoints = 11)
@ExcelProperty("应发薪酬")
private BigDecimal averageSalary;
}
......@@ -17,15 +17,25 @@
package com.yifu.cloud.plus.v1.yifu.salary.controller;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ResultConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.redis.RedisDistributedLock;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.salary.service.TAverageSalaryService;
import com.yifu.cloud.plus.v1.yifu.salary.vo.TAverageSalaryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 前12月平均工资(MVP-TDC接口)
......@@ -53,5 +63,36 @@ public class TAverageSalaryController {
public void doCreateAverageSalary() {
tAverageSalaryService.createAverageSalary();
}
/**
* @Author fxj
* @Description 获取-前12月平均工资数据
* @Date 10:20 2023/6/20
* @Param
* @return
**/
@Operation(description = "获取-前12月平均工资数据")
@GetMapping("/getAverageSalary")
public R<List<TAverageSalaryVo>> getAverageSalary(String idNum) {
// 获取redis分布式事务锁
String key = CacheConstants.PAYMENT_DISPATCH_BATCH_ADD_IMPORT + CommonConstants.DOWN_LINE_STRING + "getAverageSalary";
String requestId;
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
if (Common.isNotNull(requestId)) {
//主动释放锁
return tAverageSalaryService.getAverageSalary(idNum);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
}
}
}
......@@ -2,7 +2,11 @@ package com.yifu.cloud.plus.v1.yifu.salary.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.yifu.salary.entity.TAverageSalary;
import com.yifu.cloud.plus.v1.yifu.salary.vo.TAverageSalaryVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 前12月平均工资(MVP-TDC接口)
......@@ -29,4 +33,12 @@ public interface TAverageSalaryMapper extends BaseMapper<TAverageSalary> {
**/
int insertAverageSalary();
/**
* @return
* @Author fxj
* @Description 获取-前12月平均工资数据 取值增量
* @Date 10:26 2023/6/20
* @Param
**/
List<TAverageSalaryVo> getAverageSalary(@Param("idNum") String idNum);
}
package com.yifu.cloud.plus.v1.yifu.salary.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.salary.entity.TAverageSalary;
import com.yifu.cloud.plus.v1.yifu.salary.vo.TAverageSalaryVo;
import java.util.List;
/**
* @Author hgw
......@@ -18,4 +22,5 @@ public interface TAverageSalaryService extends IService<TAverageSalary> {
**/
void createAverageSalary();
R<List<TAverageSalaryVo>> getAverageSalary(String idNum);
}
package com.yifu.cloud.plus.v1.yifu.salary.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.salary.entity.TAverageSalary;
import com.yifu.cloud.plus.v1.yifu.salary.mapper.TAverageSalaryMapper;
import com.yifu.cloud.plus.v1.yifu.salary.service.TAverageSalaryService;
import com.yifu.cloud.plus.v1.yifu.salary.vo.TAverageSalaryVo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @Author hgw
* @Description 前12月平均工资(MVP-TDC接口)
......@@ -26,6 +32,18 @@ public class TAverageSalaryServiceImpl extends ServiceImpl<TAverageSalaryMapper,
baseMapper.insertAverageSalary();
}
/**
* @return
* @Author fxj
* @Description 获取-前12月平均工资数据
* @Date 10:25 2023/6/20
* @Param
**/
@Override
public R<List<TAverageSalaryVo>> getAverageSalary(String idNum) {
return R.ok(baseMapper.getAverageSalary(idNum), CommonConstants.RESULT_DATA_SUCESS);
}
}
......
......@@ -7,30 +7,45 @@
<resultMap id="tAverageSalaryMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TAverageSalary">
<id property="id" column="ID"/>
<result property="empIdcard" column="EMP_IDCARD"/>
<result property="relaySalary" column="RELAY_SALARY"/>
<result property="averageSalary" column="AVERAGE_SALARY"/>
<result property="createMonth" column="CREATE_MONTH"/>
</resultMap>
<resultMap id="tAverageSalaryVoMap" type="com.yifu.cloud.plus.v1.yifu.salary.vo.TAverageSalaryVo">
<result property="empIdcard" column="EMP_IDCARD"/>
<result property="averageSalary" column="AVERAGE_SALARY"/>
</resultMap>
<!-- 删除不需要的数据 -->
<delete id="deleteByCreateMonth" >
<delete id="deleteByCreateMonth">
delete
from t_average_salary
where CREATE_MONTH in (
DATE_FORMAT(now(),'%Y%m')
,DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 2 MONTH), '%Y%m')
DATE_FORMAT(now(), '%Y%m'), DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 2 MONTH), '%Y%m')
)
</delete>
<!-- 生成需要的数据 -->
<insert id="insertAverageSalary" >
<insert id="insertAverageSalary">
insert into t_average_salary
select
CONCAT(DATE_FORMAT(now(),'%Y%m-'),a.ID) ID
,a.EMP_IDCARD
,round(sum(a.RELAY_SALARY)/ifnull(count(DISTINCT a.SALARY_MONTH),1),2) AVERAGE_SALARY
,DATE_FORMAT(now(),'%Y%m') CREATE_MONTH
select CONCAT(DATE_FORMAT(now(), '%Y%m-'), a.ID) ID
, a.EMP_IDCARD
, round(sum(a.RELAY_SALARY) / ifnull(count(DISTINCT a.SALARY_MONTH), 1), 2) AVERAGE_SALARY
, DATE_FORMAT(now(), '%Y%m') CREATE_MONTH
from t_salary_account a
where a.SALARY_MONTH >= date_format(DATE_SUB(NOW(),INTERVAL 1 YEAR), '%Y%m' )
where a.SALARY_MONTH >= date_format(DATE_SUB(NOW(), INTERVAL 1 YEAR), '%Y%m')
GROUP BY a.EMP_IDCARD
</insert>
<select id="getAverageSalary" resultMap="tAverageSalaryVoMap">
select x.* from
(select a.EMP_IDCARD,a.AVERAGE_SALARY from view_average_cur_month a) x
LEFT JOIN
(select a.EMP_IDCARD,a.AVERAGE_SALARY from view_average_last_month a) y
on x.EMP_IDCARD=y.EMP_IDCARD
where (x.AVERAGE_SALARY <![CDATA[ <> ]]> IFNULL(y.AVERAGE_SALARY,-1))
<if test="idNum != null and idNum != ''">
and x.EMP_IDCARD = #{idNum}
</if>
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment