Browse Source

完善收购商地址管理

李书文 1 year ago
parent
commit
7e651634fc

+ 4 - 1
sp-core/sp-base/src/main/java/com/pj/utils/sg/AjaxJson.java

@@ -207,7 +207,10 @@ public class AjaxJson extends LinkedHashMap<String, Object> implements Serializa
 	public static AjaxJson getByBoolean(boolean b){
 		return b ? getSuccess("ok") : getError("error"); 
 	}
-	
+
+	public static AjaxJson toAjax(boolean result) {
+		return result ? getSuccess() : getError();
+	}
 	
 	// 重写toString,转json格式输出 
 	@Override

+ 0 - 28
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/MethodPurchaserAddressService.java

@@ -1,28 +0,0 @@
-package com.pj.tb_purchaser_address;
-
-import com.pj.tb_purchaser.TbPurchaserMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * @Author Mechrevo
- * @Date 2023 07 27 14 39
- **/
-@Service
-@Transactional
-public class MethodPurchaserAddressService {
-
-    @Autowired
-    private TbPurchaserMapper tbPurchaserMapper;
-
-    String addressString(TbPurchaserAddress tbPurchaserAddress){
-        String detailAddress = (tbPurchaserAddress.getProvince() == null ? "" : tbPurchaserAddress.getProvince()
-                + tbPurchaserAddress.getCity() == null ? "" : tbPurchaserAddress.getCity()
-                + tbPurchaserAddress.getTown() == null ? "" : tbPurchaserAddress.getTown()
-                + tbPurchaserAddress.getStreet() == null ? "" : tbPurchaserAddress.getStreet()
-                + tbPurchaserAddress.getBuildingNo() == null ? "" : tbPurchaserAddress.getBuildingNo()).trim();
-        return detailAddress;
-    }
-
-}

+ 51 - 45
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/PurchaserAddressAppController.java

@@ -1,63 +1,69 @@
 package com.pj.tb_purchaser_address;
 
-import cn.dev33.satoken.annotation.SaCheckPermission;
-import com.pj.project4sp.SP;
-import com.pj.tb_purchaser_address.param.TbPurchaserAddressParam;
+import com.pj.current.satoken.StpAPPUserUtil;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
 
 /**
  * Controller: tb_purchaser_address -- 收购商个人地址管理表
- * @author qzy 
+ *
+ * @author qzy
  */
 @RestController
-@RequestMapping("/app/TbPurchaserAddress/")
+@RequestMapping("/app/address/")
 public class PurchaserAddressAppController {
 
-	/** 底层 Service 对象 */
-	@Autowired
-	TbPurchaserAddressService tbPurchaserAddressService;
-
-	/** 增 */  
-	@RequestMapping("appAdd")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_ADD)
-	public AjaxJson add(@Validated @RequestBody TbPurchaserAddressParam t){
-		boolean b = tbPurchaserAddressService.appAdd(t);
-		if(b)return AjaxJson.getSuccess("地址添加成功!");
-		return AjaxJson.getSuccess("地址添加失败!");
-	}
-
-	/** 删 */  
-	@RequestMapping("appDelete")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_DEL)
-	public AjaxJson delete(@RequestBody List<Long> ids){
-		 tbPurchaserAddressService.appDelete(ids);
-		return AjaxJson.getSuccess();
-	}
-	
-	/** 改 */  
-	@RequestMapping("appUpdate")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_EDIT)
-	public AjaxJson update(@Validated @RequestBody TbPurchaserAddressParam t){
-		tbPurchaserAddressService.appUpdate(t);
-		return AjaxJson.getSuccess();
-	}
-
-	/** 查集合 - 仅查询当前登陆人的地址信息 */
-	@RequestMapping("selectOwnAddress")
-		@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE)
-	public AjaxJson selectOwnAddress() {
-		SoMap so = SoMap.getRequestSoMap();
-		List<TbPurchaserAddress> list = tbPurchaserAddressService.selectOwnAddress(so.startPage());
-		return AjaxJson.getPageData(so.getDataCount(), list);
-	}
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    TbPurchaserAddressService service;
+
+    /**
+     * 新增/编辑
+     */
+    @PostMapping("saveOrUpdate")
+    public AjaxJson saveOrUpdate(@Validated TbPurchaserAddress address) {
+        address.setUserId(StpAPPUserUtil.getAPPLoginInfo().getLoginId());
+        return AjaxJson.toAjax(service.saveOrUpdate(address));
+    }
+
+    /**
+     * 获取详情
+     */
+    @GetMapping("getById/{id}")
+    public AjaxJson getById(@PathVariable Long id) {
+        return AjaxJson.getSuccessData(service.getById(id));
+    }
+
+    /**
+     * 删除
+     */
+    @GetMapping("delete/{id}")
+    public AjaxJson delete(@PathVariable Long id) {
+        TbPurchaserAddress address = new TbPurchaserAddress();
+        address.setId(id);
+        address.setUserId(StpAPPUserUtil.getAPPLoginInfo().getLoginId());
+        return AjaxJson.toAjax(service.deleteByIdAndUserId(address));
+    }
+
+    /**
+     * 我的地址
+     *
+     * @return
+     */
+    @RequestMapping("getList")
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        so.put("userId", StpAPPUserUtil.getAPPLoginInfo().getLoginId());
+        List<TbPurchaserAddress> list = service.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
 
 }

