package com.alatus.web; import com.alatus.result.Result; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import com.alatus.service.StatisticService; import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController public class SummaryController { @Resource private StatisticService statisticService; @GetMapping(value = "/api/summary/data") public Result getSummary(){ SummaryData summaryData = statisticService.loadSummary(); return Result.OK(summaryData); } @GetMapping(value = "/api/summary/SaleFunnel") public Result getSaleFunnel(){ List<SaleFunnelData> saleFunnel = statisticService.loadSaleFunnel(); return Result.OK(saleFunnel); } }
package com.alatus.web; import com.alatus.result.Result; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import com.alatus.service.StatisticService; import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController public class SummaryController { @Resource private StatisticService statisticService; @GetMapping(value = "/api/summary/data") public Result getSummary(){ SummaryData summaryData = statisticService.loadSummary(); return Result.OK(summaryData); } @GetMapping(value = "/api/summary/SaleFunnel") public Result getSaleFunnel(){ List<SaleFunnelData> saleFunnel = statisticService.loadSaleFunnel(); return Result.OK(saleFunnel); } }
package com.alatus.service.impl; import com.alatus.manager.StatisticManager; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import com.alatus.service.StatisticService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import java.util.List; @Service public class StatisticServiceImpl implements StatisticService { @Resource private StatisticManager statisticManager; @Override public SummaryData loadSummary() { return statisticManager.loadSummaryData(); } @Override public List<SaleFunnelData> loadSaleFunnel() { return statisticManager.loadSaleFunnel(); } }
package com.alatus.service.impl; import com.alatus.manager.StatisticManager; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import com.alatus.service.StatisticService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import java.util.List; @Service public class StatisticServiceImpl implements StatisticService { @Resource private StatisticManager statisticManager; @Override public SummaryData loadSummary() { return statisticManager.loadSummaryData(); } @Override public List<SaleFunnelData> loadSaleFunnel() { return statisticManager.loadSaleFunnel(); } }
package com.alatus.service; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import java.util.List; public interface StatisticService { SummaryData loadSummary(); List<SaleFunnelData> loadSaleFunnel(); }
package com.alatus.service; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import java.util.List; public interface StatisticService { SummaryData loadSummary(); List<SaleFunnelData> loadSaleFunnel(); }
package com.alatus.manager; import com.alatus.mapper.TActivityMapper; import com.alatus.mapper.TClueMapper; import com.alatus.mapper.TCustomerMapper; import com.alatus.mapper.TTranMapper; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import jakarta.annotation.Resource; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @Component public class StatisticManager { @Resource private TActivityMapper tActivityMapper; @Resource private TClueMapper tClueMapper; @Resource private TCustomerMapper tCustomerMapper; @Resource private TTranMapper tTranMapper; public SummaryData loadSummaryData() { //有效的市场活动总数 Integer effectiveActivityCount = tActivityMapper.selectOnGoingActivities().size(); //总的市场活动数 Integer totalActivityCount = tActivityMapper.selectActivityCount(); //线索总数 Integer totalClueCount = tClueMapper.selectClueCount(); //客户总数 Integer totalCustomerCount = tCustomerMapper.selectCustomerCount(); //成功的交易额 BigDecimal successTranAmount = tTranMapper.selectTranSuccessAmount(); //总的交易额(包含成功和不成功的) BigDecimal totalTranAmount = tTranMapper.selectAllTranAmount(); return SummaryData.builder() .effectiveActivityCount(effectiveActivityCount) .totalActivityCount(totalActivityCount) .totalClueCount(totalClueCount) .totalCustomerCount(totalCustomerCount) .successTranAmount(successTranAmount) .totalTranAmount(totalTranAmount) .build(); } public List<SaleFunnelData> loadSaleFunnel() { List<SaleFunnelData> saleFunnel = new ArrayList<>(); // 多少个线索 Integer clueCount = tClueMapper.selectClueCount(); // 多少个顾客 Integer totalCustomerCount = tCustomerMapper.selectCustomerCount(); // 多少个成交 Integer TranAmount = tTranMapper.selectTranAmount(); // 多少个成功交易 Integer TranSuccessAmount = tTranMapper.selectTranSuccessNum(); SaleFunnelData clue = SaleFunnelData.builder().name("线索").value(clueCount).build(); saleFunnel.add(clue); SaleFunnelData customer = SaleFunnelData.builder().name("客户").value(totalCustomerCount).build(); saleFunnel.add(customer); SaleFunnelData tran = SaleFunnelData.builder().name("交易").value(TranAmount).build(); saleFunnel.add(tran); SaleFunnelData successTran = SaleFunnelData.builder().name("成交").value(TranSuccessAmount).build(); saleFunnel.add(successTran); return saleFunnel; } }
package com.alatus.manager; import com.alatus.mapper.TActivityMapper; import com.alatus.mapper.TClueMapper; import com.alatus.mapper.TCustomerMapper; import com.alatus.mapper.TTranMapper; import com.alatus.result.SaleFunnelData; import com.alatus.result.SummaryData; import jakarta.annotation.Resource; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @Component public class StatisticManager { @Resource private TActivityMapper tActivityMapper; @Resource private TClueMapper tClueMapper; @Resource private TCustomerMapper tCustomerMapper; @Resource private TTranMapper tTranMapper; public SummaryData loadSummaryData() { //有效的市场活动总数 Integer effectiveActivityCount = tActivityMapper.selectOnGoingActivities().size(); //总的市场活动数 Integer totalActivityCount = tActivityMapper.selectActivityCount(); //线索总数 Integer totalClueCount = tClueMapper.selectClueCount(); //客户总数 Integer totalCustomerCount = tCustomerMapper.selectCustomerCount(); //成功的交易额 BigDecimal successTranAmount = tTranMapper.selectTranSuccessAmount(); //总的交易额(包含成功和不成功的) BigDecimal totalTranAmount = tTranMapper.selectAllTranAmount(); return SummaryData.builder() .effectiveActivityCount(effectiveActivityCount) .totalActivityCount(totalActivityCount) .totalClueCount(totalClueCount) .totalCustomerCount(totalCustomerCount) .successTranAmount(successTranAmount) .totalTranAmount(totalTranAmount) .build(); } public List<SaleFunnelData> loadSaleFunnel() { List<SaleFunnelData> saleFunnel = new ArrayList<>(); // 多少个线索 Integer clueCount = tClueMapper.selectClueCount(); // 多少个顾客 Integer totalCustomerCount = tCustomerMapper.selectCustomerCount(); // 多少个成交 Integer TranAmount = tTranMapper.selectTranAmount(); // 多少个成功交易 Integer TranSuccessAmount = tTranMapper.selectTranSuccessNum(); SaleFunnelData clue = SaleFunnelData.builder().name("线索").value(clueCount).build(); saleFunnel.add(clue); SaleFunnelData customer = SaleFunnelData.builder().name("客户").value(totalCustomerCount).build(); saleFunnel.add(customer); SaleFunnelData tran = SaleFunnelData.builder().name("交易").value(TranAmount).build(); saleFunnel.add(tran); SaleFunnelData successTran = SaleFunnelData.builder().name("成交").value(TranSuccessAmount).build(); saleFunnel.add(successTran); return saleFunnel; } }
package com.alatus.mapper; import com.alatus.model.TTran; import java.math.BigDecimal; public interface TTranMapper { int deleteByPrimaryKey(Integer id); int insert(TTran record); int insertSelective(TTran record); TTran selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(TTran record); int updateByPrimaryKey(TTran record); BigDecimal selectTranSuccessAmount(); BigDecimal selectAllTranAmount(); Integer selectTranAmount(); Integer selectTranSuccessNum(); }
package com.alatus.mapper; import com.alatus.model.TTran; import java.math.BigDecimal; public interface TTranMapper { int deleteByPrimaryKey(Integer id); int insert(TTran record); int insertSelective(TTran record); TTran selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(TTran record); int updateByPrimaryKey(TTran record); BigDecimal selectTranSuccessAmount(); BigDecimal selectAllTranAmount(); Integer selectTranAmount(); Integer selectTranSuccessNum(); }
<?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.alatus.mapper.TTranMapper"> <resultMap id="BaseResultMap" type="com.alatus.model.TTran"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="tran_no" jdbcType="VARCHAR" property="tranNo" /> <result column="customer_id" jdbcType="INTEGER" property="customerId" /> <result column="money" jdbcType="DECIMAL" property="money" /> <result column="expected_date" jdbcType="TIMESTAMP" property="expectedDate" /> <result column="stage" jdbcType="INTEGER" property="stage" /> <result column="description" jdbcType="VARCHAR" property="description" /> <result column="next_contact_time" jdbcType="TIMESTAMP" property="nextContactTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_by" jdbcType="INTEGER" property="createBy" /> <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" /> <result column="edit_by" jdbcType="INTEGER" property="editBy" /> </resultMap> <sql id="Base_Column_List"> id, tran_no, customer_id, money, expected_date, stage, description, next_contact_time, create_time, create_by, edit_time, edit_by </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from t_tran where id = #{id,jdbcType=INTEGER} </select> <select id="selectAllTranAmount" resultType="java.math.BigDecimal"> select sum(money) from t_tran </select> <select id="selectTranSuccessAmount" resultType="java.math.BigDecimal"> select sum(money) from t_tran where stage = 42 </select> <select id="selectTranAmount" resultType="java.lang.Integer"> select count(0) from (select distinct customer_id from t_tran) t </select> <select id="selectTranSuccessNum" resultType="java.lang.Integer"> select count(0) from (select distinct customer_id from t_tran where stage = 42) t </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> delete from t_tran where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TTran" useGeneratedKeys="true"> insert into t_tran (tran_no, customer_id, money, expected_date, stage, description, next_contact_time, create_time, create_by, edit_time, edit_by) values (#{tranNo,jdbcType=VARCHAR}, #{customerId,jdbcType=INTEGER}, #{money,jdbcType=DECIMAL}, #{expectedDate,jdbcType=TIMESTAMP}, #{stage,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, #{nextContactTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}) </insert> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TTran" useGeneratedKeys="true"> insert into t_tran <trim prefix="(" suffix=")" suffixOverrides=","> <if test="tranNo != null"> tran_no, </if> <if test="customerId != null"> customer_id, </if> <if test="money != null"> money, </if> <if test="expectedDate != null"> expected_date, </if> <if test="stage != null"> stage, </if> <if test="description != null"> description, </if> <if test="nextContactTime != null"> next_contact_time, </if> <if test="createTime != null"> create_time, </if> <if test="createBy != null"> create_by, </if> <if test="editTime != null"> edit_time, </if> <if test="editBy != null"> edit_by, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="tranNo != null"> #{tranNo,jdbcType=VARCHAR}, </if> <if test="customerId != null"> #{customerId,jdbcType=INTEGER}, </if> <if test="money != null"> #{money,jdbcType=DECIMAL}, </if> <if test="expectedDate != null"> #{expectedDate,jdbcType=TIMESTAMP}, </if> <if test="stage != null"> #{stage,jdbcType=INTEGER}, </if> <if test="description != null"> #{description,jdbcType=VARCHAR}, </if> <if test="nextContactTime != null"> #{nextContactTime,jdbcType=TIMESTAMP}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="createBy != null"> #{createBy,jdbcType=INTEGER}, </if> <if test="editTime != null"> #{editTime,jdbcType=TIMESTAMP}, </if> <if test="editBy != null"> #{editBy,jdbcType=INTEGER}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TTran"> update t_tran <set> <if test="tranNo != null"> tran_no = #{tranNo,jdbcType=VARCHAR}, </if> <if test="customerId != null"> customer_id = #{customerId,jdbcType=INTEGER}, </if> <if test="money != null"> money = #{money,jdbcType=DECIMAL}, </if> <if test="expectedDate != null"> expected_date = #{expectedDate,jdbcType=TIMESTAMP}, </if> <if test="stage != null"> stage = #{stage,jdbcType=INTEGER}, </if> <if test="description != null"> description = #{description,jdbcType=VARCHAR}, </if> <if test="nextContactTime != null"> next_contact_time = #{nextContactTime,jdbcType=TIMESTAMP}, </if> <if test="createTime != null"> create_time = #{createTime,jdbcType=TIMESTAMP}, </if> <if test="createBy != null"> create_by = #{createBy,jdbcType=INTEGER}, </if> <if test="editTime != null"> edit_time = #{editTime,jdbcType=TIMESTAMP}, </if> <if test="editBy != null"> edit_by = #{editBy,jdbcType=INTEGER}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.alatus.model.TTran"> update t_tran set tran_no = #{tranNo,jdbcType=VARCHAR}, customer_id = #{customerId,jdbcType=INTEGER}, money = #{money,jdbcType=DECIMAL}, expected_date = #{expectedDate,jdbcType=TIMESTAMP}, stage = #{stage,jdbcType=INTEGER}, description = #{description,jdbcType=VARCHAR}, next_contact_time = #{nextContactTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP}, create_by = #{createBy,jdbcType=INTEGER}, edit_time = #{editTime,jdbcType=TIMESTAMP}, edit_by = #{editBy,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> </mapper>
<?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.alatus.mapper.TTranMapper"> <resultMap id="BaseResultMap" type="com.alatus.model.TTran"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="tran_no" jdbcType="VARCHAR" property="tranNo" /> <result column="customer_id" jdbcType="INTEGER" property="customerId" /> <result column="money" jdbcType="DECIMAL" property="money" /> <result column="expected_date" jdbcType="TIMESTAMP" property="expectedDate" /> <result column="stage" jdbcType="INTEGER" property="stage" /> <result column="description" jdbcType="VARCHAR" property="description" /> <result column="next_contact_time" jdbcType="TIMESTAMP" property="nextContactTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_by" jdbcType="INTEGER" property="createBy" /> <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" /> <result column="edit_by" jdbcType="INTEGER" property="editBy" /> </resultMap> <sql id="Base_Column_List"> id, tran_no, customer_id, money, expected_date, stage, description, next_contact_time, create_time, create_by, edit_time, edit_by </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from t_tran where id = #{id,jdbcType=INTEGER} </select> <select id="selectAllTranAmount" resultType="java.math.BigDecimal"> select sum(money) from t_tran </select> <select id="selectTranSuccessAmount" resultType="java.math.BigDecimal"> select sum(money) from t_tran where stage = 42 </select> <select id="selectTranAmount" resultType="java.lang.Integer"> select count(0) from (select distinct customer_id from t_tran) t </select> <select id="selectTranSuccessNum" resultType="java.lang.Integer"> select count(0) from (select distinct customer_id from t_tran where stage = 42) t </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> delete from t_tran where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TTran" useGeneratedKeys="true"> insert into t_tran (tran_no, customer_id, money, expected_date, stage, description, next_contact_time, create_time, create_by, edit_time, edit_by) values (#{tranNo,jdbcType=VARCHAR}, #{customerId,jdbcType=INTEGER}, #{money,jdbcType=DECIMAL}, #{expectedDate,jdbcType=TIMESTAMP}, #{stage,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, #{nextContactTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}) </insert> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TTran" useGeneratedKeys="true"> insert into t_tran <trim prefix="(" suffix=")" suffixOverrides=","> <if test="tranNo != null"> tran_no, </if> <if test="customerId != null"> customer_id, </if> <if test="money != null"> money, </if> <if test="expectedDate != null"> expected_date, </if> <if test="stage != null"> stage, </if> <if test="description != null"> description, </if> <if test="nextContactTime != null"> next_contact_time, </if> <if test="createTime != null"> create_time, </if> <if test="createBy != null"> create_by, </if> <if test="editTime != null"> edit_time, </if> <if test="editBy != null"> edit_by, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="tranNo != null"> #{tranNo,jdbcType=VARCHAR}, </if> <if test="customerId != null"> #{customerId,jdbcType=INTEGER}, </if> <if test="money != null"> #{money,jdbcType=DECIMAL}, </if> <if test="expectedDate != null"> #{expectedDate,jdbcType=TIMESTAMP}, </if> <if test="stage != null"> #{stage,jdbcType=INTEGER}, </if> <if test="description != null"> #{description,jdbcType=VARCHAR}, </if> <if test="nextContactTime != null"> #{nextContactTime,jdbcType=TIMESTAMP}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="createBy != null"> #{createBy,jdbcType=INTEGER}, </if> <if test="editTime != null"> #{editTime,jdbcType=TIMESTAMP}, </if> <if test="editBy != null"> #{editBy,jdbcType=INTEGER}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TTran"> update t_tran <set> <if test="tranNo != null"> tran_no = #{tranNo,jdbcType=VARCHAR}, </if> <if test="customerId != null"> customer_id = #{customerId,jdbcType=INTEGER}, </if> <if test="money != null"> money = #{money,jdbcType=DECIMAL}, </if> <if test="expectedDate != null"> expected_date = #{expectedDate,jdbcType=TIMESTAMP}, </if> <if test="stage != null"> stage = #{stage,jdbcType=INTEGER}, </if> <if test="description != null"> description = #{description,jdbcType=VARCHAR}, </if> <if test="nextContactTime != null"> next_contact_time = #{nextContactTime,jdbcType=TIMESTAMP}, </if> <if test="createTime != null"> create_time = #{createTime,jdbcType=TIMESTAMP}, </if> <if test="createBy != null"> create_by = #{createBy,jdbcType=INTEGER}, </if> <if test="editTime != null"> edit_time = #{editTime,jdbcType=TIMESTAMP}, </if> <if test="editBy != null"> edit_by = #{editBy,jdbcType=INTEGER}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.alatus.model.TTran"> update t_tran set tran_no = #{tranNo,jdbcType=VARCHAR}, customer_id = #{customerId,jdbcType=INTEGER}, money = #{money,jdbcType=DECIMAL}, expected_date = #{expectedDate,jdbcType=TIMESTAMP}, stage = #{stage,jdbcType=INTEGER}, description = #{description,jdbcType=VARCHAR}, next_contact_time = #{nextContactTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP}, create_by = #{createBy,jdbcType=INTEGER}, edit_time = #{editTime,jdbcType=TIMESTAMP}, edit_by = #{editBy,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> </mapper>
package com.alatus.result; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Builder @AllArgsConstructor @NoArgsConstructor @Data public class SaleFunnelData { private String name; private Integer value; }
package com.alatus.result; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Builder @AllArgsConstructor @NoArgsConstructor @Data public class SaleFunnelData { private String name; private Integer value; }
本文转载自: https://blog.csdn.net/2201_75960169/article/details/136505365
版权归原作者 旧约Alatus 所有, 如有侵权,请联系我们删除。
版权归原作者 旧约Alatus 所有, 如有侵权,请联系我们删除。