AssetGroupServiceImpl.java 7.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
package pwc.taxtech.atms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.AssetDetailGroupMapper;
import pwc.taxtech.atms.dao.AssetGroupMapper;
import pwc.taxtech.atms.dto.AssetDetailGroupDto;
import pwc.taxtech.atms.dto.AssetDetailGroupStringDto;
import pwc.taxtech.atms.entity.AssetDetailGroup;
import pwc.taxtech.atms.entity.AssetDetailGroupExample;
import pwc.taxtech.atms.entity.AssetGroup;
import pwc.taxtech.atms.entity.AssetGroupExample;

import java.util.*;

/**
 * @Author zhikai.z.wei
 * 资产分类service
 */
@Service
public class AssetGroupServiceImpl extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(AssetGroupServiceImpl.class);

    @Autowired
    private AssetDetailGroupMapper assetDetailGroupMapper;

    @Autowired
    private AssetGroupMapper assetGroupMapper;

    @Autowired
    private FileService fileService;

    /**
   获取资产一级分类相关数据
    */
    public List<AssetGroup> getAllAssetGroup() throws Exception {
        logger.debug("获取资产一级分类相关数据");
        AssetGroupExample assetGroupExample = new AssetGroupExample();
        return assetGroupMapper.selectByExample(assetGroupExample);
    }

    /**
   获取固定资产全部二级分类
    */
    public PageInfo<AssetDetailGroupStringDto> getAllFixedAssetDetailGroup(AssetDetailGroupDto assetDetailGroupDto) throws Exception {
        logger.debug("获取固定资产全部二级分类");
        AssetDetailGroupExample assetDetailGroupExample = new AssetDetailGroupExample();
        AssetDetailGroupExample.Criteria criteria = assetDetailGroupExample.createCriteria();
        //detail_group_name 表中asset_group_type 1:固定资产
        criteria.andAssetGroupTypeEqualTo(assetDetailGroupDto.getAssetGroupType());
        assetDetailGroupExample.setOrderByClause("id asc");
        PageHelper.startPage(assetDetailGroupDto.getPageIndex(), assetDetailGroupDto.getPageSize());
        List<AssetDetailGroup> assetDetailGroups = assetDetailGroupMapper.selectByExample(assetDetailGroupExample);

        //当时用分页包装数据后,不能对Long类型的字段进行序列化,仍会导致到前台精度缺失,
        // 创建一个全为String的实体,并进行复制
        List<AssetDetailGroupStringDto> assetDetailGroupDtos = new ArrayList<>();
        for (AssetDetailGroup assetDetailGroup:assetDetailGroups){
            AssetDetailGroupStringDto stringDto = new AssetDetailGroupStringDto();
            //相同类型及字段进行copy
            BeanUtils.copyProperties(assetDetailGroup,stringDto);
            //把Long类型数据转为String并赋给新的实体
            stringDto.setId(assetDetailGroup.getId().toString());
            stringDto.setAssetGroupId(assetDetailGroup.getAssetGroupId().toString());
            assetDetailGroupDtos.add(stringDto);
        }

//       assetDetailGroups.stream().forEach(assetDetailGroup -> {
//            AssetDetailGroupStringDto stringDto = new AssetDetailGroupStringDto();
//            //相同类型及字段进行copy
//            BeanUtils.copyProperties(assetDetailGroup,stringDto);
//            //把Long类型数据转为String并赋给新的实体
//            stringDto.setId(assetDetailGroup.getId().toString());
//            stringDto.setAssetGroupId(assetDetailGroup.getAssetGroupId().toString());
//            assetDetailGroupDtos.add(stringDto);
//        });


//        BeanUtils.copyProperties(assetDetailGroups,assetDetailGroupDtos);

//        PageInfo<AssetDetailGroup> pageInfo = new PageInfo<>(assetDetailGroups);
            PageInfo<AssetDetailGroupStringDto> pageInfoStringDto = new PageInfo<AssetDetailGroupStringDto>(assetDetailGroupDtos);

//        BeanUtils.copyProperties(pageInfo,pageInfoStringDto);
        return pageInfoStringDto;
    }

    /**
   获取长期待摊全部二级分类
    */
    public List<AssetDetailGroup> getAllLongTermPendingDetailGroup() throws Exception {
        logger.debug("获取长期待摊全部二级分类");
        AssetDetailGroupExample assetDetailGroupExample = new AssetDetailGroupExample();
        AssetDetailGroupExample.Criteria criteria = assetDetailGroupExample.createCriteria();
        //detail_group_name 表中asset_group_type 2:长期待摊
        criteria.andAssetGroupTypeEqualTo(2);
        return assetDetailGroupMapper.selectByExample(assetDetailGroupExample);
    }

    /**
   获取无形资产全部二级分类
    */
    public List<AssetDetailGroup> getAllIntangibleAssetsDetailGroup() throws Exception {
        logger.debug("获取无形资产全部二级分类");
        AssetDetailGroupExample assetDetailGroupExample = new AssetDetailGroupExample();
        AssetDetailGroupExample.Criteria criteria = assetDetailGroupExample.createCriteria();
        //detail_group_name 表中asset_group_type 3:无形资产
        criteria.andAssetGroupTypeEqualTo(3);
        return assetDetailGroupMapper.selectByExample(assetDetailGroupExample);
    }

    /**
     根据资产类型得到其总数
     */
    public Long countAssetByType(Integer assetGroupType) throws Exception {
        return assetDetailGroupMapper.countAssetByType(assetGroupType);
    }

    /**
   通过一级分类的类型获取一级分类的ID
    */
    public List<AssetGroup> getAssetGroupByType(Integer type) throws Exception {
        logger.debug("通过一级分类的类型获取一级分类的ID");
        AssetGroupExample assetGroupExample = new AssetGroupExample();
        AssetGroupExample.Criteria criteria = assetGroupExample.createCriteria();
        criteria.andAssetGroupTypeEqualTo(type);
        List<AssetGroup> assetGroups = assetGroupMapper.selectByExample(assetGroupExample);
        //判断查询出的List是否为null或者为空,
        // 若为其中一种,则创建对象并add进入list中,一面controller取用报空指针异常
        if(assetGroups == null || assetGroups.size()==0){
            AssetGroup assetGroup = new AssetGroup();
            assetGroups = new ArrayList<>();
            assetGroups.add(assetGroup);
        }
        return assetGroups;

    }

    /**
    新增固定资产二级分类
     */
    public int addFixedAssetDetailGroup(AssetDetailGroupDto assetDetailGroupDto) throws Exception {
        logger.debug("新增固定资产二级分类");
        AssetDetailGroup assetDetailGroup = new AssetDetailGroup();
        //把页面Dto的值赋给entity
        BeanUtils.copyProperties(assetDetailGroupDto,assetDetailGroup);
        assetDetailGroup.setId(idService.nextId());
        assetDetailGroup.setCreateTime(new Date());
        assetDetailGroup.setUpdateTime(new Date());
        return assetDetailGroupMapper.insertSelective(assetDetailGroup);
    }

    /**
    编辑固定资产二级分类
     */
    public int editFixedAssetDetailGroup(AssetDetailGroupDto assetDetailGroupDto) throws Exception {
        logger.debug("编辑固定资产二级分类");
        AssetDetailGroup assetDetailGroup = new AssetDetailGroup();
        //把页面Dto的值赋给entity
        BeanUtils.copyProperties(assetDetailGroupDto,assetDetailGroup);
        //81407534426099710     81407534426099710
        assetDetailGroup.setUpdateTime(new Date());
        return assetDetailGroupMapper.updateByPrimaryKeySelective(assetDetailGroup);
    }

    /**
    新增固定资产二级分类
     */
    public int deleteFixedAssetDetailGroup(Long id) throws Exception {
        logger.debug("删除固定资产二级分类");
        return assetDetailGroupMapper.deleteByPrimaryKey(id);
    }

}