+ 73 - 77
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/TbPurchaserAddress.java

@@ -1,16 +1,21 @@
 package com.pj.tb_purchaser_address;
 
-import java.io.Serializable;
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
-import lombok.EqualsAndHashCode;
-
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Pattern;
+import java.io.Serializable;
+
 /**
  * Model: tb_purchaser_address -- 收购商个人地址管理表
- * @author qzy 
+ *
+ * @author qzy
  */
 @Data
 @Accessors(chain = true)
@@ -18,78 +23,69 @@ import lombok.experimental.Accessors;
 @EqualsAndHashCode(callSuper = false)
 public class TbPurchaserAddress extends Model<TbPurchaserAddress> implements Serializable {
 
-	// ---------- 模块常量 ----------
-	/**
-	 * 序列化版本id 
-	 */
-	private static final long serialVersionUID = 1L;	
-	/**
-	 * 此模块对应的表名 
-	 */
-	public static final String TABLE_NAME = "tb_purchaser_address";	
-	/**
-	 * 此模块对应的权限码 
-	 */
-	public static final String PERMISSION_CODE = "tb-purchaser-address";
-	public static final String PERMISSION_CODE_ADD = "tb-purchaser-address-add";
-	public static final String PERMISSION_CODE_EDIT = "tb-purchaser-address-edit";
-	public static final String PERMISSION_CODE_DEL = "tb-purchaser-address-del";
-
-
-
-
-	// ---------- 表中字段 ----------
-	/**
-	 * 收购商地址表主键ID 
-	 */
-	@TableId(type = IdType.AUTO)
-	private Integer id;	
-
-	/**
-	 * 该地址拥有者主键 
-	 */
-	private Long owner;	
-
-	/**
-	 * 省 
-	 */
-	private String province;	
-
-	/**
-	 * 市 
-	 */
-	private String city;	
-
-	/**
-	 * 镇/区 
-	 */
-	private String town;	
-
-	/**
-	 * 街道 
-	 */
-	private String street;	
-
-	/**
-	 * 楼号 
-	 */
-	private String buildingNo;	
-
-	/**
-	 * 地址全称 
-	 */
-	private String addressName;	
-
-	/**
-	 * 邮编 
-	 */
-	private Integer postNum;	
-
-
-
-
-
-	
+    // ---------- 模块常量 ----------
+    /**
+     * 序列化版本id
+     */
+    private static final long serialVersionUID = 1L;
+    /**
+     * 此模块对应的表名
+     */
+    public static final String TABLE_NAME = "tb_purchaser_address";
+    /**
+     * 此模块对应的权限码
+     */
+    public static final String PERMISSION_CODE = "tb-purchaser-address";
+    public static final String PERMISSION_CODE_ADD = "tb-purchaser-address-add";
+    public static final String PERMISSION_CODE_EDIT = "tb-purchaser-address-edit";
+    public static final String PERMISSION_CODE_DEL = "tb-purchaser-address-del";
+
+
+    // ---------- 表中字段 ----------
+    /**
+     * 收购商地址表主键ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 该地址拥有者主键
+     */
+    private Long userId;
+
+    /**
+     * 收件人姓名
+     */
+    @NotBlank(message = "收件人不能为空")
+    private String name;
+
+    /**
+     * 收件人电话
+     */
+    @Pattern(regexp = "^1[0-9]{10}$", message = "手机号不合法")
+    private String phone;
+
+    /**
+     * 省
+     */
+    private String province;
+
+    /**
+     * 市
+     */
+    private String city;
+
+    /**
+     * 区
+     */
+    @NotBlank(message = "省市区不能为空")
+    private String area;
+
+    /**
+     * 详细地址
+     */
+    @NotBlank(message = "详细地址不能为空")
+    private String street;
 
 
 }

