|
@@ -1,10 +1,21 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
+import com.baomidou.mybatisplus.plugins.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.yh.saas.common.support.util.IdGenerator;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.NumberConstant;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.CargoOwnerAddressInfo;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.CargoOwnerAddressInfoMapper;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.service.ICargoOwnerAddressInfoService;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +28,107 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CargoOwnerAddressInfoServiceImpl extends ServiceImpl<CargoOwnerAddressInfoMapper, CargoOwnerAddressInfo> implements ICargoOwnerAddressInfoService {
|
|
|
|
|
|
+ /**
|
|
|
+ * 选择地址列表
|
|
|
+ * @param cargoOwnerAddressInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<CargoOwnerAddressInfo> selectCargoOwnerAddress(CargoOwnerAddressInfo cargoOwnerAddressInfo) {
|
|
|
+ Map<String, Object> pageView = new HashMap<>();
|
|
|
+ pageView.put("startRecord", (cargoOwnerAddressInfo.getCurrentPage() - 1)
|
|
|
+ * cargoOwnerAddressInfo.getPageSize());
|
|
|
+ //用户id
|
|
|
+ pageView.put("commonId", cargoOwnerAddressInfo.getCommonId());
|
|
|
+ pageView.put("searchKeyWord", cargoOwnerAddressInfo.getSearchKeyWord());
|
|
|
+ pageView.put("pageSize", cargoOwnerAddressInfo.getPageSize());
|
|
|
+ pageView.put("currentPage", cargoOwnerAddressInfo.getCurrentPage());
|
|
|
+ // 查询任务总数
|
|
|
+ Integer dataCount = baseMapper.getCountByCondition(pageView);
|
|
|
+ List<CargoOwnerAddressInfo> dataList = baseMapper.getListByCondition(pageView);
|
|
|
+ Page<CargoOwnerAddressInfo> page = new Page<>();
|
|
|
+ page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
|
|
|
+ page.setTotal(dataCount == null ? 0 : dataCount);
|
|
|
+ page.setCurrent(cargoOwnerAddressInfo.getCurrentPage());
|
|
|
+ page.setSize(cargoOwnerAddressInfo.getPageSize());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增地址
|
|
|
+ * @param cargoOwnerAddressInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String addCargoOwnerAddress(CargoOwnerAddressInfo cargoOwnerAddressInfo){
|
|
|
+ //新增主键id
|
|
|
+ cargoOwnerAddressInfo.setId(IdGenerator.generateUUID());
|
|
|
+ this.insert(cargoOwnerAddressInfo);
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑地址
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String editCargoOwnerAddress(CargoOwnerAddressInfo cargoOwnerAddressInfo) {
|
|
|
+ //信息编辑
|
|
|
+ this.updateById(cargoOwnerAddressInfo);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除地址
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteCargoOwnerAddress(String id) {
|
|
|
+ CargoOwnerAddressInfo cargoOwnerAddressInfo = this.selectById(id);
|
|
|
+ this.deleteById(cargoOwnerAddressInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置默认/置顶
|
|
|
+ * @param cargoOwnerAddressInfo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String setDefault(CargoOwnerAddressInfo cargoOwnerAddressInfo) {
|
|
|
+ //查询货主所有地址
|
|
|
+ List<CargoOwnerAddressInfo> cargoOwnerAddressInfoList = this.selectList(new EntityWrapper<CargoOwnerAddressInfo>()
|
|
|
+ .eq(CargoOwnerAddressInfo.QueryFiles.COMMON_ID, cargoOwnerAddressInfo.getCommonId())
|
|
|
+ .eq(CargoOwnerAddressInfo.QueryFiles.DELETE_FLAG, NumberConstant.CONSTANT0));
|
|
|
+ if(!CollectionUtils.isEmpty(cargoOwnerAddressInfoList)){
|
|
|
+ for (CargoOwnerAddressInfo cargoOwnerAddressInfo1 : cargoOwnerAddressInfoList){
|
|
|
+ //id相等设置默认,其余数据取消默认
|
|
|
+ if(cargoOwnerAddressInfo1.getId().equals(cargoOwnerAddressInfo.getId())){
|
|
|
+ if("1".equals(cargoOwnerAddressInfo.getDefaultFlag())){
|
|
|
+ //设置默认发货
|
|
|
+ cargoOwnerAddressInfo1.setDefaultShipment("1");
|
|
|
+ }else if("2".equals(cargoOwnerAddressInfo.getDefaultFlag())){
|
|
|
+ //设置默认收货
|
|
|
+ cargoOwnerAddressInfo1.setDefaultReceipt("1");
|
|
|
+ }else {
|
|
|
+ //设置置顶
|
|
|
+ cargoOwnerAddressInfo1.setToppingFlag("1");
|
|
|
+ }
|
|
|
+ this.updateById(cargoOwnerAddressInfo1);
|
|
|
+ }else {
|
|
|
+ if("1".equals(cargoOwnerAddressInfo.getDefaultFlag())){
|
|
|
+ //取消默认发货
|
|
|
+ cargoOwnerAddressInfo1.setDefaultShipment("0");
|
|
|
+ }else if("2".equals(cargoOwnerAddressInfo.getDefaultFlag())){
|
|
|
+ //取消默认收货
|
|
|
+ cargoOwnerAddressInfo1.setDefaultReceipt("0");
|
|
|
+ }else {
|
|
|
+ //取消置顶
|
|
|
+ cargoOwnerAddressInfo1.setToppingFlag("0");
|
|
|
+ }
|
|
|
+ this.updateById(cargoOwnerAddressInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
}
|