package doumeemes.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 doumeemes.core.model.ApiResponse;
|
import doumeemes.core.model.LoginUserInfo;
|
import doumeemes.core.model.PageData;
|
import doumeemes.core.model.PageWrap;
|
import doumeemes.core.utils.Constants;
|
import doumeemes.core.utils.Utils;
|
import doumeemes.dao.business.BarcodeParamMapper;
|
import doumeemes.dao.business.model.Appliances;
|
import doumeemes.dao.business.model.BarcodeParam;
|
import doumeemes.service.business.AppliancesService;
|
import doumeemes.service.business.BarcodeParamService;
|
import doumeemes.service.ext.BarcodeParamExtService;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 设置类-二维码设置表Service实现
|
* @author 江蹄蹄
|
* @date 2022/04/20 09:33
|
*/
|
@Service
|
public class BarcodeParamServiceImpl implements BarcodeParamService {
|
|
@Autowired
|
private BarcodeParamMapper barcodeParamMapper;
|
@Autowired
|
private BarcodeParamExtService barcodeParamExtService;
|
|
@Autowired
|
private AppliancesService appliancesService;
|
|
@Override
|
public ApiResponse create(BarcodeParam barcodeParam) {
|
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
BarcodeParam queryParam=new BarcodeParam();
|
queryParam.setDeleted(Constants.ZERO);
|
queryParam.setDepartId(user.getCurComDepartment().getId());
|
queryParam.setRootDepartId(user.getRootDepartment().getId());
|
queryParam.setType(barcodeParam.getType());
|
queryParam.setStatus(Constants.ONE);
|
List<BarcodeParam> alllist= this.findList(queryParam);
|
if(alllist!=null&&alllist.size()>0){
|
return ApiResponse.failed("类型已存在,不允许重复添加");
|
}
|
|
BarcodeParam queryParam1=new BarcodeParam();
|
queryParam1.setDeleted(Constants.ZERO);
|
queryParam1.setDepartId(user.getCurComDepartment().getId());
|
queryParam1.setRootDepartId(user.getRootDepartment().getId());
|
queryParam1.setStatus(Constants.ONE);
|
queryParam1.setPrefix(barcodeParam.getPrefix());
|
List<BarcodeParam> all1list= this.findList(queryParam1);
|
if(all1list!=null&&all1list.size()>0){
|
return ApiResponse.failed("前缀已存在,不允许重复添加");
|
}
|
barcodeParam.setDeleted(Constants.ZERO);
|
barcodeParam.setCreateTime(new Date());
|
barcodeParam.setCreateUser(user.getId());
|
barcodeParam.setRootDepartId(user.getRootDepartment().getRootId());
|
barcodeParam.setDepartId(user.getCurComDepartment().getId());
|
barcodeParam.setStatus(Constants.ONE);
|
int r =barcodeParamMapper.insert(barcodeParam);
|
barcodeParamExtService.loadCom(user.getCompany());
|
return ApiResponse.success(r);
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
BarcodeParam barcodeParam=this.findById(id);
|
barcodeParam.setDeleted(Constants.ONE);
|
barcodeParamMapper.updateById(barcodeParam);
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
barcodeParamExtService.loadCom(user.getCompany());
|
// barcodeParamMapper.deleteById(id);
|
}
|
|
@Override
|
public void delete(BarcodeParam barcodeParam) {
|
UpdateWrapper<BarcodeParam> deleteWrapper = new UpdateWrapper<>(barcodeParam);
|
barcodeParamMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
for(Integer id:ids){
|
BarcodeParam barcodeParam= this.findById(id);
|
barcodeParam.setDeleted(Constants.ONE);
|
barcodeParamMapper.updateById(barcodeParam);
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
barcodeParamExtService.loadCom(user.getCompany());
|
}
|
|
@Override
|
public ApiResponse updateById(BarcodeParam barcodeParam) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
|
Appliances appliances=new Appliances();
|
appliances.setBrcode(barcodeParam.getId());
|
appliances.setDeleted(Constants.ZERO);
|
appliances.setDepartId(user.getCurComDepartment().getId());
|
appliances.setRootDepartId(user.getRootDepartment().getId());
|
List<Appliances> appList=appliancesService.findList(appliances);
|
if(appList.size()>0){
|
return ApiResponse.failed("已经产生标签的规则,不允许修改") ;
|
}
|
|
BarcodeParam queryParam=new BarcodeParam();
|
queryParam.setDeleted(Constants.ZERO);
|
queryParam.setDepartId(user.getCurComDepartment().getId());
|
queryParam.setRootDepartId(user.getRootDepartment().getId());
|
queryParam.setType(barcodeParam.getType());
|
queryParam.setStatus(Constants.ONE);
|
List<BarcodeParam> alllist= this.findList(queryParam);
|
if(alllist!=null&&alllist.size()>0){
|
if(alllist.get(0).getId()!=barcodeParam.getId()){
|
return ApiResponse.failed("类型已存在,不允许重复添加");
|
}
|
}
|
|
BarcodeParam queryParam1=new BarcodeParam();
|
queryParam1.setDeleted(Constants.ZERO);
|
queryParam1.setDepartId(user.getCurComDepartment().getId());
|
queryParam1.setRootDepartId(user.getRootDepartment().getId());
|
queryParam1.setStatus(Constants.ONE);
|
queryParam1.setPrefix(barcodeParam.getPrefix());
|
List<BarcodeParam> alll1ist= this.findList(queryParam1);
|
if(alll1ist!=null&&alll1ist.size()>0){
|
if(alll1ist.get(0).getId()!=barcodeParam.getId()){
|
return ApiResponse.failed("前缀已存在,不允许重复添加");
|
}
|
}
|
BarcodeParam find= this.findById(barcodeParam.getId());
|
find.setUpdateTime(new Date());
|
find.setUpdateUser(user.getId());
|
find.setPrefix(barcodeParam.getPrefix());
|
find.setType(barcodeParam.getType());
|
barcodeParamExtService.loadCom(user.getCompany());
|
|
return ApiResponse.success(barcodeParamMapper.updateById(find)) ;
|
}
|
|
@Override
|
public void updateByIdInBatch(List<BarcodeParam> barcodeParams) {
|
if (CollectionUtils.isEmpty(barcodeParams)) {
|
return;
|
}
|
for (BarcodeParam barcodeParam: barcodeParams) {
|
this.updateById(barcodeParam);
|
}
|
}
|
|
@Override
|
public BarcodeParam findById(Integer id) {
|
return barcodeParamMapper.selectById(id);
|
}
|
|
@Override
|
public BarcodeParam findOne(BarcodeParam barcodeParam) {
|
QueryWrapper<BarcodeParam> wrapper = new QueryWrapper<>(barcodeParam);
|
return barcodeParamMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<BarcodeParam> findList(BarcodeParam barcodeParam) {
|
QueryWrapper<BarcodeParam> wrapper = new QueryWrapper<>(barcodeParam);
|
return barcodeParamMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<BarcodeParam> findPage(PageWrap<BarcodeParam> pageWrap) {
|
IPage<BarcodeParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
QueryWrapper<BarcodeParam> queryWrapper = new QueryWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
if (pageWrap.getModel().getId() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getId, pageWrap.getModel().getId());
|
}
|
if (pageWrap.getModel().getDeleted() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getDeleted, pageWrap.getModel().getDeleted());
|
}
|
if (pageWrap.getModel().getCreateUser() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getCreateUser, pageWrap.getModel().getCreateUser());
|
}
|
if (pageWrap.getModel().getCreateTime() != null) {
|
queryWrapper.lambda().ge(BarcodeParam::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime()));
|
queryWrapper.lambda().le(BarcodeParam::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime()));
|
}
|
if (pageWrap.getModel().getUpdateUser() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getUpdateUser, pageWrap.getModel().getUpdateUser());
|
}
|
if (pageWrap.getModel().getUpdateTime() != null) {
|
queryWrapper.lambda().ge(BarcodeParam::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime()));
|
queryWrapper.lambda().le(BarcodeParam::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime()));
|
}
|
if (pageWrap.getModel().getRemark() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getRemark, pageWrap.getModel().getRemark());
|
}
|
if (pageWrap.getModel().getRootDepartId() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getRootDepartId, pageWrap.getModel().getRootDepartId());
|
}
|
if (pageWrap.getModel().getDepartId() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getDepartId, pageWrap.getModel().getDepartId());
|
}
|
if (pageWrap.getModel().getType() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getType, pageWrap.getModel().getType());
|
}
|
if (pageWrap.getModel().getPrefix() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getPrefix, pageWrap.getModel().getPrefix());
|
}
|
if (pageWrap.getModel().getStatus() != null) {
|
queryWrapper.lambda().eq(BarcodeParam::getStatus, pageWrap.getModel().getStatus());
|
}
|
for(PageWrap.SortData sortData: pageWrap.getSorts()) {
|
if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
|
queryWrapper.orderByDesc(sortData.getProperty());
|
} else {
|
queryWrapper.orderByAsc(sortData.getProperty());
|
}
|
}
|
return PageData.from(barcodeParamMapper.selectPage(page, queryWrapper));
|
}
|
|
@Override
|
public long count(BarcodeParam barcodeParam) {
|
QueryWrapper<BarcodeParam> wrapper = new QueryWrapper<>(barcodeParam);
|
return barcodeParamMapper.selectCount(wrapper);
|
}
|
|
|
@Override
|
public ApiResponse updateStatusById(BarcodeParam barcodeParam) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
|
Appliances appliances=new Appliances();
|
appliances.setBrcode(barcodeParam.getId());
|
appliances.setDeleted(Constants.ZERO);
|
appliances.setDepartId(user.getCurComDepartment().getId());
|
appliances.setRootDepartId(user.getRootDepartment().getId());
|
List<Appliances> appList=appliancesService.findList(appliances);
|
if(appList.size()>0){
|
return ApiResponse.failed("已经产生标签的规则,不允许失效") ;
|
}
|
return ApiResponse.success(barcodeParamMapper.updateById(barcodeParam)) ;
|
}
|
}
|