Kaynağa Gözat

增加地址获取与变更

jz.kai 1 yıl önce
ebeveyn
işleme
3510acac45

+ 1 - 0
common/src/main/java/com/jpsoft/employment/modules/base/dao/AddressInfoDAO.java

@@ -15,4 +15,5 @@ public interface AddressInfoDAO {
 	int delete(String id);
 	List<AddressInfo> list();
 	List<AddressInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+	AddressInfo getByUser(String userId);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/employment/modules/base/service/AddressInfoService.java

@@ -14,4 +14,5 @@ public interface AddressInfoService {
 	int delete(String id);
 	List<AddressInfo> list();
 	Page<AddressInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
+	AddressInfo getByUser(String userId);
 }

+ 6 - 0
common/src/main/java/com/jpsoft/employment/modules/base/service/impl/AddressInfoServiceImpl.java

@@ -67,4 +67,10 @@ public class AddressInfoServiceImpl implements AddressInfoService {
         
         return page;
 	}
+
+	@Override
+	public AddressInfo getByUser(String userId) {
+		// TODO Auto-generated method stub
+		return addressInfoDAO.getByUser(userId);
+	}
 }

+ 3 - 0
common/src/main/resources/mapper/base/AddressInfo.xml

@@ -83,6 +83,9 @@
 	<select id="get" parameterType="string" resultMap="AddressInfoMap">
 		select * from base_address_info where id_=#{0}
 	</select>
+	<select id="getByUser" parameterType="string" resultMap="AddressInfoMap">
+		select * from base_address_info where reg_user_id=#{0} limit 1
+	</select>
 	<select id="exist" parameterType="string" resultType="int">
 		select count(*) from base_address_info where id_=#{0}
 	</select>

+ 63 - 13
web/src/main/java/com/jpsoft/employment/modules/base/api/WishApi.java

@@ -1,8 +1,10 @@
 package com.jpsoft.employment.modules.base.api;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.employment.modules.base.entity.AddressInfo;
 import com.jpsoft.employment.modules.base.entity.WishInfo;
 import com.jpsoft.employment.modules.base.entity.WishInfoUserRecord;
+import com.jpsoft.employment.modules.base.service.AddressInfoService;
 import com.jpsoft.employment.modules.base.service.StudentAspirationsService;
 import com.jpsoft.employment.modules.base.service.WishInfoService;
 import com.jpsoft.employment.modules.base.service.WishInfoUserRecordService;
@@ -22,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -31,6 +34,8 @@ import java.util.*;
 public class WishApi {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
+    @Autowired
+    private AddressInfoService addressInfoService;
     @Autowired
     private WishInfoService wishInfoService;
     @Autowired
@@ -100,18 +105,20 @@ public class WishApi {
 
     @ApiOperation(value="提交心愿单")
     @RequestMapping(value = "add",method = RequestMethod.POST)
-//    @Transactional(rollbackFor = Exception.class)
+    @Transactional(rollbackFor = Exception.class)
     @ApiImplicitParams({
             @ApiImplicitParam(name="wishInfoId", value="心愿信息ID", required=true, paramType="query"),
             @ApiImplicitParam(name="isSpot", value="是否现场互换心愿", required=true, paramType="query"),
             @ApiImplicitParam(name="recipients", value="收件人", required=false, paramType="query"),
             @ApiImplicitParam(name="recipientsPhone", value="收件人电话", required=false, paramType="query"),
+            @ApiImplicitParam(name="recipientsRegion", value="收件人区域", required=false, paramType="query"),
             @ApiImplicitParam(name="recipientsAddress", value="收件人地址", required=false, paramType="query"),
     })
     public MessageResult<WishInfoUserRecord> add(String wishInfoId, Boolean isSpot,
-        String recipients, String recipientsPhone, String recipientsAddress,
-        @RequestAttribute String subject){
+        String recipients, String recipientsPhone, String recipientsRegion, String recipientsAddress,
+        HttpServletRequest request){
         MessageResult<WishInfoUserRecord> msgResult = new MessageResult<>();
+        String subject = (String)request.getAttribute("subject");
 
         try {
             WishInfoUserRecord wishInfoUserRecord = new WishInfoUserRecord();
@@ -123,20 +130,36 @@ public class WishApi {
             wishInfoUserRecord.setNum(getSerialNumber());
             wishInfoUserRecord.setRecipients (recipients);
             wishInfoUserRecord.setRecipientsPhone(recipientsPhone);
-            wishInfoUserRecord.setRecipientsAddress(recipientsAddress);
+            wishInfoUserRecord.setRecipientsAddress(recipientsRegion + recipientsAddress);
             wishInfoUserRecord.setDelFlag(false);
             wishInfoUserRecord.setCreateBy(subject);
             wishInfoUserRecord.setCreateTime(new Date());
-
-            int affectCount = wishInfoUserRecordService.insert(wishInfoUserRecord);
-
-            if (affectCount > 0) {
-                msgResult.setResult(true);
-                msgResult.setData(wishInfoUserRecord);
-            } else {
-                msgResult.setResult(false);
-                msgResult.setMessage("数据库添加失败");
+            wishInfoUserRecordService.insert(wishInfoUserRecord);
+
+            AddressInfo addressInfo = addressInfoService.getByUser(subject);
+            if(addressInfo == null) {
+                addressInfo = new AddressInfo();
+                addressInfo.setRecipients(recipients);
+                addressInfo.setPhone(recipientsPhone);
+                addressInfo.setRegion(recipientsRegion);
+                addressInfo.setDetailAddress(recipientsAddress);
+                addressInfo.setRegUserId(subject);
+                addressInfo.setDelFlag(false);
+                addressInfo.setCreateBy(subject);
+                addressInfo.setCreateTime(new Date());
+                addressInfoService.insert(addressInfo);
+            }
+            else {
+                addressInfo.setRecipients(recipients);
+                addressInfo.setPhone(recipientsPhone);
+                addressInfo.setRegion(recipientsRegion);
+                addressInfo.setDetailAddress(recipientsAddress);
+                addressInfo.setUpdateBy(subject);
+                addressInfo.setUpdateTime(new Date());
+                addressInfoService.update(addressInfo);
             }
+
+            msgResult.setResult(true);
         }
         catch(Exception ex){
             logger.error(ex.getMessage(),ex);
@@ -167,6 +190,33 @@ public class WishApi {
         return messageResult;
     }
 
+    @ApiOperation(value="地址详情")
+    @RequestMapping(value = "getAddress",method = RequestMethod.POST)
+    public MessageResult<AddressInfo> getAddress(HttpServletRequest request){
+        MessageResult<AddressInfo> msgResult = new MessageResult<>();
+        String subject = (String)request.getAttribute("subject");
+
+        try {
+            AddressInfo addressInfo = addressInfoService.getByUser(subject);
+
+            if (addressInfo != null) {
+                msgResult.setResult(true);
+                msgResult.setData(addressInfo);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
     private String getSerialNumber() {
         String serialNumber = "";