提交 d8664c5d authored 作者: 李秋林's avatar 李秋林

促销员今日活动上报\活动查询,历史活动查询

上级 156bd344
package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import com.wangxiaolu.promotion.pojo.activity.temporary.vo.TemporaryActivityDataVo;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityCoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -17,18 +22,19 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/activity/temporary/core")
public class TemporaryActivityCoreController {
@Autowired
private TemporaryActivityCoreService tempActivityCoreService;
/**
* 促销员今日活动上报
* 返回活动生成id
*/
@PostMapping("/today/reported")
public Long todayActivityDataReported(@RequestBody TemporaryActivityDataVo activityVo){
/**
*
*/
return 0l;
public Long todayActivityDataReported(@RequestBody @Validated TemporaryActivityDataVo activityVo) {
TemporaryActivityReportedDto temActDto = new TemporaryActivityReportedDto();
BeanUtils.copyProperties(activityVo, temActDto);
return tempActivityCoreService.activityDataReportedSave(temActDto);
}
}
package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-04-18 13
* @describe : 促销员活动上报数据查询
*/
@Slf4j
@RestController
@RequestMapping("/activity/temporary/query")
public class TemporaryActivityQueryController {
@Autowired
TemporaryActivityQueryService temporaryActivityQueryService;
/**
* 根据促销员id查询所有任务
* @return 所有任务 todo 之后改为分页
*/
@GetMapping("/all/{id}")
public List<TemporaryActivityReportedDto> findtemporaryIdActivityDataList(@PathVariable("id") @NotNull Long temporaryId) {
List<TemporaryActivityReportedDto> dtos = temporaryActivityQueryService.findtemporaryIdActivityDataList(temporaryId);
return dtos;
}
/**
* 根据促销员id查询今日任务
*/
@GetMapping("/today/{id}")
public TemporaryActivityReportedDto findtemporaryIdTodayActivityData(@PathVariable("id") @NotNull Long temporaryId) {
TemporaryActivityReportedDto dto = temporaryActivityQueryService.findtemporaryIdTodayActivityData(temporaryId);
return dto;
}
}
package com.wangxiaolu.promotion.domain.activity.dao;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-04-18 10
* @describe :
*/
public interface TemporaryActivityReportedDao {
long activityDataSave(TemporaryActivityReportedDto temActDto);
List<TemporaryActivityReportedDto> findListByTemporaryId(Long temporaryId);
TemporaryActivityReportedDto findOneByCurrentDate(Long temporaryId);
}
package com.wangxiaolu.promotion.domain.activity.dao.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wangxiaolu.promotion.domain.activity.dao.TemporaryActivityReportedDao;
import com.wangxiaolu.promotion.domain.activity.mapper.TemporaryActivityReportedMapper;
import com.wangxiaolu.promotion.domain.activity.mapper.entity.TemporaryActivityReportedDO;
import com.wangxiaolu.promotion.domain.activity.mapper.wrapperQo.TemporaryActivityWrapper;
import com.wangxiaolu.promotion.enums.activity.TemActApproveStatus;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author : liqiulin
* @date : 2024-04-18 10
* @describe :
*/
@Service
@Slf4j
public class TemporaryActivityReportedDaoImpl implements TemporaryActivityReportedDao {
@Autowired
TemporaryActivityReportedMapper temporaryActivityReportedMapper;
/**
* 保存促销员任务
*/
@Override
public long activityDataSave(TemporaryActivityReportedDto temActDto) {
TemporaryActivityReportedDO tDo = new TemporaryActivityReportedDO();
BeanUtils.copyProperties(temActDto, tDo);
tDo.setCreateDate(DateUtil.today());
int tId = temporaryActivityReportedMapper.insert(tDo);
log.info("促销员今日活动上报数据完成,生成id[{}],数据信息:{}", tId, tDo);
return tId;
}
/**
* 根据促销员id查询所有任务
*/
@Override
public List<TemporaryActivityReportedDto> findListByTemporaryId(Long temporaryId) {
TemporaryActivityWrapper taw = new TemporaryActivityWrapper()
.setTemporaryId(temporaryId);
LambdaQueryWrapper<TemporaryActivityReportedDO> temQw = buildQueryList(taw);
List<TemporaryActivityReportedDO> temDOS = temporaryActivityReportedMapper.selectList(temQw);
return transitionDtos(temDOS);
}
/**
* 根据促销员id查询今日任务
*/
@Override
public TemporaryActivityReportedDto findOneByCurrentDate(Long temporaryId) {
TemporaryActivityWrapper taw = new TemporaryActivityWrapper()
.setTemporaryId(temporaryId)
.setCreateDate(DateUtil.today());
LambdaQueryWrapper<TemporaryActivityReportedDO> temQw = buildQueryList(taw);
TemporaryActivityReportedDO temDO = temporaryActivityReportedMapper.selectOne(temQw);
return transitionDto(temDO);
}
private LambdaQueryWrapper<TemporaryActivityReportedDO> buildQueryList(TemporaryActivityWrapper tw) {
LambdaQueryWrapper<TemporaryActivityReportedDO> queryWrapper = new LambdaQueryWrapper<>();
if (Objects.nonNull(tw.getTemporaryId())) {
queryWrapper.eq(TemporaryActivityReportedDO::getTemporaryId, tw.getTemporaryId());
}
if (!StringUtils.isEmpty(tw.getCreateDate())) {
queryWrapper.eq(TemporaryActivityReportedDO::getCreateDate, tw.getCreateDate());
}
return queryWrapper;
}
/**
* DO to DTO (单个对象)
*
* @param temDos DO对象List
* @return DTO对象
*/
private List<TemporaryActivityReportedDto> transitionDtos(List<TemporaryActivityReportedDO> temDos) {
if (CollectionUtils.isEmpty(temDos)) {
return new ArrayList<>();
}
List<TemporaryActivityReportedDto> dtos = new ArrayList<>(temDos.size() * 2);
for (TemporaryActivityReportedDO temDo : temDos) {
dtos.add(transitionDto(temDo));
}
return dtos;
}
/**
* DO to DTO (单个对象)
*
* @param temDo DO对象
* @return DTO对象
*/
private TemporaryActivityReportedDto transitionDto(TemporaryActivityReportedDO temDo) {
TemporaryActivityReportedDto temporaryDto = null;
if (Objects.isNull(temDo)) {
return temporaryDto;
}
temporaryDto = new TemporaryActivityReportedDto();
BeanUtils.copyProperties(temDo, temporaryDto);
// 审批状态回显
if (Objects.nonNull(temDo.getApproveStatus())) {
temporaryDto.setApproveStatus(TemActApproveStatus.valueOf(temDo.getApproveStatus()));
temporaryDto.setApproveStatusMsg(temporaryDto.getApproveStatus().getMsg());
}
return temporaryDto;
}
}
package com.wangxiaolu.promotion.domain.activity.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wangxiaolu.promotion.domain.activity.mapper.entity.TemporaryActivityReportedDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/**
* @author a02200059
* @description 针对表【temporary_activity_reported】的数据库操作Mapper
* @createDate 2024-04-18 10:38:42
* @Entity generator.domain.TemporaryActivityReported
*/
@Mapper
@Repository
public interface TemporaryActivityReportedMapper extends BaseMapper<TemporaryActivityReportedDO> {
}
package com.wangxiaolu.promotion.domain.activity.mapper.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName temporary_activity_reported
*/
@TableName(value ="temporary_activity_reported")
@Data
public class TemporaryActivityReportedDO implements Serializable {
/**
* 主键id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 关联—temporary_info表id
*/
private Integer temporaryId;
/**
* 关联—temporary_info表name
*/
private String temporaryName;
/**
* 关联—活动店铺id
*/
private Long shopId;
/**
* 关联—活动店铺名称(例:小美超市)
*/
private String shopName;
/**
* 关联—活动店铺地址(例:小美超市)
*/
private String shopAddress;
/**
* 关联—审核人员id
*/
private Long approverId;
/**
* 关联—审核人员姓名
*/
private String approveName;
/**
* 审批状态(审批中、审批通过、退回……)
* 关联enum类 TemActApproveStatus
*/
private String approveStatus;
/**
* 最后一次审批时间
*/
private Date approveTime;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建日期
*/
private String createDate;
/**
* 修改时间
*/
private Date modifyTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.wangxiaolu.promotion.domain.activity.mapper.wrapperQo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* @author : liqiulin
* @date : 2024-04-09 18
* @describe :
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class TemporaryActivityWrapper {
/**
* temporaryId
*/
Long temporaryId;
/**
* 创建时间YYYY-MM-DD
*/
String createDate;
}
......@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.domain.user.mapper.TemporaryInfoMapper;
import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO;
import com.wangxiaolu.promotion.domain.user.wrapper.TemporaryWrapper;
import com.wangxiaolu.promotion.domain.user.wrapperQo.TemporaryWrapper;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......
package com.wangxiaolu.promotion.domain.user.wrapper;
package com.wangxiaolu.promotion.domain.user.wrapperQo;
import lombok.AllArgsConstructor;
import lombok.Data;
......
package com.wangxiaolu.promotion.enums.activity;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author : liqiulin
* @date : 2024-04-18 11
* @describe :temproary activity approve status
* 促销员活动上报审批状态
*/
@Getter
@AllArgsConstructor
public enum TemActApproveStatus {
/**
* 审批状态
*/
SUBMITTED("已提交"),
IN_APPROVAL("审批中"),
APPROVED("审批通过"),
SEND_BACK("退回"),
;
private String msg;
}
package com.wangxiaolu.promotion.pojo.activity.temporary.dto;
import com.wangxiaolu.promotion.enums.activity.TemActApproveStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author : liqiulin
* @date : 2024-04-18 10
* @describe :
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class TemporaryActivityReportedDto {
/**
* temporary_activity_reported主键id
*/
private Long id;
/**
* 关联—temporary_info表id
*/
private Integer temporaryId;
/**
* 关联—temporary_info表name
*/
private String temporaryName;
/**
* 关联—活动店铺id
*/
private Long shopId;
/**
* 关联—活动店铺名称(例:小美超市)
*/
private String shopName;
/**
* 关联—活动店铺地址(例:小美超市)
*/
private String shopAddress;
/**
* 关联—审核人员id
*/
private Long approverId;
/**
* 关联—审核人员姓名
*/
private String approveName;
/**
* 审批状态(审批中、审批通过、退回……)
*/
private TemActApproveStatus approveStatus;
private String approveStatusMsg;
/**
* 最后一次审批时间
*/
private Date approveTime;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建日期
*/
private String createDate;
/**
* 修改时间
*/
private Date modifyTime;
}
......@@ -5,6 +5,8 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* @author : liqiulin
* @date : 2024-04-17 19
......@@ -16,20 +18,11 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
public class TemporaryActivityDataVo {
/**
* 活动店铺
*/
private String shopName;
/**
* 店铺地址
*/
private String shopAddress;
/**
* 促销员id
* temporaryInfo表id
*/
@NotNull(message = "促销员账号异常")
private Integer temporaryId;
/**
......@@ -39,8 +32,21 @@ public class TemporaryActivityDataVo {
private String temporaryName;
/**
* 活动店铺Id
*/
@NotNull(message = "活动店铺异常")
private Long shopId;
/**
* 活动店铺
*/
private String shopName;
/**
* 店铺地址
*/
private String shopAddress;
}
......@@ -4,6 +4,7 @@ import com.wangxiaolu.promotion.exception.APIException;
import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
......@@ -49,4 +50,10 @@ public class ControllerExceptionAdvice {
String msg = e.getBindingResult().getFieldError().getDefaultMessage();
return new R(RCode.PARAM_ERROR.getCode(), msg);
}
@ExceptionHandler({DataIntegrityViolationException.class})
public R dataIntegrityViolationExceptionHandler(DataIntegrityViolationException e) {
String msg = e.getMessage();
return new R(RCode.API_DATA_ERROR.getCode(), RCode.API_DATA_ERROR.getMsg(), msg);
}
}
......@@ -23,6 +23,7 @@ public enum RCode implements StatusCode {
* 2000+
*/
API_ERROR(2000, "业务异常"),
API_DATA_ERROR(2001, "业务数据异常"),
/**
* user
......
package com.wangxiaolu.promotion.service.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
/**
* @author : liqiulin
* @date : 2024-04-18 11
* @describe :
*/
public interface TemporaryActivityCoreService {
/**
* 活动上报保存
* @return 生成id
*/
long activityDataReportedSave(TemporaryActivityReportedDto temActDto);
}
package com.wangxiaolu.promotion.service.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-04-18 13
* @describe :
*/
public interface TemporaryActivityQueryService {
/**
* 根据促销员id查询所有任务
*/
List<TemporaryActivityReportedDto> findtemporaryIdActivityDataList(Long temporaryId);
/**
* 根据促销员id查询今日任务
*/
TemporaryActivityReportedDto findtemporaryIdTodayActivityData(Long temporaryId);
}
package com.wangxiaolu.promotion.service.activity.temporary.impl;
import com.wangxiaolu.promotion.domain.activity.dao.TemporaryActivityReportedDao;
import com.wangxiaolu.promotion.enums.activity.TemActApproveStatus;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityCoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2024-04-18 11
* @describe :
*/
@Service
@Slf4j
public class TemporaryActivityCoreServiceImpl implements TemporaryActivityCoreService {
@Autowired
TemporaryActivityReportedDao temporaryActivityReportedDao;
/**
* 活动上报保存
*
* @return 生成id
*/
@Override
public long activityDataReportedSave(TemporaryActivityReportedDto temActDto) {
return temporaryActivityReportedDao.activityDataSave(temActDto);
}
}
package com.wangxiaolu.promotion.service.activity.temporary.impl;
import com.wangxiaolu.promotion.domain.activity.dao.TemporaryActivityReportedDao;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-04-18 13
* @describe :
*/
@Service
@Slf4j
public class TemporaryActivityQueryServiceImpl implements TemporaryActivityQueryService {
@Autowired
TemporaryActivityReportedDao temporaryActivityReportedDao;
/**
* 根据促销员id查询所有任务
*/
@Override
public List<TemporaryActivityReportedDto> findtemporaryIdActivityDataList(Long temporaryId) {
List<TemporaryActivityReportedDto> dtos = temporaryActivityReportedDao.findListByTemporaryId(temporaryId);
return dtos;
}
/**
* 根据促销员id查询今日任务
*/
@Override
public TemporaryActivityReportedDto findtemporaryIdTodayActivityData(Long temporaryId) {
TemporaryActivityReportedDto dto = temporaryActivityReportedDao.findOneByCurrentDate(temporaryId);
return dto;
}
}
<?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.wangxiaolu.promotion.domain.activity.mapper.TemporaryActivityReportedMapper">
<resultMap id="BaseResultMap"
type="com.wangxiaolu.promotion.domain.activity.mapper.entity.TemporaryActivityReportedDO">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="temporaryId" column="temporary_id" jdbcType="INTEGER"/>
<result property="temporaryName" column="temporary_name" jdbcType="VARCHAR"/>
<result property="shopId" column="shop_id" jdbcType="BIGINT"/>
<result property="shopName" column="shop_name" jdbcType="VARCHAR"/>
<result property="shopAddress" column="shop_address" jdbcType="VARCHAR"/>
<result property="approverId" column="approver_id" jdbcType="BIGINT"/>
<result property="approveName" column="approve_name" jdbcType="VARCHAR"/>
<result property="approveStatus" column="approve_status" jdbcType="VARCHAR"/>
<result property="approveTime" column="approve_time" jdbcType="TIMESTAMP"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="createDate" column="create_date" jdbcType="CHAR"/>
<result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id
,temporary_id,temporary_name,
shop_id,shop_name,shop_address,
approver_id,approve_name,approve_status,
create_time,modify_time
</sql>
</mapper>
package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.vo.TemporaryActivityDataVo;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author : liqiulin
* @date : 2024-04-18 11
* @describe :
*/
@SpringBootTest
@RunWith(SpringRunner.class)
class TemporaryActivityCoreControllerTest {
@Autowired
TemporaryActivityCoreController temporaryActivityCoreController;
@Test
void todayActivityDataReported() {
TemporaryActivityDataVo activityVo = new TemporaryActivityDataVo();
Long aLong = temporaryActivityCoreController.todayActivityDataReported(activityVo);
System.out.println(" 促销员活动上报成功,生成id:" + aLong);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论