!3 根据统一社会信用代码 和年份查询收入财务信息 ,取并集, 年份可为空
Merge pull request !3 from haoran1009/auto-9270061-master-fc46b781-1pull/178/head
commit
8ff106281d
|
@ -3,8 +3,10 @@ package org.sk.module.data.controller.finance;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
||||||
import org.sk.module.data.dal.param.finance.FinanceParam;
|
import org.sk.module.data.dal.param.finance.FinanceParam;
|
||||||
|
import org.sk.module.data.dal.param.finance.IncomeAndTaxParam;
|
||||||
import org.sk.module.data.dal.vo.FinanceVO;
|
import org.sk.module.data.dal.vo.FinanceVO;
|
||||||
import org.sk.module.data.service.finance.FinanceService;
|
import org.sk.module.data.service.finance.FinanceService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/finance")
|
@RequestMapping("/finance")
|
||||||
|
@ -37,4 +40,15 @@ public class FinanceController {
|
||||||
|
|
||||||
return CommonResult.success(BeanUtils.toBean(result, FinanceVO.class));
|
return CommonResult.success(BeanUtils.toBean(result, FinanceVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据统一社会信用代码和年份查询企业收入和税收
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@GetMapping("/getIncomeAndTax")
|
||||||
|
public CommonResult<List<FinanceVO>> getIncomeAndTax(@Valid @RequestBody IncomeAndTaxParam param) {
|
||||||
|
return CommonResult.success(financeService.getIncomeAndTax(param));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface FinanceMapper {
|
public interface FinanceMapper {
|
||||||
|
|
||||||
|
@ -14,4 +16,7 @@ public interface FinanceMapper {
|
||||||
* @return FinanceBO
|
* @return FinanceBO
|
||||||
*/
|
*/
|
||||||
FinanceBO getFinanceByCreditCodeAndYear(@Param("creditCode") String creditCode, @Param("year") String year);
|
FinanceBO getFinanceByCreditCodeAndYear(@Param("creditCode") String creditCode, @Param("year") String year);
|
||||||
|
|
||||||
|
|
||||||
|
List<FinanceBO> getIncomeAndTax(@Param("creditCodes")List<String> creditCodes, @Param("year") String year);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.sk.module.data.dal.param.finance;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 财务数据入参
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IncomeAndTaxParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社会统一代码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "社会统一代码不能为空")
|
||||||
|
private String creditCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 年份
|
||||||
|
*/
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,21 @@
|
||||||
package org.sk.module.data.service.finance;
|
package org.sk.module.data.service.finance;
|
||||||
|
|
||||||
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
||||||
|
import org.sk.module.data.dal.param.finance.IncomeAndTaxParam;
|
||||||
|
import org.sk.module.data.dal.vo.FinanceVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface FinanceService {
|
public interface FinanceService {
|
||||||
|
|
||||||
|
|
||||||
FinanceBO getFinanceByCreditCodeAndYear(String creditCode, String year);
|
FinanceBO getFinanceByCreditCodeAndYear(String creditCode, String year);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 creditCode 和 year 查询财务信息
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<FinanceVO> getIncomeAndTax(IncomeAndTaxParam param);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
package org.sk.module.data.service.finance;
|
package org.sk.module.data.service.finance;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
import org.sk.module.data.dal.bo.finance.FinanceBO;
|
||||||
import org.sk.module.data.dal.mapper.finance.FinanceMapper;
|
import org.sk.module.data.dal.mapper.finance.FinanceMapper;
|
||||||
|
import org.sk.module.data.dal.param.finance.IncomeAndTaxParam;
|
||||||
|
import org.sk.module.data.dal.vo.FinanceVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@DS("master")
|
||||||
public class FinanceServiceImpl implements FinanceService {
|
public class FinanceServiceImpl implements FinanceService {
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,4 +30,13 @@ public class FinanceServiceImpl implements FinanceService {
|
||||||
}
|
}
|
||||||
return financeMapper.getFinanceByCreditCodeAndYear(creditCode, year);
|
return financeMapper.getFinanceByCreditCodeAndYear(creditCode, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FinanceVO> getIncomeAndTax(IncomeAndTaxParam param) {
|
||||||
|
String[] split = param.getCreditCodes().split(",");
|
||||||
|
List<FinanceBO> financeBOList = financeMapper.getIncomeAndTax(Arrays.asList(split), param.getYear());
|
||||||
|
List<FinanceVO> financeVOList = new ArrayList<>();
|
||||||
|
BeanUtils.copyProperties(financeBOList, financeVOList);
|
||||||
|
return financeVOList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ knife4j:
|
||||||
|
|
||||||
# MyBatis Plus 的配置项
|
# MyBatis Plus 的配置项
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
|
mapper-locations: classpath*:mappers/**/*Mapper.xml
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
|
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
|
||||||
global-config:
|
global-config:
|
||||||
|
|
|
@ -3,14 +3,69 @@
|
||||||
<mapper namespace="org.sk.module.data.dal.mapper.finance.FinanceMapper">
|
<mapper namespace="org.sk.module.data.dal.mapper.finance.FinanceMapper">
|
||||||
|
|
||||||
<select id="getFinanceByCreditCodeAndYear" resultType="org.sk.module.data.dal.bo.finance.FinanceBO">
|
<select id="getFinanceByCreditCodeAndYear" resultType="org.sk.module.data.dal.bo.finance.FinanceBO">
|
||||||
select
|
select a.comName,
|
||||||
a.comName,
|
a.creditCode,
|
||||||
a.creditCode,
|
a.Income,
|
||||||
a.Income,
|
(b.valueAddTax + b.corporateIncomeTax) / 10000 'tax', a.nd 'year'
|
||||||
(b.valueAddTax + b.corporateIncomeTax)/ 10000 'tax',
|
|
||||||
a.nd 'year'
|
|
||||||
from com_operate_info_year a
|
from com_operate_info_year a
|
||||||
left join com_pay_taxs_all b on a.creditCode = b.creditCode and b.mouth = '12' and a.nd = b.year
|
left join com_pay_taxs_all b on a.creditCode = b.creditCode and b.mouth = '12' and a.nd = b.year
|
||||||
where a.creditCode = ${creditCode} and a.nd = ${year}
|
where a.creditCode = #{creditCode}
|
||||||
|
and a.nd = #{year}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getIncomeAndTax" resultType="org.sk.module.data.dal.bo.finance.FinanceBO">
|
||||||
|
WITH
|
||||||
|
income_data AS (
|
||||||
|
SELECT comName, creditCode, nd AS year,income FROM com_operate_info_year
|
||||||
|
where creditCode in
|
||||||
|
<foreach item="code" collection="creditCodes" open="(" separator="," close=")">
|
||||||
|
#{code}
|
||||||
|
</foreach>
|
||||||
|
<if test="year != null and year != ''">
|
||||||
|
AND nd = #{year}
|
||||||
|
</if>
|
||||||
|
),
|
||||||
|
tax_data AS (
|
||||||
|
SELECT entName AS comName, creditCode, `year`,
|
||||||
|
CASE WHEN
|
||||||
|
year < YEAR(CURDATE())
|
||||||
|
THEN
|
||||||
|
(SELECT (valueAddTax + corporateIncomeTax) FROM com_pay_taxs_all WHERE year = t.year AND creditCode = t.creditCode AND mouth = 12)
|
||||||
|
ELSE
|
||||||
|
(SELECT (valueAddTax + corporateIncomeTax) FROM com_pay_taxs_all WHERE year = t.year AND creditCode = t.creditCode ORDER BY mouth DESC LIMIT 1)
|
||||||
|
END AS tax
|
||||||
|
FROM com_pay_taxs_all t
|
||||||
|
where creditCode in
|
||||||
|
<foreach item="code" collection="creditCodes" open="(" separator="," close=")">
|
||||||
|
#{code}
|
||||||
|
</foreach>
|
||||||
|
<if test="year != null and year != ''">
|
||||||
|
AND year = #{year}
|
||||||
|
</if>
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
COALESCE(i.creditCode, t.creditCode) AS creditCode,
|
||||||
|
COALESCE(i.comName, t.comName) AS comName,
|
||||||
|
COALESCE(i.year, t.year) AS year,
|
||||||
|
i.income,
|
||||||
|
t.tax/10000
|
||||||
|
FROM
|
||||||
|
income_data i
|
||||||
|
LEFT JOIN tax_data t
|
||||||
|
ON i.creditCode = t.creditCode AND i.year = t.year
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
COALESCE(t.creditCode, i.creditCode) AS creditCode,
|
||||||
|
COALESCE(t.comName, i.comName) AS comName,
|
||||||
|
COALESCE(t.year, i.year) AS year,
|
||||||
|
i.income,
|
||||||
|
t.tax/10000
|
||||||
|
FROM
|
||||||
|
tax_data t
|
||||||
|
LEFT JOIN income_data i
|
||||||
|
ON t.creditCode = i.creditCode AND t.year = i.year
|
||||||
|
ORDER BY creditCode, year
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue