add:客户

This commit is contained in:
2024-03-08 16:29:14 +08:00
parent 73b7d0408f
commit cd88702022
10 changed files with 955 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
package org.nl.wms.base_manage.customer.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.TableDataInfo;
import org.nl.common.anno.Log;
import org.nl.common.domain.entity.PageQuery;
import org.nl.common.utils.RedissonUtils;
import org.nl.wms.base_manage.customer.service.IBmCustomerService;
import org.nl.wms.base_manage.customer.service.dao.BmCustomer;
import org.nl.wms.base_manage.customer.service.dto.CustomerQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
/**
* @author ldjun
* @date 2021-12-06
**/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/bmCustomer")
@Slf4j
public class BmCustomerController {
@Autowired
private IBmCustomerService customerService;
@GetMapping
@Log("查询客户基础表")
public ResponseEntity<Object> query(CustomerQuery query, PageQuery page) {
return new ResponseEntity<>(TableDataInfo.build(customerService.page(page.build(), query.build())), HttpStatus.OK);
}
@PostMapping
@Log("新增客户基础表")
public ResponseEntity<Object> create(@Validated @RequestBody JSONObject dto) {
customerService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改客户基础表")
public ResponseEntity<Object> update(@Validated @RequestBody JSONObject dto) {
customerService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除客户基础表")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
if (ids.length > 0) {
customerService.removeByIds(Arrays.asList(ids));
}
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/excelImport")
@Log("excel导入")
public ResponseEntity<Object> excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
RedissonUtils.lock(() -> {
customerService.excelImport(file, request, response);
}, "客户信息导入", null);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/selectList")
@SaIgnore
public ResponseEntity<Object> getSelectList() {
List<Map> selectList = new ArrayList<>();
List<BmCustomer> list = customerService.list();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(cus -> {
Map<String, String> item = new HashMap<>();
item.put("value", cus.getCust_code());
item.put("label", cus.getCust_name());
selectList.add(item);
});
}
return new ResponseEntity<>(TableDataInfo.build(selectList), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,28 @@
package org.nl.wms.base_manage.customer.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.wms.base_manage.customer.service.dao.BmCustomer;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* <p>
* 客户基本信息表 服务类
* </p>
*
* @author generator
* @since 2023-06-25
*/
public interface IBmCustomerService extends IService<BmCustomer> {
void create(JSONObject dto);
void update(JSONObject dto);
void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException;
}

View File

@@ -0,0 +1,147 @@
package org.nl.wms.base_manage.customer.service.dao;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* <p>
* 客户基本信息表
* </p>
*
* @author generator
* @since 2023-06-25
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("bm_customer")
public class BmCustomer implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 客户标识
*/
@TableId(value = "cust_id")
private String cust_id;
/**
* 客户编码
*/
private String cust_code;
/**
* 客户名称
*/
private String cust_name;
/**
* 法人代表
*/
private String jurid_name;
/**
* 税务登记号
*/
private String tax_no;
/**
* 工商注册号
*/
private String register_no;
/**
* 经营许可证号
*/
private String manage_lice_no;
/**
* 营业执照
*/
private String busi_char_name;
/**
* 行政区划
*/
private Long area_id;
/**
* 邮政编码
*/
private String zip_code;
/**
* 公司电话
*/
private String corp_tele_no;
/**
* 公司地址
*/
private String corp_address;
/**
* 创建人
*/
private String create_id;
/**
* 创建人姓名
*/
private String create_name;
/**
* 创建时间
*/
private String create_time;
/**
* 修改人
*/
private String update_id;
/**
* 修改人姓名
*/
private String update_name;
/**
* 修改时间
*/
private String update_time;
/**
* 启用时间
*/
private String is_used_time;
/**
* 是否启用
*/
private String is_used;
/**
* 是否删除
*/
private String is_delete;
/**
* 外部标识
*/
private String ext_id;
/**
* 备注
*/
private String remark;
/**
* 分类标识
*/
private String class_id;
}

View File

@@ -0,0 +1,16 @@
package org.nl.wms.base_manage.customer.service.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.nl.wms.base_manage.customer.service.dao.BmCustomer;
/**
* <p>
* 客户基本信息表 Mapper 接口
* </p>
*
* @author generator
* @since 2023-06-25
*/
public interface BmCustomerMapper extends BaseMapper<BmCustomer> {
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.nl.wms.base_manage.customer.service.dao.mapper.BmCustomerMapper">
</mapper>

View File

@@ -0,0 +1,22 @@
package org.nl.wms.base_manage.customer.service.dto;
import lombok.Data;
import org.nl.common.domain.entity.BaseQuery;
import org.nl.common.domain.entity.QParam;
import org.nl.common.enums.QueryTEnum;
import org.nl.wms.base_manage.customer.service.dao.BmCustomer;
/*
* @author ZZQ
* @Date 2023/5/14 17:13
*/
@Data
public class CustomerQuery extends BaseQuery<BmCustomer> {
private String search;
@Override
public void paramMapping() {
super.doP.put("search", QParam.builder().k(new String[]{"cust_code","cust_name"}).type(QueryTEnum.LK).build());
}
}

View File

@@ -0,0 +1,115 @@
package org.nl.wms.base_manage.customer.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.nl.common.domain.exception.BadRequestException;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.wms.base_manage.customer.service.IBmCustomerService;
import org.nl.wms.base_manage.customer.service.dao.BmCustomer;
import org.nl.wms.base_manage.customer.service.dao.mapper.BmCustomerMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 客户基本信息表 服务实现类
* </p>
*
* @author generator
* @since 2023-06-25
*/
@Service
public class BmCustomerServiceImpl extends ServiceImpl<BmCustomerMapper, BmCustomer> implements IBmCustomerService {
@Override
public void create(JSONObject dto) {
Assert.notNull(dto, "请求参数不能为空");
String cust_code = dto.getString("cust_code");
BmCustomer custCode = this.getOne(new QueryWrapper<BmCustomer>().eq("cust_code", cust_code));
if (custCode != null) {
throw new BadRequestException("存在相同的客户编号");
}
BmCustomer entity = dto.toJavaObject(BmCustomer.class);
entity.setCust_id(IdUtil.getStringId());
entity.setCreate_id(SecurityUtils.getCurrentUserId());
entity.setCreate_name(SecurityUtils.getCurrentNickName());
entity.setCreate_time(DateUtil.now());
this.save(entity);
}
@Override
public void update(JSONObject dto) {
BmCustomer entity = dto.toJavaObject(BmCustomer.class);
entity.setUpdate_id(SecurityUtils.getCurrentUserId());
entity.setUpdate_name(SecurityUtils.getCurrentNickName());
entity.setUpdate_time(DateUtil.now());
this.updateById(entity);
}
@Override
public void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = file.getInputStream();
ExcelReader excelReader = ExcelUtil.getReader(inputStream);
List<List<Object>> read = excelReader.read();
Map<String, String> errorMap = new HashMap();
for (int i = 1; i < read.size(); i++) {
List<Object> list = read.get(i);
if (ObjectUtil.isEmpty(list)) {
continue;
}
String cust_code = (String) list.get(0);
if (StrUtil.isEmpty(cust_code)) {
errorMap.put("" + (i + 1) + "行:", "客户编码为空!");
}
String cust_name = (String) list.get(1);
if (StrUtil.isEmpty(cust_name)) {
errorMap.put("" + (i + 1) + "行:", "客户名称为空!");
}
boolean need_update = false;
BmCustomer cust_jo = this.getOne(new QueryWrapper<BmCustomer>().eq("cust_code", cust_code));
if (ObjectUtil.isNotEmpty(cust_jo)){
need_update = true;
}else {
cust_jo = new BmCustomer();
}
if (need_update){
cust_jo.setCust_name(cust_name);
cust_jo.setUpdate_id(SecurityUtils.getCurrentUserId());
cust_jo.setUpdate_name(SecurityUtils.getCurrentNickName());
cust_jo.setUpdate_time(DateUtil.now());
this.updateById(cust_jo);
}else {
cust_jo.setCust_code(cust_code);
cust_jo.setCust_name(cust_name);
cust_jo.setCust_id(IdUtil.getStringId());
cust_jo.setCreate_id(SecurityUtils.getCurrentUserId());
cust_jo.setCreate_name(SecurityUtils.getCurrentNickName());
cust_jo.setCreate_time(DateUtil.now());
cust_jo.setIs_delete("0");
cust_jo.setIs_used("1");
this.save(cust_jo);
}
}
}
}