package com.doumee.service.business.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.business.YwElectricalParamMapper;
|
import com.doumee.dao.business.model.YwElectricalParam;
|
import com.doumee.service.business.YwElectricalParamService;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
@Service
|
public class YwElectricalParamServiceImpl implements YwElectricalParamService {
|
|
@Autowired
|
private YwElectricalParamMapper ywElectricalParamMapper;
|
|
@Override
|
public Integer create(YwElectricalParam row) {
|
fillPrice(row);
|
fillCreate(row);
|
ywElectricalParamMapper.insert(row);
|
return row.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
ywElectricalParamMapper.deleteById(id);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
for (Integer id : ids) {
|
deleteById(id);
|
}
|
}
|
|
@Override
|
public void deleteById(Integer id, LoginUserInfo user) {
|
YwElectricalParam upd = new YwElectricalParam();
|
upd.setId(id);
|
upd.setIsdeleted(Constants.ONE);
|
upd.setEdirot(user.getId());
|
upd.setEditDate(new Date());
|
ywElectricalParamMapper.updateById(upd);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
for (Integer id : ids) {
|
deleteById(id, user);
|
}
|
}
|
|
@Override
|
public void delete(YwElectricalParam ywElectricalParam) {
|
UpdateWrapper<YwElectricalParam> deleteWrapper = new UpdateWrapper<>(ywElectricalParam);
|
ywElectricalParamMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void updateById(YwElectricalParam row) {
|
if (row == null || row.getId() == null) {
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
fillPrice(row);
|
if (row.getLoginUserInfo() != null) {
|
row.setEdirot(row.getLoginUserInfo().getId());
|
row.setEditDate(new Date());
|
}
|
ywElectricalParamMapper.updateById(row);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<YwElectricalParam> rows) {
|
if (CollectionUtils.isEmpty(rows)) {
|
return;
|
}
|
for (YwElectricalParam row : rows) {
|
updateById(row);
|
}
|
}
|
|
@Override
|
public YwElectricalParam findById(Integer id) {
|
YwElectricalParam row = ywElectricalParamMapper.selectById(id);
|
if (row == null || Objects.equals(row.getIsdeleted(), Constants.ONE)) {
|
return null;
|
}
|
return row;
|
}
|
|
@Override
|
public YwElectricalParam findOne(YwElectricalParam ywElectricalParam) {
|
QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>(ywElectricalParam).last("limit 1");
|
return ywElectricalParamMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<YwElectricalParam> findList(YwElectricalParam ywElectricalParam) {
|
QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>();
|
wrapper.lambda().eq(YwElectricalParam::getIsdeleted, Constants.ZERO);
|
if (ywElectricalParam != null && ywElectricalParam.getStatus() != null) {
|
wrapper.lambda().eq(YwElectricalParam::getStatus, ywElectricalParam.getStatus());
|
}
|
wrapper.lambda().orderByDesc(YwElectricalParam::getId);
|
return ywElectricalParamMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<YwElectricalParam> findPage(PageWrap<YwElectricalParam> pageWrap) {
|
IPage<YwElectricalParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
MPJLambdaWrapper<YwElectricalParam> queryWrapper = new MPJLambdaWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
queryWrapper.eq(YwElectricalParam::getIsdeleted, Constants.ZERO);
|
if (pageWrap.getModel() != null && StringUtils.isNotBlank(pageWrap.getModel().getNameKeyword())) {
|
queryWrapper.like(YwElectricalParam::getName, pageWrap.getModel().getNameKeyword().trim());
|
}
|
queryWrapper.eq(pageWrap.getModel().getStatus() != null, YwElectricalParam::getStatus, pageWrap.getModel().getStatus());
|
queryWrapper.orderByDesc(YwElectricalParam::getId);
|
IPage<YwElectricalParam> result = ywElectricalParamMapper.selectJoinPage(page, YwElectricalParam.class, queryWrapper);
|
return PageData.from(result);
|
}
|
|
@Override
|
public long count(YwElectricalParam ywElectricalParam) {
|
QueryWrapper<YwElectricalParam> wrapper = new QueryWrapper<>(ywElectricalParam);
|
return ywElectricalParamMapper.selectCount(wrapper);
|
}
|
|
private void fillPrice(YwElectricalParam row) {
|
BigDecimal base = row.getBasePrice() != null ? row.getBasePrice() : BigDecimal.ZERO;
|
BigDecimal extra = row.getExtraPrice() != null ? row.getExtraPrice() : BigDecimal.ZERO;
|
row.setPrice(base.add(extra));
|
}
|
|
private void fillCreate(YwElectricalParam row) {
|
Date now = new Date();
|
row.setCreateDate(now);
|
row.setEditDate(now);
|
row.setIsdeleted(Constants.ZERO);
|
if (row.getStatus() == null) {
|
row.setStatus(Constants.ZERO);
|
}
|
if (row.getLoginUserInfo() != null) {
|
row.setCreator(row.getLoginUserInfo().getId());
|
row.setEdirot(row.getLoginUserInfo().getId());
|
}
|
}
|
}
|