+ 0 - 85
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/TbPurchaserAddressController.java

@@ -1,85 +0,0 @@
-package com.pj.tb_purchaser_address;
-
-import java.util.List;
-import com.pj.utils.so.SoMap;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import com.pj.utils.sg.*;
-import com.pj.project4sp.SP;
-
-import cn.dev33.satoken.annotation.SaCheckPermission;
-
-
-/**
- * Controller: tb_purchaser_address -- 收购商个人地址管理表
- * @author qzy 
- */
-@RestController
-@RequestMapping("/TbPurchaserAddress/")
-public class TbPurchaserAddressController {
-
-	/** 底层 Service 对象 */
-	@Autowired
-	TbPurchaserAddressService tbPurchaserAddressService;
-
-	/** 增 */  
-	@RequestMapping("add")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_ADD)
-	public AjaxJson add(TbPurchaserAddress t){
-		tbPurchaserAddressService.add(t);
-		t = tbPurchaserAddressService.getById(SP.publicMapper.getPrimarykey());
-		return AjaxJson.getSuccessData(t);
-	}
-
-	/** 删 */  
-	@RequestMapping("delete")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_DEL)
-	public AjaxJson delete(Long id){
-		 tbPurchaserAddressService.delete(id);
-		return AjaxJson.getSuccess();
-	}
-	
-	/** 删 - 根据id列表 */  
-	@RequestMapping("deleteByIds")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_DEL)
-	public AjaxJson deleteByIds(){
-		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
-		int line = SP.publicMapper.deleteByIds(TbPurchaserAddress.TABLE_NAME, ids);
-		return AjaxJson.getByLine(line);
-	}
-	
-	/** 改 */  
-	@RequestMapping("update")
-	@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE_EDIT)
-	public AjaxJson update(TbPurchaserAddress t){
-		tbPurchaserAddressService.update(t);
-		return AjaxJson.getSuccess();
-	}
-
-	/** 查 - 根据id */  
-	@RequestMapping("getById")
-		@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE)
-	public AjaxJson getById(Integer id){
-		TbPurchaserAddress t = tbPurchaserAddressService.getById(id);
-		return AjaxJson.getSuccessData(t);
-	}
-
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	@RequestMapping("getList")
-		@SaCheckPermission(TbPurchaserAddress.PERMISSION_CODE)
-	public AjaxJson getList() { 
-		SoMap so = SoMap.getRequestSoMap();
-		List<TbPurchaserAddress> list = tbPurchaserAddressService.getList(so.startPage());
-		return AjaxJson.getPageData(so.getDataCount(), list);
-	}
-	
-	
-	
-	
-
-	
-	
-	
-
-}

+ 13 - 8
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/TbPurchaserAddressMapper.java

@@ -2,6 +2,7 @@ package com.pj.tb_purchaser_address;
 
 import java.util.List;
 
+import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
@@ -10,21 +11,25 @@ import org.springframework.stereotype.Repository;
 
 /**
  * Mapper: tb_purchaser_address -- 收购商个人地址管理表
- * @author qzy 
+ *
+ * @author qzy
  */
 
 @Mapper
 @Repository
