📖 CRM:code review 合同金额排行榜、回款金额排行榜

This commit is contained in:
YunaiV 2024-01-30 09:24:42 +08:00
parent 278f220cef
commit 52a68e1838
13 changed files with 92 additions and 22 deletions

View File

@ -3,8 +3,7 @@ GET {{baseUrl}}/bi/rank/contract-ranKing
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
### 回款金额排行榜
GET {{baseUrl}}/bi/rank/receivables-ranKing
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
tenant-id: {{adminTenentId}}

View File

@ -19,6 +19,7 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
// TODO @anhaohao写了 swagger 注解不写注释哈
/**
* @author anhaohao
*/
@ -50,4 +51,5 @@ public class BiRankingController {
public CommonResult<List<BiReceivablesRanKingRespVO>> receivablesRanKing(BiRankReqVO biRankReqVO) {
return success(biRankingService.receivablesRanKing(biRankReqVO));
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO @anhaohaoVO 类有 swagger 注解不写注释哈
/**
* 管理后台 - BI 排行榜 Response VO
*
@ -12,13 +13,14 @@ import lombok.Data;
@Data
public class BiContractRanKingRespVO {
// TODO @anhaohao如果一定返回的字段需要加 requiredMode = Schema.RequiredMode.REQUIRED,
@Schema(description = "金额", example = "1")
private Integer price;
@Schema(description = "姓名", example = "1")
private String nickname;
@Schema(description = "部门名称", example = "1")
private String deptName;
}

View File

@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import java.util.List;
// TODO @anhaohao这个类的命名还是保持和其它一致使用 ReqVO 结尾例如说CrmStatisticsCommonParamReqVO
/**
* @author anhaohao
* bi参数
@ -25,17 +26,19 @@ public class BiParams extends PageParam {
@Schema(description = "用户IDs")
private List<Long> userIds;
// TODO @anhaohao这个字段可以融合到 startTimeendTime 里去交给前端计算哈
@Schema(description = "类型")
private String type;
// TODO @anhaohao还是使用 LocalDateTime
@Schema(description = "开始时间")
private String startTime;
@Schema(description = "结束时间")
private String endTime;
// TODO @anhaohao这个字段是不是直接只基于 deptId userId 来判断即可哈
@Schema(description = "0 部门 1员工")
private Integer isUser = 1;
}

View File

@ -15,6 +15,8 @@ public class BiRankReqVO {
@Schema(description = "部门id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long deptId;
// TODO @anhaohao这个字段参考 BiParams type 建议
@Schema(description = "分析类型(1.今天 2.昨天 3.本周 4.上周 5.本月 6.上月 7.本季度 8.上季度 9.本年 10 上年)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String type;
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO @anhaohao参考 BiContractRanKingRespVO 的建议
/**
* 管理后台 - BI 排行榜 Response VO
*
@ -20,4 +21,5 @@ public class BiReceivablesRanKingRespVO {
@Schema(description = "部门名称", example = "研发部")
private String deptName;
}

View File

@ -3,5 +3,8 @@
* 例如说报表图表数据分析等等
* <p>
* 1. Controller URL /bi/ 开头避免和其它 Module 冲突
*
* TODO @anhaohaomall 当时独立拆分一个 statistics 模块的原因是因为 mall 拆分了多个模块没有模块适合承接统计的能力所以独立了
* TODO crm 因为没有拆分所以可以直接放在 crm 模块下面这样我们可以在 controller/admin service 新建一个 bi 专门放置统计的代码
*/
package cn.iocoder.yudao.module.bi;

View File

@ -11,7 +11,7 @@ import java.util.List;
*
* @author anhaohao
*/
public interface BiRankingService {
public interface BiRankingService { // TODO @anhaohao第一个方法和类要有一个空行
/**
* 合同金额排行榜
*

View File

@ -28,6 +28,7 @@ public class BiTimeUtil {
// 解析时间
BiTimeEntity biTimeEntity = analyzeTime(biParams);
// 解析权限
// TODO @anhaohao涉及到数据的读取不放在 Util 还是搞会到 Service
biTimeEntity.setUserIds(analyzeAuth(biParams));
return biTimeEntity;
}

View File

@ -7,6 +7,7 @@
resultType="cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO">
SELECT IFNULL(SUM(t.price), 0) AS price, su.nickname, t.owner_user_id, dept.name AS deptName
FROM crm_contract t
<!-- TODO @anhaohaosystem_users、system_dept 是不是没用到?尽量不连这 2 个表,微服务下会是独立仓库;如果显示需要,可以在 service 读取后拼接; -->
LEFT JOIN system_users AS su ON su.id = t.owner_user_id
LEFT JOIN system_dept AS dept ON dept.id = su.dept_id
WHERE t.deleted = 0
@ -17,10 +18,12 @@
#{item}
</foreach>
</if>
<!-- TODO @anhaohao在某个区间的时间这么做有点浪费性能一般做法是 beginTime 是开始时间00:00:00finalTime 是结束时间23:59:59这样实现的 -->
AND DATE_FORMAT(t.order_date,'${sqlDateFormat}') between #{beginTime} and #{finalTime}
GROUP BY t.owner_user_id
ORDER BY price DESC
</select>
<select id="receivablesRanKing"
resultType="cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO">
SELECT IFNULL(SUM(t.price), 0) AS price, su.nickname, t.owner_user_id, dept.name AS deptName

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSalesOrderItemDO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
@ -30,7 +29,7 @@ public class ErpSaleOrderSaveReqVO {
private LocalDateTime orderTime;
@Schema(description = "销售员编号数组")
private String salePersonIds;
private List<Long> salePersonIds;
@Schema(description = "合计价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "26094")
@NotNull(message = "合计价格,单位:元不能为空")
@ -69,6 +68,61 @@ public class ErpSaleOrderSaveReqVO {
// private Integer status;
@Schema(description = "ERP 销售订单明细列表")
private List<ErpSalesOrderItemDO> salesOrderItems;
private List<Item> salesOrderItems;
@Schema(description = "管理后台 - ERP 销售订单明细新增/修改 Request VO")
@Data
public class Item {
@Schema(description = "编号", example = "20704")
private Long id;
// TODO 芋艿后面删除
// @Schema(description = "销售订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "30765")
// @NotNull(message = "销售订单编号不能为空")
// private Long orderId;
// @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5574")
// @NotNull(message = "商品 SPU 编号不能为空")
// private Long productSpuId;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21273")
@NotNull(message = "商品 SKU 编号不能为空")
private Long productSkuId;
@Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "商品单位不能为空")
private String productUnit;
@Schema(description = "商品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "6897")
@NotNull(message = "商品单价不能为空")
private BigDecimal productPrice;
@Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "22100")
@NotNull(message = "数量不能为空")
private Integer count;
// TODO 芋艿后面删除
// @Schema(description = "总价", requiredMode = Schema.RequiredMode.REQUIRED, example = "26868")
// @NotNull(message = "总价不能为空")
// private BigDecimal totalPrice;
@Schema(description = "备注", example = "你说的对")
private String description;
@Schema(description = "税率,百分比", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "税率,百分比不能为空")
private BigDecimal taxPercent;
@Schema(description = "税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "15791")
@NotNull(message = "税额,单位:元不能为空")
private BigDecimal taxPrice;
// TODO 芋艿后面删除
// @Schema(description = "支付金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "21930")
// @NotNull(message = "支付金额,单位:元不能为空")
// private BigDecimal payPrice;
}
}

View File

@ -40,11 +40,16 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
saleOrderMapper.insert(saleOrder);
// 插入子表
createSalesOrderItemsList(saleOrder.getId(), createReqVO.getSalesOrderItems());
// createSalesOrderItemsList(saleOrder.getId(), createReqVO.getSalesOrderItems());
// 返回
return saleOrder.getId();
}
private void createSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
list.forEach(o -> o.setId(id));
salesOrderItemMapper.insertBatch(list);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateSaleOrder(ErpSaleOrderSaveReqVO updateReqVO) {
@ -55,7 +60,13 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
saleOrderMapper.updateById(updateObj);
// 更新子表
updateSalesOrderItemsList(updateReqVO.getId(), updateReqVO.getSalesOrderItems());
// updateSalesOrderItemsList(updateReqVO.getId(), updateReqVO.getSalesOrderItems());
}
private void updateSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
deleteSalesOrderItemsById(id);
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下1id 冲突2updateTime 不更新
createSalesOrderItemsList(id, list);
}
@Override
@ -88,17 +99,6 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
// ==================== 子表ERP 销售订单明细 ====================
private void createSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
list.forEach(o -> o.setId(id));
salesOrderItemMapper.insertBatch(list);
}
private void updateSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
deleteSalesOrderItemsById(id);
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下1id 冲突2updateTime 不更新
createSalesOrderItemsList(id, list);
}
private void deleteSalesOrderItemsById(Long id) {
salesOrderItemMapper.deleteById(id);
}

View File

@ -46,5 +46,4 @@ public class DeptApiImpl implements DeptApi {
return BeanUtils.toBean(childDeptList, DeptRespDTO.class);
}
}