8 changed files with 410 additions and 5 deletions
@ -0,0 +1,103 @@ |
|||
package com.qs.serve.modules.goods.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import com.qs.serve.common.util.CopierUtil; |
|||
import com.qs.serve.common.util.StringUtils; |
|||
import com.qs.serve.modules.goods.entity.bo.GoodsCustomerPriceBo; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import com.qs.serve.modules.goods.entity.GoodsCustomerPrice; |
|||
import com.qs.serve.modules.goods.service.GoodsCustomerPriceService; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 商品 客户价格关系表 |
|||
* @author YenHex |
|||
* @since 2024-01-08 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("goods/customerPrice") |
|||
public class GoodsCustomerPriceController { |
|||
|
|||
private GoodsCustomerPriceService goodsCustomerPriceService; |
|||
|
|||
/** |
|||
* 列表 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/list") |
|||
public R<List<GoodsCustomerPrice>> getList(GoodsCustomerPrice param){ |
|||
if(param.getSupplierId()==null){ |
|||
return R.error("请选择客户"); |
|||
} |
|||
LambdaQueryWrapper<GoodsCustomerPrice> lqw = new LambdaQueryWrapper<>(param); |
|||
List<GoodsCustomerPrice> list = goodsCustomerPriceService.list(lqw); |
|||
return R.ok(list); |
|||
} |
|||
|
|||
/** |
|||
* 翻页 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page") |
|||
public R<PageVo<GoodsCustomerPrice>> getPage(GoodsCustomerPrice param){ |
|||
LambdaQueryWrapper<GoodsCustomerPrice> lqw = new LambdaQueryWrapper<>(param); |
|||
PageUtil.startPage(); |
|||
List<GoodsCustomerPrice> list = goodsCustomerPriceService.list(lqw); |
|||
return R.byPageHelperList(list); |
|||
} |
|||
|
|||
/** |
|||
* ID查询 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
//@GetMapping("/getById/{id}")
|
|||
@SysLog(module = SystemModule.GOODS, title = "客户价格关系表", biz = BizType.QUERY) |
|||
public R<GoodsCustomerPrice> getById(@PathVariable("id") String id){ |
|||
GoodsCustomerPrice goodsCustomerPrice = goodsCustomerPriceService.getById(id); |
|||
return R.ok(goodsCustomerPrice); |
|||
} |
|||
|
|||
/** |
|||
* 批量保存 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/saveBatch") |
|||
@SysLog(module = SystemModule.GOODS, title = "批量保存", biz = BizType.INSERT) |
|||
public R<?> saveBatch(@RequestBody @Valid GoodsCustomerPriceBo param){ |
|||
goodsCustomerPriceService.saveBatch(param); |
|||
return R.ok(); |
|||
} |
|||
|
|||
/** |
|||
* 删除 |
|||
* @param ids |
|||
* @return |
|||
*/ |
|||
@DeleteMapping("/deleteById/{ids}") |
|||
@SysLog(module = SystemModule.GOODS, title = "客户价格关系表", biz = BizType.DELETE) |
|||
public R<?> deleteById(@PathVariable("ids") String ids){ |
|||
List<Long> idsLong = StringUtils.splitIdLong(ids); |
|||
boolean result = goodsCustomerPriceService.removeByIds(idsLong); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,143 @@ |
|||
package com.qs.serve.modules.goods.entity; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 客户价格关系表 实体类 |
|||
* @author YenHex |
|||
* @since 2024-01-08 |
|||
*/ |
|||
@Data |
|||
@TableName("goods_customer_price") |
|||
public class GoodsCustomerPrice implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 客户ID */ |
|||
private String supplierId; |
|||
|
|||
/** 客户编号 */ |
|||
@NotNull(message = "客户编号不能为空") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String supplierCode; |
|||
|
|||
/** 客户名称(冗余) */ |
|||
@Length(max = 50,message = "客户名称(冗余)长度不能超过50字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String supplierName; |
|||
|
|||
/** 存货编码 */ |
|||
@NotNull(message = "存货编码不能为空") |
|||
private String skuId; |
|||
|
|||
/** 存货编码 */ |
|||
@NotNull(message = "存货编码不能为空") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String skuCode; |
|||
|
|||
/** 存货名称(冗余) */ |
|||
@Length(max = 255,message = "存货名称(冗余)长度不能超过255字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String skuName; |
|||
|
|||
/** 计量单位 */ |
|||
@Length(max = 50,message = "计量单位长度不能超过50字") |
|||
private String skuUnit; |
|||
|
|||
/** 初始价格 */ |
|||
private BigDecimal initPrice; |
|||
|
|||
/** 真实价格 */ |
|||
@NotNull(message = "真实价格不能为空") |
|||
private BigDecimal realPrice; |
|||
|
|||
/** 定价人 */ |
|||
@Length(max = 50,message = "定价人长度不能超过50字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String maker; |
|||
|
|||
/** 定价人编号 */ |
|||
@Length(max = 50,message = "定价人编号长度不能超过50字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String makerCode; |
|||
|
|||
/** 定价时间 */ |
|||
@Length(max = 0,message = "定价时间长度不能超过0字") |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
private LocalDateTime markTime; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 租户id */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 删除标识 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private Boolean delFlag; |
|||
|
|||
|
|||
public static GoodsCustomerPrice toNewObject(GoodsCustomerPrice source){ |
|||
GoodsCustomerPrice customerPrice = new GoodsCustomerPrice(); |
|||
customerPrice.setId(source.getId()); |
|||
customerPrice.setSupplierId(source.getSupplierId()); |
|||
customerPrice.setSupplierCode(source.getSupplierCode()); |
|||
customerPrice.setSupplierName(source.getSupplierName()); |
|||
customerPrice.setSkuCode(source.getSkuCode()); |
|||
customerPrice.setSkuName(source.getSkuName()); |
|||
customerPrice.setSkuUnit(source.getSkuUnit()); |
|||
customerPrice.setInitPrice(source.getInitPrice()); |
|||
customerPrice.setRealPrice(source.getRealPrice()); |
|||
customerPrice.setMaker(source.getMaker()); |
|||
customerPrice.setMakerCode(source.getMakerCode()); |
|||
customerPrice.setMarkTime(source.getMarkTime()); |
|||
customerPrice.setCreateTime(source.getCreateTime()); |
|||
customerPrice.setCreateBy(source.getCreateBy()); |
|||
customerPrice.setUpdateTime(source.getUpdateTime()); |
|||
customerPrice.setUpdateBy(source.getUpdateBy()); |
|||
customerPrice.setTenantId(source.getTenantId()); |
|||
customerPrice.setDelFlag(source.getDelFlag()); |
|||
return customerPrice; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,46 @@ |
|||
package com.qs.serve.modules.goods.entity.bo; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
import java.util.List; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 客户价格关系表 Bo |
|||
* @author YenHex |
|||
* @since 2024-01-08 |
|||
*/ |
|||
@Data |
|||
public class GoodsCustomerPriceBo implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** 客户ID */ |
|||
private String supplierId; |
|||
|
|||
private List<SkuPriceItem> skuPriceItemList; |
|||
|
|||
@Data |
|||
public static class SkuPriceItem{ |
|||
|
|||
/** sku编码 */ |
|||
private String skuCode; |
|||
|
|||
/** 客户价格 */ |
|||
private BigDecimal price; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
package com.qs.serve.modules.goods.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.goods.entity.GoodsCustomerPrice; |
|||
|
|||
/** |
|||
* 客户价格关系表 Mapper |
|||
* @author YenHex |
|||
* @date 2024-01-08 |
|||
*/ |
|||
public interface GoodsCustomerPriceMapper extends BaseMapper<GoodsCustomerPrice> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,20 @@ |
|||
package com.qs.serve.modules.goods.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.goods.entity.GoodsCustomerPrice; |
|||
import com.qs.serve.modules.goods.entity.bo.GoodsCustomerPriceBo; |
|||
|
|||
/** |
|||
* 客户价格关系表 服务接口 |
|||
* @author YenHex |
|||
* @date 2024-01-08 |
|||
*/ |
|||
public interface GoodsCustomerPriceService extends IService<GoodsCustomerPrice> { |
|||
|
|||
|
|||
void saveBatch(GoodsCustomerPriceBo param); |
|||
|
|||
GoodsCustomerPrice getBySupplierIdAndCode(String supplierId,String skuCode); |
|||
|
|||
} |
|||
|
@ -0,0 +1,79 @@ |
|||
package com.qs.serve.modules.goods.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.qs.serve.common.util.AuthContextUtils; |
|||
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|||
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|||
import com.qs.serve.modules.goods.entity.GoodsSku; |
|||
import com.qs.serve.modules.goods.entity.bo.GoodsCustomerPriceBo; |
|||
import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; |
|||
import com.qs.serve.modules.sys.entity.SysUser; |
|||
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.goods.entity.GoodsCustomerPrice; |
|||
import com.qs.serve.modules.goods.service.GoodsCustomerPriceService; |
|||
import com.qs.serve.modules.goods.mapper.GoodsCustomerPriceMapper; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 客户价格关系表 服务实现类 |
|||
* @author YenHex |
|||
* @since 2024-01-08 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class GoodsCustomerPriceServiceImpl extends ServiceImpl<GoodsCustomerPriceMapper,GoodsCustomerPrice> implements GoodsCustomerPriceService { |
|||
|
|||
private final BmsSupplierMapper bmsSupplierMapper; |
|||
private final GoodsSkuMapper goodsSkuMapper; |
|||
private final SysUserMapper sysUserMapper; |
|||
|
|||
@Override |
|||
public void saveBatch(GoodsCustomerPriceBo param) { |
|||
BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId()); |
|||
SysUser sysUser = sysUserMapper.selectById(AuthContextUtils.getSysUserId()); |
|||
LocalDateTime nowTime = LocalDateTime.now(); |
|||
for (GoodsCustomerPriceBo.SkuPriceItem item : param.getSkuPriceItemList()) { |
|||
GoodsCustomerPrice customerPrice = this.getBySupplierIdAndCode(param.getSupplierId(),item.getSkuCode()); |
|||
if(customerPrice==null){ |
|||
GoodsSku goodsSku = goodsSkuMapper.selectBySkuCode(item.getSkuCode()); |
|||
if(goodsSku==null){ |
|||
continue; |
|||
} |
|||
customerPrice = new GoodsCustomerPrice(); |
|||
customerPrice.setSupplierId(supplier.getId()); |
|||
customerPrice.setSupplierCode(supplier.getCode()); |
|||
customerPrice.setSupplierName(supplier.getSupplierName()); |
|||
customerPrice.setSkuCode(goodsSku.getSkuCode()); |
|||
customerPrice.setSkuName(goodsSku.getSkuName()); |
|||
customerPrice.setSkuUnit(goodsSku.getUnitName()); |
|||
customerPrice.setInitPrice(goodsSku.getSalesPrice()); |
|||
customerPrice.setRealPrice(item.getPrice()); |
|||
customerPrice.setMaker(sysUser.getName()); |
|||
customerPrice.setMakerCode(sysUser.getCode()); |
|||
customerPrice.setMarkTime(nowTime); |
|||
this.save(customerPrice); |
|||
}else { |
|||
customerPrice.setRealPrice(item.getPrice()); |
|||
customerPrice.setMaker(sysUser.getName()); |
|||
customerPrice.setMakerCode(sysUser.getCode()); |
|||
customerPrice.setMarkTime(nowTime); |
|||
this.updateById(customerPrice); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public GoodsCustomerPrice getBySupplierIdAndCode(String supplierId, String skuCode) { |
|||
LambdaQueryWrapper<GoodsCustomerPrice> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.eq(GoodsCustomerPrice::getSupplierId,supplierId) |
|||
.eq(GoodsCustomerPrice::getSkuCode,skuCode); |
|||
return this.getOne(lqw,false); |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue