Commit 4598abb1 authored by lining's avatar lining

feat: 逻辑删除地址

parent 2452c0df
......@@ -67,7 +67,7 @@ public class ServiceAddressController {
@ApiOperation(value = "修改服务地址")
@PutMapping("update")
public Result saveOrUpdate(@RequestBody @NonNull @Validated UpdateServiceAddressDTO dto, @CurrentUserId Long userId) {
public Result update(@RequestBody @NonNull @Validated UpdateServiceAddressDTO dto, @CurrentUserId Long userId) {
return serviceAddressService.update(dto, userId) == 1 ? success() : fail("修改失败");
}
......
......@@ -8,7 +8,9 @@ import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.mapper.service.ServiceAddressMapper;
import com.onsiteservice.dao.mapper.service.ServiceAreaMapper;
import com.onsiteservice.dao.mapper.service.ServiceOrderMapper;
import com.onsiteservice.entity.address.ServiceAddress;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.miniapp.controller.address.dto.PageServiceAddressDTO;
......@@ -37,6 +39,9 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
@Resource
private ServiceAddressBizMapper serviceAddressBizMapper;
@Resource
private ServiceAddressMapper serviceAddressMapper;
@Resource
private ServiceAreaMapper serviceAreaMapper;
......@@ -57,11 +62,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
public ServiceAddressVO selectById(Long id, Long userId) {
log.info("address selectById id: {}, userId: {}", id, userId);
Condition c = new Condition(ServiceAddress.class);
c.createCriteria().andEqualTo("id", id).andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId)
.andEqualTo(BizConstants.CommonConstants.DELETED, false);
List<ServiceAddress> serviceAddressList = this.selectByCondition(c);
List<ServiceAddress> serviceAddressList = serviceAddressMapper.selectByCondition(generateCondition(id, userId));
if (CollectionUtils.isEmpty(serviceAddressList)) {
throw new ServiceException(BizCodeEnum.SERVICE_ADDRESS_NOT_EXIST);
}
......@@ -70,17 +71,6 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
}
public List<ServiceAddressVO> selectByUserId(Long userId) {
Condition condition = new Condition(ServiceAddress.class);
condition.createCriteria().andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId);
List<ServiceAddress> serviceAddresses = this.selectByCondition(condition);
return serviceAddresses.parallelStream()
.map(e -> AttrCopyUtils.copy(e, new ServiceAddressVO()))
.collect(Collectors.toList());
}
public int save(SaveServiceAddressDTO dto, Long userId) {
log.info("address save dto: {}, userId: {}", dto, userId);
......@@ -91,7 +81,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
// 有默认收货地址的话,置为非默认
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
return this.insertSelective(serviceAddress);
return serviceAddressMapper.insertSelective(serviceAddress);
}
......@@ -102,21 +92,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
ServiceAddress serviceAddress = AttrCopyUtils.copy(dto, new ServiceAddress());
serviceAddress.setAccountNo(userId);
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
Condition c = new Condition(ServiceAddress.class);
c.createCriteria().andEqualTo("id", dto.getId()).andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId);
return this.updateByConditionSelective(serviceAddress, c);
return serviceAddressMapper.updateByConditionSelective(serviceAddress, generateCondition(dto.getId(), userId));
}
public int delete(Long id, Long userId) {
log.info("address delete id: {}, userId: {}", id, userId);
Condition c = new Condition(ServiceAddress.class);
// 删除条件里加上账户号防越权攻击
c.createCriteria().andEqualTo("id", id).andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId);
return this.deleteByCondition(c);
return serviceAddressMapper.deleteByCondition(generateCondition(id, userId));
}
......@@ -142,12 +129,12 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
Condition c = new Condition(ServiceAddress.class);
c.createCriteria().andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId)
.andEqualTo("def", true);
List<ServiceAddress> defaultServiceAddressList = this.selectByCondition(c);
List<ServiceAddress> defaultServiceAddressList = serviceAddressMapper.selectByCondition(c);
if (!CollectionUtils.isEmpty(defaultServiceAddressList)) {
defaultServiceAddressList.forEach(defaultServiceAddress -> {
defaultServiceAddress.setDef(false);
this.updateByPrimaryKeySelective(defaultServiceAddress);
serviceAddressMapper.updateByPrimaryKeySelective(defaultServiceAddress);
});
}
......@@ -159,9 +146,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
checkAndCancelDefaultServiceAddress(userId);
Condition c = new Condition(ServiceAddress.class);
c.createCriteria().andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId).andEqualTo("id", id);
List<ServiceAddress> serviceAddressList = this.selectByCondition(c);
List<ServiceAddress> serviceAddressList = serviceAddressMapper.selectByCondition(generateCondition(id, userId));
if (CollectionUtils.isEmpty(serviceAddressList)) {
throw new ServiceException(BizCodeEnum.SERVICE_ADDRESS_NOT_EXIST);
}
......@@ -169,9 +154,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
ServiceAddress serviceAddress = serviceAddressList.get(0);
serviceAddress.setDef(true);
return this.updateByPrimaryKeySelective(serviceAddress);
return serviceAddressMapper.updateByPrimaryKeySelective(serviceAddress);
}
private Condition generateCondition(Long id, Long userId) {
Condition c = new Condition(ServiceAddress.class);
c.createCriteria()
.andEqualTo("id", id)
.andEqualTo(BizConstants.UserConstants.ACCOUNT_NO, userId)
.andEqualTo(BizConstants.CommonConstants.DELETED, false);
return c;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment