@@ -50,7 +50,7 @@ public class AddressInfo extends StringPropertyUUIDEntity { | |||
@NotNull | |||
@Column(name = "DEFAULT_ADDRESS") | |||
private Integer defaultAddress;//是否为默认地址 | |||
@NotBlank | |||
@NotNull | |||
@Column(name = "STATUS") | |||
private Integer status;//状态 0-删除 1-正常 | |||
@NotNull |
@@ -52,6 +52,10 @@ public enum OperateType { | |||
//退费管理 | |||
ORDER_REFUND_RESULT("退费审核结果"), | |||
//地址管理 | |||
ADDRESS_INFO_ADD_OR_UPDATE("收货地址新增或修改"), | |||
ADDRESS_INFO_DELETE("收货地址删除"), | |||
; | |||
private final String value; | |||
@@ -28,6 +28,8 @@ dependencies { | |||
runtimeOnly 'com.oracle.database.jdbc:ojdbc8:19.10.0.0' | |||
runtimeOnly 'cn.easyproject:orai18n:12.1.0.2.0' | |||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis' | |||
} | |||
bootJar { |
@@ -33,14 +33,14 @@ public class AddressController extends MyValidController { | |||
@ApiOperation("地址查询") | |||
@PostMapping("/findById") | |||
public ApiResponse<AddressInfo> findById(@Valid @RequestBody AddressInfoRequestDTO dto) throws ManagerException { | |||
public ApiResponse<AddressInfo> findById(@Valid @RequestBody AddressInfoRequestDTO dto) { | |||
return ApiResponse.of(manager.findById(dto)); | |||
} | |||
@ApiOperation("地址添加、修改") | |||
@PostMapping("/add") | |||
public ApiResponse<AddressInfo> add(@Valid @RequestBody AddressAddRequestDTO dto) throws ManagerException { | |||
return ApiResponse.of(manager.add(dto)); | |||
@PostMapping("/saveOrUpdate") | |||
public ApiResponse<AddressInfo> saveOrUpdate(@Valid @RequestBody AddressAddRequestDTO dto) throws ManagerException { | |||
return ApiResponse.of(manager.saveOrUpdate(dto)); | |||
} | |||
@ApiOperation("地址删除") |
@@ -16,15 +16,10 @@ import javax.validation.constraints.NotNull; | |||
@Setter | |||
@Accessors(chain = true) | |||
public class AddressAddRequestDTO extends AbstractBizRequestDTO { | |||
@Override | |||
protected void validate(ViolationValidator validator) { | |||
} | |||
/*** 新增时传值。编辑时必传*/ | |||
@ApiModelProperty(value = "id",required = false) | |||
private String id; | |||
@ApiModelProperty(value = "手机号",required = false) | |||
private String mobile; | |||
@ApiModelProperty(value = "收货人",required = true) | |||
@NotBlank(message = "收货人不能为空") | |||
private String consignee; |
@@ -19,9 +19,5 @@ public class AddressInfoRequestDTO extends AbstractBizRequestDTO { | |||
@ApiModelProperty(value = "id",required = false) | |||
@NotBlank(message = "id不能为空") | |||
private String id; | |||
@Override | |||
protected void validate(ViolationValidator validator) { | |||
} | |||
} |
@@ -2,14 +2,25 @@ package cn.com.taiji.iaw.manager; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.common.pub.IPTools; | |||
import cn.com.taiji.common.pub.TimeTools; | |||
import cn.com.taiji.common.pub.json.JsonTools; | |||
import cn.com.taiji.core.entity.comm.OcrResult; | |||
import cn.com.taiji.core.entity.dict.OcrType; | |||
import cn.com.taiji.core.entity.dict.basic.SourceType; | |||
import cn.com.taiji.core.entity.dict.log.OperateType; | |||
import cn.com.taiji.core.entity.log.OperateLog; | |||
import cn.com.taiji.core.entity.user.AccountInfo; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsResponse; | |||
import cn.com.taiji.core.model.comm.protocol.ats.ocr.*; | |||
import cn.com.taiji.core.repo.jpa.comm.OcrResultRepo; | |||
import cn.com.taiji.core.repo.jpa.log.OperateLogRepo; | |||
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.context.request.RequestContextHolder; | |||
import org.springframework.web.context.request.ServletRequestAttributes; | |||
import javax.servlet.http.HttpServletRequest; | |||
import java.io.IOException; | |||
import java.time.LocalDateTime; | |||
@@ -17,6 +28,10 @@ public abstract class AbstractIawManager extends AbstractCommManager { | |||
@Autowired | |||
private OcrResultRepo ocrResultRepo; | |||
@Autowired | |||
private OperateLogRepo operateLogRepo; | |||
@Autowired | |||
private AccountInfoRepo accountInfoRepo; | |||
/** | |||
* type:1-身份证-人像面 2-身份证-国徽面 3-行驶证前页 4-行驶证背页 5-营业执照 | |||
@@ -102,4 +117,40 @@ public abstract class AbstractIawManager extends AbstractCommManager { | |||
} | |||
} | |||
// 操作日志记录 | |||
protected void persistOperateLog(OperateType operateType, String operatorDataId, SourceType source, | |||
String openId, String msg) { | |||
saveOperateLog(operateType, operatorDataId, source, openId, getAccountName(openId), msg); | |||
} | |||
protected void saveOperateLog(OperateType operateType, String dataId, SourceType source, String openId, | |||
String operatorName, String msg) { | |||
HttpServletRequest request = | |||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
String ip = IPTools.getIpAddr(request); | |||
LocalDateTime now = LocalDateTime.now(); | |||
OperateLog log = new OperateLog(); | |||
log.setPartKey(Long.valueOf(now.format(TimeTools.yyyyMM))); | |||
log.setLoginSource(source); | |||
log.setOperatorId(openId); | |||
log.setOperatorName(operatorName); | |||
log.setOperateTime(now); | |||
log.setOperateIp(ip); | |||
log.setOperateType(operateType); | |||
log.setOperatorDataId(dataId); | |||
log.setMsg(msg); | |||
operateLogRepo.persist(log); | |||
} | |||
protected String getAccountName(String openId) { | |||
return getAccountInfo(openId).getUserName(); | |||
} | |||
protected AccountInfo getAccountInfo(String openId) { | |||
if (openId == null) { | |||
return null; | |||
} | |||
return accountInfoRepo.findByOpenId(openId); | |||
} | |||
} |
@@ -11,9 +11,9 @@ public interface AddressManager { | |||
Pagination page(AddressQueryRequestDTO dto) throws ManagerException; | |||
AddressInfo findById(AddressInfoRequestDTO dto) throws ManagerException; | |||
AddressInfo findById(AddressInfoRequestDTO dto); | |||
AddressInfo add(AddressAddRequestDTO dto) throws ManagerException; | |||
AddressInfo saveOrUpdate(AddressAddRequestDTO dto) throws ManagerException; | |||
void delete(AddressInfoRequestDTO dto) throws ManagerException; | |||
} |
@@ -2,18 +2,17 @@ package cn.com.taiji.iaw.manager.comm; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.common.pub.BeanTools; | |||
import cn.com.taiji.core.entity.comm.AddressInfo; | |||
import cn.com.taiji.core.entity.dict.basic.SourceType; | |||
import cn.com.taiji.core.entity.dict.log.OperateType; | |||
import cn.com.taiji.core.entity.user.AccountInfo; | |||
import cn.com.taiji.core.repo.jpa.comm.AddressInfoRepo; | |||
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo; | |||
import cn.com.taiji.iaw.dto.comm.*; | |||
import cn.com.taiji.iaw.manager.AbstractCommManager; | |||
import cn.com.taiji.iaw.manager.AbstractIawManager; | |||
import cn.com.taiji.iaw.repo.jpa.request.comm.AddressInfoPageRequest; | |||
import cn.hutool.core.bean.BeanUtil; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import org.apache.commons.compress.utils.Lists; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
@@ -22,44 +21,37 @@ import java.time.LocalDateTime; | |||
import java.util.List; | |||
@Service | |||
public class AddressManagerImpl extends AbstractCommManager implements AddressManager { | |||
public class AddressManagerImpl extends AbstractIawManager implements AddressManager { | |||
@Autowired | |||
private AccountInfoRepo accountInfoRepo; | |||
@Autowired | |||
private AddressInfoRepo repo; | |||
@Transactional(rollbackFor = Exception.class) | |||
@Override | |||
public Pagination page(AddressQueryRequestDTO dto) throws ManagerException { | |||
dto.validate(); | |||
AddressInfoPageRequest req = new AddressInfoPageRequest(); | |||
BeanTools.copyProperties(dto, req); | |||
List<String> openIds = Lists.newArrayList(); | |||
AddressInfoPageRequest pageRequest = copyProperties(dto, new AddressInfoPageRequest()); | |||
if (SourceType.WECHAT.equals(dto.getOrderSource()) || SourceType.ALI.equals(dto.getOrderSource())) { | |||
openIds.add(findOpenIdByToken(dto.getAccessToken())); | |||
pageRequest.setOpenId(findOpenIdByToken(dto.getAccessToken())); | |||
} else { | |||
if (!hasText(dto.getMobile())) { | |||
AccountInfo allByMobile = accountInfoRepo.findByMobile(dto.getMobile()); | |||
if (allByMobile != null) { | |||
openIds.add(allByMobile.getOpenId()); | |||
pageRequest.setOpenId(allByMobile.getOpenId()); | |||
} | |||
} | |||
} | |||
req.setOpenIds(openIds); | |||
Pagination pagn = repo.page(req); | |||
return pagn; | |||
return repo.page(pageRequest); | |||
} | |||
@Override | |||
public AddressInfo findById(AddressInfoRequestDTO dto) throws ManagerException { | |||
dto.validate(); | |||
public AddressInfo findById(AddressInfoRequestDTO dto) { | |||
return repo.findById(dto.getId()).orElse(null); | |||
} | |||
@Override | |||
public AddressInfo add(AddressAddRequestDTO dto) throws ManagerException { | |||
dto.validate(); | |||
@Transactional(rollbackFor = Exception.class) | |||
public AddressInfo saveOrUpdate(AddressAddRequestDTO dto) throws ManagerException { | |||
AddressInfo entity = new AddressInfo(); | |||
if (hasText(dto.getId())) { | |||
entity = repo.findById(dto.getId()).orElse(null); | |||
@@ -69,23 +61,21 @@ public class AddressManagerImpl extends AbstractCommManager implements AddressMa | |||
throw new ManagerException("不是您的地址信息,编辑失败"); | |||
} | |||
BeanUtil.copyProperties(dto, entity, "id", "updateTime" | |||
, "insertTime", "status", "statusTime"); | |||
entity.setUpdateTime(LocalDateTime.now()); | |||
, "insertTime", "status"); | |||
} else { | |||
BeanUtil.copyProperties(dto, entity, "id"); | |||
} | |||
if (hasText(dto.getMobile())) { | |||
AccountInfo byAccount = accountInfoRepo.findByAccount(dto.getMobile()); | |||
if (byAccount == null) { | |||
throw new ManagerException("手机号未注册:" + dto.getMobile()); | |||
} | |||
entity.setOpenId(byAccount.getOpenId()); | |||
entity.setInsertTime(LocalDateTime.now()); | |||
entity.setStatus(1); | |||
} | |||
// 如果编辑的地址设置为默认收货地址,则当前账号下原默认地址并且ID不等于当前编辑的ID需要设置为非默认 | |||
if (entity.getDefaultAddress() == 1) { | |||
changeDefault(entity); | |||
} | |||
entity.setOpenId(findOpenIdByToken(dto.getAccessToken())); | |||
entity.setUpdateTime(LocalDateTime.now()); | |||
repo.save(entity); | |||
//日志 | |||
persistOperateLog(OperateType.ADDRESS_INFO_ADD_OR_UPDATE,entity.getId(),dto.getOrderSource(),findOpenIdByToken(dto.getAccessToken()),"地址添加或更新"); | |||
return entity; | |||
} | |||
@@ -103,15 +93,15 @@ public class AddressManagerImpl extends AbstractCommManager implements AddressMa | |||
@Override | |||
public void delete(AddressInfoRequestDTO dto) throws ManagerException { | |||
dto.validate(); | |||
AddressInfo entity = repo.findById(dto.getId()).orElse(null); | |||
if (entity == null) { | |||
throw new ManagerException("地址不存在"); | |||
} else if (!findOpenIdByToken(dto.getAccessToken()).equals(entity.getOpenId())) { | |||
if (!findOpenIdByToken(dto.getAccessToken()).equals(entity.getOpenId())) { | |||
throw new ManagerException("不是您的地址信息,删除失败"); | |||
} | |||
entity.setUpdateTime(LocalDateTime.now()); | |||
entity.setStatus(0);//0-删除、1-正常 | |||
repo.save(entity); | |||
//日志 | |||
persistOperateLog(OperateType.ADDRESS_INFO_DELETE,entity.getId(),dto.getOrderSource(),findOpenIdByToken(dto.getAccessToken()),"地址删除"); | |||
} | |||
} |
@@ -14,13 +14,17 @@ import java.util.List; | |||
@Accessors(chain = true) | |||
public class AddressInfoPageRequest extends JpaDatePageableDataRequest<AddressInfo> { | |||
private List<String> openIds; // openId列表 | |||
private String openId; | |||
public AddressInfoPageRequest() { | |||
this.orderBy="insertTime"; | |||
this.desc=true; | |||
} | |||
@Override | |||
public HqlBuilder toSelectHql() { | |||
HqlBuilder hql = new HqlBuilder("from " + AddressInfo.class.getName() + " a where 1=1 AND status = 1"); | |||
hql.append(" and openId IN :openId", openIds); | |||
hql.append(" ORDER BY defaultAddress ASC, insertTime DESC"); | |||
hql.append(" and openId = :openId", openId); | |||
return hql; | |||
} | |||
@@ -0,0 +1,71 @@ | |||
package cn.com.taiji.iaw.tools; | |||
import cn.com.taiji.common.manager.AbstractManager; | |||
import cn.com.taiji.core.manager.cache.RedisManager; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.redis.core.HashOperations; | |||
import org.springframework.data.redis.core.RedisTemplate; | |||
import org.springframework.stereotype.Service; | |||
import java.util.concurrent.TimeUnit; | |||
/** | |||
* hash操作的方法以hash开头,如:hashGet<br> | |||
* | |||
* @author lijun <br> | |||
* Create Time:2018年12月9日 下午1:43:54<br> | |||
* mail:756915505@qq.com | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
@Service | |||
public class RedisWrapManager extends AbstractManager implements RedisManager { | |||
@Autowired(required = false) | |||
private RedisTemplate<String, String> redisTemplate; | |||
public Boolean expire(String key, final long timeout, final TimeUnit unit) { | |||
return redisTemplate.expire(key, timeout, unit); | |||
} | |||
public Boolean hasKey(String key) { | |||
return redisTemplate.hasKey(key); | |||
} | |||
public String get(String key) { | |||
return redisTemplate.opsForValue().get(key); | |||
} | |||
public String getAndSet(String key, String value) { | |||
return redisTemplate.opsForValue().getAndSet(key, value); | |||
} | |||
public void set(String key, String value, long timeout, TimeUnit unit) { | |||
redisTemplate.opsForValue().set(key, value, timeout, unit); | |||
} | |||
/** | |||
* 往redis中存入数据 默认为不过期 | |||
* | |||
* @param key key | |||
* @param value value | |||
*/ | |||
public void setDefault(String key, String value) { | |||
redisTemplate.opsForValue().set(key, value); | |||
} | |||
public boolean setIfAbsent(String key, String value, long timeout, TimeUnit unit) { | |||
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit); | |||
} | |||
public Boolean delete(String key) { | |||
return redisTemplate.delete(key); | |||
} | |||
private <HK, HV> HashOperations<String, HK, HV> opsForHash() { | |||
return redisTemplate.opsForHash(); | |||
} | |||
private void set(String key, String value, int timeout) { | |||
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); | |||
} | |||
} |
@@ -31,6 +31,8 @@ spring: | |||
refresh: true | |||
- data-id: comm-client.yaml | |||
refresh: true | |||
- data-id: redis.yaml | |||
refresh: true | |||
server: | |||
port: 8085 | |||
servlet: |