Commit e5f38da7 authored by 法拉51246's avatar 法拉51246

更新数据不改变数据归属

管理员也能批量打印(不会selectOne报错了)
parent f6fe6610
......@@ -61,15 +61,17 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
// 当前登录用户不为空,更新人为空,则当前登录用户为更新人
Object modifier = getFieldValByName("updater", metaObject);
Long userId = WebFrameworkUtils.getLoginUserId();
if (Objects.nonNull(userId) && Objects.isNull(modifier)) {
setFieldValByName("updater", userId.toString(), metaObject);
// Long userId = WebFrameworkUtils.getLoginUserId();
String userName = WebFrameworkUtils.getLoginUserName();
if (Objects.nonNull(userName) && Objects.isNull(modifier)) {
setFieldValByName("updater", userName, metaObject);
}
//更新不改变数据归属
//自动插入登录人所属分公司id
Long userDeptId = WebFrameworkUtils.getLoginUserDeptId();
if (Objects.nonNull(userDeptId)) {
setFieldValByName("companyId", userDeptId, metaObject);
}
// Long userDeptId = WebFrameworkUtils.getLoginUserDeptId();
// if (Objects.nonNull(userDeptId)) {
// setFieldValByName("companyId", userDeptId, metaObject);
// }
}
}
......@@ -68,7 +68,7 @@ public class CustomerInfoSaveReqVO {
private String productNames;
@Schema(description = "客户部门")
@NotEmpty(message = "客户部门不能为空")
// @NotEmpty(message = "客户部门不能为空")
private String department;
}
\ No newline at end of file
......@@ -67,11 +67,11 @@ public class InfoSaveReqVO {
private Integer customerStatus;
@Schema(description = "拜访品种(多选,逗号分隔)")
// @NotEmpty(message = "拜访品种不能为空")
@NotEmpty(message = "拜访品种不能为空")
private String visitProductIds;
@Schema(description = "拜访品种名称(多选,逗号分隔)")
// @NotEmpty(message = "拜访品种名称不能为空")
@NotEmpty(message = "拜访品种名称不能为空")
private String visitProductNames;
@Schema(description = "拜访方式(字典)")
......
......@@ -46,10 +46,26 @@ public interface CustomerInfoMapper extends BaseMapperX<CustomerInfoDO> {
//根据公司名称查询客户信息(验证是否唯一使用)
default CustomerInfoDO selectByCompanyName(String companyName){
Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
return selectOne(new LambdaQueryWrapperX<CustomerInfoDO>()
.eq(CustomerInfoDO::getCompanyName, companyName)
.eqIfPresent(CustomerInfoDO::getCompanyId, companyId)
);
LambdaQueryWrapperX<CustomerInfoDO> eq = new LambdaQueryWrapperX<CustomerInfoDO>()
.eq(CustomerInfoDO::getCompanyName, companyName);
if (companyId == null) {
eq.isNull(CustomerInfoDO::getCompanyId);
}else{
eq.eq(CustomerInfoDO::getCompanyId, companyId);
}
return selectOne(eq);
}
//根据公司名称查询客户名称和所属分公司id(打印用)
default CustomerInfoDO selectByCompanyName(String companyName,Long companyId){
LambdaQueryWrapperX<CustomerInfoDO> eq = new LambdaQueryWrapperX<CustomerInfoDO>()
.eq(CustomerInfoDO::getCompanyName, companyName);
if (companyId == null) {
eq.isNull(CustomerInfoDO::getCompanyId);
}else{
eq.eq(CustomerInfoDO::getCompanyId, companyId);
}
return selectOne(eq);
}
// 根据公司名称或手机号查询(根据任一条件带出符合条件的列表)
......
......@@ -87,7 +87,8 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
validateCustomerInfoExists(updateReqVO.getId());
// 更新
CustomerInfoDO updateObj = BeanUtils.toBean(updateReqVO, CustomerInfoDO.class);
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(updateObj.getCompanyName());
CustomerInfoDO customerInfoDO0 = customerInfoMapper.selectById(updateObj.getId());
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(updateObj.getCompanyName(), customerInfoDO0.getCompanyId());//修改的这条数据的所属分公司中,是否有重复的companyName
if (customerInfoDO != null && !customerInfoDO.getId().equals(updateObj.getId())) {
throw exception(CUSTOMER_INFO_COMPANY_NAME_DUPLICATE);
}
......@@ -95,6 +96,9 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
String url = uploadMapImageByUrl(updateObj.getLocationImage(), null);
updateObj.setLocationImage(url);
}
if (customerInfoDO != null) {
updateObj.setCompanyId(customerInfoDO.getCompanyId());// 设置原本的companyId
}
customerInfoMapper.updateById(updateObj);
}
......
......@@ -118,10 +118,15 @@ public class InfoServiceImpl implements InfoService {
validateInfoExists(updateReqVO.getId());
// 更新
InfoDO updateObj = BeanUtils.toBean(updateReqVO, InfoDO.class);
//按id查询获取companyId原本归属
InfoDO infoDO = infoMapper.selectById(updateReqVO.getId());
if (updateObj.getLocationImage() != null&& updateObj.getLocationImage().startsWith("https://apis.map.qq.com/ws/staticmap/v2/")){
String url = uploadMapImageByUrl(updateObj.getLocationImage(), null);
updateObj.setLocationImage(url);
}
if (infoDO != null){
updateObj.setCompanyId(infoDO.getCompanyId());
}
infoMapper.updateById(updateObj);
}
......@@ -152,17 +157,17 @@ public class InfoServiceImpl implements InfoService {
return vos;
}
List<List<InfoDO>> groupedByCompany = list.stream()
// 按公司名称分组,取每个公司最近四次(结果:Map<String, List<InfoDO>>)
.collect(Collectors.groupingBy(InfoDO::getCompanyName))
.values().stream() // 遍历每个公司的记录列表
// 按 (companyName, companyId) 组合分组
.collect(Collectors.groupingBy(info -> info.getCompanyName() + "::" + info.getCompanyId()))
.values().stream()
.map(companyRecords ->
companyRecords.stream()
// 按拜访时间降序排序
.sorted(Comparator.comparing(InfoDO::getVisitDate).reversed())
.limit(4) // 取最近 4 条
.sorted(Comparator.comparing(InfoDO::getVisitDate).reversed()) // 按时间降序
.limit(4) // 取前 4 条
.collect(Collectors.toList())
)
.collect(Collectors.toList()); // 收集为 List<List<InfoDO>>
.collect(Collectors.toList());
groupedByCompany.forEach(info -> {
//服务内容(最近四次)
List<String> serviceContent = new ArrayList<>();
......@@ -172,6 +177,7 @@ public class InfoServiceImpl implements InfoService {
List<LocalDate> visitDateList = new ArrayList<>();
//以第一个公司名称作为合并打印的公司
String companyName = info.get(0).getCompanyName();
Long companyId = info.get(0).getCompanyId();
//取最多4张服务图片
int maxImages = 4;
for (InfoDO infoDO : info) {
......@@ -193,7 +199,7 @@ public class InfoServiceImpl implements InfoService {
});
//下面获取客户信息
InfoPrintVO infoPrintVO = new InfoPrintVO();
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName);
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName,companyId);
if (customerInfoDO != null){
infoPrintVO.setVisitProductNames(customerInfoDO.getProductNames());//本次拜访品种
infoPrintVO.setCompanyName(customerInfoDO.getCompanyName());//公司名称
......@@ -278,6 +284,7 @@ public class InfoServiceImpl implements InfoService {
//现根据客户名称获取历史拜访记录
List<InfoDO> info = infoMapper.selectByCompanyName(companyName);
if (info != null && !info.isEmpty()){
Long companyId = info.get(0).getCompanyId();
//取最近四次
info = info.stream()
// 筛选本月记录(基于 LocalDateTime)
......@@ -306,7 +313,7 @@ public class InfoServiceImpl implements InfoService {
visitDateList.add(infoDO.getVisitDate().toLocalDate());
});
//下面获取客户信息
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName);
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName,companyId);//这个companyId是从根据companyId获取得数据List中获取得,一定和点得这条匹配
infoPrintVO.setVisitProductNames(customerInfoDO.getProductNames());//本次拜访品种
infoPrintVO.setCompanyName(customerInfoDO.getCompanyName());//公司名称
infoPrintVO.setSalesman(customerInfoDO.getCreator());//拜访记录的创建者就是该记录的业务员
......@@ -355,6 +362,7 @@ public class InfoServiceImpl implements InfoService {
List<LocalDate> visitDateList = new ArrayList<>();
//以第一个公司名称作为合并打印的公司
String companyName = info.get(0).getCompanyName();
Long companyId = info.get(0).getCompanyId();
//取最多4张服务图片
int maxImages = 4;
for (InfoDO infoDO : info) {
......@@ -376,7 +384,7 @@ public class InfoServiceImpl implements InfoService {
});
//下面获取客户信息
InfoPrintVO infoPrintVO = new InfoPrintVO();
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName);
CustomerInfoDO customerInfoDO = customerInfoMapper.selectByCompanyName(companyName,companyId);
if (customerInfoDO != null){
infoPrintVO.setVisitProductNames(customerInfoDO.getProductNames());//本次拜访品种
infoPrintVO.setCompanyName(customerInfoDO.getCompanyName());//公司名称
......
......@@ -52,8 +52,13 @@ public class ProductServiceImpl implements ProductService {
public void updateProduct(ProductSaveReqVO updateReqVO) {
// 校验存在
validateProductExists(updateReqVO.getId());
//按id查,取出归属companyId
ProductDO productDO = productMapper.selectById(updateReqVO.getId());
// 更新
ProductDO updateObj = BeanUtils.toBean(updateReqVO, ProductDO.class);
if (productDO != null){
updateObj.setCompanyId(productDO.getCompanyId());
}
productMapper.updateById(updateObj);
}
......
......@@ -5,8 +5,8 @@ VITE_DEV=true
# 请求路径
# VITE_BASE_URL='http://192.168.0.133:48080'
VITE_BASE_URL='https://hntqwl.com'
# VITE_BASE_URL='http://localhost:48080'
# VITE_BASE_URL='https://hntqwl.com'
VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
VITE_UPLOAD_TYPE=server
......@@ -33,4 +33,4 @@ VITE_MALL_H5_DOMAIN='http://localhost:3000'
VITE_APP_CAPTCHA_ENABLE=false
# GoView域名
VITE_GOVIEW_URL='http://127.0.0.1:3000'
\ No newline at end of file
VITE_GOVIEW_URL='http://127.0.0.1:3000'
......@@ -104,7 +104,7 @@ const chartOption = computed(() => {
{
name: props.tooltipTip,
type: 'pie',
radius: ['40%', '70%'],
radius: ['30%', '50%'],
center: ['30%', '50%'],
label: {
show: false
......
......@@ -9,10 +9,10 @@
:disabled="isDetail"
>
<el-form-item label="客户姓名" prop="customerName">
<el-input v-model="formData.customerName" placeholder="请输入客户姓名" />
<el-input v-model="formData.customerName" :placeholder="isDetail ? '' : '请输入客户姓名'" />
</el-form-item>
<el-form-item label="联系方式" prop="contact">
<el-input v-model="formData.contact" maxlength="11" placeholder="请输入联系方式" />
<el-input v-model="formData.contact" maxlength="11" :placeholder="isDetail ? '' : '请输入联系方式'" />
</el-form-item>
<el-form-item label="公司名称" prop="companyName">
<el-input v-model="formData.companyName" placeholder="请输入公司名称" />
......@@ -78,14 +78,14 @@
<!-- <UploadImg v-model="formData.locationImage" />-->
<!-- </el-form-item>-->
<el-form-item label="产品信息" prop="productNames">
<el-input v-model="formData.productNames" placeholder="请点击右侧选择" readonly>
<el-input v-model="formData.productNames" :placeholder="isDetail ? '' : '请点击右侧选择'" readonly>
<template #append v-if="formType !== 'detail'">
<el-link type="primary" @click="openProduct">选择产品</el-link>
</template>
</el-input>
</el-form-item>
<el-form-item label="客户部门" prop="department">
<el-select v-model="formData.department" placeholder="请选择客户部门">
<el-select v-model="formData.department" :placeholder="isDetail ? '' : '请选择客户部门'">
<el-option
v-for="dict in getStrDictOptions(DICT_TYPE.CUSTOMER_DEPT)"
:key="dict.value"
......@@ -170,7 +170,6 @@ const formData = ref<CustomerFormData>({
const formRules = reactive({
companyName: [{ required: true, message: '公司名称不能为空', trigger: 'blur' }],
customerType: [{ required: true, message: '性质等级不能为空', trigger: 'change' }],
department: [{ required: true, message: '客户部门不能为空', trigger: 'change' }],
provinceName: [{ required: true, message: '省名称不能为空', trigger: 'blur' }],
cityName: [{ required: true, message: '市名称不能为空', trigger: 'blur' }],
areaName: [{ required: true, message: '区名称不能为空', trigger: 'blur' }],
......@@ -189,9 +188,6 @@ const productListRef = ref<InstanceType<typeof productTable> | null>(null) //
// 打开二级产品列表弹窗
const openProduct = () => {
if (formData.value.productNames) {
return
}
productListRef.value?.open() // 调用子组件暴露的方法
}
......
......@@ -174,6 +174,7 @@ const handleSelectionChange = (val) => {
/** 查询列表 */
const getList = async () => {
loading.value = true
queryParams.status = getIntDictOptions(DICT_TYPE.COMMON_STATUS).find(item => item.label === '正常')?.value
try {
const data = await ProductApi.getProductPage(queryParams)
list.value = data.list
......
......@@ -9,10 +9,10 @@
:disabled="isDetail"
>
<el-form-item label="客户姓名" prop="customerName">
<el-input v-model="formData.customerName" placeholder="请输入拜访人姓名" />
<el-input v-model="formData.customerName" :placeholder="isDetail ? '' : '请输入拜访人姓名'" />
</el-form-item>
<el-form-item label="联系方式" prop="contact">
<el-input v-model="formData.contact" maxlength="11" placeholder="请输入联系方式" />
<el-input v-model="formData.contact" maxlength="11" :placeholder="isDetail ? '' : '请输入联系方式'" />
</el-form-item>
<el-form-item label="公司名称" prop="companyName">
<el-autocomplete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment