package com.bashi.dk.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.bashi.common.annotation.Log; import com.bashi.common.annotation.RepeatSubmit; import com.bashi.common.com.PageParams; import com.bashi.common.core.controller.BaseController; import com.bashi.common.core.domain.AjaxResult; import com.bashi.common.core.domain.entity.Customer; import com.bashi.common.core.page.TableDataInfo; import com.bashi.common.enums.BusinessType; import com.bashi.common.utils.PageUtils; import com.bashi.common.utils.poi.ExcelUtil; import com.bashi.dk.dto.admin.req.UpdatePwdCustomerReq; import com.bashi.dk.dto.admin.resp.CustomerAdminResp; import com.bashi.dk.dto.admin.resp.CustomerExportVo; import com.bashi.dk.mapper.CustomerMapper; import com.bashi.dk.service.CustomerService; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController @RequestMapping("/dk/dkCustomer") public class DkCustomerController extends BaseController { private final CustomerService customerService; @Resource private CustomerMapper customerMapper; @PreAuthorize("@ss.hasPermi('dk:dkCustomer:list')") @GetMapping("/list") public TableDataInfo list(PageParams pageParams, @Validated CustomerAdminResp bo) { IPage page = customerService.pageAdmin(pageParams, bo); return PageUtils.buildDataInfo(page); } @ApiOperation("导出客户列表") @PreAuthorize("@ss.hasPermi('dk:dkCustomer:export')") @Log(title = "客户", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(@Validated CustomerAdminResp bo) { List list = customerMapper.exportAdmin(bo); ExcelUtil util = new ExcelUtil<>(CustomerExportVo.class); return util.exportExcel(list, "客户"); } @PreAuthorize("@ss.hasPermi('dk:dkCustomer:query')") @GetMapping("/{id}") public AjaxResult getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) { return AjaxResult.success(customerService.getById(id)); } @PreAuthorize("@ss.hasPermi('dk:dkCustomer:edit')") @Log(title = "客户", businessType = BusinessType.UPDATE) @RepeatSubmit @PutMapping() public AjaxResult edit(@Validated @RequestBody Customer bo) { return toAjax(customerService.updateById(bo) ? 1 : 0); } @DeleteMapping("/{ids}") public AjaxResult remove(@NotEmpty(message = "主键不能为空") @PathVariable String ids) { List idList = Stream.of(ids.split(",")).collect(Collectors.toList()); return toAjax(customerService.removeByIds(idList) ? 1 : 0); } @Log(title = "修改密码" , businessType = BusinessType.DELETE) @PostMapping("/resetPwd") public AjaxResult resetPwd(@RequestBody UpdatePwdCustomerReq customer) { return toAjax(customerService.updatePwd(customer.getCustomerId(),customer.getPassword())); } }