package com.cloudroam.controller.v1; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.cloudroam.bo.ContactInfoBO; import com.cloudroam.common.util.PageUtil; import com.cloudroam.dto.company.CreateOrUpdateCompanyInfoDTO; import com.cloudroam.dto.contact.CreateOrUpdateContactDTO; import com.cloudroam.dto.contact.QueryContactDTO; import com.cloudroam.dto.projectInfo.CreateOrUpdateProjectInfoDTO; import com.cloudroam.model.CompanyInfoDO; import com.cloudroam.service.ContactInfoService; import io.github.talelin.autoconfigure.exception.NotFoundException; import io.github.talelin.core.annotation.Logger; import io.github.talelin.core.annotation.LoginRequired; import io.github.talelin.core.annotation.PermissionMeta; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import com.cloudroam.model.ContactInfoDO; import com.cloudroam.vo.CreatedVO; import com.cloudroam.vo.DeletedVO; import com.cloudroam.vo.PageResponseVO; import com.cloudroam.vo.UpdatedVO; import javax.validation.constraints.Positive; import java.util.List; /** * @author generator@TaoJie * @since 2023-08-08 */ @RestController @RequestMapping("/v1/contact-info") @Validated public class ContactInfoController { @Autowired private ContactInfoService contactInfoService; @PostMapping("") @LoginRequired @PermissionMeta(value = "客户联系人创建", module = "客户联系人",mount = false) @Logger(template = "{user.nickname} 创建了客户联系人 ") public CreatedVO create(@RequestBody @Validated CreateOrUpdateContactDTO validator) { contactInfoService.CreateContactInfo(validator); return new CreatedVO(); } @PutMapping("/{id}") @LoginRequired @PermissionMeta(value = "客户联系人编辑", module = "客户联系人",mount = false) @Logger(template = "{user.nickname} 编辑了客户联系人 ") public UpdatedVO update(@PathVariable String id,@RequestBody @Validated CreateOrUpdateContactDTO validator) { if(StrUtil.isBlank(id)){ throw new NotFoundException("传入的Id不能为空"); } ContactInfoDO contactInfoDO = contactInfoService.getById(id); if(contactInfoDO == null){ throw new NotFoundException("记录不存在"); } contactInfoService.updateContactInfo(validator); return new UpdatedVO(); } @DeleteMapping("/{id}") @LoginRequired @PermissionMeta(value = "客户联系人删除", module = "客户联系人",mount = false) @Logger(template = "{user.nickname} 删除了客户联系人 ") public DeletedVO delete(@PathVariable String id) { if(StrUtil.isBlank(id)){ throw new NotFoundException("id不能为空"); } ContactInfoDO contactInfoDO = contactInfoService.getById(id); if (contactInfoDO == null) { throw new NotFoundException("记录不存在"); } contactInfoService.removeByIdLogic(id); return new DeletedVO(); } @GetMapping("/{id}") public ContactInfoDO get(@PathVariable(value = "id") String id) { if(StrUtil.isBlank(id)){ throw new NotFoundException("id不能为空"); } ContactInfoDO contactInfoDO = contactInfoService.getById(id); if (contactInfoDO == null) { throw new NotFoundException("记录不存在"); } return contactInfoDO; } @LoginRequired @PermissionMeta(value = "客户联系人列表", module = "客户联系人",mount = true) @Logger(template = "{user.nickname} 查看客户联系人 ") @GetMapping("/page") public PageResponseVO page( @Validated QueryContactDTO dto ) { IPage iPage=contactInfoService.getContactInfoPage(dto); return PageUtil.build(iPage); } @GetMapping("/list") public List list( @Validated QueryContactDTO dto ) { List list=contactInfoService.getContactList(dto); return list; } }