Files
dk-server/bashi-dk/src/main/java/com/bashi/dk/controller/DkCustomerController.java
dute7liang 5b04a92a55 init
2023-12-19 22:26:38 +08:00

89 lines
3.6 KiB
Java

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<CustomerAdminResp> list(PageParams pageParams, @Validated CustomerAdminResp bo) {
IPage<CustomerAdminResp> 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<CustomerExportVo> export(@Validated CustomerAdminResp bo) {
List<CustomerExportVo> list = customerMapper.exportAdmin(bo);
ExcelUtil<CustomerExportVo> util = new ExcelUtil<>(CustomerExportVo.class);
return util.exportExcel(list, "客户");
}
@PreAuthorize("@ss.hasPermi('dk:dkCustomer:query')")
@GetMapping("/{id}")
public AjaxResult<Customer> 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<Void> edit(@Validated @RequestBody Customer bo) {
return toAjax(customerService.updateById(bo) ? 1 : 0);
}
@DeleteMapping("/{ids}")
public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable String ids) {
List<String> idList = Stream.of(ids.split(",")).collect(Collectors.toList());
return toAjax(customerService.removeByIds(idList) ? 1 : 0);
}
@Log(title = "修改密码" , businessType = BusinessType.DELETE)
@PostMapping("/resetPwd")
public AjaxResult<Void> resetPwd(@RequestBody UpdatePwdCustomerReq customer) {
return toAjax(customerService.updatePwd(customer.getCustomerId(),customer.getPassword()));
}
}