-public interface TbPurchaserAddressMapper extends BaseMapper <TbPurchaserAddress> {
+public interface TbPurchaserAddressMapper extends BaseMapper<TbPurchaserAddress> {
 
 
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     *
+     * @param so 参数集合
+     * @return 数据列表
+     */
+    List<TbPurchaserAddress> getList(SoMap so);
 
-	/**
-	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
-	 * @param so 参数集合 
-	 * @return 数据列表 
-	 */
-	List<TbPurchaserAddress> getList(SoMap so);
 
+    @Delete("DELETE FROM tb_purchaser_address WHERE id=#{id} AND user_id=#{userId}")
+    boolean deleteByIdAndUserId(TbPurchaserAddress address);
 
 }

+ 19 - 107
sp-service/level-two-server/src/main/java/com/pj/tb_purchaser_address/TbPurchaserAddressService.java

@@ -1,125 +1,37 @@
 package com.pj.tb_purchaser_address;
 
-import java.util.List;
-
-import com.pj.current.dto.APPLoginUserInfo;
-import com.pj.current.satoken.StpAPPUserUtil;
-import com.pj.tb_purchaser_address.param.TbPurchaserAddressParam;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.pj.utils.so.SoMap;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
-import com.pj.utils.sg.*;
+
+import java.util.List;
 
 /**
  * Service: tb_purchaser_address -- 收购商个人地址管理表
- * @author qzy 
+ *
+ * @author qzy
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
-public class TbPurchaserAddressService extends ServiceImpl<TbPurchaserAddressMapper, TbPurchaserAddress> implements IService<TbPurchaserAddress>{
-
-	/** 底层 Mapper 对象 */
-	@Autowired
-	TbPurchaserAddressMapper tbPurchaserAddressMapper;
-
-	@Autowired
-	private MethodPurchaserAddressService methodPurchaserService;
-
-	/** 增 */
-	void add(TbPurchaserAddress t){
-		save(t);
-	}
-
-	/** 删 */
-	void delete(Long id){
-		removeById(id);
-	}
-
-	/** 改 */
-	void update(TbPurchaserAddress t){
-		updateById(t);
-
-	}
-
-	/** 查 */
-	TbPurchaserAddress getById(Integer id){
-		return super.getById(id);
-	}
-
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	List<TbPurchaserAddress> getList(SoMap so) {
-		return tbPurchaserAddressMapper.getList(so);	
-	}
-
-	/** 查集合 - 仅查询当前登陆人的地址信息 */
-	List<TbPurchaserAddress> selectOwnAddress(SoMap so) {
-		//获取当前登陆人ID
-		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
-		if(appLoginInfo == null)throw new RuntimeException("当前登录账号信息已失效!");
-		so.set("owner",appLoginInfo.getLoginId());
-		return tbPurchaserAddressMapper.getList(so);
-	}
-
-	/** app增地址 */
-	boolean appAdd(TbPurchaserAddressParam t){
-		//获取当前登陆人ID
-		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
-		if(appLoginInfo == null)throw new RuntimeException("当前登录账号信息已失效!");
-		TbPurchaserAddress tbPurchaserAddress = new TbPurchaserAddress();
-		BeanUtils.copyProperties(t,tbPurchaserAddress);
-		//地址所属人
-		tbPurchaserAddress.setOwner(appLoginInfo.getLoginId());
-		//地址全称  省 市 镇/区 街道 楼号  邮编
-		String addressString = methodPurchaserService.addressString(tbPurchaserAddress);
-		tbPurchaserAddress.setAddressName(addressString);
-		boolean save = save(tbPurchaserAddress);
-		return save;
-	}
-
+public class TbPurchaserAddressService extends ServiceImpl<TbPurchaserAddressMapper, TbPurchaserAddress> implements IService<TbPurchaserAddress> {
 
-	/** app改地址 */
-	void appUpdate(TbPurchaserAddressParam t){
-		//获取当前登陆人ID
-		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
-		if(appLoginInfo == null)throw new RuntimeException("当前登录账号信息已失效!");
-		//安全判定
-		if(!appLoginInfo.getLoginId().toString().equals(t.getOwner().toString())){
-			throw new RuntimeException("非法操作!");
-		}
-		//数据拷贝
-		TbPurchaserAddress tbPurchaserAddress = new TbPurchaserAddress();
-		BeanUtils.copyProperties(t,tbPurchaserAddress);
-		//拼接详细地址
-		String addressString = methodPurchaserService.addressString(tbPurchaserAddress);
-		//保存
-		t.setAddressName(addressString);
-		updateById(tbPurchaserAddress);
+    /**
+     * 底层 Mapper 对象
+     */
+    @Autowired
+    TbPurchaserAddressMapper tbPurchaserAddressMapper;
 
-	}
 
-	/** 删 */
-	void appDelete(List<Long> ids){
-		if(ids.size() == 0)return;
-		//获取登陆人
-		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
-		if(appLoginInfo == null)throw new RuntimeException("当前登录账号信息已失效!");
-		//查询验证
-		ids.forEach(item -> {
-			TbPurchaserAddress tbPurchaserAddress = tbPurchaserAddressMapper.selectById(item);
-			if(tbPurchaserAddress != null){
-				//验证
-				if(tbPurchaserAddress.getOwner().toString().equals(appLoginInfo.getLoginId().toString())){
-					//验证通过删除
-					removeById(item);
-				}
-				throw new RuntimeException("非法操作!");
-			}
-		});
-	}
+    /** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
+    List<TbPurchaserAddress> getList(SoMap so) {
+        return tbPurchaserAddressMapper.getList(so);
+    }
 
+    boolean deleteByIdAndUserId(TbPurchaserAddress address) {
+        return tbPurchaserAddressMapper.deleteByIdAndUserId(address);
+    }
 
 }