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

活动计划新增并返回解析数据、活动计划提交、阿里云oss获取token

上级 372bb68b
...@@ -47,7 +47,7 @@ public class PromPlanCoreController { ...@@ -47,7 +47,7 @@ public class PromPlanCoreController {
//todo String filePath = "/home/" + fileId; //todo String filePath = "/home/" + fileId;
// FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath); // FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath);
String filePath = "/Users/a02200059/Desktop/测试新增v3.xlsx"; String filePath = "/Users/a02200059/Desktop/测试新增v3 2.xlsx";
activityPlanVo.setExcelId(fileId); activityPlanVo.setExcelId(fileId);
Map<String, Object> map = promPlanCoreService.selfPlanUp(activityPlanVo, filePath); Map<String, Object> map = promPlanCoreService.selfPlanUp(activityPlanVo, filePath);
return R.success(map); return R.success(map);
......
...@@ -3,6 +3,9 @@ package com.wangxiaolu.promotion.domain.activityplanv2.dao; ...@@ -3,6 +3,9 @@ package com.wangxiaolu.promotion.domain.activityplanv2.dao;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.wangxiaolu.promotion.domain.manage.wrapperQo.ActivityPlanInfoWrapper; import com.wangxiaolu.promotion.domain.manage.wrapperQo.ActivityPlanInfoWrapper;
import com.wangxiaolu.promotion.pojo.PageInfo; import com.wangxiaolu.promotion.pojo.PageInfo;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.ActivityPlanInfoDto;
import java.util.Date;
/** /**
* @author : liqiulin * @author : liqiulin
...@@ -13,4 +16,6 @@ public interface ActivityPlanInfoDao { ...@@ -13,4 +16,6 @@ public interface ActivityPlanInfoDao {
void saveList(JSONArray table, Long recordId); void saveList(JSONArray table, Long recordId);
void page(PageInfo pageInfo, ActivityPlanInfoWrapper wrapper); void page(PageInfo pageInfo, ActivityPlanInfoWrapper wrapper);
ActivityPlanInfoDto selectPlan(String storeCode, Date date);
} }
...@@ -4,18 +4,22 @@ import com.alibaba.fastjson.JSONArray; ...@@ -4,18 +4,22 @@ import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangxiaolu.promotion.common.enums.StatusType; import com.wangxiaolu.promotion.common.enums.StatusType;
import com.wangxiaolu.promotion.common.util.BeanUtils;
import com.wangxiaolu.promotion.common.util.DataUtils;
import com.wangxiaolu.promotion.domain.activityplanv2.dao.ActivityPlanInfoDao; import com.wangxiaolu.promotion.domain.activityplanv2.dao.ActivityPlanInfoDao;
import com.wangxiaolu.promotion.domain.activityplanv2.mapper.ActivityPlanInfoMapper; import com.wangxiaolu.promotion.domain.activityplanv2.mapper.ActivityPlanInfoMapper;
import com.wangxiaolu.promotion.domain.activityplanv2.mapper.entity.ActivityPlanInfoDo; import com.wangxiaolu.promotion.domain.activityplanv2.mapper.entity.ActivityPlanInfoDo;
import com.wangxiaolu.promotion.domain.manage.wrapperQo.ActivityPlanInfoWrapper; import com.wangxiaolu.promotion.domain.manage.wrapperQo.ActivityPlanInfoWrapper;
import com.wangxiaolu.promotion.exception.DataException; import com.wangxiaolu.promotion.exception.DataException;
import com.wangxiaolu.promotion.pojo.PageInfo; import com.wangxiaolu.promotion.pojo.PageInfo;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.ActivityPlanInfoDto;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -48,6 +52,11 @@ public class ActivityPlanInfoDaoImpl implements ActivityPlanInfoDao { ...@@ -48,6 +52,11 @@ public class ActivityPlanInfoDaoImpl implements ActivityPlanInfoDao {
pageInfo.setRecords(doPage.getRecords()); pageInfo.setRecords(doPage.getRecords());
} }
@Override
public ActivityPlanInfoDto selectPlan(String storeCode, Date date) {
ActivityPlanInfoDo activityPlanInfoDo = activityPlanInfoMapper.selectPlan(storeCode, date);
return BeanUtils.transitionDto(activityPlanInfoDo, ActivityPlanInfoDto.class);
}
private LambdaQueryWrapper<ActivityPlanInfoDo> buildWrapper(ActivityPlanInfoWrapper wrapper) { private LambdaQueryWrapper<ActivityPlanInfoDo> buildWrapper(ActivityPlanInfoWrapper wrapper) {
......
...@@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date;
/** /**
* @author a02200059 * @author a02200059
* @description 针对表【activity_plan_info(活动计划列表)】的数据库操作Mapper * @description 针对表【activity_plan_info(活动计划列表)】的数据库操作Mapper
...@@ -18,6 +20,8 @@ import org.springframework.stereotype.Repository; ...@@ -18,6 +20,8 @@ import org.springframework.stereotype.Repository;
public interface ActivityPlanInfoMapper extends BaseMapper<ActivityPlanInfoDo> { public interface ActivityPlanInfoMapper extends BaseMapper<ActivityPlanInfoDo> {
void saveList(@Param("table") JSONArray table,@Param("recordId") Long recordId); void saveList(@Param("table") JSONArray table,@Param("recordId") Long recordId);
ActivityPlanInfoDo selectPlan(String storeCode, Date date);
} }
......
...@@ -122,11 +122,6 @@ public class ActivityPlanInfoDo implements Serializable { ...@@ -122,11 +122,6 @@ public class ActivityPlanInfoDo implements Serializable {
*/ */
private String area; private String area;
/**
* 门店所属行政区域-乡镇街道名称,如:宁海路街道
*/
private String street;
/** /**
* 门店所在地址 * 门店所在地址
*/ */
......
...@@ -157,6 +157,8 @@ public class ActivityPlanInfoDto implements Serializable { ...@@ -157,6 +157,8 @@ public class ActivityPlanInfoDto implements Serializable {
private Integer index; private Integer index;
private Date createTime;
/** /**
* 当前行错误,不可保存 * 当前行错误,不可保存
* 错误信息 * 错误信息
......
...@@ -71,11 +71,14 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -71,11 +71,14 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void selfPlanAf(String planUuid) { public synchronized void selfPlanAf(String planUuid) {
JSONObject mapJson = redisCache.getToJson(RedisKeys.Manage.ACTIVITY_PLAN_UP.getKey() + planUuid); String key = RedisKeys.Manage.ACTIVITY_PLAN_UP.getKey() + planUuid;
JSONObject mapJson = redisCache.getToJson(key);
if (Objects.isNull(mapJson)){ if (Objects.isNull(mapJson)){
throw new DataException(RCode.REDIS_PUSH_DATA_NOT_EXIT); throw new DataException(RCode.REDIS_PUSH_DATA_NOT_EXIT);
} }
redisCache.removeKey(key);
JSONObject record = mapJson.getJSONObject("record"); JSONObject record = mapJson.getJSONObject("record");
JSONArray table = mapJson.getJSONArray("table"); JSONArray table = mapJson.getJSONArray("table");
...@@ -84,6 +87,12 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -84,6 +87,12 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
activityPlanInfoDao.saveList(table,recordId); activityPlanInfoDao.saveList(table,recordId);
} }
/**
* 解析excel文件中的计划
* @param planVo 请求信息(包含人员信息)
* @param filePath 文件地址
* @throws DataException 数据异常
*/
private Map<String, Object> readSheetByCSJLUp(ActivityPlanVo planVo, String filePath) throws DataException { private Map<String, Object> readSheetByCSJLUp(ActivityPlanVo planVo, String filePath) throws DataException {
ReadExcelUtils readExcelUtils = new ReadExcelUtils(filePath); ReadExcelUtils readExcelUtils = new ReadExcelUtils(filePath);
String[] headers = readExcelUtils.readTitle(); String[] headers = readExcelUtils.readTitle();
...@@ -112,7 +121,8 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -112,7 +121,8 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
Map<String, Object> rMap = new HashMap<>(); Map<String, Object> rMap = new HashMap<>();
rMap.put("uuid", UUID.randomUUID().toString()); rMap.put("uuid", UUID.randomUUID().toString());
List<ActivityPlanInfoDto> rDtos = new ArrayList<>(rows.size() * 2);
List<ActivityPlanInfoDto> rDtos = new ArrayList<>(rows.size() * 4);
for (Map.Entry<Integer, List<Object>> row : rows.entrySet()) { for (Map.Entry<Integer, List<Object>> row : rows.entrySet()) {
List<ActivityPlanInfoDto> infoDtos = getRowByCSJLUp(planVo, row.getValue(),rMap); List<ActivityPlanInfoDto> infoDtos = getRowByCSJLUp(planVo, row.getValue(),rMap);
rDtos.addAll(infoDtos); rDtos.addAll(infoDtos);
...@@ -123,12 +133,14 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -123,12 +133,14 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
/** /**
* 城市经理上传的计划工号只能是自己 * 城市经理上传的计划工号只能是自己
*
* @param row 表中的每一行数据 * @param row 表中的每一行数据
* @return * @return
*/ */
private List<ActivityPlanInfoDto> getRowByCSJLUp(ActivityPlanVo planVo, List<Object> row,Map<String, Object> rMap) { private List<ActivityPlanInfoDto> getRowByCSJLUp(ActivityPlanVo planVo, List<Object> row,Map<String, Object> rMap) {
List<ActivityPlanInfoDto> dtos = new ArrayList<>(); List<ActivityPlanInfoDto> dtos = new ArrayList<>();
LocalDate now = LocalDate.now();
int nextMonthValue = now.plusMonths(1).getMonthValue();
/** /**
* 5:多日期 * 5:多日期
*/ */
...@@ -150,6 +162,8 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -150,6 +162,8 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
dto.setEmployeeId(planVo.getEmployeeId()); dto.setEmployeeId(planVo.getEmployeeId());
dto.setEmployeeNo(planVo.getEmployeeNo()); dto.setEmployeeNo(planVo.getEmployeeNo());
dto.setEmployeeName(planVo.getEmployeeName()); dto.setEmployeeName(planVo.getEmployeeName());
dto.setOrgQcId(planVo.getDeptQcId());
dto.setOrgName(planVo.getDeptQcName());
} }
/** /**
...@@ -161,7 +175,9 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -161,7 +175,9 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
if (ObjectUtil.isEmpty(storeDto)) { if (ObjectUtil.isEmpty(storeDto)) {
dto.setErrorMsg("门店编码错误;"); dto.setErrorMsg("门店编码错误;");
} else { } else {
// todo 门店一定有系统名称? if (StringUtils.isAnyBlank(storeDto.getLineName(), storeDto.getDealersName(), storeDto.getDealerId())) {
dto.setErrorMsg("门店系统名称或经销商为空,请到勤策中进充;");
}
dto.setLineName(storeDto.getLineName()); dto.setLineName(storeDto.getLineName());
dto.setStoreCode(sc); dto.setStoreCode(sc);
dto.setStoreName(storeDto.getStoreName()); dto.setStoreName(storeDto.getStoreName());
...@@ -183,39 +199,34 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -183,39 +199,34 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
dto.setErrorMsg("活动模式分为:单点CP、常规MINI秀、校园活动;"); dto.setErrorMsg("活动模式分为:单点CP、常规MINI秀、校园活动;");
} }
/**
* 4:月份
* 年份 todo 以后判断是否跨年
*/
int year = DateUtil.thisYear();
Month month = Month.of(Integer.parseInt(row.get(4).toString()));
LocalDate planDate = LocalDate.of(year, month, day);
dto.setYear(year).setMonth(planDate.getMonthValue()).setDate(DateUtils.parseDateBylocalDate(planDate));
if (planDate.isBefore(LocalDate.now())) {
dto.setErrorMsg("不能是过去日期;");
}
/**
* 6:促销员上班时间
*/
LocalTime inLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(6).toString());
/** /**
* 4:月份 新增逻辑只支持次月计划;
* 6:促销员上班时间 当月份错误,促销员上下班时间也不进行计算
* 7:促销员下班时间 * 7:促销员下班时间
* 年份:当月份为1时,判定为跨年
*/ */
LocalTime outLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(7).toString()); int year = DateUtil.thisYear();
int monthInt = Integer.parseInt(row.get(4).toString());
if (ObjectUtils.anyNull(inLocalTime, outLocalTime)) { Month month = Month.of(monthInt);
dto.setErrorMsg("上下班时间必填;"); if (month.equals(Month.JANUARY)) {
year += 1;
} }
LocalDate planDate = LocalDate.of(year, month, day);
if (ObjectUtils.allNotNull(inLocalTime, outLocalTime) && inLocalTime.isAfter(outLocalTime)) { if (monthInt != nextMonthValue) {
dto.setErrorMsg("下班时间需晚于上班时间;"); dto.setErrorMsg("月份必需是下个月;");
} else { } else {
dto.setClockInTime(LocalDateTime.of(planDate, inLocalTime)); dto.setYear(year).setMonth(planDate.getMonthValue()).setDate(DateUtils.parseDateBylocalDate(planDate));
dto.setClockOutTime(LocalDateTime.of(planDate, outLocalTime)); LocalTime inLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(6).toString());
LocalTime outLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(7).toString());
if (ObjectUtils.anyNull(inLocalTime, outLocalTime)) {
dto.setErrorMsg("上下班时间必填;");
}
if (ObjectUtils.allNotNull(inLocalTime, outLocalTime) && inLocalTime.isAfter(outLocalTime)) {
dto.setErrorMsg("下班时间需晚于上班时间;");
} else {
dto.setClockInTime(LocalDateTime.of(planDate, inLocalTime));
dto.setClockOutTime(LocalDateTime.of(planDate, outLocalTime));
}
} }
// 8:工资 // 8:工资
...@@ -223,6 +234,12 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService { ...@@ -223,6 +234,12 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
// 9:杂费 // 9:杂费
dto.setIncidentals(new BigDecimal(row.get(9).toString())); dto.setIncidentals(new BigDecimal(row.get(9).toString()));
// 判断计划是否已存在
ActivityPlanInfoDto hasDto = activityPlanInfoDao.selectPlan(dto.getStoreCode(), dto.getDate());
if (Objects.nonNull(hasDto)) {
dto.setErrorMsg("此计划已存在,创建人:" + hasDto.getEmployeeName() + ",创建时间:" + DateUtil.formatDate(hasDto.getCreateTime()) + ";");
}
} catch (DateTimeException e) { } catch (DateTimeException e) {
dto.setErrorMsg("月份、日期、时间需要调整;"); dto.setErrorMsg("月份、日期、时间需要调整;");
} }
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
<result property="province" column="province" jdbcType="VARCHAR"/> <result property="province" column="province" jdbcType="VARCHAR"/>
<result property="city" column="city" jdbcType="VARCHAR"/> <result property="city" column="city" jdbcType="VARCHAR"/>
<result property="area" column="area" jdbcType="VARCHAR"/> <result property="area" column="area" jdbcType="VARCHAR"/>
<result property="street" column="street" jdbcType="VARCHAR"/>
<result property="addr" column="addr" jdbcType="VARCHAR"/> <result property="addr" column="addr" jdbcType="VARCHAR"/>
<result property="planStatus" column="plan_status" jdbcType="INTEGER"/> <result property="planStatus" column="plan_status" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
...@@ -34,6 +33,13 @@ ...@@ -34,6 +33,13 @@
<result property="isDelete" column="is_delete" jdbcType="INTEGER"/> <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
</resultMap> </resultMap>
<resultMap id="PlanBase" type="com.wangxiaolu.promotion.domain.activityplanv2.mapper.entity.ActivityPlanInfoDo">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="employeeName" column="employee_name" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,plan_file_id,employee_id, id,plan_file_id,employee_id,
employee_name,employee_no,year, employee_name,employee_no,year,
...@@ -48,17 +54,22 @@ ...@@ -48,17 +54,22 @@
<insert id="saveList"> <insert id="saveList">
INSERT INTO activity_plan_info INSERT INTO activity_plan_info
(plan_file_id,employee_id,employee_name,employee_no,year,month,date,line_name,store_name,store_code,org_qc_id,org_name,pattern_id,pattern,dealer_id,dealer_name,both_t,province,city,area,street,addr,clock_in_time,clock_out_time,salary,incidentals) (plan_file_id,employee_id,employee_name,employee_no,year,month,date,line_name,store_name,store_code,org_qc_id,org_name,pattern_id,pattern,dealer_id,dealer_name,both_t,province,city,area,addr,clock_in_time,clock_out_time,salary,incidentals)
VALUES VALUES
<foreach collection="table" item="item" index="index" separator=","> <foreach collection="table" item="item" index="index" separator=",">
(#{recordId}, #{item.employeeId}, #{item.employeeName}, #{item.employeeNo}, #{item.year}, (#{recordId}, #{item.employeeId}, #{item.employeeName}, #{item.employeeNo}, #{item.year},
#{item.month}, FROM_UNIXTIME(#{item.date} / 1000), #{item.lineName}, #{item.storeName}, #{item.storeCode}, #{item.month}, FROM_UNIXTIME(#{item.date} / 1000), #{item.lineName}, #{item.storeName}, #{item.storeCode},
'', #{item.orgQcId},#{item.orgName}, 0, #{item.pattern}, #{item.dealerId}, #{item.dealerName}, '未确定',
'', 0, #{item.pattern}, #{item.dealerId}, #{item.dealerName}, '未确定', #{item.province}, #{item.city}, #{item.area}, #{item.addr},
#{item.province}, #{item.city}, #{item.area}, #{item.street}, #{item.addr},
FROM_UNIXTIME(#{item.clockInTime} / 1000), FROM_UNIXTIME(#{item.clockOutTime} / 1000), #{item.salary}, FROM_UNIXTIME(#{item.clockInTime} / 1000), FROM_UNIXTIME(#{item.clockOutTime} / 1000), #{item.salary},
#{item.incidentals}) #{item.incidentals})
</foreach> </foreach>
</insert> </insert>
<select id="selectPlan" resultMap="BaseResultMap">
select employee_name, create_time
from activity_plan_info
where date = #{date} and store_code = #{storeCode} and is_delete = 1;
</select>
</mapper> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论