/*
|
* Copyright 2019-2020 Zheng Jie
|
*
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
*/
|
package me.zhengjie.modules.approval.service.impl;
|
|
import me.zhengjie.modules.approval.domain.TemplateControl;
|
import me.zhengjie.utils.ValidationUtil;
|
import me.zhengjie.utils.FileUtil;
|
import lombok.RequiredArgsConstructor;
|
import me.zhengjie.modules.approval.repository.TemplateControlRepository;
|
import me.zhengjie.modules.approval.service.TemplateControlService;
|
import me.zhengjie.modules.approval.service.dto.TemplateControlDto;
|
import me.zhengjie.modules.approval.service.dto.TemplateControlQueryCriteria;
|
import me.zhengjie.modules.approval.service.mapstruct.TemplateControlMapper;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Pageable;
|
import me.zhengjie.utils.PageUtil;
|
import me.zhengjie.utils.QueryHelp;
|
import java.util.List;
|
import java.util.Map;
|
import java.io.IOException;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
|
/**
|
* @website https://eladmin.vip
|
* @description 服务实现
|
* @author baolh
|
* @date 2025-03-17
|
**/
|
@Service
|
@RequiredArgsConstructor
|
public class TemplateControlServiceImpl implements TemplateControlService {
|
|
private final TemplateControlRepository templateControlRepository;
|
private final TemplateControlMapper templateControlMapper;
|
|
@Override
|
public Map<String,Object> queryAll(TemplateControlQueryCriteria criteria, Pageable pageable){
|
Page<TemplateControl> page = templateControlRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
return PageUtil.toPage(page.map(templateControlMapper::toDto));
|
}
|
|
@Override
|
public List<TemplateControlDto> queryAll(TemplateControlQueryCriteria criteria){
|
return templateControlMapper.toDto(templateControlRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
}
|
|
@Override
|
@Transactional
|
public TemplateControlDto findById(Long id) {
|
TemplateControl templateControl = templateControlRepository.findById(id).orElseGet(TemplateControl::new);
|
ValidationUtil.isNull(templateControl.getId(),"TemplateControl","id",id);
|
return templateControlMapper.toDto(templateControl);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public TemplateControlDto create(TemplateControl resources) {
|
return templateControlMapper.toDto(templateControlRepository.save(resources));
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void update(TemplateControl resources) {
|
TemplateControl templateControl = templateControlRepository.findById(resources.getId()).orElseGet(TemplateControl::new);
|
ValidationUtil.isNull( templateControl.getId(),"TemplateControl","id",resources.getId());
|
templateControl.copy(resources);
|
templateControlRepository.save(templateControl);
|
}
|
|
@Override
|
public void deleteAll(Long[] ids) {
|
for (Long id : ids) {
|
templateControlRepository.deleteById(id);
|
}
|
}
|
|
@Override
|
public void download(List<TemplateControlDto> all, HttpServletResponse response) throws IOException {
|
List<Map<String, Object>> list = new ArrayList<>();
|
for (TemplateControlDto templateControl : all) {
|
Map<String,Object> map = new LinkedHashMap<>();
|
map.put(" 模版ID", templateControl.getTemplateId());
|
map.put("控件类型", templateControl.getControlType());
|
map.put("控件ID", templateControl.getControlId());
|
map.put("占位符文本(中文)", templateControl.getPlaceholderTextZh());
|
map.put("占位符文本(英文)", templateControl.getPlaceholderTextEn());
|
map.put("是否必填", templateControl.getContentRequire());
|
map.put("是否参与打印", templateControl.getContentPrint());
|
map.put("控件设定", templateControl.getContentConfig());
|
map.put("删除判定", templateControl.getDelStatus());
|
map.put("创建时间", templateControl.getCreateTime());
|
map.put("创建人", templateControl.getCreateBy());
|
map.put("更新时间", templateControl.getUpdateTime());
|
map.put("更新人", templateControl.getUpdateBy());
|
map.put("标题文本(中文)", templateControl.getTitleTextZh());
|
map.put("标题文本(英文)", templateControl.getTitleTextEn());
|
list.add(map);
|
}
|
FileUtil.downloadExcel(list, response);
|
}
|
}
|