Commit 130762da authored by chenzhao's avatar chenzhao

统计bug修改

parent 1aa50b46
......@@ -45,7 +45,8 @@ public interface StatisticsHomepageMapper {
public Map<String,Object> statisticsPreparationMoney(String developerCode, String regionalCompaniesCode, String province, String city, String district);
public String selectProvince (String regionSeq);
public List<Map<String,Object>> getRent (String regionalCompaniesCode);
@UserEmpower(field ={"hygf_repayment.regional_companies_code"},dealerField ={"hygf_peasant_household.developer_code"} ,fieldConditions ={"eq"} ,relationship="and")
public List<Map<String,Object>> getRent (@RequestParam(value = "regionalCompaniesCode") String regionalCompaniesCode, @RequestParam(value = "regions")List<String> regions);
}
......@@ -2,42 +2,81 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.hygf.api.mapper.PowerStationMapper">
<select id="queryPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerStationDto">
select DISTINCT
hygf_power_station.*,
b.initiate_status,
b.contract_lock_id,
hygf_peasant_household.regional_companies_code,
hygf_peasant_household.regional_companies_name,
hygf_peasant_household.developer_code,
hygf_peasant_household.developer_user_id,
hygf_peasant_household.project_address_detail,
substring_index ( hygf_peasant_household.project_address_name, '/', 1 ) AS province,
b.stamp_status,
b.status
from hygf_power_station LEFT JOIN ( SELECT bb.peasant_household_id, initiate_status, contract_lock_id, stamp_status, status FROM (SELECT peasant_household_id,MAX(sequence_nbr) AS sequence_nbr from hygf_household_contract GROUP BY peasant_household_id ) aa INNER JOIN hygf_household_contract bb ON aa.sequence_nbr=bb.sequence_nbr) b on b.peasant_household_id=hygf_power_station.peasant_household_id
LEFT JOIN hygf_peasant_household on hygf_peasant_household.sequence_nbr=hygf_power_station.peasant_household_id
where hygf_power_station.is_delete=0
<if test="powerStationCode!=null and powerStationCode!=''">
and hygf_power_station.power_station_code like concat(concat('%',#{powerStationCode}),'%')
SELECT DISTINCT
ps.sequence_nbr,
ps.power_station_code,
ps.owners_name,
ps.project_address,
ps.service_agent,
ps.power_station_type,
ps.process_status,
ps.design_status,
ps.business_status,
ps.technology_status,
ps.process_instance_id,
ps.peasant_household_id,
ps.task_id,
ps.node_routing,
ps.process_definition_id,
ps.node_role,
ps.next_process_node,
ps.flow_task_id,
ps.plan_instance_id,
ps.drawing_review,
ps.next_node_name,
ps.next_execute_user_ids,
lc.initiate_status,
lc.contract_lock_id,
ph.regional_companies_code,
ph.regional_companies_name,
ph.developer_code,
ph.developer_user_id,
ph.project_address_detail,
SUBSTRING_INDEX(ph.project_address_name, '/', 1) AS province,
lc.stamp_status,
lc.status
FROM
hygf_power_station ps
LEFT JOIN (
SELECT
peasant_household_id,
initiate_status,
contract_lock_id,
stamp_status,
status
FROM (
SELECT
hhc.*,
ROW_NUMBER() OVER (PARTITION BY peasant_household_id ORDER BY sequence_nbr DESC) AS rn
FROM
hygf_household_contract hhc
) subq
WHERE subq.rn = 1
) lc
ON lc.peasant_household_id = ps.peasant_household_id
LEFT JOIN hygf_peasant_household ph
ON ph.sequence_nbr = ps.peasant_household_id
WHERE
ps.is_delete = 0
<if test="powerStationCode != null and powerStationCode != ''">
AND ps.power_station_code LIKE CONCAT('%', #{powerStationCode}, '%')
</if>
<if test="ownersName!=null and ownersName!=''">
and hygf_power_station.owners_name like concat(concat('%',#{ownersName}),'%')
<if test="ownersName != null and ownersName != ''">
AND ps.owners_name LIKE CONCAT('%', #{ownersName}, '%')
</if>
<if test="serviceAgent!=null and serviceAgent!=''">
and hygf_power_station.service_agent like concat(concat('%',#{serviceAgent}),'%')
<if test="serviceAgent != null and serviceAgent != ''">
AND ps.service_agent LIKE CONCAT('%', #{serviceAgent}, '%')
</if>
<if test="regionalCompaniesName!=null and regionalCompaniesName!=''">
and hygf_peasant_household.regional_companies_name like concat(concat('%',#{regionalCompaniesName}),'%')
<if test="regionalCompaniesName != null and regionalCompaniesName != ''">
AND ph.regional_companies_name LIKE CONCAT('%', #{regionalCompaniesName}, '%')
</if>
<if test="processStatus != null and processStatus != ''">
and hygf_power_station.process_status = #{processStatus}
AND ps.process_status = #{processStatus}
</if>
<if test="province != null and province != ''">
and hygf_peasant_household.project_address like concat(concat('%',#{province}),'%')
AND ph.project_address_name LIKE CONCAT('%', #{province}, '%')
</if>
<!-- GROUP BY hygf_peasant_household.sequence_nbr-->
ORDER BY hygf_power_station.rec_date desc
ORDER BY ps.rec_date DESC
</select>
<select id="getInstanceIdByhouseId" resultType="java.lang.String">
select process_instance_id From hygf_power_station where peasant_household_id = #{peasantHouseholdId}
......
......@@ -87,8 +87,6 @@
LEFT JOIN
hygf_peasant_household ON hygf_power_station.peasant_household_id = hygf_peasant_household.sequence_nbr
<where>
next_node_name IN ( '经销商设计人员上传设计图', '设计上传典型图库' )
AND process_status = '进行中'
<if test="developerCode != null and developerCode != ''">
AND hygf_peasant_household.developer_code = #{developerCode}
</if>
......@@ -391,9 +389,9 @@
'' AS kcywcrl,
SUM(CASE WHEN ph.preparation_money_state = '备货完成' THEN 1 ELSE 0 END) AS bhywc,
'' AS bhywcrl,
SUM(CASE WHEN ph.preparation_money_state = '待收货' THEN 1 ELSE 0 END) AS bhjxz,
SUM(CASE WHEN ph.preparation_money_state = '待发货' or ph.preparation_money_state = '暂存发货'or ph.preparation_money_state = '待补货' THEN 1 ELSE 0 END ) AS bhwtg,
'' AS bhjxzrl,
SUM(CASE WHEN ph.preparation_money_state = '待补货' THEN 1 ELSE 0 END) AS bhwtg,
SUM(CASE WHEN ph.preparation_money_state = '待收货' THEN 1 ELSE 0 END) AS bhjxz,
'' AS bhwtgrl,
SUM(CASE WHEN wops.power_station_construction_status = '未通过' THEN 1 ELSE 0 END) AS sgwtg,
SUM(CASE WHEN wops.power_station_construction_status = '未通过' THEN ROUND(COALESCE(ei.real_scale/1000, 0), 2) ELSE 0 END) AS sgwtgrl,
......@@ -427,7 +425,7 @@
LEFT JOIN hygf_basic_grid_record br ON br.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_financing_info fi ON fi.peasant_household_id = ph.sequence_nbr
WHERE
ps.is_delete = 0
ph.is_delete = 0
<if test="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
......@@ -532,15 +530,25 @@
<select id="getRent" resultType="map">
SELECT
sum( CASE WHEN repay_state = '1' THEN rent ELSE 0 END ) yhk,
sum( CASE WHEN repay_state = '0' THEN rent ELSE 0 END ) sywhk,
sum( CASE WHEN repay_state = '0' AND ( YEAR ( repay_date ) = YEAR ( CURDATE())) THEN rent ELSE 0 END ) jnwhk,
max(regional_companies_code) regionalCompaniesCode
sum( CASE WHEN repay_state = '1' THEN rent ELSE 0 END ) yhk,
sum( CASE WHEN repay_state = '0' THEN rent ELSE 0 END ) sywhk,
sum( CASE WHEN repay_state = '0' AND ( YEAR ( repay_date ) = YEAR ( CURDATE())) THEN rent ELSE 0 END ) jnwhk,
max(regional_companies_code) regionalCompaniesCode,
max(hygf_repayment.company_name) regionalCompaniesName,
max(pc.REGION_SEQ) regionSeq
FROM
`hygf_repayment`
hygf_repayment
LEFT JOIN
privilege_company pc on pc.ORG_CODE = hygf_repayment.regional_companies_code
<where>
<if test="regionalCompaniesCode != null and regionalCompaniesCode != ''">
regional_companies_code = #{regionalCompaniesCode}
and regional_companies_code = #{regionalCompaniesCode}
</if>
<if test="regions != null and regions.size()>0 ">
and pc.REGION_SEQ in
<foreach collection="regions" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</if>
</where>
GROUP BY
......@@ -550,19 +558,30 @@
<select id="statisticsPowerStation" resultType="map">
SELECT
IFNULL( sum( CASE WHEN lc.STATUS = '已作废' THEN 1 ELSE 0 END ), 0 ) yzf,
IFNULL( sum( CASE WHEN lc.STATUS = '双方已签署' THEN 1 ELSE 0 END ), 0 ) sfyqs,
IFNULL( sum( CASE WHEN lc.STATUS = '农户已签署' THEN 1 ELSE 0 END ), 0 ) nhyqs,
IFNULL( sum( CASE WHEN lc.STATUS = '未签署' THEN 1 ELSE 0 END ), 0 ) wqs,
IFNULL( SUM( CASE WHEN ps.process_status = '不通过' THEN 1 ELSE 0 END ), 0 ) AS kcwtg,
IFNULL( SUM( CASE WHEN ps.process_status = '进行中' THEN 1 ELSE 0 END ), 0 ) AS kcjxz,
IFNULL( SUM( CASE WHEN ps.process_status = '完成' THEN 1 ELSE 0 END ), 0 ) AS kcywc,
IFNULL( SUM( CASE WHEN hc.STATUS = '未签署' THEN 1 ELSE 0 END ), 0 ) AS wqs,
IFNULL( SUM( CASE WHEN hc.STATUS = '农户已签署' THEN 1 ELSE 0 END ), 0 ) AS nhyqs,
IFNULL( SUM( CASE WHEN hc.STATUS = '双方已签署' THEN 1 ELSE 0 END ), 0 ) AS sfyqs,
IFNULL( SUM( CASE WHEN hc.STATUS = '已作废' THEN 1 ELSE 0 END ), 0 ) AS yzf
IFNULL( SUM( CASE WHEN ps.process_status = '完成' THEN 1 ELSE 0 END ), 0 ) AS kcywc
FROM
hygf_peasant_household ph
LEFT JOIN hygf_power_station ps ON ps.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_household_contract hc ON hc.peasant_household_id = ph.sequence_nbr
hygf_power_station ps
LEFT JOIN (
SELECT
peasant_household_id,
initiate_status,
contract_lock_id,
stamp_status,
STATUS
FROM
( SELECT hhc.*, ROW_NUMBER() OVER ( PARTITION BY peasant_household_id ORDER BY sequence_nbr DESC ) AS rn FROM hygf_household_contract hhc ) subq
WHERE
ps.is_delete = 0 and ph.is_delete = 0
subq.rn = 1
) lc ON lc.peasant_household_id = ps.peasant_household_id
LEFT JOIN hygf_peasant_household ph ON ph.sequence_nbr = ps.peasant_household_id
WHERE
ps.is_delete = 0
<if test="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
......
......@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.hygf.api.entity.PeasantHousehold;
import com.yeejoin.amos.boot.module.hygf.api.mapper.JpStationMapper;
import com.yeejoin.amos.boot.module.hygf.api.mapper.StatisticsHomepageMapper;
import org.apache.activemq.util.MapHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
......@@ -61,7 +62,16 @@ public class StatisticsHomepageServiceImpl {
this.resuleMapBuild(map,resultMap,acceptanceMaps,"acceptance");
List<Map<String, Object>> financingMaps = statisticsHomepageMapper.financingStatusTotal(developerCode, regionalCompaniesCode, province, city, district);
this.resuleMapBuild(map,resultMap,financingMaps,"financing");
List<String> regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
List<String> regionNodeByCode = new ArrayList<>();
if (StringUtils.isNotEmpty(province)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
if (StringUtils.isNotEmpty(city)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
if (StringUtils.isNotEmpty(district)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
List<Map<String, Object>> inverterMaps = statisticsHomepageMapper.inverterTotal(developerCode, regionalCompaniesCode, province, city, district,regionNodeByCode);
List<Map<String, Object>> inverterJpMaps = statisticsHomepageMapper.inverterTotalJp(developerCode, regionalCompaniesCode, province, city, district,regionNodeByCode);
inverterMaps.addAll(inverterJpMaps);
......@@ -306,7 +316,9 @@ public class StatisticsHomepageServiceImpl {
}
public void homePageExport(String developerCode, String regionalCompaniesCode, String province, String city, String district, HttpServletResponse response) throws IOException {
//获取电站数据
List<Map<String, Object>> maps = statisticsHomepageMapper.homePageExport(developerCode, regionalCompaniesCode, province, city, district);
//获取区域公司对应的经销商数量 用来合并表格
List<Map<String, Object>> merCountMap = statisticsHomepageMapper.merCount(developerCode, regionalCompaniesCode, province, city, district);
String templatePath = "templates/homePageExport.xlsx";
Workbook workbook = null;
......@@ -315,8 +327,22 @@ public class StatisticsHomepageServiceImpl {
Sheet firstSheet = workbook.getSheetAt(0);
fillSheet(firstSheet, maps);
int startNum = 4;
List<Map<String, Object>> rent = statisticsHomepageMapper.getRent(null);
int replenishStartNum = 4+maps.size();
//根据区域公司的省市区进行筛选
List<String> regionNodeByCode = new ArrayList<>();
if (StringUtils.isNotEmpty(province)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
if (StringUtils.isNotEmpty(city)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
if (StringUtils.isNotEmpty(district)){
regionNodeByCode = jpStationMapper.getRegionNodeByCode(province);
}
//查询区域公司的还款计划
List<Map<String, Object>> rent = statisticsHomepageMapper.getRent(regionalCompaniesCode,regionNodeByCode);
for (Map<String, Object> map : merCountMap) {
//此处逻辑针对需要合并表格的数据
if (!map.get("total").toString().equals("1")){
int total = Integer.valueOf(map.get("total").toString()) -1 ;
int endNum = startNum+total;
......@@ -326,6 +352,7 @@ public class StatisticsHomepageServiceImpl {
cell.setCellValue(regionName);
applyBorder(cell);
boolean flag = true;
//判断是不是区域公司存在还款计划 若不存在则给0
for (Map<String, Object> stringObjectMap : rent) {
if (stringObjectMap.get("regionalCompaniesCode").equals(map.get("regionalCompaniesCode"))){
Cell cell3 = firstSheet.getRow(startNum).createCell(40);
......@@ -353,7 +380,7 @@ public class StatisticsHomepageServiceImpl {
cell2.setCellValue(0);
applyBorder(cell2);
}
//合并表格及设置样式
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(startNum, endNum, 1, 1);
CellRangeAddress cellRangeAddress = new CellRangeAddress(startNum, endNum, 2, 2);
CellRangeAddress cellRangeAddress1 = new CellRangeAddress(startNum, endNum, 35, 35);
......@@ -386,6 +413,7 @@ public class StatisticsHomepageServiceImpl {
cell.setCellValue(regionName);
applyBorder(cell);
boolean flag = true;
//判断是不是区域公司存在还款计划 若不存在则给0
for (Map<String, Object> stringObjectMap : rent) {
if (stringObjectMap.get("regionalCompaniesCode").equals(map.get("regionalCompaniesCode"))){
Cell cell3 = firstSheet.getRow(startNum).createCell(40);
......@@ -397,6 +425,7 @@ public class StatisticsHomepageServiceImpl {
Cell cell2 = firstSheet.getRow(startNum).createCell(42);
cell2.setCellValue(stringObjectMap.get("sywhk").toString());
applyBorder(cell2);
flag = false;
}
}
......@@ -415,9 +444,47 @@ public class StatisticsHomepageServiceImpl {
}
}
}
//导出主体是电站,但可能存在部分区域公司不存在电站但存在还款计划 需将此类数据补充进excel
for (Map<String, Object> map : rent) {
boolean exist = false;
for (Map<String, Object> stringObjectMap : merCountMap) {
if (stringObjectMap.get("regionalCompaniesCode").equals(map.get("regionalCompaniesCode"))){
exist = true;
break;
}
}
if (!exist){
Row row = firstSheet.createRow(replenishStartNum);
Cell cell = row.createCell(0);
cell.setCellValue(maps.size()+1);
applyBorder(cell);
Cell cell1 = row.createCell(1);
String regionName = statisticsHomepageMapper.selectProvince(map.get("regionSeq").toString());
cell1.setCellValue(regionName);
applyBorder(cell1);
Cell cell2 = row.createCell(2);
cell2.setCellValue(map.get("regionalCompaniesName").toString());
applyBorder(cell2);
Cell cell40= row.createCell(40);
cell40.setCellValue(map.get("yhk").toString());
applyBorder(cell40);
Cell cell41 = row.createCell(41);
cell41.setCellValue(map.get("jnwhk").toString());
applyBorder(cell41);
Cell cell42 = row.createCell(42);
cell42.setCellValue(map.get("sywhk").toString());
applyBorder(cell42);
for (int i = 3; i <40; i++) {
Cell celli = row.createCell(i);
celli.setCellValue("");
applyBorder(celli);
}
}
}
autoSizeColumns(firstSheet);
// autoSizeColumns(firstSheet);
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("统计数据.xlsx", "UTF-8"));
response.setHeader("content-Type", "application/vnd.ms-excel");
response.flushBuffer();
......
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