ProjectStatusManageServiceImpl.java 5.56 KB
Newer Older
1 2
package pwc.taxtech.atms.service.impl;

3
import org.apache.commons.lang3.StringUtils;
4 5 6 7 8 9 10
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.ProjectStatusManageMapper;
import pwc.taxtech.atms.dto.FieldsMapper;
import pwc.taxtech.atms.dto.OperationResultDto;
11
import pwc.taxtech.atms.dto.taxadmin.ProjectImportSubStatusDto;
12
import pwc.taxtech.atms.dto.taxadmin.ProjectStatusManageDto;
13 14
import pwc.taxtech.atms.entity.ProjectStatusManage;
import pwc.taxtech.atms.entity.ProjectStatusManageExample;
15 16 17 18 19 20

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
21
public class ProjectStatusManageServiceImpl {
22 23 24 25 26 27 28
    private static final int FIRST_OR_DFAULT = 0;

    private static Logger LOGGER = LoggerFactory.getLogger(ProjectStatusManageServiceImpl.class);

    @Autowired
    ProjectStatusManageMapper projectStatusManageMapper;

29
    public OperationResultDto<ProjectStatusManageDto> setProjectStatus(String projectId, Integer periodId, Integer status, String creatorId) {
30 31
        try {
            ProjectStatusManageExample example = new ProjectStatusManageExample();
eddie.woo's avatar
eddie.woo committed
32
            example.createCriteria().andProjectIdEqualTo(projectId).andPeriodIdEqualTo(periodId);
33 34 35 36 37 38 39 40 41 42 43
            List<ProjectStatusManage> psmList = projectStatusManageMapper.selectByExample(example);
            ProjectStatusManage psm = null;

            if (psmList != null && !psmList.isEmpty()) {
                psm = psmList.get(FIRST_OR_DFAULT);
                psm.setStatus(status);
                psm.setUpdateTime(new Date());

                projectStatusManageMapper.updateByPrimaryKey(psm);
            } else {
                psm = new ProjectStatusManage();
44
                psm.setId(UUID.randomUUID().toString());
eddie.woo's avatar
eddie.woo committed
45
                psm.setProjectId(projectId);
46 47
                psm.setPeriodId(periodId);
                psm.setStatus(status);
48
                psm.setCreatorId(creatorId);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
                psm.setCreateTime(new Date());
                psm.setUpdateTime(new Date());

                projectStatusManageMapper.insert(psm);
            }

            OperationResultDto<ProjectStatusManageDto> ord = new OperationResultDto<>();
            ord.setResult(true);
            ord.setResultMsg("");
            ProjectStatusManageDto dto = new ProjectStatusManageDto();

            try {
                FieldsMapper.map(psm, dto);
            } catch (Exception e) {
                e.printStackTrace();
                LOGGER.warn("cast filed some error", e);
            }
            ord.setData(dto);
            return ord;
68 69
        } catch (Exception e) {
            LOGGER.error("ProjectStatusManageService,SetProjectStatus(string dbName, int periodId)发生错误: {}", e.getMessage());
70 71 72 73 74 75 76 77
            OperationResultDto<ProjectStatusManageDto> ord = new OperationResultDto<>();
            ord.setResult(false);
            ord.setResultMsg(e.getMessage());
            ord.setData(null);

            return ord;
        }
    }
78

79
    public OperationResultDto<ProjectStatusManageDto> getProjectStatus(String projectId, Integer periodId) {
80 81 82
        try {

            ProjectStatusManageExample example = new ProjectStatusManageExample();
83
            example.createCriteria().andPeriodIdEqualTo(periodId);
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
            List<ProjectStatusManage> psmList = projectStatusManageMapper.selectByExample(example);

            if (psmList != null && !psmList.isEmpty()) {
                ProjectStatusManage first = psmList.get(FIRST_OR_DFAULT);
                ProjectStatusManageDto dto = new ProjectStatusManageDto();

                try {
                    FieldsMapper.map(first, dto);
                } catch (Exception e) {
                    e.printStackTrace();
                    LOGGER.warn("field map some error");
                }

                ProjectImportSubStatusDto ssd = new ProjectImportSubStatusDto();//TODO:should query status from db (neo)
                ssd.setAdjustImport(false);
                ssd.setCustomInvoiceImport(false);
                ssd.setEntryImport(false);
                ssd.setErpImport(false);
                ssd.setInputInvoiceImport(false);
                ssd.setOutputInvoiceImport(false);
                ssd.setTbImport(false);
                ssd.setVoucherMapImport(false);
                dto.setImportSubStatus(ssd);

                OperationResultDto resultDto = new OperationResultDto();
                resultDto.setResult(true);
                resultDto.setResultMsg("");
                resultDto.setData(dto);

                return resultDto;
114 115
            } else {
                throw new Exception("数据库" + projectId + "状态信息为NULL");
116 117
            }

118
        } catch (Exception e) {
119 120 121 122 123 124 125 126 127
            OperationResultDto resultDto = new OperationResultDto();
            resultDto.setResult(false);
            resultDto.setResultMsg(e.getMessage());
            resultDto.setData(null);

            return resultDto;
        }

    }
128 129 130

    public OperationResultDto<ProjectStatusManage> isProjectStatusExisted(String projectId, int periodId) {
        ProjectStatusManageExample example = new ProjectStatusManageExample();
eddie.woo's avatar
eddie.woo committed
131
        example.createCriteria().andProjectIdEqualTo(projectId).andPeriodIdEqualTo(periodId);
132 133 134 135 136 137 138
        List<ProjectStatusManage> manage = projectStatusManageMapper.selectByExample(example);
        OperationResultDto<ProjectStatusManage> dto = new OperationResultDto();
        dto.setResult(true);
        dto.setResultMsg(StringUtils.EMPTY);
        dto.setData(manage.isEmpty() ? null : manage.get(0));
        return dto;
    }
139
}