增加批量绑定
This commit is contained in:
-8
@@ -69,10 +69,6 @@ public class BmsCustomerPriceSetServiceImpl implements IBmsCustomerPriceSetServi
|
||||
{
|
||||
throw new ServiceException("所选套餐不存在");
|
||||
}
|
||||
if (!"E".equals(set.getStatus()))
|
||||
{
|
||||
throw new ServiceException("仅生效中的套餐允许绑定,当前套餐状态不可用");
|
||||
}
|
||||
if (bind.getBindPriority() == null || bind.getBindPriority() < 1)
|
||||
{
|
||||
bind.setBindPriority(1);
|
||||
@@ -141,10 +137,6 @@ public class BmsCustomerPriceSetServiceImpl implements IBmsCustomerPriceSetServi
|
||||
{
|
||||
throw new ServiceException("所选套餐不存在");
|
||||
}
|
||||
if (!"E".equals(set.getStatus()))
|
||||
{
|
||||
throw new ServiceException("仅生效中的套餐允许绑定,当前套餐状态不可用");
|
||||
}
|
||||
Integer priority = (req.getBindPriority() == null || req.getBindPriority() < 1) ? 1 : req.getBindPriority();
|
||||
boolean overwrite = Boolean.TRUE.equals(req.getOverwriteExisting());
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.bms.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Price-set detail batch bind customers.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PrcCustomerPriceSetBatch extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long priceSetId;
|
||||
private Integer bindPriority;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date prBegindate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date prEnddate;
|
||||
private String priceSetNote;
|
||||
/** Customers to bind (need customerCode; id/name optional). */
|
||||
private List<PrcCustomerPriceSet> customers;
|
||||
/** true = move already-bound customers onto this set; false = skip them. */
|
||||
private Boolean overwriteExisting;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.bms.price.domain.PrcCustomerPriceSet;
|
||||
import com.bms.price.domain.PrcCustomerPriceSetBatch;
|
||||
import com.bms.price.domain.PrcPriceSet;
|
||||
import com.bms.price.domain.PrcPriceSetCheckItem;
|
||||
import com.bms.price.domain.PrcPriceSetDetail;
|
||||
@@ -92,6 +93,9 @@ public interface IPrcPriceSetService
|
||||
|
||||
public int insertCustomer(PrcCustomerPriceSet customer);
|
||||
|
||||
/** Batch bind customers to a price set; returns summary message. */
|
||||
public String batchInsertCustomers(PrcCustomerPriceSetBatch batch);
|
||||
|
||||
public int updateCustomer(PrcCustomerPriceSet customer);
|
||||
|
||||
public int deleteCustomerByIds(Long[] customerPricesetIds);
|
||||
|
||||
+133
-3
@@ -2432,6 +2432,128 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
|
||||
public String batchInsertCustomers(com.bms.price.domain.PrcCustomerPriceSetBatch batch)
|
||||
{
|
||||
if (batch == null || batch.getCustomers() == null || batch.getCustomers().isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.batch.empty"));
|
||||
}
|
||||
if (batch.getPriceSetId() == null)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.customerId.empty"));
|
||||
}
|
||||
PrcPriceSet db = requireSet(batch.getPriceSetId());
|
||||
assertChildEditable(db);
|
||||
Integer priority = (batch.getBindPriority() == null || batch.getBindPriority().intValue() < 1)
|
||||
? Integer.valueOf(1) : batch.getBindPriority();
|
||||
boolean overwrite = Boolean.TRUE.equals(batch.getOverwriteExisting());
|
||||
|
||||
java.util.LinkedHashMap<String, PrcCustomerPriceSet> uniq = new java.util.LinkedHashMap<String, PrcCustomerPriceSet>();
|
||||
for (PrcCustomerPriceSet item : batch.getCustomers())
|
||||
{
|
||||
if (item == null || StringUtils.isEmpty(item.getCustomerCode()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String code = item.getCustomerCode().trim();
|
||||
if (!uniq.containsKey(code))
|
||||
{
|
||||
uniq.put(code, item);
|
||||
}
|
||||
}
|
||||
if (uniq.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.batch.empty"));
|
||||
}
|
||||
|
||||
int inserted = 0;
|
||||
int replaced = 0;
|
||||
int skipped = 0;
|
||||
java.util.List<String> skippedNames = new java.util.ArrayList<String>();
|
||||
for (PrcCustomerPriceSet item : uniq.values())
|
||||
{
|
||||
PrcCustomerPriceSet query = new PrcCustomerPriceSet();
|
||||
query.setCustomerCode(item.getCustomerCode().trim());
|
||||
java.util.List<PrcCustomerPriceSet> found = customerMapper.selectPrcCustomerPriceSetList(query);
|
||||
PrcCustomerPriceSet existing = (found == null || found.isEmpty()) ? null : found.get(0);
|
||||
|
||||
PrcCustomerPriceSet row = new PrcCustomerPriceSet();
|
||||
row.setPriceSetId(batch.getPriceSetId());
|
||||
row.setCustomerId(item.getCustomerId());
|
||||
row.setCustomerCode(item.getCustomerCode().trim());
|
||||
row.setCustomerName(item.getCustomerName());
|
||||
row.setBindPriority(priority);
|
||||
row.setPrBegindate(batch.getPrBegindate());
|
||||
row.setPrEnddate(batch.getPrEnddate());
|
||||
row.setPriceSetNote(batch.getPriceSetNote());
|
||||
row.setCreateBy(batch.getCreateBy());
|
||||
row.setUpdateBy(batch.getUpdateBy());
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
boolean sameSet = batch.getPriceSetId().equals(existing.getPriceSetId());
|
||||
if (sameSet)
|
||||
{
|
||||
skipped++;
|
||||
skippedNames.add(StringUtils.isNotEmpty(item.getCustomerName())
|
||||
? item.getCustomerName() : item.getCustomerCode());
|
||||
continue;
|
||||
}
|
||||
if (!overwrite)
|
||||
{
|
||||
skipped++;
|
||||
skippedNames.add(StringUtils.isNotEmpty(item.getCustomerName())
|
||||
? item.getCustomerName() : item.getCustomerCode());
|
||||
continue;
|
||||
}
|
||||
row.setCustomerPricesetId(existing.getCustomerPricesetId());
|
||||
if (row.getPrBegindate() == null)
|
||||
{
|
||||
row.setPrBegindate(existing.getPrBegindate());
|
||||
}
|
||||
if (row.getPrEnddate() == null)
|
||||
{
|
||||
row.setPrEnddate(existing.getPrEnddate());
|
||||
}
|
||||
validateCustomer(row, db);
|
||||
customerMapper.updatePrcCustomerPriceSet(row);
|
||||
replaced++;
|
||||
}
|
||||
else
|
||||
{
|
||||
validateCustomer(row, db);
|
||||
try
|
||||
{
|
||||
customerMapper.insertPrcCustomerPriceSet(row);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (isCustomerUniqueViolation(e))
|
||||
{
|
||||
skipped++;
|
||||
skippedNames.add(StringUtils.isNotEmpty(item.getCustomerName())
|
||||
? item.getCustomerName() : item.getCustomerCode());
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
inserted++;
|
||||
}
|
||||
}
|
||||
|
||||
String msg = MessageUtils.message("price.set.customer.batch.done",
|
||||
Integer.valueOf(uniq.size()), Integer.valueOf(inserted),
|
||||
Integer.valueOf(replaced), Integer.valueOf(skipped));
|
||||
if (skipped > 0 && !overwrite)
|
||||
{
|
||||
String names = skippedNames.stream().limit(10).collect(java.util.stream.Collectors.joining(", "));
|
||||
msg = msg + " [" + names + (skippedNames.size() > 10 ? "..." : "") + "]";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateCustomer(PrcCustomerPriceSet customer)
|
||||
{
|
||||
@@ -2962,6 +3084,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.customerId.empty"));
|
||||
}
|
||||
// UI no longer collects bind dates: fall back to set / version / today.
|
||||
// Do not reject empty begin date — always fill a value.
|
||||
if (customer.getPrBegindate() == null)
|
||||
{
|
||||
customer.setPrBegindate(set.getEffectiveDate());
|
||||
@@ -2972,11 +3096,17 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
}
|
||||
if (customer.getPrBegindate() == null)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.beginDate.empty"));
|
||||
customer.setPrBegindate(DateUtils.getNowDate());
|
||||
}
|
||||
if (customer.getPrEnddate() != null && customer.getPrBegindate().after(customer.getPrEnddate()))
|
||||
if (customer.getPrEnddate() == null)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.customer.date.invalid"));
|
||||
customer.setPrEnddate(set.getExpireDate());
|
||||
}
|
||||
// Auto-filled dates may conflict (e.g. set expire already past); keep bind, clear end.
|
||||
if (customer.getPrEnddate() != null && customer.getPrBegindate() != null
|
||||
&& customer.getPrBegindate().after(customer.getPrEnddate()))
|
||||
{
|
||||
customer.setPrEnddate(null);
|
||||
}
|
||||
if (customer.getBindPriority() != null && customer.getBindPriority().intValue() < 1)
|
||||
{
|
||||
|
||||
@@ -141,6 +141,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<update id="updatePrcCustomerPriceSet" parameterType="PrcCustomerPriceSet">
|
||||
update prc_customer_price_set
|
||||
<set>
|
||||
<if test="priceSetId != null">price_set_id = #{priceSetId},</if>
|
||||
<if test="customerId != null">customer_id = #{customerId},</if>
|
||||
<if test="customerCode != null">customer_code = #{customerCode},</if>
|
||||
<if test="customerName != null">customer_name = #{customerName},</if>
|
||||
|
||||
Reference in New Issue
Block a user