|
|
@ -1,9 +1,32 @@ |
|
|
|
package com.yxt.yyth.biz.lpkgiftbag; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
|
import com.yxt.common.base.utils.StringUtils; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.yyth.api.lpkcustomer.LpkCustomer; |
|
|
|
import com.yxt.yyth.api.lpkgiftbag.LpkGiftBag; |
|
|
|
import com.yxt.yyth.api.lpkgiftbag.*; |
|
|
|
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoods; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoods; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoodsQuery; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoodsVo; |
|
|
|
import com.yxt.yyth.biz.lpkgiftbaggoods.LpkGiftBagGoodsService; |
|
|
|
import com.yxt.yyth.biz.lpkgoods.LpkGoodsService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author wangpengfei |
|
|
@ -12,4 +35,139 @@ import org.springframework.stereotype.Service; |
|
|
|
@Service |
|
|
|
public class LpkGiftBagService extends MybatisBaseService<LpkGiftBagMapper, LpkGiftBag> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
private LpkGiftBagGoodsService lpkGiftBagGoodsService; |
|
|
|
@Autowired |
|
|
|
private LpkGoodsService lpkGoodsService; |
|
|
|
|
|
|
|
public ResultBean<PagerVo<LpkGiftBagVo>> giftBagListPage(PagerQuery<LpkGiftBagQuery> pq) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkGiftBagQuery query = pq.getParams(); |
|
|
|
QueryWrapper<LpkGiftBag> qw = new QueryWrapper<>(); |
|
|
|
if (StringUtils.isNotBlank(query.getName())) { |
|
|
|
qw.like("name", query.getName()); |
|
|
|
} |
|
|
|
IPage<LpkGiftBag> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<LpkGiftBagVo> pagging = baseMapper.giftBagListPage(page, qw); |
|
|
|
PagerVo<LpkGiftBagVo> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
List<LpkGiftBagVo> records = pagging.getRecords(); |
|
|
|
records.removeAll(Collections.singleton(null)); |
|
|
|
if (!records.isEmpty()) { |
|
|
|
for (LpkGiftBagVo record : records) { |
|
|
|
if (StringUtils.isNotBlank(record.getIconUrl())) { |
|
|
|
record.setIconUrl(fileUploadComponent.getUrlPrefix() + record.getIconUrl()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success().setData(p); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public ResultBean saveGiftBag(LpkGiftBagDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
if (StringUtils.isNotBlank(dto.getSid())) { |
|
|
|
lpkGiftBagGoodsService.deleteGoodsByBagSid(dto.getSid()); |
|
|
|
LpkGiftBag lpkGiftBag = fetchBySid(dto.getSid()); |
|
|
|
BeanUtil.copyProperties(dto, lpkGiftBag, "id", "sid"); |
|
|
|
lpkGiftBag.setCreateTime(new DateTime()); |
|
|
|
if (StringUtils.isNotBlank(dto.getIconUrl())) { |
|
|
|
String urlPrefix = fileUploadComponent.getUrlPrefix(); |
|
|
|
String path = dto.getIconUrl().substring(urlPrefix.length()); |
|
|
|
lpkGiftBag.setIconUrl(path); |
|
|
|
} |
|
|
|
baseMapper.updateById(lpkGiftBag); |
|
|
|
if (!dto.getGoods().isEmpty()) { |
|
|
|
List<GiftBagGoods> goodsList = dto.getGoods(); |
|
|
|
for (GiftBagGoods goods : goodsList) { |
|
|
|
LpkGiftBagGoods lpkGiftBagGoods = new LpkGiftBagGoods(); |
|
|
|
lpkGiftBagGoods.setCreateTime(new DateTime()); |
|
|
|
lpkGiftBagGoods.setGoodsSid(goods.getGoodsSid()); |
|
|
|
lpkGiftBagGoods.setGiftbagSid(lpkGiftBag.getSid()); |
|
|
|
lpkGiftBagGoods.setGoodsNumber(goods.getGoodsNumber()); |
|
|
|
lpkGiftBagGoodsService.insert(lpkGiftBagGoods); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
LpkGiftBag lpkGiftBag = new LpkGiftBag(); |
|
|
|
BeanUtil.copyProperties(dto, lpkGiftBag, "id", "sid"); |
|
|
|
lpkGiftBag.setCreateTime(new DateTime()); |
|
|
|
if (StringUtils.isNotBlank(dto.getIconUrl())) { |
|
|
|
String urlPrefix = fileUploadComponent.getUrlPrefix(); |
|
|
|
String path = dto.getIconUrl().substring(urlPrefix.length()); |
|
|
|
lpkGiftBag.setIconUrl(path); |
|
|
|
} |
|
|
|
baseMapper.insert(lpkGiftBag); |
|
|
|
if (!dto.getGoods().isEmpty()) { |
|
|
|
List<GiftBagGoods> goodsList = dto.getGoods(); |
|
|
|
for (GiftBagGoods goods : goodsList) { |
|
|
|
LpkGiftBagGoods lpkGiftBagGoods = new LpkGiftBagGoods(); |
|
|
|
lpkGiftBagGoods.setCreateTime(new DateTime()); |
|
|
|
lpkGiftBagGoods.setGoodsSid(goods.getGoodsSid()); |
|
|
|
lpkGiftBagGoods.setGiftbagSid(lpkGiftBag.getSid()); |
|
|
|
lpkGiftBagGoods.setGoodsNumber(goods.getGoodsNumber()); |
|
|
|
lpkGiftBagGoodsService.insert(lpkGiftBagGoods); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean giftBagInit(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkGiftBagInitVo vo = new LpkGiftBagInitVo(); |
|
|
|
LpkGiftBag entity = fetchBySid(sid); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
if (null != entity) { |
|
|
|
BeanUtil.copyProperties(entity, vo); |
|
|
|
if (null != entity.getDateStart()) { |
|
|
|
vo.setDateStart(sdf.format(entity.getDateStart())); |
|
|
|
} |
|
|
|
if (null != entity.getDateEnd()) { |
|
|
|
vo.setDateEnd(sdf.format(entity.getDateEnd())); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(entity.getIconUrl())) { |
|
|
|
vo.setIconUrl(fileUploadComponent.getUrlPrefix() + entity.getIconUrl()); |
|
|
|
} |
|
|
|
List<GiftBagGoods> goods = new ArrayList<>(); |
|
|
|
List<LpkGiftBagGoods> records = lpkGiftBagGoodsService.getRecordsByBagSid(sid); |
|
|
|
if (!records.isEmpty()) { |
|
|
|
for (LpkGiftBagGoods record : records) { |
|
|
|
GiftBagGoods bagGoods = new GiftBagGoods(); |
|
|
|
if (StringUtils.isNotBlank(record.getGoodsNumber())) { |
|
|
|
bagGoods.setGoodsNumber(record.getGoodsNumber()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(record.getGoodsSid())) { |
|
|
|
bagGoods.setGoodsSid(record.getGoodsSid()); |
|
|
|
LpkGoods lpkGoods = lpkGoodsService.fetchBySid(record.getGoodsSid()); |
|
|
|
if (null != lpkGoods) { |
|
|
|
if (StringUtils.isNotBlank(lpkGoods.getName())) { |
|
|
|
bagGoods.setName(lpkGoods.getName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(lpkGoods.getUnitName())) { |
|
|
|
bagGoods.setUnitName(lpkGoods.getUnitName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(lpkGoods.getPrice())) { |
|
|
|
bagGoods.setPrice(lpkGoods.getPrice()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
goods.add(bagGoods); |
|
|
|
} |
|
|
|
} |
|
|
|
vo.setGoods(goods); |
|
|
|
} |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean deleteBag(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkGiftBag lpkGiftBag = fetchBySid(sid); |
|
|
|
if (null != lpkGiftBag) { |
|
|
|
baseMapper.deleteById(lpkGiftBag.getId()); |
|
|
|
lpkGiftBagGoodsService.deleteGoodsByBagSid(sid); |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
} |
|
|
|