备份高德基础代码

This commit is contained in:
lulz1 2024-04-16 15:08:47 +08:00
parent 1c92c4332e
commit 502774614e
17 changed files with 422 additions and 5 deletions

View File

@ -0,0 +1,15 @@
package com.chint.application.dtos;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class SystemAnnouncementDTO {
private String title; // 公告的标题
private String content; // 公告的详细内容
private String postedBy; // 发布公告的用户或管理员的用户名
private LocalDateTime postDate; // 公告发布的日期和时间
private LocalDateTime expiryDate; // 公告的过期日期
private Integer priority; // 公告的优先级用于排序
}

View File

@ -0,0 +1,54 @@
package com.chint.application.system;
import com.chint.application.dtos.SystemAnnouncementDTO;
import com.chint.domain.aggregates.system.SystemAnnouncement;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.SystemAnnouncementRepository;
import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@Slf4j
@RestController
@RequestMapping("/system")
public class SystemController {
@Autowired
private SystemAnnouncementRepository systemAnnouncementRepository;
@ApiOperation("新增公告")
@PostMapping("/announcement/save")
public Result<SystemAnnouncement> save(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
SystemAnnouncement systemAnnouncement = SystemAnnouncement.of(systemAnnouncementDTO);
return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement));
}
@ApiOperation("查询最新公告")
@PostMapping("/announcement/query/last")
public Result<SystemAnnouncement> queryLastAnnouncement() {
return Result.Success(SUCCESS, systemAnnouncementRepository.findNew().orElseThrow(() -> new NotFoundException(NOT_FOUND)));
}
@ApiOperation("查询有效公告")
@PostMapping("/announcement/query/effective")
public Result<List<SystemAnnouncement>> queryEffectiveAnnouncement() {
// List<SystemAnnouncement> effective = systemAnnouncementRepository.findEffective();
//
// effective.forEach(it->{
//
// });
//
// return Result.Success(SUCCESS, systemAnnouncementRepository.findNew().orElseThrow(() -> new NotFoundException(NOT_FOUND)));
return null;
}
}

View File

@ -20,7 +20,6 @@ public class Client implements Serializable {
private Long id;
private String clientId;
private String clientSecret;
private Integer clientType;
private Integer systemCodeId;
}

View File

@ -158,6 +158,7 @@ public class RouteOrder implements Serializable {
}
if (data.getBelongDeptCode() != null) {
orderExtensionField.setBelongDeptCode(data.getBelongDeptCode());
this.setRouterOrderExtensionField(orderExtensionField);
}
parseAndSetTime(data.getStartTime(), true);

View File

@ -0,0 +1,49 @@
package com.chint.domain.aggregates.system;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.dtos.SystemAnnouncementDTO;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@Table("system_announcements")
public class SystemAnnouncement implements Serializable {
@Serial
private static final long serialVersionUID = 1993629455989054214L;
@Id
private Long announcementId; // 公告的唯一标识符
private String title; // 公告的标题
private String content; // 公告的详细内容
private String postedBy; // 发布公告的用户或管理员的用户名
private LocalDateTime postDate; // 公告发布的日期和时间
private LocalDateTime expiryDate; // 公告的过期日期
private String status; // 公告的状态
private Integer priority; // 公告的优先级用于排序
public static SystemAnnouncement of(SystemAnnouncementDTO dto) {
SystemAnnouncement systemAnnouncement = BeanUtil.copyProperties(dto, SystemAnnouncement.class);
if (systemAnnouncement.getPostDate() == null) {
systemAnnouncement.setPostDate(LocalDateTime.now());
}
if (systemAnnouncement.getExpiryDate() == null) {
systemAnnouncement.setExpiryDate(LocalDateTime.now().plusDays(15L));
}
systemAnnouncement.setStatus("1");
systemAnnouncement.setPriority(0);
User currentUser = BaseContext.getCurrentUser();
if (currentUser != null) {
systemAnnouncement.setPostedBy(currentUser.getEmployeeNo() == null ? "unknown" : currentUser.getEmployeeNo());
} else {
systemAnnouncement.setPostedBy("unknown");
}
return systemAnnouncement;
}
}

View File

@ -0,0 +1,16 @@
package com.chint.domain.repository;
import com.chint.domain.aggregates.system.SystemAnnouncement;
import java.util.List;
import java.util.Optional;
public interface SystemAnnouncementRepository {
SystemAnnouncement save(SystemAnnouncement systemAnnouncement);
Optional<SystemAnnouncement> findNew();
List<SystemAnnouncement> findAll();
List<SystemAnnouncement> findEffective();
}

View File

