From fb9de099ac1343d0e4627481e3c2598b8a3565ab Mon Sep 17 00:00:00 2001 From: 199901012 Date: Thu, 22 Apr 2021 23:52:42 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8F=90=E4=BA=A4diam'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighCouponAgentController.java | 8 ++- .../com/hai/dao/HighCouponAgentRelMapper.java | 23 +++---- .../hai/dao/HighCouponAgentRelMapperExt.java | 16 ++++- .../dao/HighCouponAgentRelSqlProvider.java | 14 +++++ .../com/hai/entity/HighCouponAgentRel.java | 16 +++++ .../hai/entity/HighCouponAgentRelExample.java | 60 +++++++++++++++++++ .../java/com/hai/model/AgentSalesModel.java | 31 ++++++++++ .../hai/service/HighCouponAgentService.java | 7 +++ .../impl/HighCouponAgentServiceImpl.java | 48 +++++++++++++-- 9 files changed, 205 insertions(+), 18 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/model/AgentSalesModel.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java index 34462404..ce3cd643 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -69,10 +69,12 @@ public class HighCouponAgentController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); - Map map = new HashMap<>(); - map.put("", ""); + if (userInfoModel.getHighAgent() == null) { + log.error("HighCouponAgentController -> assignCouponAgent() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } - return ResponseMsgUtil.success(map); + return ResponseMsgUtil.success(highCouponAgentService.getSalesCountByAgent(userInfoModel.getHighAgent().getId())); } catch (Exception e) { log.error("HighCouponAgentController --> getCodeById() error!", e); diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java index 9afd9bf1..a166f0ee 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java @@ -41,16 +41,16 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Insert({ "insert into high_coupon_agent_rel (coupon_name, sales_price, ", "coupon_id, agent_id, ", - "stock_count, create_time, ", - "`status`, operator_id, ", - "operator_name, ext_1, ", - "ext_2, ext_3)", + "stock_count, sales_count, ", + "create_time, `status`, ", + "operator_id, operator_name, ", + "ext_1, ext_2, ext_3)", "values (#{couponName,jdbcType=VARCHAR}, #{salesPrice,jdbcType=DECIMAL}, ", "#{couponId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", - "#{stockCount,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{status,jdbcType=INTEGER}, #{operatorId,jdbcType=BIGINT}, ", - "#{operatorName,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{stockCount,jdbcType=INTEGER}, #{salesCount,jdbcType=INTEGER}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, ", + "#{operatorId,jdbcType=BIGINT}, #{operatorName,jdbcType=VARCHAR}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighCouponAgentRel record); @@ -67,6 +67,7 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="stock_count", property="stockCount", jdbcType=JdbcType.INTEGER), + @Result(column="sales_count", property="salesCount", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="operator_id", property="operatorId", jdbcType=JdbcType.BIGINT), @@ -79,8 +80,8 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Select({ "select", - "id, coupon_name, sales_price, coupon_id, agent_id, stock_count, create_time, ", - "`status`, operator_id, operator_name, ext_1, ext_2, ext_3", + "id, coupon_name, sales_price, coupon_id, agent_id, stock_count, sales_count, ", + "create_time, `status`, operator_id, operator_name, ext_1, ext_2, ext_3", "from high_coupon_agent_rel", "where id = #{id,jdbcType=BIGINT}" }) @@ -91,6 +92,7 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="stock_count", property="stockCount", jdbcType=JdbcType.INTEGER), + @Result(column="sales_count", property="salesCount", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="operator_id", property="operatorId", jdbcType=JdbcType.BIGINT), @@ -117,6 +119,7 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { "coupon_id = #{couponId,jdbcType=BIGINT},", "agent_id = #{agentId,jdbcType=BIGINT},", "stock_count = #{stockCount,jdbcType=INTEGER},", + "sales_count = #{salesCount,jdbcType=INTEGER},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "`status` = #{status,jdbcType=INTEGER},", "operator_id = #{operatorId,jdbcType=BIGINT},", diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java index 2af8f271..c58dafcd 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java @@ -1,7 +1,21 @@ package com.hai.dao; +import com.hai.model.AgentSalesModel; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.Map; + /** * mapper扩展类 */ public interface HighCouponAgentRelMapperExt { -} \ No newline at end of file + + + @Select(" select case when sum(1) is not null then sum(1) else 0 end count," + + " case when sum(c.sales_price) is not null then sum(c.sales_price) else 0 end salesCountPrice " + + " from high_coupon_agent_code a,high_coupon_code b,high_coupon_agent_rel c" + + " where c.id = a.coupon_agent_id and c.agent_id = #{agentId}" + + " and a.status = 2 and a.coupon_code_id = b.id and b.consume_time >= #{consumeTimeS} and b.consume_time <= #{consumeTimeE}") + AgentSalesModel getAgentSales(@Param("agentId") Long agentId, @Param("consumeTimeS")String consumeTimeS, @Param("consumeTimeE")String consumeTimeE); +} diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java index 6ee52b00..7783432a 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java @@ -48,6 +48,10 @@ public class HighCouponAgentRelSqlProvider { sql.VALUES("stock_count", "#{stockCount,jdbcType=INTEGER}"); } + if (record.getSalesCount() != null) { + sql.VALUES("sales_count", "#{salesCount,jdbcType=INTEGER}"); + } + if (record.getCreateTime() != null) { sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); } @@ -91,6 +95,7 @@ public class HighCouponAgentRelSqlProvider { sql.SELECT("coupon_id"); sql.SELECT("agent_id"); sql.SELECT("stock_count"); + sql.SELECT("sales_count"); sql.SELECT("create_time"); sql.SELECT("`status`"); sql.SELECT("operator_id"); @@ -139,6 +144,10 @@ public class HighCouponAgentRelSqlProvider { sql.SET("stock_count = #{record.stockCount,jdbcType=INTEGER}"); } + if (record.getSalesCount() != null) { + sql.SET("sales_count = #{record.salesCount,jdbcType=INTEGER}"); + } + if (record.getCreateTime() != null) { sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); } @@ -181,6 +190,7 @@ public class HighCouponAgentRelSqlProvider { sql.SET("coupon_id = #{record.couponId,jdbcType=BIGINT}"); sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); sql.SET("stock_count = #{record.stockCount,jdbcType=INTEGER}"); + sql.SET("sales_count = #{record.salesCount,jdbcType=INTEGER}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("operator_id = #{record.operatorId,jdbcType=BIGINT}"); @@ -218,6 +228,10 @@ public class HighCouponAgentRelSqlProvider { sql.SET("stock_count = #{stockCount,jdbcType=INTEGER}"); } + if (record.getSalesCount() != null) { + sql.SET("sales_count = #{salesCount,jdbcType=INTEGER}"); + } + if (record.getCreateTime() != null) { sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java index d7efdce4..78f33d29 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java @@ -46,6 +46,11 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria */ private Integer stockCount; + /** + * 销售数量 + */ + private Integer salesCount; + /** * 创建时间 */ @@ -122,6 +127,14 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria this.stockCount = stockCount; } + public Integer getSalesCount() { + return salesCount; + } + + public void setSalesCount(Integer salesCount) { + this.salesCount = salesCount; + } + public Date getCreateTime() { return createTime; } @@ -196,6 +209,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId())) && (this.getAgentId() == null ? other.getAgentId() == null : this.getAgentId().equals(other.getAgentId())) && (this.getStockCount() == null ? other.getStockCount() == null : this.getStockCount().equals(other.getStockCount())) + && (this.getSalesCount() == null ? other.getSalesCount() == null : this.getSalesCount().equals(other.getSalesCount())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getOperatorId() == null ? other.getOperatorId() == null : this.getOperatorId().equals(other.getOperatorId())) @@ -215,6 +229,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode()); result = prime * result + ((getAgentId() == null) ? 0 : getAgentId().hashCode()); result = prime * result + ((getStockCount() == null) ? 0 : getStockCount().hashCode()); + result = prime * result + ((getSalesCount() == null) ? 0 : getSalesCount().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getOperatorId() == null) ? 0 : getOperatorId().hashCode()); @@ -237,6 +252,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria sb.append(", couponId=").append(couponId); sb.append(", agentId=").append(agentId); sb.append(", stockCount=").append(stockCount); + sb.append(", salesCount=").append(salesCount); sb.append(", createTime=").append(createTime); sb.append(", status=").append(status); sb.append(", operatorId=").append(operatorId); diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java index c27d627a..3d82ecff 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java @@ -496,6 +496,66 @@ public class HighCouponAgentRelExample { return (Criteria) this; } + public Criteria andSalesCountIsNull() { + addCriterion("sales_count is null"); + return (Criteria) this; + } + + public Criteria andSalesCountIsNotNull() { + addCriterion("sales_count is not null"); + return (Criteria) this; + } + + public Criteria andSalesCountEqualTo(Integer value) { + addCriterion("sales_count =", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountNotEqualTo(Integer value) { + addCriterion("sales_count <>", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountGreaterThan(Integer value) { + addCriterion("sales_count >", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountGreaterThanOrEqualTo(Integer value) { + addCriterion("sales_count >=", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountLessThan(Integer value) { + addCriterion("sales_count <", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountLessThanOrEqualTo(Integer value) { + addCriterion("sales_count <=", value, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountIn(List values) { + addCriterion("sales_count in", values, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountNotIn(List values) { + addCriterion("sales_count not in", values, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountBetween(Integer value1, Integer value2) { + addCriterion("sales_count between", value1, value2, "salesCount"); + return (Criteria) this; + } + + public Criteria andSalesCountNotBetween(Integer value1, Integer value2) { + addCriterion("sales_count not between", value1, value2, "salesCount"); + return (Criteria) this; + } + public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/model/AgentSalesModel.java b/hai-service/src/main/java/com/hai/model/AgentSalesModel.java new file mode 100644 index 00000000..0c5ab5a7 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/AgentSalesModel.java @@ -0,0 +1,31 @@ +package com.hai.model; + +import java.math.BigDecimal; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/22 23:44 + */ +public class AgentSalesModel { + + private Integer count; + + private BigDecimal salesCountPrice; + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public BigDecimal getSalesCountPrice() { + return salesCountPrice; + } + + public void setSalesCountPrice(BigDecimal salesCountPrice) { + this.salesCountPrice = salesCountPrice; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index 8a4eb7f8..ec058098 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -55,4 +55,11 @@ public interface HighCouponAgentService { * @Date 2021/4/21 22:35 **/ Map generateCode(Long couponAgentCodeId); + + /** + * @Author 胡锐 + * @Description 根据代理商 查询销售统计 + * @Date 2021/4/22 22:26 + **/ + Map getSalesCountByAgent(Long agentId) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 9a93f744..5b2432a0 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -4,10 +4,12 @@ import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.DateUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.dao.HighCouponAgentCodeMapper; import com.hai.dao.HighCouponAgentRelMapper; import com.hai.entity.*; +import com.hai.model.AgentSalesModel; import com.hai.service.HighCouponAgentService; import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponService; @@ -17,10 +19,8 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -168,4 +168,44 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { map.put("couponAgentCode", couponAgentCode); return map; } + + @Override + public Map getSalesCountByAgent(Long agentId) throws Exception { + BigDecimal surplusCountPrice = new BigDecimal("0"); + BigDecimal salesCountPrice = new BigDecimal("0"); + + Map listMap = new HashMap<>(); + listMap.put("agentId", agentId); + List list = getCouponAgentList(listMap); + for (HighCouponAgentRel highCouponAgentRel : list) { + BigDecimal surplusPrice = new BigDecimal(highCouponAgentRel.getStockCount()).multiply((highCouponAgentRel.getSalesPrice())); + surplusCountPrice = surplusCountPrice.add(surplusPrice); + + BigDecimal salesPrice = new BigDecimal(highCouponAgentRel.getStockCount()).multiply((highCouponAgentRel.getSalesPrice())); + surplusCountPrice = surplusCountPrice.add(salesPrice); + } + + // 计算使用有效期 + Calendar consumeTimeS = Calendar.getInstance(); + consumeTimeS.setTime(new Date()); + consumeTimeS.set(Calendar.HOUR_OF_DAY, 00); + consumeTimeS.set(Calendar.MINUTE, 00); + consumeTimeS.set(Calendar.SECOND, 00); + + Calendar consumeTimeE = Calendar.getInstance(); + consumeTimeS.setTime(new Date()); + consumeTimeS.set(Calendar.HOUR_OF_DAY, 23); + consumeTimeS.set(Calendar.MINUTE, 59); + consumeTimeS.set(Calendar.SECOND, 59); + + AgentSalesModel agentSales = highCouponAgentRelMapper.getAgentSales(agentId, DateUtil.date2String(consumeTimeS.getTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.date2String(consumeTimeE.getTime(), "yyyy-MM-dd HH:mm:ss")); + + Map returnMap = new HashMap<>(); + returnMap.put("orderCount", agentSales.getCount()); + returnMap.put("turnoverPrice", agentSales.getSalesCountPrice()); + returnMap.put("surplusCountPrice", surplusCountPrice); // 剩余总额 + returnMap.put("salesCountPrice", salesCountPrice); // 销售总额 + returnMap.put("list", list); + return returnMap; + } }