Commit 3aabd163 authored by frank.xa.zhang's avatar frank.xa.zhang

add the code for KeyValueConfiguration

parent 0a860d94
package pwc.taxtech.atms.constant.enums;
public enum KeyValueConfigType {
SystemFundation (1),
Customize (2);
private Integer code;
KeyValueConfigType(Integer code) {
this.code = code;
}
public Integer getCode() {
return code;
}
}
......@@ -2,18 +2,17 @@ package pwc.taxtech.atms.controller;
import java.util.List;
import javassist.tools.web.BadHttpRequest;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import pwc.taxtech.atms.dto.KeyValueConfigDisplayDto;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.*;
import pwc.taxtech.atms.dto.Common.RemoteValidationRetDto;
import pwc.taxtech.atms.dto.formula.FormulaConfigDto;
import pwc.taxtech.atms.service.KeyValueConfigService;
......@@ -21,19 +20,88 @@ import pwc.taxtech.atms.service.KeyValueConfigService;
@RequestMapping("/api/v1/keyValueConfig")
public class KeyValueConfigController {
private static final Logger logger = LoggerFactory.getLogger(EnterpriseAccountManagerController.class);
@Autowired
private KeyValueConfigService keyValueConfigService;
@ApiOperation(value="get keyValueConfig")
@RequestMapping(value="",method=RequestMethod.GET)
public @ResponseBody List<KeyValueConfigDisplayDto> get(){
return keyValueConfigService.get();
@ApiOperation(value = "get keyValueConfig")
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody
List<KeyValueConfigDisplayDto> get() {
return keyValueConfigService.get();
}
@RequestMapping(value = "dataSource",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "dataSource", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
OperationResultDto<List<FormulaConfigDto>> getDataSource(){
OperationResultDto<List<FormulaConfigDto>> getDataSource() {
return keyValueConfigService.getAllFormulaList();
}
@RequestMapping(value = "getFinacialReference/{keyValueID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<FinancialStatementDetail> getFinacialStatementReference(@PathVariable String keyValueID) throws BadHttpRequest {
if (StringUtils.isBlank(keyValueID)) {
throw new BadHttpRequest(new Exception("keyValueID is null"));
}
return keyValueConfigService.getFinacialStatement(keyValueID);
}
@RequestMapping(value = "getTaxReference/{keyValueID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<TaxReturnDetail> getTaxReturnReference(@PathVariable String keyValueID) throws BadHttpRequest {
if (StringUtils.isBlank(keyValueID)) {
throw new BadHttpRequest(new Exception("keyValueID is null"));
}
return keyValueConfigService.getTaxReturn(keyValueID);
}
@RequestMapping(value = "getModelReference/{keyValueID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<AnalyticsModelDetail> getAnalyticsModelReference(@PathVariable String keyValueID) throws BadHttpRequest {
if (StringUtils.isBlank(keyValueID)) {
throw new BadHttpRequest(new Exception("keyValueID is null"));
}
return keyValueConfigService.getAnalyticsModel(keyValueID);
}
@RequestMapping(value = "add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void addKeyValueConfiguration(@RequestBody AddKeyValueConfigDto addKeyValueConfigDto) {
//todo: add userName @ here
addKeyValueConfigDto.setUserName("");
keyValueConfigService.addKeyValueConfiguration(addKeyValueConfigDto);
}
@RequestMapping(value = "update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void updateKeyValueConfiguration(@RequestBody UpdateKeyValueConfigDto updateKeyValueConfigDto) {
//todo: add userName @ here
updateKeyValueConfigDto.setUserName("");
keyValueConfigService.updateKeyValueConfiguration(updateKeyValueConfigDto);
}
@RequestMapping(method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
int delelte(@RequestParam String keyValueID) throws BadHttpRequest {
if (StringUtils.isBlank(keyValueID)) {
throw new BadHttpRequest(new Exception("keyValueID is null"));
}
return keyValueConfigService.deleteKeyValueConfiguration(keyValueID);
}
@RequestMapping(value = "getByOrgID/{orgID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<KeyValueConfigDisplayDto> getByOrgID(@PathVariable String orgID) {
return keyValueConfigService.getByOrgID(orgID);
}
@RequestMapping(value = "isDuplicated", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
RemoteValidationRetDto isDuplicated(@RequestParam String value) {
boolean isDuplicated = keyValueConfigService.isKeyValueDuplicated(value);
RemoteValidationRetDto result = new RemoteValidationRetDto();
result.setValid(!isDuplicated);
result.setValue(value);
return result;
}
}
package pwc.taxtech.atms.dto.Common;
public class RemoteValidationRetDto {
private boolean isValid;
private String value;
public boolean isValid() {
return isValid;
}
public void setValid(boolean valid) {
isValid = valid;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
......@@ -16,7 +16,7 @@ public interface KeyValueConfigService {
List<AnalyticsModelDetail> getAnalyticsModel(String configurationID);
int deleteKeyValueConfiguration(String keyID,String userName);
int deleteKeyValueConfiguration(String keyID);
void addKeyValueConfiguration(AddKeyValueConfigDto addKeyValueConfigDto);
......
......@@ -41,9 +41,12 @@ public interface OperationLogService {
*/
void addOrDeleteDataAddLog(UpdateLogParams updateLogParams);
void AddDataAddLog(Object newObj, OperationModule operationModule, String userName, String operationDesc, String operationContent, String OperationObject, OperateLogType logType);
void addDataAddLog(Object newObj, OperationModule operationModule, String userName, String operationDesc
, String operationContent, String OperationObject, OperateLogType logType);
void UpdateDataAddLog(Object originalObj,Object updateObj,OperationModule operationModule,String userName,String comment,String operationObject,String operationContent,OperateLogType logType);
void updateDataAddLog(Object originalObj, Object updateObj, OperationModule operationModule, String userName
, String comment, String operationObject, String operationContent, OperateLogType logType);
void DeleteDataAddLog(Object deleteObj, OperationModule operationModule, String userName, String comment, String operationContent, String OperationObject, OperateLogType logType);
void deleteDataAddLog(Object deleteObj, OperationModule operationModule, String userName, String comment
, String operationContent, String OperationObject, OperateLogType logType);
}
package pwc.taxtech.atms.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.nutz.lang.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
......@@ -15,6 +13,10 @@ import com.alibaba.druid.util.StringUtils;
import pwc.taxtech.atms.common.ApplyScope;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.OperateLogType;
import pwc.taxtech.atms.common.OperationModule;
import pwc.taxtech.atms.constant.enums.KeyValueConfigType;
import pwc.taxtech.atms.dao.KeyValueConfigMapper;
import pwc.taxtech.atms.dto.*;
import pwc.taxtech.atms.dto.formula.FormulaConfigDto;
import pwc.taxtech.atms.entitiy.*;
......@@ -25,6 +27,8 @@ public class KeyValueConfigServiceImpl extends AbstractService implements KeyVal
private static final Logger logger = LoggerFactory.getLogger(KeyValueConfigServiceImpl.class);
private OperateLogType logType = OperateLogType.OperationLogKeyvalue;
@Override
public List<KeyValueConfigDisplayDto> get() {
List<KeyValueConfig> list = keyValueConfigMapper.selectKeyValueConfigsByOrderByCreateTime();
......@@ -42,7 +46,7 @@ public class KeyValueConfigServiceImpl extends AbstractService implements KeyVal
dtoObj.setIndustrys(getNamesByIDs(keyValueConfig.getIndustryIDs(), industryList));
dtoObj.setIndustryIds(Arrays.asList(keyValueConfig.getIndustryIDs().split(",")));
dtoObj.setServiceTypeIds(Arrays.asList(keyValueConfig.getServiceTypeIDs().split(",")));
List<KeyValueReference> selectScopeList = scopes.stream().filter(item -> item.getKeyValueConfigID().equals(item.getID())).collect(Collectors.toList());
List<KeyValueReference> selectScopeList = scopes.stream().filter(item -> item.getKeyValueConfigID().equals(keyValueConfig.getID())).collect(Collectors.toList());
List<Integer> selectScopes = selectScopeList.stream().map(KeyValueReference::getScope).distinct().collect(Collectors.toList());
Map<Integer, Integer> scopeCount = new HashMap<>();
if (selectScopeList.size() > 0) {
......@@ -107,28 +111,109 @@ public class KeyValueConfigServiceImpl extends AbstractService implements KeyVal
}
@Override
public int deleteKeyValueConfiguration(String keyID, String userName) {
return 0;
public int deleteKeyValueConfiguration(String keyID) {
KeyValueReferenceExample example = new KeyValueReferenceExample();
example.createCriteria().andKeyValueConfigIDEqualTo(keyID);
int referenceCount = (int) keyValueReferenceMapper.countByExample(example);
if (referenceCount == 0) {
KeyValueConfigExample kvcExample = new KeyValueConfigExample();
kvcExample.createCriteria().andIDEqualTo(keyID).andKeyValueTypeEqualTo(KeyValueConfigType.Customize.getCode());
Optional<KeyValueConfig> deleteKey = keyValueConfigMapper.selectByExample(kvcExample).stream().findFirst();
if (deleteKey.isPresent()) {
keyValueConfigMapper.deleteByPrimaryKey(deleteKey.get().getID());
operationLogService.deleteDataAddLog(deleteKey, OperationModule.KeyValueConfig, ""
, "DeleteKeyValueConfiguration", "", deleteKey.get().getName(), logType);
referenceCount = 1;
}
} else {
referenceCount = -1;
}
return referenceCount;
}
@Override
public void addKeyValueConfiguration(AddKeyValueConfigDto addKeyValueConfigDto) {
Date now = new Date();
KeyValueConfig keyValueConfig = new KeyValueConfig();
CommonUtils.copyProperties(addKeyValueConfigDto, keyValueConfig);
keyValueConfig.setIndustryIDs(Strings.join(",", addKeyValueConfigDto.getIndustryIds()));
keyValueConfig.setServiceTypeIDs(Strings.join(",", addKeyValueConfigDto.getServiceTypeIds()));
String guid = CommonUtils.getUUID();
keyValueConfig.setID(guid);
keyValueConfig.setKeyCode(guid.replaceAll("-", ""));
keyValueConfig.setIsConstant(0);
keyValueConfig.setCalculateStatus(99);
keyValueConfig.setCreateTime(now);
keyValueConfig.setUpdateTime(now);
keyValueConfig.setUpdator(addKeyValueConfigDto.getUserName());
keyValueConfig.setKeyValueType(2);
keyValueConfigMapper.insert(keyValueConfig);
operationLogService.addDataAddLog(keyValueConfig, OperationModule.KeyValueConfig, addKeyValueConfigDto.getUserName()
, Message.Log.AddKeyValueConfiguration, "", keyValueConfig.getName(), logType);
}
@Override
public void updateKeyValueConfiguration(UpdateKeyValueConfigDto updateKeyValueConfigDto) {
KeyValueConfig keyValueConfig = keyValueConfigMapper.selectByPrimaryKey(updateKeyValueConfigDto.getID());
if (keyValueConfig == null) {
throw new InvalidOperationException("Not found");
}
KeyValueConfig original = new KeyValueConfig();
CommonUtils.copyProperties(keyValueConfig, original);
keyValueConfig.setFormula(updateKeyValueConfigDto.getFormula());
keyValueConfig.setDescription(updateKeyValueConfigDto.getDescription());
keyValueConfig.setName(updateKeyValueConfigDto.getName());
keyValueConfig.setDataSource(updateKeyValueConfigDto.getDataSource());
keyValueConfig.setServiceTypeIDs(Strings.join(",", updateKeyValueConfigDto.getServiceTypeIDs()));
keyValueConfig.setIndustryIDs(Strings.join(",", updateKeyValueConfigDto.getIndustryIDs()));
keyValueConfigMapper.updateByPrimaryKey(keyValueConfig);
operationLogService.updateDataAddLog(original, keyValueConfig, OperationModule.KeyValueConfig
, updateKeyValueConfigDto.getUserName(), Message.Log.UpdateKeyValueConfiguration
, keyValueConfig.getName(), "Operation content", logType);
}
@Override
public boolean isKeyValueDuplicated(String name) {
return false;
KeyValueConfigExample example = new KeyValueConfigExample();
example.createCriteria().andNameEqualTo(name);
Optional<KeyValueConfig> keyValueConfig = keyValueConfigMapper.selectByExample(example).stream().findFirst();
return keyValueConfig.isPresent();
}
@Override
public List<KeyValueConfigDisplayDto> getByOrgID(String orgID) {
return null;
Organization organization = organizationMapper.selectByPrimaryKey(orgID);
if (organization == null) {
return new ArrayList<>();
}
KeyValueConfigExample example = new KeyValueConfigExample();
example.createCriteria().andIndustryIDsLike(organization.getIndustryID());
List<KeyValueConfig> list = keyValueConfigMapper.selectByExample(example);
List<KeyValueConfigDisplayDto> result = new ArrayList<>();
if (list.size() > 0) {
Map<String, String> industryList = new HashMap<>();
industryMapper.selectByExample(new IndustryExample()).forEach(a -> industryList.put(a.getID(), a.getName()));
Map<String, String> serviceType = new HashMap<>();
serviceTypeMapper.selectByExample(new ServiceTypeExample()).forEach(a -> serviceType.put(a.getID(), a.getName()));
List<KeyValueReference> scopes = keyValueReferenceMapper.selectByExample(new KeyValueReferenceExample());
for (KeyValueConfig item : list) {
KeyValueConfigDisplayDto dtoObj = new KeyValueConfigDisplayDto();
CommonUtils.copyProperties(item, dtoObj);
dtoObj.setServiceTypes(getNamesByIDs(item.getServiceTypeIDs(), serviceType));
dtoObj.setIndustrys(getNamesByIDs(item.getIndustryIDs(), industryList));
dtoObj.setIndustryIds(new ArrayList<>(Arrays.asList(item.getIndustryIDs().split(","))));
List<Integer> selectScopes = scopes.stream().filter(a -> a.getKeyValueConfigID().equals(item.getID()))
.map(KeyValueReference::getScope).collect(Collectors.toList());
dtoObj.setScopeSummary(jointToString(selectScopes));
result.add(dtoObj);
}
}
return result;
}
private String jointToString(List<Integer> selectScopes) {
......
......@@ -450,8 +450,8 @@ public class OperationLogServiceImpl extends AbstractService implements Operatio
}
@Override
public void AddDataAddLog(Object newObj, OperationModule operationModule, String userName, String operationDesc,
String operationContent, String OperationObject, OperateLogType logType) {
public void addDataAddLog(Object newObj, OperationModule operationModule, String userName, String operationDesc,
String operationContent, String OperationObject, OperateLogType logType) {
OperationLogDto addLog = new OperationLogDto();
addLog.setID(CommonUtils.getUUID());
......@@ -470,8 +470,8 @@ public class OperationLogServiceImpl extends AbstractService implements Operatio
}
@Override
public void UpdateDataAddLog(Object originalObj, Object updateObj, OperationModule operationModule, String userName,
String comment, String operationObject, String operationContent, OperateLogType logType) {
public void updateDataAddLog(Object originalObj, Object updateObj, OperationModule operationModule, String userName,
String comment, String operationObject, String operationContent, OperateLogType logType) {
UpdateLogParams params = new UpdateLogParams();
params.setOriginalState(originalObj);
params.setOperationContent(operationContent);
......@@ -486,8 +486,8 @@ public class OperationLogServiceImpl extends AbstractService implements Operatio
}
@Override
public void DeleteDataAddLog(Object deleteObj, OperationModule operationModule, String userName, String comment,
String operationContent, String OperationObject, OperateLogType logType) {
public void deleteDataAddLog(Object deleteObj, OperationModule operationModule, String userName, String comment,
String operationContent, String OperationObject, OperateLogType logType) {
OperationLogDto addLog = new OperationLogDto();
addLog.setID(CommonUtils.getUUID());
addLog.setOperationContent(operationContent);
......
......@@ -115,7 +115,7 @@ public class RuleEngineeConfigServiceImpl extends AbstractService implements Rul
taxRuleSettingOrganizationMapper.deleteByExample(trsoExample);
taxRuleSettingMapper.deleteByPrimaryKey(taxRuleSetting.getID());
operationService.DeleteDataAddLog(taxRuleSetting, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
operationService.deleteDataAddLog(taxRuleSetting, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
"DeleteRuleEngineConfiguration", "", taxRuleSetting.getName(),
OperateLogType.OperationLogRuleEngine);
}
......@@ -136,7 +136,7 @@ public class RuleEngineeConfigServiceImpl extends AbstractService implements Rul
SaveOrganizationServiceTemplateGroup(taxPayerReportRule,tprrdo.getAction());
if("Add".equals(tprrdo.getAction())) {
taxPayerReportRuleMapper.insert(taxPayerReportRule);
operationService.AddDataAddLog(taxPayerReportRule, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
operationService.addDataAddLog(taxPayerReportRule, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
"AddRuleEngineConfiguration", "纳税类型", "纳税类型添加特殊机构", OperateLogType.OperationLogRuleEngine);
}
else if("Update".equals(tprrdo.getAction())) {
......@@ -152,13 +152,13 @@ public class RuleEngineeConfigServiceImpl extends AbstractService implements Rul
old.setUpdateTime(taxPayerReportRule.getUpdateTime());
taxPayerReportRuleMapper.updateByPrimaryKey(old);
operationService.UpdateDataAddLog(original, taxPayerReportRule, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
operationService.updateDataAddLog(original, taxPayerReportRule, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
"UpdateRuleEngineConfiguration", "纳税类型", taxPayerReportRule.getIsDefault() ? "默认纳税类型或默认纳税报表" : "纳税类型更新特殊机构", OperateLogType.OperationLogRuleEngine);
}
else if("Delete".equals(tprrdo.getAction())) {
taxPayerReportRuleMapper.deleteByPrimaryKey(taxPayerReportRule.getID());
operationService.DeleteDataAddLog(reportDto, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
operationService.deleteDataAddLog(reportDto, OperationModule.RuleEngineConfig, authUserHelper.getCurrentUserID(),
"DeleteRuleEngineConfiguration", "纳税类型", "纳税类型删除特殊机构", OperateLogType.OperationLogRuleEngine);
}
}
......@@ -174,13 +174,13 @@ public class RuleEngineeConfigServiceImpl extends AbstractService implements Rul
trso.setUpdateTime(new Date());
trso.setCreateTime(new Date());
if ("Add".equals(taxRuleSettingOperation.getAction())) {
operationLogService.AddDataAddLog(taxRuleSetting, OperationModule.RuleEngineConfig, userName,
operationLogService.addDataAddLog(taxRuleSetting, OperationModule.RuleEngineConfig, userName,
"AddRuleEngineConfiguration", taxRuleSetting.getName() + org, taxRuleSetting.getName(),
OperateLogType.OperationLogRuleEngine);
} else {
TaxRuleSetting original = new TaxRuleSetting();
CommonUtils.copyProperties(old, original);
operationService.UpdateDataAddLog(original, taxRuleSetting, OperationModule.RuleEngineConfig, userName,
operationService.updateDataAddLog(original, taxRuleSetting, OperationModule.RuleEngineConfig, userName,
"UpdateRuleEngineConfiguration", taxRuleSetting.getName(),
taxRuleSetting.getIsDefault() ? "默认税基或默认税率" : taxRuleSetting.getName(),
OperateLogType.OperationLogRuleEngine);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment