|
|
@@ -0,0 +1,164 @@
|
|
|
+package org.dromara.customer.pc.controller;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import jakarta.validation.constraints.*;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.log.annotation.Log;
|
|
|
+import org.dromara.common.log.enums.BusinessType;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.common.web.core.BaseController;
|
|
|
+import org.dromara.customer.domain.bo.CustomerContactBo;
|
|
|
+import org.dromara.customer.domain.vo.CustomerContactVo;
|
|
|
+import org.dromara.customer.service.ICustomerContactService;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.dromara.common.core.validate.AddGroup;
|
|
|
+import org.dromara.common.core.validate.EditGroup;
|
|
|
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * PC端 - 人员管理
|
|
|
+ * 前端访问路由地址为:/pc/organization/contact
|
|
|
+ *
|
|
|
+ * @author Claude
|
|
|
+ * @date 2026-01-27
|
|
|
+ */
|
|
|
+@SaIgnore
|
|
|
+@Validated
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/pc/organization/contact")
|
|
|
+public class PcContactController extends BaseController {
|
|
|
+
|
|
|
+ private final ICustomerContactService customerContactService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前登录用户的个人信息
|
|
|
+ */
|
|
|
+ @GetMapping("/current")
|
|
|
+ public R<CustomerContactVo> getCurrentUserInfo() {
|
|
|
+ // TODO: 需要根据当前登录用户的实际ID查询联系人信息
|
|
|
+ // 目前LoginHelper.getUserId()返回的是customerId(企业ID)
|
|
|
+ // 需要通过其他方式(如手机号、用户名)来查询当前用户的联系人记录
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 查询该企业下的联系人(不限制是否为主联系人)
|
|
|
+ CustomerContactBo bo = new CustomerContactBo();
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ List<CustomerContactVo> list = customerContactService.queryList(bo);
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ return R.ok(list.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.fail("未找到当前用户信息,customerId: " + customerId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前企业的联系人列表
|
|
|
+ * PC端用户只能查询自己企业的联系人
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo<CustomerContactVo> list(CustomerContactBo bo, PageQuery pageQuery) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+ // 强制设置企业ID,防止越权访问
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return customerContactService.queryPageList(bo, pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取联系人详细信息
|
|
|
+ * PC端用户只能查询自己企业的联系人
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ */
|
|
|
+ @GetMapping("/{id:[0-9]+}")
|
|
|
+ public R<CustomerContactVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
+ @PathVariable("id") Long id) {
|
|
|
+ // 查询联系人信息
|
|
|
+ CustomerContactVo vo = customerContactService.queryById(id);
|
|
|
+
|
|
|
+ // 验证联系人是否属于当前用户的企业
|
|
|
+ if (vo != null) {
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+ if (!customerId.equals(vo.getCustomerId())) {
|
|
|
+ return R.fail("无权访问该联系人");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增联系人
|
|
|
+ */
|
|
|
+ @Log(title = "PC端-人员管理", businessType = BusinessType.INSERT)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping()
|
|
|
+ public R<Void> add(@Validated(AddGroup.class) @RequestBody CustomerContactBo bo) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+ // 强制设置企业ID,防止为其他企业添加联系人
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return toAjax(customerContactService.insertByBo(bo));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改联系人
|
|
|
+ */
|
|
|
+ @Log(title = "PC端-人员管理", businessType = BusinessType.UPDATE)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PutMapping()
|
|
|
+ public R<Void> edit(@Validated(EditGroup.class) @RequestBody CustomerContactBo bo) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 验证联系人是否属于当前用户的企业
|
|
|
+ CustomerContactVo existingContact = customerContactService.queryById(bo.getId());
|
|
|
+ if (existingContact == null) {
|
|
|
+ return R.fail("联系人不存在");
|
|
|
+ }
|
|
|
+ if (!customerId.equals(existingContact.getCustomerId())) {
|
|
|
+ return R.fail("无权修改该联系人");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制设置企业ID
|
|
|
+ bo.setCustomerId(customerId);
|
|
|
+
|
|
|
+ return toAjax(customerContactService.updateByBo(bo));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除联系人
|
|
|
+ *
|
|
|
+ * @param ids 主键串
|
|
|
+ */
|
|
|
+ @Log(title = "PC端-人员管理", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
|
|
+ @PathVariable("ids") Long[] ids) {
|
|
|
+ // 获取当前登录用户的企业ID
|
|
|
+ Long customerId = LoginHelper.getUserId();
|
|
|
+
|
|
|
+ // 验证所有联系人是否都属于当前用户的企业
|
|
|
+ for (Long id : ids) {
|
|
|
+ CustomerContactVo contact = customerContactService.queryById(id);
|
|
|
+ if (contact == null) {
|
|
|
+ return R.fail("联系人ID " + id + " 不存在");
|
|
|
+ }
|
|
|
+ if (!customerId.equals(contact.getCustomerId())) {
|
|
|
+ return R.fail("无权删除联系人ID " + id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return toAjax(customerContactService.deleteWithValidByIds(List.of(ids), true));
|
|
|
+ }
|
|
|
+}
|