diff --git a/src/main/java/org/springblade/modules/jinchao/controller/CustomerController.java b/src/main/java/org/springblade/modules/jinchao/controller/CustomerController.java index abc263a..2f99690 100644 --- a/src/main/java/org/springblade/modules/jinchao/controller/CustomerController.java +++ b/src/main/java/org/springblade/modules/jinchao/controller/CustomerController.java @@ -33,15 +33,14 @@ import lombok.AllArgsConstructor; import jakarta.validation.Valid; import org.springblade.core.secure.BladeUser; -import org.springblade.core.secure.annotation.IsAdmin; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.utils.Func; import org.springblade.modules.jinchao.constant.BaseCol; import org.springblade.modules.jinchao.pojo.request.CustomerSearch; import org.springblade.modules.jinchao.pojo.request.CustomerSubmit; +import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -80,9 +79,12 @@ public class CustomerController extends BladeController { @GetMapping("/detail") @ApiOperationSupport(order = 1) @Operation(summary = "详情", description = "传入customer") - public R detail(CustomerEntity customer) { + public R detail(CustomerEntity customer) { CustomerEntity detail = service.getOne(Condition.getQueryWrapper(customer)); - return R.data(CustomerWrapper.build().entityVO(detail)); + CustomerSubmit submit = new CustomerSubmit(); + BeanUtils.copyProperties(detail, submit); + service.setVoValueDetail(submit); + return R.data(submit); } /** @@ -100,7 +102,7 @@ public class CustomerController extends BladeController { .orderByDesc(BaseCol.CREATE_TIME) ); IPage pagesVo = CustomerWrapper.build().pageVO(pages); - pagesVo.getRecords().stream().peek(service::setVoValue).collect(Collectors.toList()); + pagesVo.getRecords().stream().peek(service::setVoValueMain).collect(Collectors.toList()); return R.data(pagesVo); } diff --git a/src/main/java/org/springblade/modules/jinchao/controller/ProductController.java b/src/main/java/org/springblade/modules/jinchao/controller/ProductController.java index f101b28..fd452f7 100644 --- a/src/main/java/org/springblade/modules/jinchao/controller/ProductController.java +++ b/src/main/java/org/springblade/modules/jinchao/controller/ProductController.java @@ -29,6 +29,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import jakarta.annotation.Resource; import lombok.AllArgsConstructor; import jakarta.validation.Valid; @@ -37,8 +38,11 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; +import org.springblade.modules.jinchao.constant.BaseCol; import org.springblade.modules.jinchao.constant.ProductConst; +import org.springblade.modules.jinchao.pojo.entity.BizPriceEntity; import org.springblade.modules.jinchao.pojo.vo.ProductVO; +import org.springblade.modules.jinchao.service.IBizPriceService; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -53,6 +57,7 @@ import org.springblade.core.excel.util.ExcelUtil; import java.util.Map; import java.util.List; import java.util.Objects; +import java.util.Optional; import jakarta.servlet.http.HttpServletResponse; @@ -68,7 +73,10 @@ import jakarta.servlet.http.HttpServletResponse; @Tag(name = "[产品]", description = "[产品]接口") public class ProductController extends BladeController { - private final IProductService service; + @Resource + private IProductService service; + @Resource + private IBizPriceService bizPriceService; /** * [产品] 详情 @@ -157,24 +165,38 @@ public class ProductController extends BladeController { @ApiOperationSupport(order = 6) @Operation(summary = "批量新增或修改", description = "ProductEntity List") public R submitBat(@Valid @RequestBody List vos) { + // todo:删除的情况 + + // if (vos != null && !vos.isEmpty()) { for (ProductVO vo : vos) { - if (vo != null && Objects.equals(vo.getBizType(), ProductConst.TYPE_PRICE_CUSTOM)) { - // 跳过 - continue; - } - if (Objects.requireNonNull(vo).getId() == null || vo.getId() == 0L) { - // 新增check - if (service.existsCode(vo.getCode())) { - return R.fail("已经存在此code"); - } - if (service.existsNameCn(vo.getNameCn())) { - return R.fail("已经存在此nameCn"); + final Integer bizType = vo.getBizType(); + if (Objects.equals(bizType, ProductConst.TYPE_PRICE_STANDARD)) { // 标准价 + if (Objects.requireNonNull(vo).getId() == null || vo.getId() == 0L) { + // 新增check + if (service.existsCode(vo.getCode())) { + return R.fail("已经存在此code"); + } + if (service.existsNameCn(vo.getNameCn())) { + return R.fail("已经存在此nameCn"); + } + // 新增 + service.save(vo); + } else { + service.updateById(vo); } - // 新增 - service.save(vo); - } else { - service.updateById(vo); + } else if (Objects.equals(bizType, ProductConst.TYPE_PRICE_CUSTOM)) { // 指定价 + QueryWrapper qw = new QueryWrapper() + .eq(BaseCol.ID, vo.getBizPriceId()); + Optional opt = bizPriceService.getOneOpt(qw); + opt.ifPresent( + bp -> { + bp.setSaleUserId(vo.getSaleUserId()); + bp.setCustomerId(vo.getCustomerId()); + bp.setBizPrice(vo.getBizPrice()); + bizPriceService.save(bp); + } + ); } } } diff --git a/src/main/java/org/springblade/modules/jinchao/controller/ProductObjController.java b/src/main/java/org/springblade/modules/jinchao/controller/ProductObjController.java index ebb849c..38c63ce 100644 --- a/src/main/java/org/springblade/modules/jinchao/controller/ProductObjController.java +++ b/src/main/java/org/springblade/modules/jinchao/controller/ProductObjController.java @@ -41,6 +41,7 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; +import org.springblade.modules.jinchao.constant.BaseCol; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -94,7 +95,11 @@ public class ProductObjController extends BladeController { @ApiOperationSupport(order = 2) @Operation(summary = "list分页", description = "传入productObj") public R> list(@Parameter(hidden = true) @RequestParam Map productObj, Query query) { - IPage pages = productObjService.page(Condition.getPage(query), Condition.getQueryWrapper(productObj, ProductObjEntity.class)); + IPage pages = productObjService.page( + Condition.getPage(query), + Condition.getQueryWrapper(productObj, ProductObjEntity.class) + .orderByAsc(BaseCol.ID) + ); return R.data(ProductObjWrapper.build().pageVO(pages)); } diff --git a/src/main/java/org/springblade/modules/jinchao/pojo/entity/BizPriceEntity.java b/src/main/java/org/springblade/modules/jinchao/pojo/entity/BizPriceEntity.java index a784753..79cff35 100644 --- a/src/main/java/org/springblade/modules/jinchao/pojo/entity/BizPriceEntity.java +++ b/src/main/java/org/springblade/modules/jinchao/pojo/entity/BizPriceEntity.java @@ -30,6 +30,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import com.baomidou.mybatisplus.annotation.TableName; import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; + import java.io.Serial; /** @@ -47,6 +48,8 @@ public class BizPriceEntity extends TenantEntity { @Serial private static final long serialVersionUID = 1L; + public static final String COL_PRODUCT_ID = "product_id"; + /** * [产品]id */ @@ -63,8 +66,8 @@ public class BizPriceEntity extends TenantEntity { @Schema(description = "[客户]id") private Long customerId; /** - * 特定用户价格 + * 特定业务员价格 */ - @Schema(description = "特定用户价格") + @Schema(description = "特定业务员价格") private Double bizPrice; } diff --git a/src/main/java/org/springblade/modules/jinchao/pojo/entity/ProductEntity.java b/src/main/java/org/springblade/modules/jinchao/pojo/entity/ProductEntity.java index 222e21d..36dcd87 100644 --- a/src/main/java/org/springblade/modules/jinchao/pojo/entity/ProductEntity.java +++ b/src/main/java/org/springblade/modules/jinchao/pojo/entity/ProductEntity.java @@ -30,6 +30,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import com.baomidou.mybatisplus.annotation.TableName; import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; + import java.io.Serial; /** @@ -47,6 +48,10 @@ public class ProductEntity extends TenantEntity { @Serial private static final long serialVersionUID = 1L; + public static final String COL_CODE = "code"; + + public static final String COL_NAME_CN = "name_cn"; + /** * 编号 */ diff --git a/src/main/java/org/springblade/modules/jinchao/pojo/vo/CustomerVO.java b/src/main/java/org/springblade/modules/jinchao/pojo/vo/CustomerVO.java index 209e1b8..f6da99c 100644 --- a/src/main/java/org/springblade/modules/jinchao/pojo/vo/CustomerVO.java +++ b/src/main/java/org/springblade/modules/jinchao/pojo/vo/CustomerVO.java @@ -32,6 +32,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serial; +import java.time.LocalDateTime; /** * [客户] 视图实体类 @@ -46,22 +47,39 @@ public class CustomerVO extends CustomerEntity { @Serial private static final long serialVersionUID = 1L; + /** + * 创建人 真名 + */ + @Schema(description = "创建人 真名") + private String createUserRealName; /** * 所属国家dict */ @Schema(description = "所属国家dict") private String countryValue; - - /** * 客户来源dict */ @Schema(description = "客户来源dict") private String fromTypeValue; - /** * 主要[客户联系人] */ @Schema(description = "主要[客户联系人]") private ContactEntity contactMain; + /** + * 最近订单状态 + */ + @Schema(description = "最近订单状态") + private Integer lastOrderStatus = 2; + /** + * 最近订单状态 + */ + @Schema(description = "最近订单状态") + private String lastOrderStatusValue = "已付款"; + /** + * 最近成交时间 + */ + @Schema(description = "最近成交时间") + private LocalDateTime lastOrderDealDateTime = LocalDateTime.now(); } diff --git a/src/main/java/org/springblade/modules/jinchao/service/ICustomerService.java b/src/main/java/org/springblade/modules/jinchao/service/ICustomerService.java index eae34e8..6465bb6 100644 --- a/src/main/java/org/springblade/modules/jinchao/service/ICustomerService.java +++ b/src/main/java/org/springblade/modules/jinchao/service/ICustomerService.java @@ -69,5 +69,7 @@ public interface ICustomerService extends BaseService { R> listForSelect(); - void setVoValue(CustomerVO vo); + void setVoValueMain(CustomerVO vo); + + void setVoValueDetail(CustomerSubmit submit); } diff --git a/src/main/java/org/springblade/modules/jinchao/service/impl/CustomerServiceImpl.java b/src/main/java/org/springblade/modules/jinchao/service/impl/CustomerServiceImpl.java index 2bf153e..1990a78 100644 --- a/src/main/java/org/springblade/modules/jinchao/service/impl/CustomerServiceImpl.java +++ b/src/main/java/org/springblade/modules/jinchao/service/impl/CustomerServiceImpl.java @@ -41,7 +41,9 @@ import org.springblade.modules.jinchao.excel.CustomerExcel; import org.springblade.modules.jinchao.mapper.CustomerMapper; import org.springblade.modules.jinchao.service.IContactService; import org.springblade.modules.jinchao.service.ICustomerService; +import org.springblade.modules.system.pojo.entity.User; import org.springblade.modules.system.service.IDictService; +import org.springblade.modules.system.service.IUserService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.Wrapper; @@ -70,6 +72,8 @@ public class CustomerServiceImpl extends BaseServiceImpl selectCustomerPage(IPage page, CustomerVO customer) { @@ -91,19 +95,19 @@ public class CustomerServiceImpl extends BaseServiceImpl existList = contactService.list( +// new QueryWrapper().eq("", "") +// ); for (int i = 0; i < submit.getContacts().size(); i++) { ContactEntity co = submit.getContacts().get(i); co.setCustomerId(cu.getId()); if (co.getSort() == null || co.getSort() == 0L) { - co.setSort(i); + co.setSort(i + 1); } if (co.getContactType() == null || co.getContactType() == 0L) { co.setContactType(ContactConst.TYPE_SECONDARY); } } contactService.saveOrUpdateBatch(submit.getContacts()); - return R.status(save); + return R.status(update); } @Override public IPage search(IPage page, CustomerSearch search) { IPage pagesVo = page.setRecords(baseMapper.searchPage(page, search)); - pagesVo.getRecords().stream().peek(this::setVoValue).collect(Collectors.toList()); + pagesVo.getRecords().stream().peek(this::setVoValueMain).collect(Collectors.toList()); return pagesVo; } @@ -147,7 +155,7 @@ public class CustomerServiceImpl extends BaseServiceImpl list = contactService.list( + new QueryWrapper() + .eq("customer_id", submit.getId()) + .orderByAsc("sort") + ); + submit.setContacts(list); } } diff --git a/src/main/java/org/springblade/modules/jinchao/service/impl/ProductServiceImpl.java b/src/main/java/org/springblade/modules/jinchao/service/impl/ProductServiceImpl.java index a324841..02493bd 100644 --- a/src/main/java/org/springblade/modules/jinchao/service/impl/ProductServiceImpl.java +++ b/src/main/java/org/springblade/modules/jinchao/service/impl/ProductServiceImpl.java @@ -79,7 +79,7 @@ public class ProductServiceImpl extends BaseServiceImpl selectProductPage(IPage page, org.springblade.modules.jinchao.pojo.vo.ProductVO product) { + public IPage selectProductPage(IPage page, ProductVO product) { return page.setRecords(baseMapper.selectProductPage(page, product)); } @@ -101,30 +101,35 @@ public class ProductServiceImpl extends BaseServiceImpl pagesVo = ProductWrapper.build().pageVO(pages); ListIterator it = pagesVo.getRecords().listIterator(); while (it.hasNext()) { - ProductVO vo = it.next(); - vo.setBizType(ProductConst.TYPE_PRICE_STANDARD); + ProductVO vo1 = it.next(); + // 默认 + vo1.setBizType(ProductConst.TYPE_PRICE_STANDARD); // TYPE_PRICE_CUSTOM 数据是拼接上的 long count = bizPriceService.count( - new QueryWrapper().eq("product_id", vo.getId()) + new QueryWrapper().eq(BizPriceEntity.COL_PRODUCT_ID, vo1.getId()) ); if (count != 0L) { - List listBP = bizPriceService.listByProductId(vo.getId()); + List listBP = bizPriceService.listByProductId(vo1.getId()); listBP.forEach(bp -> { - log.info("bp = {}", bp); ProductVO vo2 = new ProductVO(); - BeanUtils.copyProperties(vo, vo2); + BeanUtils.copyProperties(vo1, vo2); + vo2.setId(vo1.getId()); + // 特定价 vo2.setBizType(ProductConst.TYPE_PRICE_CUSTOM); vo2.setBizPriceId(bp.getId()); BeanUtils.copyProperties(bp, vo2); - User u = userService.getById(vo2.getSaleUserId()); - if (u != null) { - vo2.setSaleUserRealName(u.getRealName()); + // + CustomerEntity customer = customerService.getById(bp.getCustomerId()); + if (customer != null) { + vo2.setBizRemark("客户:" + customer.getCompanyName()); + vo2.setCustomerCompanyName(customer.getCompanyName()); } - CustomerEntity c = customerService.getById(vo2.getCustomerId()); - if (c != null) { - vo2.setCustomerCompanyName(c.getCompanyName()); + { + User u = userService.getById(vo2.getSaleUserId()); + if (u != null) { + vo2.setSaleUserRealName(u.getRealName()); + } } - vo2.setBizRemark("客户:" + customerService.getById(bp.getCustomerId()).getCompanyName()); it.add(vo2); }); } else { @@ -136,12 +141,12 @@ public class ProductServiceImpl extends BaseServiceImpl().eq("code", code)); + return baseMapper.exists(new QueryWrapper().eq(ProductEntity.COL_CODE, code)); } @Override public Boolean existsNameCn(String nameCn) { - return baseMapper.exists(new QueryWrapper().eq("name_cn", nameCn)); + return baseMapper.exists(new QueryWrapper().eq(ProductEntity.COL_NAME_CN, nameCn)); } /** @@ -162,7 +167,7 @@ public class ProductServiceImpl extends BaseServiceImpl> oneKeyMatch(List list) { List listNew = list.stream() .map(vo -> { - ProductEntity pFind = getOne(new QueryWrapper().eq("name_cn", vo.getNameCn())); + ProductEntity pFind = getOne(new QueryWrapper().eq(ProductEntity.COL_NAME_CN, vo.getNameCn())); if (pFind != null) { ProductVO voNew = new ProductVO(); BeanUtils.copyProperties(pFind, voNew);