入参:
@Table(name="UPLUS_ADDRESS")
public class UplusAddress implements Serializable{
@Id
@Column(name="ID")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="USER_ID")
private Long userId;
@Column(name="PROVINCE_ID")
private Long provinceId;
@Column(name="CITY_ID")
private Long cityId;
@Column(name="DISTRICT_ID")
private Long districtId;
@Column(name="NAME")
private String name;
@Column(name="TAG")
private String tag;
@Column(name="MOBILE")
private String mobile;
@Column(name="REMARK")
private String remark;
@Column(name="IS_DEFAULT")
private Boolean isDefault;
@Column(name="CREATE_DATE")
private Date createDate;
@Column(name="UPDATE_DATE")
private Date updateDate;
@Column(name="CREATE_USER")
private Long createUser;
}
Controller:
@RestController
@RequestMapping({ "/uplus/phone/address" })
public class PhoneAddressController extends BaseController {
// @CryptoType(CryptoType.Type.CRYPTO)
@PostMapping({ "/save" })
public Result save(UplusAddress uplusAddress) {
UplusUser user = getUser();
if ((isAuthenticated()) && (user != null)) {
if (uplusAddress != null) {
UplusArea ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getProvinceId());
if (ua == null) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
List cityModels = this.uplusAreaService
.findByPid(Integer.valueOf(uplusAddress.getProvinceId().intValue()));
if (cityModels.size() == 1) {
UplusArea cityModel = (UplusArea) cityModels.get(0);
if ((cityModel.getId() != uplusAddress.getCityId()) && (cityModel.getName().indexOf("市辖区") >= 0)) {
uplusAddress.setCityId(cityModel.getId());
}
}
ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getCityId());
if (ua == null) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getDistrictId());
if (ua == null) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
if (StringUtils.isEmpty(uplusAddress.getName())) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
if (StringUtils.isEmpty(uplusAddress.getRemark())) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
if (StringUtils.isEmpty(uplusAddress.getMobile())) {
return ResultGenerator.genFailResult("地区不存在,请联系管理员");
}
uplusAddress.setCreateDate(getCurrentDate());
uplusAddress.setUserId(user.getId());
uplusAddress.setCreateUser(user.getId());
this.uplusAddressService.save(uplusAddress);
return ResultGenerator.genSuccessResult(uplusAddress);
}
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
return ResultGenerator.unauthorized(this.UNAUTHORIZED_ERROR_MESSAGE);
}
// @CryptoType(CryptoType.Type.CRYPTO)
@PostMapping({ "/delete" })
public Result delete(Long id) {
UplusUser user = getUser();
if ((isAuthenticated()) && (user != null)) {
if (id != null) {
this.uplusAddressService.deleteById(id);
return ResultGenerator.genSuccessResult();
}
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
return ResultGenerator.unauthorized(this.UNAUTHORIZED_ERROR_MESSAGE);
}
// @CryptoType(CryptoType.Type.CRYPTO)
@PostMapping({ "/update" })
public Result update(UplusAddress uplusAddress) {
UplusUser user = getUser();
if ((isAuthenticated()) && (user != null)) {
if ((uplusAddress != null) && (uplusAddress.getId() != null)) {
UplusAddress uplusAddress2 = (UplusAddress) this.uplusAddressService.findById(uplusAddress.getId());
UplusArea ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getProvinceId());
if (ua == null) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
List cityModels = this.uplusAreaService
.findByPid(Integer.valueOf(uplusAddress.getProvinceId().intValue()));
if (cityModels.size() == 1) {
UplusArea cityModel = (UplusArea) cityModels.get(0);
if ((cityModel.getId() != uplusAddress.getCityId()) && (cityModel.getName().indexOf("市辖区") >= 0)) {
uplusAddress.setCityId(cityModel.getId());
}
}
ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getCityId());
if (ua == null) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
ua = (UplusArea) this.uplusAreaService.findById(uplusAddress.getDistrictId());
if (ua == null) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
if (StringUtils.isEmpty(uplusAddress.getName())) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
if (StringUtils.isEmpty(uplusAddress.getRemark())) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
if (StringUtils.isEmpty(uplusAddress.getMobile())) {
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
uplusAddress2.setUserId(user.getId());
uplusAddress2.setProvinceId(uplusAddress.getProvinceId());
uplusAddress2.setCityId(uplusAddress.getCityId());
uplusAddress2.setDistrictId(uplusAddress.getDistrictId());
uplusAddress2.setName(uplusAddress.getName());
uplusAddress2.setRemark(uplusAddress.getRemark());
uplusAddress2.setMobile(uplusAddress.getMobile());
uplusAddress2.setUpdateDate(getCurrentDate());
this.uplusAddressService.update(uplusAddress2);
return ResultGenerator.genSuccessResult();
}
return ResultGenerator.genFailResult(this.REQUEST_PARAMS_ERROR_MESSAGE);
}
return ResultGenerator.unauthorized(this.UNAUTHORIZED_ERROR_MESSAGE);
}
}
Service:
public abstract interface UplusAreaService extends Service {
public abstract List findByPid(Integer paramInteger);
public abstract int updateTest(@Param("list") List paramList);
public abstract List findTest();
public abstract UplusArea findByAreaId(@Param("areaId") Integer paramInteger);
}
public abstract interface UplusAddressService extends Service {
public abstract List findByUserId(@Param("userId") Long paramLong);
public abstract AddressModel findByAddressId(@Param("addressId") Long paramLong);
public abstract int updateDefault(@Param("userId") Long paramLong);
public abstract int copyAddressInOrderById(UplusOrderAddress paramUplusOrderAddress);
public abstract AddressModel findByOrderAddressId(@Param("addressId") Long paramLong);
}
Service impl:
@Service
@Transactional
public class UplusAreaServiceImpl extends AbstractService implements UplusAreaService {
@Resource
private UplusAreaMapper uplusAreaMapper;
public List findByPid(Integer pid) {
return this.uplusAreaMapper.findByPid(pid);
}
public int updateTest(List list) {
return this.uplusAreaMapper.updateTest(list);
}
public List findTest() {
return this.uplusAreaMapper.findTest();
}
public UplusArea findByAreaId(Integer areaId) {
return this.uplusAreaMapper.findByAreaId(areaId);
}
}
@Service
@Transactional
public class UplusAddressServiceImpl extends AbstractService implements UplusAddressService {
@Resource
private UplusAddressMapper uplusAddressMapper;
public List findByUserId(Long userId)
{
return this.uplusAddressMapper.findByUserId(userId);
}
public AddressModel findByAddressId(Long addressId)
{
return this.uplusAddressMapper.findByAddressId(addressId);
}
public int updateDefault(Long userId)
{
return this.uplusAddressMapper.updateDefault(userId);
}
public int copyAddressInOrderById(UplusOrderAddress uplusOrderAddress)
{
return this.uplusAddressMapper.copyAddressInOrderById(uplusOrderAddress);
}
public AddressModel findByOrderAddressId(Long addressId)
{
return this.uplusAddressMapper.findByOrderAddressId(addressId);
}
}
mapper:
public abstract interface UplusAddressMapper extends Mapper{
public abstract List findByUserId(@Param("userId") Long paramLong);
public abstract AddressModel findByAddressId(@Param("addressId") Long paramLong);
public abstract int updateDefault(@Param("userId") Long paramLong);
public abstract int copyAddressInOrderById(UplusOrderAddress paramUplusOrderAddress);
public abstract AddressModel findByOrderAddressId(@Param("addressId") Long paramLong);
}
update UPLUS_ADDRESS set IS_DEFAULT = 0 where USER_ID = #{userId};
INSERT INTO UPLUS_ORDER_ADDRESS (USER_ID,PROVINCE_ID,CITY_ID,DISTRICT_ID, NAME, TAG, MOBILE, REMARK, IS_DEFAULT,CREATE_DATE,UPDATE_DATE ,CREATE_USER)
(SELECT USER_ID,PROVINCE_ID,CITY_ID,DISTRICT_ID, NAME, TAG, MOBILE, REMARK, IS_DEFAULT,CREATE_DATE,UPDATE_DATE ,CREATE_USER FROM UPLUS_ADDRESS WHERE ID = #{tag})
select LAST_INSERT_ID() AS id