@ -0,0 +1,8 @@
package com.chint.infrastructure.constant;
public class AmapConstant {
public static final String USER_CREATE_PATH = "/ws/boss/enterprise/openapi/employee/create";
public static final String USER_UPDATE_PATH = "/ws/boss/enterprise/openapi/employee/query";
public static final String USER_QUERY_PATH = "/ws/boss/enterprise/openapi/employee/update";
public static final String USER_DELETE_PATH = "/ws/boss/enterprise/openapi/employee/delete";
}

View File

@ -0,0 +1,41 @@
package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.system.SystemAnnouncement;
import com.chint.domain.repository.SystemAnnouncementRepository;
import com.chint.infrastructure.repository.jdbc.JdbcSystemAnnouncementRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Repository
public class SystemAnnouncementRepositoryImpl implements SystemAnnouncementRepository {
@Autowired
private JdbcSystemAnnouncementRepository jdbcSystemAnnouncementRepository;
@Override
public SystemAnnouncement save(SystemAnnouncement systemAnnouncement) {
return jdbcSystemAnnouncementRepository.save(systemAnnouncement);
}
@Override
public Optional<SystemAnnouncement> findNew() {
return jdbcSystemAnnouncementRepository.findTopByOrderByAnnouncementIdDesc();
}
@Override
public List<SystemAnnouncement> findAll() {
List<SystemAnnouncement> res = new ArrayList<>();
jdbcSystemAnnouncementRepository.findAll().forEach(res::add);
return res;
}
@Override
public List<SystemAnnouncement> findEffective() {
return jdbcSystemAnnouncementRepository.findByStatus("1");
}
}

View File

@ -0,0 +1,15 @@
package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.system.SystemAnnouncement;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface JdbcSystemAnnouncementRepository extends CrudRepository<SystemAnnouncement, Long> {
Optional<SystemAnnouncement> findTopByOrderByAnnouncementIdDesc();
List<SystemAnnouncement> findByStatus(String status);
}

View File

