Commit 803d5ac4 authored by zhouqian's avatar zhouqian

增加修改接口

parent b2b93a1d
package cn.quantgroup.xyqb.controller.external.user; package cn.quantgroup.xyqb.controller.external.user;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserExtInfo;
import cn.quantgroup.xyqb.entity.enumerate.*; import cn.quantgroup.xyqb.entity.enumerate.*;
import cn.quantgroup.xyqb.model.*; import cn.quantgroup.xyqb.model.*;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService; import cn.quantgroup.xyqb.service.user.*;
import cn.quantgroup.xyqb.service.user.IUserExtInfoService; import com.alibaba.fastjson.JSONObject;
import cn.quantgroup.xyqb.service.user.IUserService; import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -36,6 +36,10 @@ public class InnerController { ...@@ -36,6 +36,10 @@ public class InnerController {
private IIdCardService idCardService; private IIdCardService idCardService;
@Autowired @Autowired
private IUserExtInfoService userExtInfoService; private IUserExtInfoService userExtInfoService;
@Autowired
private IContactService contactService;
@Autowired
private IAddressService addressService;
@RequestMapping("/user/search/phoneNo") @RequestMapping("/user/search/phoneNo")
...@@ -190,6 +194,73 @@ public class InnerController { ...@@ -190,6 +194,73 @@ public class InnerController {
return JsonResult.buildSuccessResult(null, null); return JsonResult.buildSuccessResult(null, null);
} }
@RequestMapping("/contact/search/user_id")
public JsonResult findContactsByUserId(Long userId) {
if (null == userId) {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> contacts = contactService.findByUserId(userId);
return JsonResult.buildErrorStateResult(null, ContactRet.contacts2ContactRets(contacts));
}
@RequestMapping("/contact/save/contacts")
public JsonResult save2Contact(Long userId, @RequestParam(value = "contacts") String contactsStr) {
if (StringUtils.isEmpty(contactsStr)) {
return JsonResult.buildErrorStateResult(null, null);
}
if (userId == null) {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {});
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult(null, null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
for (Contact c : contacts) {
c.setId(null);
c.setUserId(userId);
c.setCreatedAt(now);
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(result));
}
@RequestMapping("/address/search/user_id")
public JsonResult findAddressByUserId(Long userId) {
if (userId == null) {
return JsonResult.buildErrorStateResult(null, null);
}
Address address = addressService.findByUserId(userId);
if (address == null) {
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(address));
}
@RequestMapping("/address/save")
public JsonResult saveAddress(
Long userId, Long provinceCode, Long cityCode, String city,
Long districtCode, String district, String address, String province) {
if (userId == null || provinceCode == null || cityCode == null) {
return JsonResult.buildErrorStateResult(null, null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
Address addressObj = new Address();
addressObj.setUserId(userId);
addressObj.setProvinceCode(provinceCode);
addressObj.setCityCode(cityCode);
addressObj.setCity(city);
addressObj.setDistrictCode(districtCode);
addressObj.setDistrict(district);
addressObj.setAddress(address);
addressObj.setProvince(province);
addressObj.setCreatedAt(now);
addressObj.setUpdateAt(now);
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(addressObj));
}
@RequestMapping("/user_ext_info/update") @RequestMapping("/user_ext_info/update")
public JsonResult updateMarryStatus( public JsonResult updateMarryStatus(
Long userId, IncomeEnum incomeEnum, IncomeRangeEnum incomeRangeEnum, Long userId, IncomeEnum incomeEnum, IncomeRangeEnum incomeRangeEnum,
......
...@@ -32,7 +32,7 @@ public class Address implements Serializable{ ...@@ -32,7 +32,7 @@ public class Address implements Serializable{
@Column(name = "city") @Column(name = "city")
private String city; private String city;
@Column(name = "districtCode") @Column(name = "districtCode")
private Long district_code; private Long districtCode;
@Column(name = "district") @Column(name = "district")
private String district; private String district;
@Column(name = "address") @Column(name = "address")
......
package cn.quantgroup.xyqb.model;
import cn.quantgroup.xyqb.entity.Address;
import lombok.Data;
/**
* Created by Miraculous on 2017/2/14.
*/
@Data
public class AddressRet {
private static final long serialVersionUID = -1L;
private Long id;
private Long userId;
private Long provinceCode;
private String province;
private Long cityCode;
private String city;
private Long districtCode;
private String district;
private String address;
private Long createdAt;
private Long updateAt;
public static AddressRet address2AddressRet(Address address) {
if (address == null) {
return null;
}
AddressRet ret = new AddressRet();
ret.setId(address.getId());
ret.setUserId(address.getUserId());
ret.setProvinceCode(address.getProvinceCode());
ret.setCityCode(address.getCityCode());
ret.setDistrictCode(address.getDistrictCode());
ret.setDistrict(address.getDistrict());
ret.setProvince(address.getProvince());
ret.setCity(address.getCity());
ret.setAddress(address.getAddress());
ret.setCreatedAt(address.getCreatedAt().getTime());
ret.setUpdateAt(address.getUpdateAt().getTime());
return ret;
}
}
package cn.quantgroup.xyqb.model;
import cn.quantgroup.xyqb.entity.Contact;
import cn.quantgroup.xyqb.entity.enumerate.Relation;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Miraculous on 2017/2/14.
*/
@Data
public class ContactRet implements Serializable {
private static final long serialVersionUID = -1L;
private Long id;
private Long userId;
private String name;
private String phoneNo;
private Relation relation;
private Long createdAt;
private Long updateAt;
public static ContactRet contact2ContactRet (Contact c) {
if (c == null) {
return null;
}
ContactRet ret = new ContactRet();
ret.setId(c.getId());
ret.setUserId(c.getUserId());
ret.setName(c.getName());
ret.setPhoneNo(c.getPhoneNo());
ret.setRelation(c.getRelation());
ret.setCreatedAt(c.getCreatedAt().getTime());
ret.setUpdateAt(c.getUpdateAt().getTime());
return ret;
}
public static List<ContactRet> contacts2ContactRets(List<Contact> cs) {
if (CollectionUtils.isEmpty(cs)) {
return Collections.emptyList();
}
List<ContactRet> contactRets = new ArrayList<>();
for (Contact c : cs) {
contactRets.add(contact2ContactRet(c));
}
return contactRets;
}
}
...@@ -9,4 +9,6 @@ import java.util.List; ...@@ -9,4 +9,6 @@ import java.util.List;
*/ */
public interface IContactService { public interface IContactService {
List<Contact> findByUserId(Long userId); List<Contact> findByUserId(Long userId);
List<Contact> save(List<Contact> contacts);
} }
...@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.Contact; ...@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.Contact;
import cn.quantgroup.xyqb.repository.IContactRepository; import cn.quantgroup.xyqb.repository.IContactRepository;
import cn.quantgroup.xyqb.service.user.IContactService; import cn.quantgroup.xyqb.service.user.IContactService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -24,5 +25,11 @@ public class ContactServiceImpl implements IContactService { ...@@ -24,5 +25,11 @@ public class ContactServiceImpl implements IContactService {
return contactRepository.findByUserId(userId); return contactRepository.findByUserId(userId);
} }
@Override
@CacheEvict(value = "contact", key = "'contact' + #contacts.get(0).userId", cacheManager = "cacheManager")
public List<Contact> save(List<Contact> contacts) {
return contactRepository.save(contacts);
}
} }
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