package com.alatus.mall.ware.service.impl;
import com.alatus.common.constant.WareConstant;
import com.alatus.mall.ware.entity.PurchaseDetailEntity;
import com.alatus.mall.ware.service.PurchaseDetailService;
import com.alatus.mall.ware.vo.MergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
import com.alatus.mall.ware.dao.PurchaseDao;
import com.alatus.mall.ware.entity.PurchaseEntity;
import com.alatus.mall.ware.service.PurchaseService;
import org.springframework.transaction.annotation.Transactional;
@Service("purchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {
@Autowired
private PurchaseDetailService purchaseDetailService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),
new QueryWrapper<PurchaseEntity>()
);
return new PageUtils(page);
}
@Override
public PageUtils queryPageUnReceive(Map<String, Object> params) {
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),
new QueryWrapper<PurchaseEntity>().eq("status",0).or().eq("status",1)
);
return new PageUtils(page);
}
@Override
@Transactional
public void mergePurchase(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
if(purchaseId == null){
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
purchaseId = purchaseEntity.getId();
}
List<Long> items = mergeVo.getItems();
Long finalPurchaseId = purchaseId;
List<PurchaseDetailEntity> detailEntities = items.stream().map(item -> {
PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
detailEntity.setPurchaseId(finalPurchaseId);
detailEntity.setId(item);
detailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode());
return detailEntity;
}).collect(Collectors.toList());
purchaseDetailService.updateBatchById(detailEntities);
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setId(purchaseId);
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.updateById(purchaseEntity);
}
}
package com.alatus.mall.ware.service.impl;
import com.alatus.common.constant.WareConstant;
import com.alatus.mall.ware.entity.PurchaseDetailEntity;
import com.alatus.mall.ware.service.PurchaseDetailService;
import com.alatus.mall.ware.vo.MergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alatus.common.utils.PageUtils;
import com.alatus.common.utils.Query;
import com.alatus.mall.ware.dao.PurchaseDao;
import com.alatus.mall.ware.entity.PurchaseEntity;
import com.alatus.mall.ware.service.PurchaseService;
import org.springframework.transaction.annotation.Transactional;
@Service("purchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {
@Autowired
private PurchaseDetailService purchaseDetailService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),
new QueryWrapper<PurchaseEntity>()
);
return new PageUtils(page);
}
@Override
public PageUtils queryPageUnReceive(Map<String, Object> params) {
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),
new QueryWrapper<PurchaseEntity>().eq("status",0).or().eq("status",1)
);
return new PageUtils(page);
}
@Override
@Transactional
public void mergePurchase(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
if(purchaseId == null){
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
purchaseId = purchaseEntity.getId();
}
List<Long> items = mergeVo.getItems();
Long finalPurchaseId = purchaseId;
List<PurchaseDetailEntity> detailEntities = items.stream().map(item -> {
PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
detailEntity.setPurchaseId(finalPurchaseId);
detailEntity.setId(item);
detailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode());
return detailEntity;
}).collect(Collectors.toList());
purchaseDetailService.updateBatchById(detailEntities);
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setId(purchaseId);
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.updateById(purchaseEntity);
}
}
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/Mall-wms
driver-class-name: com.mysql.cj.jdbc.Driver
jackson:
date-format: yyyy-MM-dd HH:mm:ss
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
server:
port: 11000
logging:
level:
com.alatus: debug
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/Mall-wms
driver-class-name: com.mysql.cj.jdbc.Driver
jackson:
date-format: yyyy-MM-dd HH:mm:ss
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
server:
port: 11000
logging:
level:
com.alatus: debug