客户管理

This commit is contained in:
2025-11-21 09:04:19 +08:00
parent c32421997f
commit acae379a25
3 changed files with 66 additions and 35 deletions

View File

@ -4,7 +4,6 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -16,19 +15,12 @@ import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pictc.datalog.DataOperationContent;
import com.pictc.datalog.DataOperationListener;
import com.pictc.enums.BusinessCode;
import com.pictc.enums.ExceptionCommonCode;
import com.xjrsoft.common.exception.BusinessException;
import com.xjrsoft.common.model.result.R; import com.xjrsoft.common.model.result.R;
import com.xjrsoft.common.page.ConventPage; import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput; import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.utils.VoToColumnUtil; import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
import com.xjrsoft.module.datalog.service.DatalogService; import com.xjrsoft.module.datalog.service.DatalogService;
import com.xjrsoft.module.datalog.vo.DataChangeLogVo; import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
import com.xjrsoft.module.mdm.dto.UpdateLngBBankDto;
import com.xjrsoft.module.sales.dto.LngCustomerPageDto; import com.xjrsoft.module.sales.dto.LngCustomerPageDto;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerDto; import com.xjrsoft.module.sales.dto.UpdateLngCustomerDto;
import com.xjrsoft.module.sales.entity.LngCustomer; import com.xjrsoft.module.sales.entity.LngCustomer;
@ -113,7 +105,12 @@ public class CustomerController {
@ApiOperation(value = "新增LngCustomer") @ApiOperation(value = "新增LngCustomer")
@SaCheckPermission("customer:add") @SaCheckPermission("customer:add")
public R add(@Valid @RequestBody UpdateLngCustomerDto dto){ public R add(@Valid @RequestBody UpdateLngCustomerDto dto){
String code = codeRuleClient.genEncode(CUSTOMER_CODE);
dto.setCuCode("C"+code);
customerService.add(dto);
codeRuleClient.useEncode(CUSTOMER_CODE);
return R.ok();
/**
return R.ok(dataService.insert(dto,new DataOperationListener<UpdateLngCustomerDto>() { return R.ok(dataService.insert(dto,new DataOperationListener<UpdateLngCustomerDto>() {
@Override @Override
@ -133,7 +130,7 @@ public class CustomerController {
return content.getObj(); return content.getObj();
} }
})); }));
**/
} }
@ -141,14 +138,16 @@ public class CustomerController {
@ApiOperation(value = "修改LngCustomer") @ApiOperation(value = "修改LngCustomer")
@SaCheckPermission("customer:edit") @SaCheckPermission("customer:edit")
public R update(@Valid @RequestBody UpdateLngCustomerDto dto){ public R update(@Valid @RequestBody UpdateLngCustomerDto dto){
return R.ok(dataService.updateById(dto)); // return R.ok(dataService.updateById(dto));
customerService.update(dto);
return R.ok();
} }
@DeleteMapping @DeleteMapping
@ApiOperation(value = "删除") @ApiOperation(value = "删除")
@SaCheckPermission("customer:delete") @SaCheckPermission("customer:delete")
public R delete(@Valid @RequestBody List<Long> ids){ public R delete(@Valid @RequestBody List<Long> ids){
return R.ok(dataService.deleteByIds(UpdateLngCustomerDto.class, ids)); return R.ok(customerService.delete(ids));
} }

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.github.yulichang.base.MPJBaseService; import com.github.yulichang.base.MPJBaseService;
import com.github.yulichang.extension.mapping.base.MPJDeepService; import com.github.yulichang.extension.mapping.base.MPJDeepService;
import com.github.yulichang.extension.mapping.base.MPJRelationService; import com.github.yulichang.extension.mapping.base.MPJRelationService;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerDto;
import com.xjrsoft.module.sales.entity.LngCustomer; import com.xjrsoft.module.sales.entity.LngCustomer;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@ -22,7 +23,8 @@ public interface ICustomerService extends MPJBaseService<LngCustomer>, MPJDeepSe
* @param lngCustomer * @param lngCustomer
* @return * @return
*/ */
Boolean add(LngCustomer lngCustomer);
Boolean add(UpdateLngCustomerDto updateLngCustomerDto);
/** /**
* 更新 * 更新
@ -30,7 +32,7 @@ public interface ICustomerService extends MPJBaseService<LngCustomer>, MPJDeepSe
* @param lngCustomer * @param lngCustomer
* @return * @return
*/ */
Boolean update(LngCustomer lngCustomer); Boolean update(UpdateLngCustomerDto updateLngCustomerDto);
/** /**
* 删除 * 删除
@ -39,4 +41,5 @@ public interface ICustomerService extends MPJBaseService<LngCustomer>, MPJDeepSe
* @return * @return
*/ */
Boolean delete(List<Long> ids); Boolean delete(List<Long> ids);
} }

View File

@ -10,9 +10,16 @@ import com.xjrsoft.module.sales.entity.LngCustomerDoc;
import com.xjrsoft.module.sales.mapper.LngCustomerDocMapper; import com.xjrsoft.module.sales.mapper.LngCustomerDocMapper;
import com.xjrsoft.module.sales.entity.LngCustomerContact; import com.xjrsoft.module.sales.entity.LngCustomerContact;
import com.xjrsoft.module.sales.mapper.LngCustomerContactMapper; import com.xjrsoft.module.sales.mapper.LngCustomerContactMapper;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerAttrPowerDto;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerBankDto;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerContactDto;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerDocDto;
import com.xjrsoft.module.sales.dto.UpdateLngCustomerDto;
import com.xjrsoft.module.sales.entity.LngCustomer; import com.xjrsoft.module.sales.entity.LngCustomer;
import com.xjrsoft.module.sales.mapper.LngCustomerMapper; import com.xjrsoft.module.sales.mapper.LngCustomerMapper;
import com.xjrsoft.module.sales.service.ICustomerService; import com.xjrsoft.module.sales.service.ICustomerService;
import cn.hutool.core.bean.BeanUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -40,21 +47,32 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean add(LngCustomer lngCustomer) { public Boolean add(UpdateLngCustomerDto updateLngCustomerDto) {
LngCustomer lngCustomer = new LngCustomer();
BeanUtil.copyProperties(updateLngCustomerDto, lngCustomer);
customerLngCustomerMapper.insert(lngCustomer); customerLngCustomerMapper.insert(lngCustomer);
for (LngCustomerAttrPower lngCustomerAttrPower : lngCustomer.getLngCustomerAttrPowerList()) { for (UpdateLngCustomerAttrPowerDto updateLngCustomerAttrPowerDto : updateLngCustomerDto.getLngCustomerAttrPowerList()) {
LngCustomerAttrPower lngCustomerAttrPower = new LngCustomerAttrPower();
BeanUtil.copyProperties(updateLngCustomerAttrPowerDto, lngCustomerAttrPower);
lngCustomerAttrPower.setCuCode(lngCustomer.getCuCode()); lngCustomerAttrPower.setCuCode(lngCustomer.getCuCode());
customerLngCustomerAttrPowerMapper.insert(lngCustomerAttrPower); customerLngCustomerAttrPowerMapper.insert(lngCustomerAttrPower);
} }
for (LngCustomerBank lngCustomerBank : lngCustomer.getLngCustomerBankList()) { for (UpdateLngCustomerBankDto updateLngCustomerBankDto : updateLngCustomerDto.getLngCustomerBankList()) {
LngCustomerBank lngCustomerBank = new LngCustomerBank();
BeanUtil.copyProperties(updateLngCustomerBankDto, lngCustomerBank);
lngCustomerBank.setCuCode(lngCustomer.getCuCode()); lngCustomerBank.setCuCode(lngCustomer.getCuCode());
customerLngCustomerBankMapper.insert(lngCustomerBank); customerLngCustomerBankMapper.insert(lngCustomerBank);
} }
for (LngCustomerDoc lngCustomerDoc : lngCustomer.getLngCustomerDocList()) { for (UpdateLngCustomerDocDto updateLngCustomerDocDto : updateLngCustomerDto.getLngCustomerDocList()) {
LngCustomerDoc lngCustomerDoc = new LngCustomerDoc();
BeanUtil.copyProperties(updateLngCustomerDocDto, lngCustomerDoc);
lngCustomerDoc.setCuCode(lngCustomer.getCuCode()); lngCustomerDoc.setCuCode(lngCustomer.getCuCode());
customerLngCustomerDocMapper.insert(lngCustomerDoc); customerLngCustomerDocMapper.insert(lngCustomerDoc);
} }
for (LngCustomerContact lngCustomerContact : lngCustomer.getLngCustomerContactList()) { for (UpdateLngCustomerContactDto updateLngCustomerContactDto : updateLngCustomerDto.getLngCustomerContactList()) {
LngCustomerContact lngCustomerContact = new LngCustomerContact();
BeanUtil.copyProperties(updateLngCustomerContactDto, lngCustomerContact);
lngCustomerContact.setCuCode(lngCustomer.getCuCode()); lngCustomerContact.setCuCode(lngCustomer.getCuCode());
customerLngCustomerContactMapper.insert(lngCustomerContact); customerLngCustomerContactMapper.insert(lngCustomerContact);
} }
@ -64,7 +82,9 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean update(LngCustomer lngCustomer) { public Boolean update(UpdateLngCustomerDto updateLngCustomerDto) {
LngCustomer lngCustomer = new LngCustomer();
BeanUtil.copyProperties(updateLngCustomerDto, lngCustomer);
customerLngCustomerMapper.updateById(lngCustomer); customerLngCustomerMapper.updateById(lngCustomer);
//********************************* LngCustomerAttrPower 增删改 开始 *******************************************/ //********************************* LngCustomerAttrPower 增删改 开始 *******************************************/
{ {
@ -72,13 +92,16 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
List<LngCustomerAttrPower> lngCustomerAttrPowerList = customerLngCustomerAttrPowerMapper.selectList(Wrappers.lambdaQuery(LngCustomerAttrPower.class).eq(LngCustomerAttrPower::getCuCode, lngCustomer.getCuCode()).select(LngCustomerAttrPower::getId)); List<LngCustomerAttrPower> lngCustomerAttrPowerList = customerLngCustomerAttrPowerMapper.selectList(Wrappers.lambdaQuery(LngCustomerAttrPower.class).eq(LngCustomerAttrPower::getCuCode, lngCustomer.getCuCode()).select(LngCustomerAttrPower::getId));
List<Long> lngCustomerAttrPowerIds = lngCustomerAttrPowerList.stream().map(LngCustomerAttrPower::getId).collect(Collectors.toList()); List<Long> lngCustomerAttrPowerIds = lngCustomerAttrPowerList.stream().map(LngCustomerAttrPower::getId).collect(Collectors.toList());
//原有子表单 没有被删除的主键 //原有子表单 没有被删除的主键
List<Long> lngCustomerAttrPowerOldIds = lngCustomer.getLngCustomerAttrPowerList().stream().map(LngCustomerAttrPower::getId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> lngCustomerAttrPowerOldIds = updateLngCustomerDto.getLngCustomerAttrPowerList().stream().map(UpdateLngCustomerAttrPowerDto::getId).filter(Objects::nonNull).collect(Collectors.toList());
//找到需要删除的id //找到需要删除的id
List<Long> lngCustomerAttrPowerRemoveIds = lngCustomerAttrPowerIds.stream().filter(item -> !lngCustomerAttrPowerOldIds.contains(item)).collect(Collectors.toList()); List<Long> lngCustomerAttrPowerRemoveIds = lngCustomerAttrPowerIds.stream().filter(item -> !lngCustomerAttrPowerOldIds.contains(item)).collect(Collectors.toList());
for (LngCustomerAttrPower lngCustomerAttrPower : lngCustomer.getLngCustomerAttrPowerList()) { for (UpdateLngCustomerAttrPowerDto lngCustomerAttrPowerDto : updateLngCustomerDto.getLngCustomerAttrPowerList()) {
LngCustomerAttrPower lngCustomerAttrPower = new LngCustomerAttrPower();
BeanUtil.copyProperties(lngCustomerAttrPowerDto, lngCustomerAttrPower);
//如果不等于空则修改 //如果不等于空则修改
if (lngCustomerAttrPower.getId() != null) { if (lngCustomerAttrPower.getId() != null) {
customerLngCustomerAttrPowerMapper.updateById(lngCustomerAttrPower); customerLngCustomerAttrPowerMapper.updateById(lngCustomerAttrPower);
} }
//如果等于空 则新增 //如果等于空 则新增
@ -101,11 +124,13 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
List<LngCustomerBank> lngCustomerBankList = customerLngCustomerBankMapper.selectList(Wrappers.lambdaQuery(LngCustomerBank.class).eq(LngCustomerBank::getCuCode, lngCustomer.getCuCode()).select(LngCustomerBank::getId)); List<LngCustomerBank> lngCustomerBankList = customerLngCustomerBankMapper.selectList(Wrappers.lambdaQuery(LngCustomerBank.class).eq(LngCustomerBank::getCuCode, lngCustomer.getCuCode()).select(LngCustomerBank::getId));
List<Long> lngCustomerBankIds = lngCustomerBankList.stream().map(LngCustomerBank::getId).collect(Collectors.toList()); List<Long> lngCustomerBankIds = lngCustomerBankList.stream().map(LngCustomerBank::getId).collect(Collectors.toList());
//原有子表单 没有被删除的主键 //原有子表单 没有被删除的主键
List<Long> lngCustomerBankOldIds = lngCustomer.getLngCustomerBankList().stream().map(LngCustomerBank::getId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> lngCustomerBankOldIds = updateLngCustomerDto.getLngCustomerBankList().stream().map(UpdateLngCustomerBankDto::getId).filter(Objects::nonNull).collect(Collectors.toList());
//找到需要删除的id //找到需要删除的id
List<Long> lngCustomerBankRemoveIds = lngCustomerBankIds.stream().filter(item -> !lngCustomerBankOldIds.contains(item)).collect(Collectors.toList()); List<Long> lngCustomerBankRemoveIds = lngCustomerBankIds.stream().filter(item -> !lngCustomerBankOldIds.contains(item)).collect(Collectors.toList());
for (LngCustomerBank lngCustomerBank : lngCustomer.getLngCustomerBankList()) { for (UpdateLngCustomerBankDto lngCustomerBankDto : updateLngCustomerDto.getLngCustomerBankList()) {
LngCustomerBank lngCustomerBank = new LngCustomerBank();
BeanUtil.copyProperties(lngCustomerBankDto, lngCustomerBank);
//如果不等于空则修改 //如果不等于空则修改
if (lngCustomerBank.getId() != null) { if (lngCustomerBank.getId() != null) {
customerLngCustomerBankMapper.updateById(lngCustomerBank); customerLngCustomerBankMapper.updateById(lngCustomerBank);
@ -130,11 +155,13 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
List<LngCustomerDoc> lngCustomerDocList = customerLngCustomerDocMapper.selectList(Wrappers.lambdaQuery(LngCustomerDoc.class).eq(LngCustomerDoc::getCuCode, lngCustomer.getCuCode()).select(LngCustomerDoc::getId)); List<LngCustomerDoc> lngCustomerDocList = customerLngCustomerDocMapper.selectList(Wrappers.lambdaQuery(LngCustomerDoc.class).eq(LngCustomerDoc::getCuCode, lngCustomer.getCuCode()).select(LngCustomerDoc::getId));
List<Long> lngCustomerDocIds = lngCustomerDocList.stream().map(LngCustomerDoc::getId).collect(Collectors.toList()); List<Long> lngCustomerDocIds = lngCustomerDocList.stream().map(LngCustomerDoc::getId).collect(Collectors.toList());
//原有子表单 没有被删除的主键 //原有子表单 没有被删除的主键
List<Long> lngCustomerDocOldIds = lngCustomer.getLngCustomerDocList().stream().map(LngCustomerDoc::getId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> lngCustomerDocOldIds = updateLngCustomerDto.getLngCustomerDocList().stream().map(UpdateLngCustomerDocDto::getId).filter(Objects::nonNull).collect(Collectors.toList());
//找到需要删除的id //找到需要删除的id
List<Long> lngCustomerDocRemoveIds = lngCustomerDocIds.stream().filter(item -> !lngCustomerDocOldIds.contains(item)).collect(Collectors.toList()); List<Long> lngCustomerDocRemoveIds = lngCustomerDocIds.stream().filter(item -> !lngCustomerDocOldIds.contains(item)).collect(Collectors.toList());
for (LngCustomerDoc lngCustomerDoc : lngCustomer.getLngCustomerDocList()) { for (UpdateLngCustomerDocDto lngCustomerDocDto : updateLngCustomerDto.getLngCustomerDocList()) {
LngCustomerDoc lngCustomerDoc = new LngCustomerDoc();
BeanUtil.copyProperties(lngCustomerDocDto, lngCustomerDoc);
//如果不等于空则修改 //如果不等于空则修改
if (lngCustomerDoc.getId() != null) { if (lngCustomerDoc.getId() != null) {
customerLngCustomerDocMapper.updateById(lngCustomerDoc); customerLngCustomerDocMapper.updateById(lngCustomerDoc);
@ -159,11 +186,13 @@ public class CustomerServiceImpl extends MPJBaseServiceImpl<LngCustomerMapper, L
List<LngCustomerContact> lngCustomerContactList = customerLngCustomerContactMapper.selectList(Wrappers.lambdaQuery(LngCustomerContact.class).eq(LngCustomerContact::getCuCode, lngCustomer.getCuCode()).select(LngCustomerContact::getId)); List<LngCustomerContact> lngCustomerContactList = customerLngCustomerContactMapper.selectList(Wrappers.lambdaQuery(LngCustomerContact.class).eq(LngCustomerContact::getCuCode, lngCustomer.getCuCode()).select(LngCustomerContact::getId));
List<Long> lngCustomerContactIds = lngCustomerContactList.stream().map(LngCustomerContact::getId).collect(Collectors.toList()); List<Long> lngCustomerContactIds = lngCustomerContactList.stream().map(LngCustomerContact::getId).collect(Collectors.toList());
//原有子表单 没有被删除的主键 //原有子表单 没有被删除的主键
List<Long> lngCustomerContactOldIds = lngCustomer.getLngCustomerContactList().stream().map(LngCustomerContact::getId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> lngCustomerContactOldIds = updateLngCustomerDto.getLngCustomerContactList().stream().map(UpdateLngCustomerContactDto::getId).filter(Objects::nonNull).collect(Collectors.toList());
//找到需要删除的id //找到需要删除的id
List<Long> lngCustomerContactRemoveIds = lngCustomerContactIds.stream().filter(item -> !lngCustomerContactOldIds.contains(item)).collect(Collectors.toList()); List<Long> lngCustomerContactRemoveIds = lngCustomerContactIds.stream().filter(item -> !lngCustomerContactOldIds.contains(item)).collect(Collectors.toList());
for (LngCustomerContact lngCustomerContact : lngCustomer.getLngCustomerContactList()) { for (UpdateLngCustomerContactDto lngCustomerContactDto : updateLngCustomerDto.getLngCustomerContactList()) {
LngCustomerContact lngCustomerContact = new LngCustomerContact();
BeanUtil.copyProperties(lngCustomerContactDto, lngCustomerContact);
//如果不等于空则修改 //如果不等于空则修改
if (lngCustomerContact.getId() != null) { if (lngCustomerContact.getId() != null) {
customerLngCustomerContactMapper.updateById(lngCustomerContact); customerLngCustomerContactMapper.updateById(lngCustomerContact);