BD团队分析

master
james.zhao 6 years ago
parent c4faa8236b
commit 80585d722c

@ -693,7 +693,20 @@ public class BDPrizeServiceImpl implements BDPrizeService {
@Override @Override
public List<JSONObject> getBDTeamKpiCompletionDegree(String month) { public List<JSONObject> getBDTeamKpiCompletionDegree(String month) {
List<JSONObject> prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountAndBdType(getReportByMonth(month)); JSONObject report = financialBDPrizeRecordMapper.findByMonth(month);
List<JSONObject> prizeAmountAndBdTypeList = new ArrayList<>();
if (report == null) {
try {
Date start_date = DateUtils.parseDate(month+"-01","yyyy-MM-dd");
Date end_date = DateUtils.addMonths(start_date,1);
prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountRealTime(start_date,end_date);
} catch (ParseException e) {
e.printStackTrace();
}
}else{
prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountAndBdType(getReportByMonth(month));
}
for (JSONObject prize : prizeAmountAndBdTypeList) { for (JSONObject prize : prizeAmountAndBdTypeList) {
BigDecimal kpi = financialBDCommissionConfigMapper.findCurrentCommissionMaxAmount(month, prize.getIntValue("bd_type")); BigDecimal kpi = financialBDCommissionConfigMapper.findCurrentCommissionMaxAmount(month, prize.getIntValue("bd_type"));
prize.put("kpi", kpi); prize.put("kpi", kpi);
@ -707,12 +720,36 @@ public class BDPrizeServiceImpl implements BDPrizeService {
@Override @Override
public List<JSONObject> getBDProportionByTeamType(String month, String teamType) { public List<JSONObject> getBDProportionByTeamType(String month, String teamType) {
return financialBDConfigMapper.findManagerByTeamType(teamType, getReportByMonth(month)); JSONObject report = financialBDPrizeRecordMapper.findByMonth(month);
if (report == null) {
try {
Date start_date = DateUtils.parseDate(month+"-01","yyyy-MM-dd");
Date end_date = DateUtils.addMonths(start_date,1);
return financialBDConfigMapper.findManagerByTeamTypeRealTime(teamType,start_date,end_date);
} catch (ParseException e) {
e.printStackTrace();
throw new BadRequestException("Month is wrong");
}
}else {
return financialBDConfigMapper.findManagerByTeamType(teamType, getReportByMonth(month));
}
} }
@Override @Override
public JSONObject getBDKpiByManagerId(String month, String manager_id) { public JSONObject getBDKpiByManagerId(String month, String manager_id) {
return financialBDPrizeLogMapper.findByReportAndBDTotal(getReportByMonth(month), manager_id); JSONObject report = financialBDPrizeRecordMapper.findByMonth(month);
if (report == null) {
try {
Date start_date = DateUtils.parseDate(month+"-01","yyyy-MM-dd");
Date end_date = DateUtils.addMonths(start_date,1);
return financialBDPrizeLogMapper.findByReportAndBDTotalRealTime(manager_id,start_date,end_date);
} catch (ParseException e) {
e.printStackTrace();
throw new BadRequestException("Month is wrong");
}
}else {
return financialBDPrizeLogMapper.findByReportAndBDTotal(getReportByMonth(month), manager_id);
}
} }
public String getReportByMonth(String month) { public String getReportByMonth(String month) {

@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -39,4 +40,6 @@ public interface FinancialBDConfigMapper {
JSONObject listCityCommission(@Param("city") String city, @Param("record_id") String record_id); JSONObject listCityCommission(@Param("city") String city, @Param("record_id") String record_id);
List<JSONObject> findManagerByTeamType(@Param("bd_type") String bdType, @Param("record_id") String record_id); List<JSONObject> findManagerByTeamType(@Param("bd_type") String bdType, @Param("record_id") String record_id);
List<JSONObject> findManagerByTeamTypeRealTime(@Param("bd_type") String bdType, @Param("start_date") Date start_date, @Param("end_date") Date end_date);
} }

@ -9,6 +9,7 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -39,6 +40,27 @@ public interface FinancialBDPrizeLogMapper {
"GROUP BY fbpl.manager_id") "GROUP BY fbpl.manager_id")
JSONObject findByReportAndBDTotal(@Param("record_id") String recordId, @Param("manager_id") String managerId); JSONObject findByReportAndBDTotal(@Param("record_id") String recordId, @Param("manager_id") String managerId);
@Select("SELECT\n" +
"\tc.bd_name,\n" +
"\tc.manager_id,\n" +
"\tc.kpi_amount,\n" +
"\tsum( o.total * d.proportion ) AS total_amount \n" +
"FROM\n" +
"\tstatistics_customer_order o\n" +
"\tINNER JOIN sys_clients sc ON sc.client_id = o.client_id\n" +
"\tINNER JOIN sys_client_bd d ON o.client_id = d.client_id\n" +
"\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id \n" +
"WHERE\n" +
"\tsc.org_id = 1 \n" +
"\tAND o.date >= #{start_date} \n" +
"\tAND o.date < #{end_date} \n" +
"\tAND d.start_date <= o.date AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date > o.date \n" +
"\t) \n" +
"\tAND c.get_prize = 1 \n" +
"\tAND c.manager_id = #{manager_id}")
JSONObject findByReportAndBDTotalRealTime(@Param("manager_id") String manage_id, @Param("start_date") Date start_date, @Param("end_date") Date end_date);
@Select("SELECT prize_log_id,record_id,manager_id,bd_name,bd_level,SUM(total_amount) total_amount," + @Select("SELECT prize_log_id,record_id,manager_id,bd_name,bd_level,SUM(total_amount) total_amount," +
"SUM(total_prize) total_prize,SUM(total_donation) total_donation, SUM(send_prize) send_prize," + "SUM(total_prize) total_prize,SUM(total_donation) total_donation, SUM(send_prize) send_prize," +
"SUM(hold_prize) hold_prize,last_punish,prize_type FROM financial_bd_prize_log fbpl " + "SUM(hold_prize) hold_prize,last_punish,prize_type FROM financial_bd_prize_log fbpl " +
@ -67,4 +89,23 @@ public interface FinancialBDPrizeLogMapper {
"WHERE prize_type = 1 AND record_id = #{record_id}\n" + "WHERE prize_type = 1 AND record_id = #{record_id}\n" +
"GROUP BY l.manager_id") "GROUP BY l.manager_id")
List<JSONObject> findBdPrizeAmountAndBdType(@Param("record_id") String recordId); List<JSONObject> findBdPrizeAmountAndBdType(@Param("record_id") String recordId);
@Select("SELECT\n" +
"\tc.*,\n" +
"\tsum( ( o.total ) * d.proportion ) AS total_amount\n" +
"FROM\n" +
"\tstatistics_customer_order o\n" +
"\tINNER JOIN sys_clients sc ON sc.client_id = o.client_id\n" +
"\tINNER JOIN sys_client_bd d ON o.client_id = d.client_id\n" +
"\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id \n" +
"WHERE\n" +
"\tsc.org_id = 1 \n" +
"\tAND o.date >= #{start_date} \n" +
"\tAND o.date < #{end_date} \n" +
"\tAND d.start_date <= o.date AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date > o.date \n" +
"\t) \n" +
"\tAND c.get_prize = 1 \n" +
"GROUP BY\n" +
"\tc.bd_group")
List<JSONObject> findBdPrizeAmountRealTime(@Param("start_date") Date start_date, @Param("end_date") Date end_date);
} }

@ -125,4 +125,27 @@
group by manager_id group by manager_id
) log ON log.manager_id = config.manager_id ) log ON log.manager_id = config.manager_id
</select> </select>
</mapper>
<select id="findManagerByTeamTypeRealTime" resultType="com.alibaba.fastjson.JSONObject">
SELECT
c.bd_name,
c.manager_id,
c.kpi_amount,
sum( o.total * d.proportion ) AS total_amount
FROM
statistics_customer_order o
INNER JOIN sys_clients sc ON sc.client_id = o.client_id
INNER JOIN sys_client_bd d ON o.client_id = d.client_id
INNER JOIN financial_bd_config c ON d.bd_id = c.manager_id
WHERE
sc.org_id = 1
AND o.date &gt;= #{start_date}
AND o.date &lt; #{end_date}
AND d.start_date &lt;= o.date AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date &gt; o.date
)
AND c.get_prize = 1
AND c.bd_group = ( SELECT fc.bd_group FROM financial_bd_config fc WHERE fc.bd_type = #{bd_type} )
GROUP BY
c.manager_id
</select>
</mapper>

Loading…
Cancel
Save