@ -1,16 +1,23 @@
package com.chint.infrastructure.util;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
@Deprecated
public class SignUtils {
private SignUtils() {
}
private static final String DIGEST_TYPE = "HmacSha256";
@ -42,7 +49,7 @@ public class SignUtils {
for (int i = 0; i < bytes.length; i++) {
temp = Integer.toHexString(bytes[i] & 0xFF);
if (temp.length() == 1) {
//1得到一位的进行补0操作
//1得到一位的进行补0操作
stringBuffer.append("0");
}
stringBuffer.append(temp);
@ -50,4 +57,46 @@ public class SignUtils {
return stringBuffer.toString().toUpperCase();
}
public static String generateSignature(Object obj, String signKey) throws Exception {
Class<?> clazz = obj.getClass();
Field[] fields = clazz.getDeclaredFields();
//获取上一级父类的字段
Class<?> parentClazz = clazz.getSuperclass();
Field[] parentFields = parentClazz.getDeclaredFields();
List<Field> fieldArrayList = new ArrayList<>(fields.length + parentFields.length);
fieldArrayList.addAll(Arrays.asList(fields));
fieldArrayList.addAll(Arrays.asList(parentFields));
fieldArrayList.sort(Comparator.comparing(Field::getName));
StringJoiner joiner = new StringJoiner("&");
for (Field field : fieldArrayList) {
// Ensure the field is accessible
field.setAccessible(true);
String fieldName = field.getName();
String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
Method method;
try {
method = clazz.getMethod(methodName);
} catch (NoSuchMethodException e) {
continue; // If there's no getter method, skip this field
}
Object value = method.invoke(obj);
if (value != null && !fieldName.equals("sign")) { // Skip the 'sign' field
// URL-encode the value to handle special characters
// String encodedValue = URLEncoder.encode(value.toString(), StandardCharsets.UTF_8);
joiner.add(fieldName + "=" + value);
}
}
String res = joiner + "@" + signKey;
return Hashing.md5().hashString(res, Charsets.UTF_8).toString().toUpperCase();
}
}

View File

@ -0,0 +1,69 @@
package com.chint.interfaces.rest.amap;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.UserNameRepository;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.user.UserHttpRequest;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import static com.chint.infrastructure.constant.AmapConstant.USER_CREATE_PATH;
@Component
public class AmapUserRequest {
@Autowired
private PostRequest postRequest;
@Autowired
private UserNameRepository userNameRepository;
@Autowired
private UserHttpRequest userHttpRequest;
@Value("${amap.eId}")
private Integer eId;
@Value("${amap.baseUrl}")
private String BaseUrl;
@Value("${amap.signKey}")
private String signKey;
public BaseResponse createUser(User user) {
String createUserUrl = BaseUrl + USER_CREATE_PATH;
BaseRequestParam baseRequestParam = createUserParamByUser(user).generateSign(signKey);
return postRequest.post(createUserUrl, baseRequestParam, BaseResponse.class);
}
@Data
public static class UserParam extends BaseRequestParam {
private String userId; // 用户Id
private String mobile; // 手机号
// The rest of the fields as defined in your request body image
private String cardId;
private String realName;
private String departmentId;
private String immediateSuperiorUserId;
private String email;
private Integer status;
private String extInfo;
private String baseAdCode;
private String employeeGroupName;
private String regulationList;
private String projectIdList;
}
public UserParam createUserParamByUser(User user) {
UserParam userParam = new UserParam();
userParam.setEid(eId);
userParam.setUserId(user.getEmployeeNo());
userParam.setEmail(user.getEmail());
userParam.setMobile(user.getPhoneNumber());
userParam.setRealName(user.getName());
return userParam;
}
}

View File

@ -0,0 +1,28 @@
package com.chint.interfaces.rest.amap;
import com.chint.infrastructure.util.SignUtils;
import lombok.Data;
@Data
public class BaseRequestParam {
// 应用ID根据业务场景填写
private String appId;
// 设备ID某些业务场景下需要
private Integer eid;
// 企业编号根据企业分配
private Integer ent;
// 请求签名保障请求安全
private String sign;
// 时间戳标记请求发送时间
private String timestamp;
public BaseRequestParam generateSign(String signKey) {
try {
String sign = SignUtils.generateSignature(this, signKey);
this.sign = sign;
return this;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,17 @@
package com.chint.interfaces.rest.amap;
import lombok.Data;
@Data
public class BaseResponse {
// 响应代码0表示成功其他值表示错误
private Integer code;
// 响应消息"Success"或错误信息
private String message;
// 返回的数据对象具体内容根据业务定义
private Object data;
// 响应时间戳标记响应生成时间
private long timestamp;
// 跟踪ID用于日志跟踪等
private String traceId;
}

View File

@ -45,6 +45,16 @@ ly:
ifForwardRequest: false
forwardRequestBaseUrl: https://secureqrdev-t.chint.com/llz
#高德
amap:
eId: 612660
appId: car_zhengtecm3noxh
key: a1vxgdwobkphirln5fgup0oj6e2rsniw
keyt: car_zhengtecm3noxh
signKey: ngwdzlembqju9lairthw264bzkhw2vto
aesKey: 7eEdUzuVflM8n9Wo
baseUrl: https://sns.testing.amap.com
sf:
openApiBaseUrl: https://openapi.chintcloud.net
akBaseUrl: https://transitbridge.chint.com

View File

@ -42,6 +42,16 @@ ly:
ifForwardRequest: true
forwardRequestBaseUrl: https://gxdev03.chint.com/routeapi
#高德
amap:
eId: 612660
appId: car_zhengtecm3noxh
key: a1vxgdwobkphirln5fgup0oj6e2rsniw
keyt: car_zhengtecm3noxh
signKey: ngwdzlembqju9lairthw264bzkhw2vto
aesKey: 7eEdUzuVflM8n9Wo
baseUrl: https://sns.testing.amap.com
sf:
openApiBaseUrl: https://openapi.chint.com
akBaseUrl: https://transitbridge.chint.com

View File

@ -55,6 +55,16 @@ ly:
ifForwardRequest: false
forwardRequestBaseUrl: https://secureqrdev-t.chint.com/llz
#高德
amap:
eId: 612660
appId: car_zhengtecm3noxh
key: a1vxgdwobkphirln5fgup0oj6e2rsniw
keyt: car_zhengtecm3noxh
signKey: ngwdzlembqju9lairthw264bzkhw2vto
aesKey: 7eEdUzuVflM8n9Wo
baseUrl: https://sns.testing.amap.com
sf:
openApiBaseUrl: https://openapi.chintcloud.net
akBaseUrl: https://transitbridge.chint.com

View File

@ -0,0 +1,26 @@
package com.chint;
import com.chint.domain.aggregates.user.User;
import com.chint.interfaces.rest.amap.AmapUserRequest;
import com.chint.interfaces.rest.amap.BaseResponse;
import com.google.gson.Gson;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class AmapTest {
@Autowired
private AmapUserRequest amapUserRequest;
private Gson gson = new Gson();
private User user = new User(1L, "230615020", 1, "卢麟哲", "1033719135@qq.com", "15857193365", "A30000001");
@Test
public void createUser(){
BaseResponse baseResponse = amapUserRequest.createUser(user);
System.out.println(gson.toJson(baseResponse));
}
}