123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package com.tld.service.impl;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.tld.excel.ExcelUtils;
- import com.tld.mapper.StorageLocationMapper;
- import com.tld.model.StorageLocation;
- import com.tld.service.StorageLocationService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.servlet.http.HttpServletResponse;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Service
- public class StorageLocationServiceImpl implements StorageLocationService {
- @Autowired
- private StorageLocationMapper storageLocationMapper;
- @Override
- public Map<String, Object> getStorage(StorageLocation storageLocation) {
- Map<String, Object> map = new HashMap<>();
- try{
- PageHelper.startPage(storageLocation.getPage(), storageLocation.getLimit());
- PageInfo<StorageLocation> list = new PageInfo<>(storageLocationMapper.getStorage(storageLocation));
- map.put("data", list);
- map.put("msg", "200");
- }catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "服务器请求异常,请稍后再试");
- }
- return map;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Map<String, Object> addStorage(StorageLocation storageLocation) {
- Map<String, Object> map = new HashMap<>();
- try{
- storageLocationMapper.addStorage(storageLocation);
- map.put("msg", "200");
- }catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "服务器请求异常,请稍后再试");
- }
- return map;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Map<String, Object> delStorage(String id) {
- Map<String, Object> map = new HashMap<>();
- try{
- storageLocationMapper.delStorage(id);
- map.put("msg", "200");
- }catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "服务器请求异常,请稍后再试");
- }
- return map;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Map<String, Object> updateStorage(StorageLocation storageLocation) {
- Map<String, Object> map = new HashMap<>();
- try{
- storageLocationMapper.updateStorage(storageLocation);
- map.put("msg", "200");
- }catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "服务器请求异常,请稍后再试");
- }
- return map;
- }
- @Override
- public void export(StorageLocation storageLocation, HttpServletResponse response) {
- try{
- //导出数据汇总
- List<List<Object>> sheetDataList = new ArrayList<>();
- //表头数据
- List<Object> head = Arrays.asList("库位编号", "库位名称", "所在仓库","库位类型","库位容量","是否禁用","创建时间");
- //查询数据
- PageHelper.startPage(storageLocation.getPage(), storageLocation.getLimit());
- PageInfo<Map<String, Object>> list = new PageInfo<>(storageLocationMapper.export(storageLocation));
- sheetDataList.add(head);
- for(Map<String, Object> userMap : list.getList()){
- List<Object> listSheet = new ArrayList<>();
- for(String key: userMap.keySet()){
- listSheet.add(userMap.get(key));
- }
- sheetDataList.add(listSheet);
- }
- //当前时间
- Date time = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss");
- ExcelUtils.export(response, "库位数据导出" + sdf.format(time), sheetDataList);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- @Override
- public Map<String, Object> getStorageAll(StorageLocation storageLocation) {
- Map<String, Object> map = new HashMap<>();
- try{
- List<StorageLocation> list = storageLocationMapper.getStorage(storageLocation);
- map.put("data", list);
- map.put("msg", "200");
- }catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "服务器请求异常,请稍后再试");
- }
- return map;
- }
- }
|