parent
e8c4837c54
commit
fba3f7140d
@ -1,95 +0,0 @@
|
||||
package com.chanko.yunxi.mes.module.heli.controller.admin.client;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.CommonResult;
|
||||
import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils;
|
||||
import static com.chanko.yunxi.mes.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.chanko.yunxi.mes.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.chanko.yunxi.mes.framework.operatelog.core.annotations.OperateLog;
|
||||
import static com.chanko.yunxi.mes.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
|
||||
import com.chanko.yunxi.mes.module.heli.service.client.ClientService;
|
||||
|
||||
@Tag(name = "管理后台 - 客户")
|
||||
@RestController
|
||||
@RequestMapping("/heli/client")
|
||||
@Validated
|
||||
public class ClientController {
|
||||
|
||||
@Resource
|
||||
private ClientService clientService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户")
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:create')")
|
||||
public CommonResult<Long> createClient(@Valid @RequestBody ClientSaveReqVO createReqVO) {
|
||||
return success(clientService.createClient(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新客户")
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:update')")
|
||||
public CommonResult<Boolean> updateClient(@Valid @RequestBody ClientSaveReqVO updateReqVO) {
|
||||
clientService.updateClient(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除客户")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:delete')")
|
||||
public CommonResult<Boolean> deleteClient(@RequestParam("id") Long id) {
|
||||
clientService.deleteClient(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得客户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:query')")
|
||||
public CommonResult<ClientRespVO> getClient(@RequestParam("id") Long id) {
|
||||
ClientDO client = clientService.getClient(id);
|
||||
return success(BeanUtils.toBean(client, ClientRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得客户分页")
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:query')")
|
||||
public CommonResult<PageResult<ClientRespVO>> getClientPage(@Valid ClientPageReqVO pageReqVO) {
|
||||
PageResult<ClientDO> pageResult = clientService.getClientPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ClientRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出客户 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('heli:client:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportClientExcel(@Valid ClientPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ClientDO> list = clientService.getClientPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "客户.xls", "数据", ClientRespVO.class,
|
||||
BeanUtils.toBean(list, ClientRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.chanko.yunxi.mes.module.heli.dal.mysql.client;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
import com.chanko.yunxi.mes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.chanko.yunxi.mes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
|
||||
|
||||
/**
|
||||
* 客户 Mapper
|
||||
*
|
||||
* @author 开发者
|
||||
*/
|
||||
@Mapper
|
||||
public interface ClientMapper extends BaseMapperX<ClientDO> {
|
||||
|
||||
default PageResult<ClientDO> selectPage(ClientPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ClientDO>()
|
||||
.likeIfPresent(ClientDO::getCode, reqVO.getCode())
|
||||
.likeIfPresent(ClientDO::getSimpleName, reqVO.getSimpleName())
|
||||
.likeIfPresent(ClientDO::getName, reqVO.getName())
|
||||
.likeIfPresent(ClientDO::getTelephone, reqVO.getTelephone())
|
||||
.eqIfPresent(ClientDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(ClientDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.client;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 客户 Service 接口
|
||||
*
|
||||
* @author 开发者
|
||||
*/
|
||||
public interface ClientService {
|
||||
|
||||
/**
|
||||
* 创建客户
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createClient(@Valid ClientSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新客户
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateClient(@Valid ClientSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteClient(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 客户
|
||||
*/
|
||||
ClientDO getClient(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 客户分页
|
||||
*/
|
||||
PageResult<ClientDO> getClientPage(ClientPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.client;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
|
||||
import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.chanko.yunxi.mes.module.heli.dal.mysql.client.ClientMapper;
|
||||
|
||||
import static com.chanko.yunxi.mes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 客户 Service 实现类
|
||||
*
|
||||
* @author 开发者
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ClientServiceImpl implements ClientService {
|
||||
|
||||
@Resource
|
||||
private ClientMapper clientMapper;
|
||||
|
||||
@Override
|
||||
public Long createClient(ClientSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ClientDO client = BeanUtils.toBean(createReqVO, ClientDO.class);
|
||||
clientMapper.insert(client);
|
||||
// 返回
|
||||
return client.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient(ClientSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateClientExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ClientDO updateObj = BeanUtils.toBean(updateReqVO, ClientDO.class);
|
||||
clientMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteClient(Long id) {
|
||||
// 校验存在
|
||||
validateClientExists(id);
|
||||
// 删除
|
||||
clientMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateClientExists(Long id) {
|
||||
if (clientMapper.selectById(id) == null) {
|
||||
throw exception(CLIENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientDO getClient(Long id) {
|
||||
return clientMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ClientDO> getClientPage(ClientPageReqVO pageReqVO) {
|
||||
return clientMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.client;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.chanko.yunxi.mes.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.mysql.client.ClientMapper;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*;
|
||||
import static com.chanko.yunxi.mes.framework.test.core.util.AssertUtils.*;
|
||||
import static com.chanko.yunxi.mes.framework.test.core.util.RandomUtils.*;
|
||||
import static com.chanko.yunxi.mes.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static com.chanko.yunxi.mes.framework.common.util.object.ObjectUtils.*;
|
||||
import static com.chanko.yunxi.mes.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link ClientServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 开发者
|
||||
*/
|
||||
@Import(ClientServiceImpl.class)
|
||||
public class ClientServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ClientServiceImpl clientService;
|
||||
|
||||
@Resource
|
||||
private ClientMapper clientMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateClient_success() {
|
||||
// 准备参数
|
||||
ClientSaveReqVO createReqVO = randomPojo(ClientSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long clientId = clientService.createClient(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(clientId);
|
||||
// 校验记录的属性是否正确
|
||||
ClientDO client = clientMapper.selectById(clientId);
|
||||
assertPojoEquals(createReqVO, client, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClient_success() {
|
||||
// mock 数据
|
||||
ClientDO dbClient = randomPojo(ClientDO.class);
|
||||
clientMapper.insert(dbClient);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
ClientSaveReqVO updateReqVO = randomPojo(ClientSaveReqVO.class, o -> {
|
||||
o.setId(dbClient.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
clientService.updateClient(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ClientDO client = clientMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClient_notExists() {
|
||||
// 准备参数
|
||||
ClientSaveReqVO updateReqVO = randomPojo(ClientSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> clientService.updateClient(updateReqVO), CLIENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClient_success() {
|
||||
// mock 数据
|
||||
ClientDO dbClient = randomPojo(ClientDO.class);
|
||||
clientMapper.insert(dbClient);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbClient.getId();
|
||||
|
||||
// 调用
|
||||
clientService.deleteClient(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(clientMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClient_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> clientService.deleteClient(id), CLIENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetClientPage() {
|
||||
// mock 数据
|
||||
ClientDO dbClient = randomPojo(ClientDO.class, o -> { // 等会查询到
|
||||
o.setCode(null);
|
||||
o.setSimpleName(null);
|
||||
o.setName(null);
|
||||
o.setTelephone(null);
|
||||
o.setStatus(null);
|
||||
});
|
||||
clientMapper.insert(dbClient);
|
||||
// 测试 code 不匹配
|
||||
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setCode(null)));
|
||||
// 测试 simpleName 不匹配
|
||||
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setSimpleName(null)));
|
||||
// 测试 name 不匹配
|
||||
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setName(null)));
|
||||
// 测试 telephone 不匹配
|
||||
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setTelephone(null)));
|
||||
// 测试 status 不匹配
|
||||
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setStatus(null)));
|
||||
// 准备参数
|
||||
ClientPageReqVO reqVO = new ClientPageReqVO();
|
||||
reqVO.setCode(null);
|
||||
reqVO.setSimpleName(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setTelephone(null);
|
||||
reqVO.setStatus(null);
|
||||
|
||||
// 调用
|
||||
PageResult<ClientDO> pageResult = clientService.getClientPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbClient, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
import request from '@/config/axios'
|
||||
|
||||
export interface ClientVO {
|
||||
id: number
|
||||
code: string
|
||||
simpleName: string
|
||||
name: string
|
||||
telephone: string
|
||||
address: string
|
||||
description: string
|
||||
status: number
|
||||
}
|
||||
|
||||
// 查询客户分页
|
||||
export const getClientPage = async (params) => {
|
||||
return await request.get({ url: `/heli/client/page`, params })
|
||||
}
|
||||
|
||||
// 查询客户详情
|
||||
export const getClient = async (id: number) => {
|
||||
return await request.get({ url: `/heli/client/get?id=` + id })
|
||||
}
|
||||
|
||||
// 新增客户
|
||||
export const createClient = async (data: ClientVO) => {
|
||||
return await request.post({ url: `/heli/client/create`, data })
|
||||
}
|
||||
|
||||
// 修改客户
|
||||
export const updateClient = async (data: ClientVO) => {
|
||||
return await request.put({ url: `/heli/client/update`, data })
|
||||
}
|
||||
|
||||
// 删除客户
|
||||
export const deleteClient = async (id: number) => {
|
||||
return await request.delete({ url: `/heli/client/delete?id=` + id })
|
||||
}
|
||||
|
||||
// 导出客户 Excel
|
||||
export const exportClient = async (params) => {
|
||||
return await request.download({ url: `/heli/client/export-excel`, params })
|
||||
}
|
Loading…
Reference in new issue