/*
|
* 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.contract.service.impl;
|
|
import me.zhengjie.modules.contract.domain.ContractSecond;
|
import me.zhengjie.utils.ValidationUtil;
|
import me.zhengjie.utils.FileUtil;
|
import lombok.RequiredArgsConstructor;
|
import me.zhengjie.modules.contract.repository.ContractSecondRepository;
|
import me.zhengjie.modules.contract.service.ContractSecondService;
|
import me.zhengjie.modules.contract.service.dto.ContractSecondDto;
|
import me.zhengjie.modules.contract.service.dto.ContractSecondQueryCriteria;
|
import me.zhengjie.modules.contract.service.mapstruct.ContractSecondMapper;
|
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 赵士淞
|
* @date 2023-02-02
|
**/
|
@Service
|
@RequiredArgsConstructor
|
public class ContractSecondServiceImpl implements ContractSecondService {
|
|
private final ContractSecondRepository contractSecondRepository;
|
private final ContractSecondMapper contractSecondMapper;
|
|
@Override
|
public Map<String,Object> queryAll(ContractSecondQueryCriteria criteria, Pageable pageable){
|
Page<ContractSecond> page = contractSecondRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
return PageUtil.toPage(page.map(contractSecondMapper::toDto));
|
}
|
|
@Override
|
public List<ContractSecondDto> queryAll(ContractSecondQueryCriteria criteria){
|
return contractSecondMapper.toDto(contractSecondRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
}
|
|
@Override
|
@Transactional
|
public ContractSecondDto findById(Long secondId) {
|
ContractSecond contractSecond = contractSecondRepository.findById(secondId).orElseGet(ContractSecond::new);
|
ValidationUtil.isNull(contractSecond.getSecondId(),"ContractSecond","secondId",secondId);
|
return contractSecondMapper.toDto(contractSecond);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public ContractSecondDto create(ContractSecond resources) {
|
return contractSecondMapper.toDto(contractSecondRepository.save(resources));
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void update(ContractSecond resources) {
|
ContractSecond contractSecond = contractSecondRepository.findById(resources.getSecondId()).orElseGet(ContractSecond::new);
|
ValidationUtil.isNull( contractSecond.getSecondId(),"ContractSecond","id",resources.getSecondId());
|
contractSecond.copy(resources);
|
contractSecondRepository.save(contractSecond);
|
}
|
|
@Override
|
public void deleteAll(Long[] ids) {
|
for (Long secondId : ids) {
|
contractSecondRepository.deleteById(secondId);
|
}
|
}
|
|
@Override
|
public void download(List<ContractSecondDto> all, HttpServletResponse response) throws IOException {
|
List<Map<String, Object>> list = new ArrayList<>();
|
for (ContractSecondDto contractSecond : all) {
|
Map<String,Object> map = new LinkedHashMap<>();
|
map.put("乙方名称", contractSecond.getSecondName());
|
map.put("乙方联系人", contractSecond.getSecondPerson());
|
map.put("乙方联系电话", contractSecond.getSecondPhone());
|
map.put("乙方邮件", contractSecond.getSecondEmail());
|
map.put("乙方传真", contractSecond.getSecondFax());
|
map.put("乙方所在地区", contractSecond.getSecondArea());
|
map.put("乙方详细地址", contractSecond.getSecondAddress());
|
map.put("备注信息", contractSecond.getRemarks());
|
map.put("创建者", contractSecond.getCreateBy());
|
map.put("创建日期", contractSecond.getCreateTime());
|
list.add(map);
|
}
|
FileUtil.downloadExcel(list, response);
|
}
|
}
|