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

获取阿里云sts_token,职能角色上传计划

上级 6925b5c2
......@@ -245,6 +245,13 @@
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun.oss.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>sts20150401</artifactId>
<version>${aliyun.sts.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -30,7 +30,7 @@ public class PromPlanCoreController {
/**
* 城市经理 - 上传计划
* 城市经理 - 上传计划(新增)
* 当月只能上传次月的新增(当月需要新增需要交由职能角色上传)
*/
@PostMapping("/self/upload")
......@@ -61,39 +61,61 @@ public class PromPlanCoreController {
}
}
@GetMapping("/self/upload/{uuid}")
/**
* todo 城市经理修改
*/
/**
* todo 职能角色修改
*/
/**
* 职能角色 - 上传计划(新增)
*/
@PostMapping("/auth/upload")
public R authPlan(@RequestBody ActivityPlanVo activityPlanVo) {
// 判断当前账号是否是城市经理
boolean isAuth = manageEmployeeQueryService.isAuth(activityPlanVo.getEmployeeId());
if (!isAuth) {
throw new DataException(RCode.EMP_PRIVILEGE_ERROR);
}
try {
String[] urlArr = activityPlanVo.getExcelUrl().split("weda-uploader/");
String fileId = urlArr[urlArr.length - 1];
if (fileId.length() > 53) {
throw new DataException(RCode.ACTIVITY_PLAN_FILENAME_LONG);
}
String filePath = "/home/" + fileId;
FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// todo String filePath = "/Users/a02200059/Desktop/职能角色-新增-1.xlsx";
activityPlanVo.setExcelId(fileId);
Map<String, Object> map = promPlanCoreService.authPlanUp(activityPlanVo, filePath);
return R.success(map);
} catch (DataException e) {
return new R(e.getCode(), e.getMsg(), null);
} catch (Exception e) {
return R.fail();
}
}
/**
* 确认上传(根据任一UUID)
*/
@GetMapping("/upload/{uuid}")
public R selfPlanAf(@PathVariable("uuid") String planUuid){
promPlanCoreService.selfPlanAf(planUuid);
return R.success();
}
/**
* 职能角色 - 上传计划
*/
@GetMapping("/auth/upload")
public void authPlan(@RequestBody ActivityPlanVo activityPlanVo) {
// 判断当前账号是否是城市经理
// boolean isSelf = manageEmployeeQueryService.isOneSelf(activityPlanVo.getEmployeeId());
// if (!isSelf) {
// throw new DataException(RCode.EMP_PRIVILEGE_ERROR);
// }
//
// try {
// String[] urlArr = activityPlanVo.getExcelUrl().split("weda-uploader/");
// String fileId = urlArr[urlArr.length - 1];
// if (fileId.length() > 53) {
// throw new DataException(RCode.ACTIVITY_PLAN_FILENAME_LONG);
// }
//
// String filePath = "/home/" + fileId;
// FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// String filePath = "/Users/a02200059/Desktop/测试新增v3 2.xlsx";
// activityPlanVo.setExcelId(fileId);
// Map<String, Object> map = promPlanCoreService.selfPlanUp(activityPlanVo, filePath);
// return R.success(map);
// } catch (DataException e) {
// return new R(e.getCode(), e.getMsg(), null);
}
/**
* 删除计划 计划日期大于今日可直接删除,如果计划日期是今日则必需是10点之前,包含过去日期不可删除
......
package com.wangxiaolu.promotion.controller.yun;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.utils.AliyunUtils;
......@@ -10,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
/**
* @author : liqiulin
* @date : 2025-02-06 13
......@@ -31,4 +32,14 @@ public class AliyunGetToken {
return R.fail();
}
}
@GetMapping("/sts_token")
public R getStsToken() {
try {
String stsToken = aliyunUtils.getStsToken();
return R.success(stsToken);
} catch (Exception e) {
return R.fail(e.getMessage());
}
}
}
......@@ -26,4 +26,6 @@ public interface ManageEmployeeInfoDao {
void updateAccount(String employeeNo, Integer privilegeId, String status);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......@@ -92,6 +92,11 @@ public class ManageEmployeeInfoInfoDaoImpl implements ManageEmployeeInfoDao {
return manageEmployeeInfoMapper.isOneSelf(employeeId);
}
@Override
public boolean isAuth(Integer employeeId) {
return manageEmployeeInfoMapper.isAuth(employeeId);
}
/**
* 增加权限
*/
......
......@@ -29,6 +29,7 @@ public interface ManageEmployeeInfoMapper extends BaseMapper<ManageEmployeeInfoD
void updatePrivilege(@Param("employeeNo") String employeeNo,@Param("privilegeId") Integer privilegeId);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......
......@@ -18,4 +18,5 @@ public interface PromPlanCoreService {
void deletePlan(List<Long> planIds);
Map<String, Object> authPlanUp(ActivityPlanVo activityPlanVo, String filePath);
}
......@@ -8,6 +8,8 @@ import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.excel.ReadExcelUtils;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.domain.activity.dao.ManageEmployeeInfoDao;
import com.wangxiaolu.promotion.domain.activity.wrapperQo.ManageEmployeeWrapper;
import com.wangxiaolu.promotion.domain.activityplanv2.dao.ActivityPlanInfoDao;
import com.wangxiaolu.promotion.domain.activityplanv2.dao.ActivityPlanRecordDao;
import com.wangxiaolu.promotion.domain.user.dao.QinCeClienteleStoreDao;
......@@ -16,6 +18,7 @@ import com.wangxiaolu.promotion.exception.DataException;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.ActivityPlanInfoDto;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.ActivityPlanRecordDto;
import com.wangxiaolu.promotion.pojo.activity.manage.vo.ActivityPlanVo;
import com.wangxiaolu.promotion.pojo.user.dto.ManageEmployeeInfoDto;
import com.wangxiaolu.promotion.pojo.user.dto.QinCeClienteleStoreDto;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.activityplanv2.PromPlanCoreService;
......@@ -45,8 +48,13 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
@Autowired
private ActivityPlanInfoDao activityPlanInfoDao;
@Autowired
private ManageEmployeeInfoDao manageEmployeeInfoDao;
@Autowired
private RedisCache redisCache;
/**
* 城市经理 - 上传计划
*/
@Override
public Map<String, Object> selfPlanUp(ActivityPlanVo planVo, String filePath) throws DataException {
// 1、解析活动计划文件是否符合规范
......@@ -92,6 +100,31 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
activityPlanInfoDao.deleteByPlanIds(planIds);
}
/**
* 职能角色 - 上传计划
*/
@Override
public Map<String, Object> authPlanUp(ActivityPlanVo planVo, String filePath) {
// 1、解析活动计划文件是否符合规范
Map<String, Object> map = readSheetByZNJSUp(planVo, filePath);
if (!map.containsKey("uuid")){
return map;
}
// 2、生成uuid并关联上传记录
ActivityPlanRecordDto record = new ActivityPlanRecordDto()
.setEmployeeId(planVo.getEmployeeId())
.setEmployeeName(planVo.getEmployeeName())
.setEmployeeNo(planVo.getEmployeeNo())
.setExcelUrl(planVo.getExcelUrl())
.setExcelFiledId(planVo.getExcelId());
map.put("record", record);
// 保存到缓存(uuid)
redisCache.addToJsonToMinute(RedisKeys.Manage.ACTIVITY_PLAN_UP.getKey()+map.get("uuid").toString(),map,30);
// 返回结果
return map;
}
/**
* 解析excel文件中的计划
* @param planVo 请求信息(包含人员信息)
......@@ -120,7 +153,7 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
indexList.add(row.getKey() + 1);
}
}
if (isEmpty) {
if (CollectionUtil.isNotEmpty(indexList)) {
throw new DataException(RCode.ACTIVITY_PLAN_CELL_NOT_NULL, indexList);
}
......@@ -136,6 +169,185 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
return rMap;
}
/**
* 解析excel文件中的计划
* @param planVo 请求信息(包含人员信息)
* @param filePath 文件地址
* @throws DataException 数据异常
*/
private Map<String, Object> readSheetByZNJSUp(ActivityPlanVo planVo, String filePath) throws DataException {
ReadExcelUtils readExcelUtils = new ReadExcelUtils(filePath);
String[] headers = readExcelUtils.readTitle();
Map<Integer, List<Object>> rows = readExcelUtils.readContent();
if (headers.length != 10) {
throw new DataException(RCode.ACTIVITY_PLAN_TEM_ERROR);
}
if (CollectionUtil.isEmpty(rows)) {
throw new DataException(RCode.DATA_NOT_HAVE_ERROR);
}
boolean isEmpty = false;
ArrayList<Integer> indexList = new ArrayList<>();
for (Map.Entry<Integer, List<Object>> row : rows.entrySet()) {
List<Object> cells = row.getValue();
// 判断当前行是否有任一数据为空,如果有则报错,不进行解析
isEmpty = (cells.size() != 10) || cells.stream().anyMatch(cell -> ObjectUtil.isNull(cell) || StringUtils.isBlank(cell.toString()));
if (isEmpty) {
indexList.add(row.getKey() + 1);
}
}
if (CollectionUtil.isNotEmpty(indexList)) {
throw new DataException(RCode.ACTIVITY_PLAN_CELL_NOT_NULL, indexList);
}
Map<String, Object> rMap = new HashMap<>();
rMap.put("uuid", UUID.randomUUID().toString());
List<ActivityPlanInfoDto> rDtos = new ArrayList<>(rows.size() * 4);
for (Map.Entry<Integer, List<Object>> row : rows.entrySet()) {
List<ActivityPlanInfoDto> infoDtos = getRowByZNJSUp(planVo, row.getValue(),rMap);
rDtos.addAll(infoDtos);
}
rMap.put("table", rDtos);
return rMap;
}
/**
* 城市经理上传的计划工号只能是自己
* @param row 表中的每一行数据
* @return
*/
private List<ActivityPlanInfoDto> getRowByZNJSUp(ActivityPlanVo planVo, List<Object> row,Map<String, Object> rMap) {
List<ActivityPlanInfoDto> dtos = new ArrayList<>();
LocalDate now = LocalDate.now();
int monthValue = now.getMonthValue();
int nextMonthValue = now.plusMonths(1).getMonthValue();
/**
* 5:多日期
*/
String days = row.get(5).toString();
String[] dayArr = days.split("、");
for (int i = 0; i < dayArr.length; i++) {
ActivityPlanInfoDto dto = new ActivityPlanInfoDto();
try {
String dayStr = dayArr[i];
int day = Integer.parseInt(dayStr);
/**
* 0:工号
*/
Object empNoO = row.get(0);
if (planVo.getEmployeeNo().equals(empNoO.toString())) {
dto.setErrorMsg("不能填写自己的工号;");
} else {
// 查询当前工号的人员信息
ManageEmployeeInfoDto employeeInfoDto = manageEmployeeInfoDao.selectOne(new ManageEmployeeWrapper().setEmployeeNo(empNoO.toString()));
if (Objects.isNull(employeeInfoDto)) {
dto.setErrorMsg("员工不存在或被禁用;");
} else {
dto.setEmployeeId(employeeInfoDto.getId());
dto.setEmployeeNo(employeeInfoDto.getEmployeeNo());
dto.setEmployeeName(employeeInfoDto.getName());
dto.setOrgQcId(employeeInfoDto.getDeptQcId());
dto.setOrgName(employeeInfoDto.getDeptQcName());
}
}
/**
* 1:门店编码
*/
String sc = row.get(1).toString();
StoreWrapper storeWrap = new StoreWrapper().setStoreCode(sc);
QinCeClienteleStoreDto storeDto = qinCeClienteleStoreDao.getOneStore(storeWrap);
if (ObjectUtil.isEmpty(storeDto)) {
dto.setErrorMsg("门店编码错误;");
} else {
if (StringUtils.isAnyBlank(storeDto.getLineName(), storeDto.getDealersName(), storeDto.getDealerId())) {
dto.setErrorMsg("门店「系统名称」或「经销商」为空,请到勤策中进充;");
}
dto.setLineName(storeDto.getLineName());
dto.setStoreCode(sc);
dto.setStoreName(storeDto.getStoreName());
dto.setDealerId(storeDto.getDealerId());
dto.setDealerName(storeDto.getDealersName());
dto.setProvince(storeDto.getStoreMssProvince());
dto.setCity(storeDto.getStoreMssCity());
dto.setArea(storeDto.getStoreMssArea());
dto.setAddr(storeDto.getStoreAddr());
}
/**
* 3:活动模式
*/
String pattern = row.get(3).toString();
if ("单点CP,常规MINI秀,校园活动".contains(pattern)) {
dto.setPattern(pattern);
} else {
dto.setErrorMsg("活动模式分为:单点CP、常规MINI秀、校园活动;");
}
/**
* 4:月份 新增逻辑只支持次月计划;
* 6:促销员上班时间 当月份错误,促销员上下班时间也不进行计算
* 7:促销员下班时间
* 年份:当月份为1时,判定为跨年
*/
int year = DateUtil.thisYear();
int monthInt = Integer.parseInt(row.get(4).toString());
Month month = Month.of(monthInt);
if (month.equals(Month.JANUARY)) {
year += 1;
}
LocalDate planDate = LocalDate.of(year, month, day);
if (monthInt != nextMonthValue || monthInt != monthValue) {
dto.setErrorMsg("月份只能是当月或次月;");
} else if (planDate.isBefore(LocalDate.now())) {
dto.setErrorMsg("日期不能是以前;");
} else {
dto.setYear(year).setMonth(planDate.getMonthValue()).setDate(DateUtils.parseDateBylocalDate(planDate));
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:工资
dto.setSalary(new BigDecimal(row.get(8).toString()));
// 9:杂费
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) {
dto.setErrorMsg("月份、日期、时间需要调整;");
}
if (StringUtils.isNotBlank(dto.getErrorMsg())){
rMap.remove("uuid");
}
dtos.add(dto);
}
return dtos;
}
/**
* 城市经理上传的计划工号只能是自己
* @param row 表中的每一行数据
......@@ -181,7 +393,7 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
dto.setErrorMsg("门店编码错误;");
} else {
if (StringUtils.isAnyBlank(storeDto.getLineName(), storeDto.getDealersName(), storeDto.getDealerId())) {
dto.setErrorMsg("门店系统名称或经销商为空,请到勤策中进充;");
dto.setErrorMsg("门店「系统名称」或「经销商」为空,请到勤策中进充;");
}
dto.setLineName(storeDto.getLineName());
dto.setStoreCode(sc);
......@@ -210,16 +422,14 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
* 7:促销员下班时间
* 年份:当月份为1时,判定为跨年
*/
int year = DateUtil.thisYear();
int monthInt = Integer.parseInt(row.get(4).toString());
Month month = Month.of(monthInt);
if (month.equals(Month.JANUARY)) {
year += 1;
}
LocalDate planDate = LocalDate.of(year, month, day);
if (monthInt != nextMonthValue) {
dto.setErrorMsg("月份必需是下个月;");
} else {
if (monthInt == nextMonthValue) {
int year = DateUtil.thisYear();
Month month = Month.of(monthInt);
if (month.equals(Month.JANUARY)) {
year += 1;
}
LocalDate planDate = LocalDate.of(year, month, day);
dto.setYear(year).setMonth(planDate.getMonthValue()).setDate(DateUtils.parseDateBylocalDate(planDate));
LocalTime inLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(6).toString());
LocalTime outLocalTime = DateUtils.parseLocalTimeByEmdtime(row.get(7).toString());
......@@ -232,6 +442,8 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
dto.setClockInTime(LocalDateTime.of(planDate, inLocalTime));
dto.setClockOutTime(LocalDateTime.of(planDate, outLocalTime));
}
} else {
dto.setErrorMsg("月份必需是下个月;");
}
// 8:工资
......@@ -242,7 +454,7 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
// 判断计划是否已存在
ActivityPlanInfoDto hasDto = activityPlanInfoDao.selectPlan(dto.getStoreCode(), dto.getDate());
if (Objects.nonNull(hasDto)) {
dto.setErrorMsg("计划已存在,创建人:" + hasDto.getEmployeeName() + ",创建时间:" + DateUtil.formatDate(hasDto.getCreateTime()) + ";");
dto.setErrorMsg("计划已存在,创建人:" + hasDto.getEmployeeName() + ",创建时间:" + DateUtil.formatDate(hasDto.getCreateTime()) + ";");
}
} catch (DateTimeException e) {
......@@ -257,4 +469,7 @@ public class PromPlanCoreServiceImpl implements PromPlanCoreService {
return dtos;
}
}
......@@ -23,4 +23,6 @@ public interface ManageEmployeeQueryService {
boolean hasByEmpNo(String employeeNo);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......@@ -62,4 +62,9 @@ public class ManageEmployeeQueryServiceImpl implements ManageEmployeeQueryServic
public boolean isOneSelf(Integer employeeId) {
return manageEmployeeInfoDao.isOneSelf(employeeId);
}
@Override
public boolean isAuth(Integer employeeId) {
return manageEmployeeInfoDao.isAuth(employeeId);
}
}
......@@ -14,6 +14,7 @@ import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.aliyun.sts20150401.Client;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
......@@ -53,11 +54,11 @@ public class AliyunUtils {
public JSONObject getSignature() throws JsonProcessingException {
//获取发送STS请求基础信息
//环境变量中获取access_key_id
//获取access_key_id
String accessKeyId = OSS_ACCESS_KEY_ID;
//环境变量中获取access_key_secret
//获取access_key_secret
String accessKeySecret = OSS_ACCESS_KEY_SECRET;
//环境变量中获取ARN
//获取ARN
String roleArnForOssUpload = OSS_STS_ROLE_ARN;
//色会话名称,用来区分不同的令牌,可自定义
String roleSessionName = YOUR_ROLE_SESSION_NAME;
......@@ -180,4 +181,22 @@ public class AliyunUtils {
throw new RuntimeException("Failed to calculate HMAC-SHA256", e);
}
}
public String getStsToken() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(OSS_ACCESS_KEY_ID)
.setAccessKeySecret(OSS_ACCESS_KEY_SECRET);
config.endpoint = "sts." + REGION_ID + ".aliyuncs.com";
Client client = new Client(config);
com.aliyun.sts20150401.models.AssumeRoleRequest assumeRoleRequest = new com.aliyun.sts20150401.models.AssumeRoleRequest()
.setDurationSeconds(3600L)
.setRoleArn(OSS_STS_ROLE_ARN)
.setRoleSessionName("000516");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.sts20150401.models.AssumeRoleResponse assumeRoleResponse = client.assumeRoleWithOptions(assumeRoleRequest, runtime);
return assumeRoleResponse.body.getCredentials().getSecurityToken();
}
}
\ No newline at end of file
......@@ -67,8 +67,15 @@
where employee_id = (select id from manage_employee_info where employee_no = #{employeeNo});
</update>
<!-- 权限(1:oneself,2:admin)-->
<select id="isOneSelf" resultType="boolean">
select count(*) > 0
from manage_employee_ref_privilege where employee_id = #{employeeId} and privilege_id = 1;
</select>
<!-- 权限(1:oneself,2:admin)-->
<select id="isAuth" resultType="boolean">
select count(*) > 0
from manage_employee_ref_privilege where employee_id = #{employeeId} and privilege_id = 2;
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论