Commit bdfa65ae authored by Mccoy Z Xia's avatar Mccoy Z Xia

trigger

parent 2ef304b0
...@@ -3,9 +3,13 @@ package pwc.taxtech.atms.calendar; ...@@ -3,9 +3,13 @@ package pwc.taxtech.atms.calendar;
import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.service.impl.CalendarActionServiceImpl;
import pwc.taxtech.atms.service.impl.CalendarEventServiceImpl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -22,38 +26,15 @@ import java.util.Map; ...@@ -22,38 +26,15 @@ import java.util.Map;
@RequestMapping("api/v1/") @RequestMapping("api/v1/")
public class TaxCalendarController { public class TaxCalendarController {
@RequestMapping("taxCalendar/getAllTaxProjectList") @Autowired
@ResponseBody private CalendarEventServiceImpl calendarEventServiceImpl;
public Object getAllTaxProjectList(){
Object result = JSONUtils.parse("[{\"id\":\"3D0B4C48-F79B-463F-B675-4413B7740420\",\"taxProjectName\":\"自定义事项\",\"orderIndex\":0,\"createTime\":\"2018-07-18T21:55:35+08:00\",\"updateTime\":\"2018-07-18T21:55:40+08:00\"},{\"id\":\"46C3A2D7-FC0D-4C85-819F-BF5528F7E77D\",\"taxProjectName\":\"企业所得税\",\"orderIndex\":2,\"createTime\":\"2018-07-05T09:05:56.597+08:00\",\"updateTime\":\"2018-07-05T09:05:56.597+08:00\"},{\"id\":\"0E53F69F-4C59-4257-BFBB-90337F0C1B8C\",\"taxProjectName\":\"个税\",\"orderIndex\":3,\"createTime\":\"2018-07-05T09:06:21.853+08:00\",\"updateTime\":\"2018-07-13T17:08:19.517+08:00\"},{\"id\":\"BD35F3E5-09AA-4075-9BCF-F42DD7E3BDBD\",\"taxProjectName\":\"印花税\",\"orderIndex\":4,\"createTime\":\"2018-07-05T09:07:26.197+08:00\",\"updateTime\":\"2018-08-29T18:41:40.347+08:00\"}]");
return result;
}
@RequestMapping("taxCalendar/getWorkPlaceList")
@ResponseBody
public Object getWorkPlaceList(){
Object result = JSONUtils.parse("[{\"id\":\"efc60e20-0c48-4ee0-82b7-6bdce2b8d8d7\",\"name\":\"阿里巴巴总部\",\"createTime\":\"2018-07-06T16:13:08.913+08:00\",\"updateTime\":\"2018-07-06T16:13:08.913+08:00\"},{\"id\":\"6437ece3-6bf0-4b96-88d0-aabcb6bca649\",\"name\":\"北京朝阳区税局\",\"createTime\":\"2018-07-11T13:39:32.47+08:00\",\"updateTime\":\"2018-07-18T11:22:42.227+08:00\"},{\"id\":\"3d258b22-438a-4d0a-a00f-dd78cbebd730\",\"name\":\"北京国贸\",\"createTime\":\"2019-03-07T11:39:08.04+08:00\",\"updateTime\":\"2019-03-07T11:39:08.04+08:00\"},{\"id\":\"9A2C0823-D0CD-4A45-964D-EDFD2E4D55F9\",\"name\":\"北京天安门\",\"createTime\":\"2018-07-05T09:03:13.727+08:00\",\"updateTime\":\"2018-11-22T20:00:45.383+08:00\"},{\"id\":\"b34ee25a-a422-4096-a3fb-7335bb6a50cd\",\"name\":\"北京西二旗\",\"createTime\":\"2019-03-07T11:39:01.993+08:00\",\"updateTime\":\"2019-03-07T11:39:01.993+08:00\"},{\"id\":\"5AEEE006-B63F-4211-A4CC-C62936C7FCBF\",\"name\":\"成都来福士广场\",\"createTime\":\"2018-07-05T09:04:27.95+08:00\",\"updateTime\":\"2018-07-10T16:20:54.18+08:00\"},{\"id\":\"1bbd0d87-1723-4f87-9547-0ca0a6959a85\",\"name\":\"上海黄埔区国家税局\",\"createTime\":\"2018-07-12T17:20:13.287+08:00\",\"updateTime\":\"2018-08-29T18:21:37.603+08:00\"}]");
return result;
}
@RequestMapping("taxCalendar/getTaxCalendarDataForDisplay")
@ResponseBody
public Object getTaxCalendarDataForDisplay(){
return new ArrayList();
}
@RequestMapping("user/getUserOwnOrganization")
@ResponseBody
public Object getUserOwnOrganization(){
Object result = JSONUtils.parse("{\"errors\":null,\"data\":{\"id\":\"A3ECE185-82CC-4375-8E36-0B62137D5367\",\"clientCode\":\"88\",\"name\":\"Bitmain Technologies Limited\",\"code\":\"88\",\"abbreviation\":null,\"parentID\":null,\"taxPayerNumber\":null,\"regionID\":\"110100\",\"parentRegionID\":null,\"structureID\":null,\"industryID\":\"0\",\"isActive\":true,\"createTime\":\"2018-10-26T15:06:58.107+08:00\",\"updateTime\":\"2018-10-26T15:06:58.107+08:00\",\"parentName\":null,\"areaName\":null,\"areaID\":\"e2c4a67d-e7de-4037-939b-e6d437265ab0\",\"businessUnitID\":\"1c5048eb-e886-4fc1-b463-f1efcaedec28\",\"subOrgs\":null,\"sameVehicleroutinglocationList\":null,\"taxControlDiskList\":null,\"legalPersonName\":null,\"manufactureAddress\":\"02-03,15/F,Tower A,Cheung Kei Center,18 Hung Luen Road,Hung Hom,Kowloon,Hong Kong\",\"registerAddress\":\"02-03,15/F,Tower A,Cheung Kei Center,18 Hung Luen Road,Hung Hom,Kowloon,Hong Kong\",\"bankAccountName\":null,\"bankAccountNumber\":null,\"phoneNumber\":\"(00852)28862301\",\"registrationType\":null,\"maximumAmount\":null,\"invoiceEntityType\":null,\"maximumPrintNumber\":null,\"payee\":null,\"reviewer\":null,\"issueBy\":null,\"loginUserAsIssuer\":null,\"districtCode\":null,\"districtName\":null,\"structureName\":null,\"regionName\":null,\"industryName\":null,\"businessUnitName\":null,\"dimensionID\":null,\"dimensionName\":null,\"dimensionValueName\":null,\"dimensionValueID\":null,\"attributeID\":null,\"attributeName\":null,\"isSystemDimension\":false,\"isSyncInputInvoice\":false,\"ratepayer\":null,\"address\":null,\"isLastUseOrgnization\":false,\"foundationDate\":null,\"registrationDate\":null,\"registrationLocation\":null,\"registrationCapital\":null,\"businessAllottedTimeFrom\":null,\"businessAllottedTimeTo\":null,\"legalCode\":null,\"companyCode\":null,\"level\":0,\"interalCustomerID\":\"1072\",\"pLevel\":0,\"maximumSpecialAmount\":null,\"maximumGeneralAmount\":null,\"maximumElectronicAmount\":null,\"canIssueElectricTicket\":false,\"isOverseasCompany\":true,\"enterpriseAccountSetOrgList\":null,\"organizationServiceTemplateGroupList\":null,\"dimensionValueOrgList\":null,\"userRoleList\":null,\"productList\":null,\"authenticationPeriod\":null,\"periodLastUpdateTime\":null,\"periodUpdateResult\":null},\"id\":null,\"result\":true,\"resultMsg\":null,\"returnCode\":0}");
return result;
}
@RequestMapping("taxCalendar/getTaxCalendarUserCompanys/admin") @RequestMapping("test")
@ResponseBody @ResponseBody
public Object getTaxCalendarUserCompanys(){ public void getAllTaxProjectList(@Param("entityId") Long entityId,
Object result = JSONUtils.parse("[{\"id\":\"1782D50E-92EE-4C58-8C15-3D0A49F92793\",\"clientCode\":null,\"name\":\"鄂托克旗哈希云科技有限公司\",\"code\":null,\"abbreviation\":null,\"parentID\":null,\"taxPayerNumber\":null,\"regionID\":null,\"parentRegionID\":null,\"structureID\":null,\"industryID\":null,\"isActive\":false,\"createTime\":\"0001-01-01T00:00:00+08:00\",\"updateTime\":\"0001-01-01T00:00:00+08:00\",\"parentName\":null,\"areaName\":null,\"areaID\":null,\"businessUnitID\":null,\"subOrgs\":null,\"sameVehicleroutinglocationList\":null,\"taxControlDiskList\":null,\"legalPersonName\":null,\"manufactureAddress\":null,\"registerAddress\":null,\"bankAccountName\":null,\"bankAccountNumber\":null,\"phoneNumber\":null,\"registrationType\":null,\"maximumAmount\":null,\"invoiceEntityType\":null,\"maximumPrintNumber\":null,\"payee\":null,\"reviewer\":null,\"issueBy\":null,\"loginUserAsIssuer\":null,\"districtCode\":null,\"districtName\":null,\"structureName\":null,\"regionName\":null,\"industryName\":null,\"businessUnitName\":null,\"dimensionID\":null,\"dimensionName\":null,\"dimensionValueName\":null,\"dimensionValueID\":null,\"attributeID\":null,\"attributeName\":null,\"isSystemDimension\":false,\"isSyncInputInvoice\":null,\"ratepayer\":null,\"address\":null,\"isLastUseOrgnization\":false,\"foundationDate\":null,\"registrationDate\":null,\"registrationLocation\":null,\"registrationCapital\":null,\"businessAllottedTimeFrom\":null,\"businessAllottedTimeTo\":null,\"legalCode\":null,\"companyCode\":null,\"level\":0,\"interalCustomerID\":null,\"pLevel\":0,\"maximumSpecialAmount\":null,\"maximumGeneralAmount\":null,\"maximumElectronicAmount\":null,\"canIssueElectricTicket\":false,\"isOverseasCompany\":false,\"enterpriseAccountSetOrgList\":null,\"organizationServiceTemplateGroupList\":null,\"dimensionValueOrgList\":null,\"userRoleList\":null,\"productList\":null,\"authenticationPeriod\":null,\"periodLastUpdateTime\":null,\"periodUpdateResult\":null}]"); @Param("triggerId") Long triggerId,
return result; @Param("areaId") Integer areaId){
calendarEventServiceImpl.addTriggerEvent(entityId, triggerId, areaId);
} }
} }
...@@ -171,111 +171,4 @@ public class CalendarActionServiceImpl extends BaseService implements ICalendarA ...@@ -171,111 +171,4 @@ public class CalendarActionServiceImpl extends BaseService implements ICalendarA
return OperationResultDto.success(actionDtoList); return OperationResultDto.success(actionDtoList);
} }
public void addTriggerEvent(Long entityId, Long triggerId, Integer areaId) {
//获取对应trigger和area的action list
List<CalendarActionByAreaDto> actionList = calendarExtMapper.getActionListByTriggerAndArea(triggerId, areaId);
if(actionList == null){
logger.info("action list is null, triggerId: {}", triggerId);
return;
}
Date effectiveDate = new Date();
actionList.forEach(p -> {
//查询是否有对应actionId,且状态为未完成状态的event,正常情况下只有一条,或者没有
CalendarEvent event = calendarExtMapper.getNotCompletedEventByEntityAndAction(entityId, p.getActionId());
//计算dueDate时间
Date dueDate = calculateDueDate(effectiveDate, p.getLogicNum(), p.getLogicUnitId());
if (event == null) {
//不存在 insert
CalendarEvent newEvent = new CalendarEvent();
buildCommonEvent(newEvent, p, effectiveDate, dueDate);
newEvent.setId(idService.nextId());
newEvent.setEntityId(entityId);
newEvent.setCreatorid(authUserHelper.getCurrentUserId());
newEvent.setCreateTime(effectiveDate);
newEvent.setIsEnable(Byte.parseByte("1"));
calendarEventMapper.insert(newEvent);
} else {
//存在 update effectiveDate&dueDate
buildCommonEvent(event, p, effectiveDate, dueDate);
calendarEventMapper.updateByPrimaryKey(event);
}
});
}
private void buildCommonEvent(CalendarEvent event, CalendarActionByAreaDto dto, Date effectiveDate, Date dueDate){
event.setActionId(dto.getActionId());
event.setTaskTypeId(dto.getTaskTypeId());
event.setNotes(dto.getDescription());
event.setStaff(authUserHelper.getCurrentUserId());
event.setStaffids(authUserHelper.getCurrentUserId());
event.setTaskName(dto.getActionName());
event.setOrderIndex(0);
event.setStatus(Byte.parseByte(CalendarEnum.CALENDAR_EVENT_NOT_COMPLETED.getCode()));
event.setEffectiveDate(effectiveDate);
event.setDueDate(dueDate);
event.setUpdateTime(effectiveDate);
}
/**
* 根据不同的logic计算due date
*
* @param effectiveDate
* @param logicNum
* @param logicUnitId
* @return
*/
private Date calculateDueDate(Date effectiveDate, Integer logicNum, Integer logicUnitId) {
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_CALENDAR_DAY.getCode()) == logicUnitId) {
return DateUtils.addDays(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_WEEK_DAY.getCode()) == logicUnitId) {
return addDaysExcludeWeekends(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_MONTH.getCode()) == logicUnitId) {
return DateUtils.addMonths(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_YEAR.getCode()) == logicUnitId) {
return DateUtils.addYears(effectiveDate, logicNum);
}
return null;
}
/**
* 排除周末的情况下,增加指定天数
*
* @param start 开始时间
* @param days 增加天数
* @return
*/
private Date addDaysExcludeWeekends(Date start, Integer days) {
Calendar c = Calendar.getInstance();
try {
c.setTime(start);
for (int i = 0; i < days; ++i) {
c.add(Calendar.DAY_OF_MONTH, 1);
//排除周六周日
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
--i;
}
}
return c.getTime();
} catch (Exception e) {
log.error("addDaysExcludeWeekends", e);
}
return null;
}
} }
package pwc.taxtech.atms.service.impl; package pwc.taxtech.atms.service.impl;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pwc.taxtech.atms.calendar.dao.*; import pwc.taxtech.atms.calendar.dao.*;
import pwc.taxtech.atms.calendar.dao.ext.CalendarExtMapper; import pwc.taxtech.atms.calendar.dao.ext.CalendarExtMapper;
import pwc.taxtech.atms.calendar.dto.CalendarActionByAreaDto;
import pwc.taxtech.atms.calendar.dto.CalendarEventDto; import pwc.taxtech.atms.calendar.dto.CalendarEventDto;
import pwc.taxtech.atms.calendar.entity.CalendarEvent; import pwc.taxtech.atms.calendar.entity.CalendarEvent;
import pwc.taxtech.atms.calendar.entity.CalendarEventExample; import pwc.taxtech.atms.constant.enums.CalendarEnum;
import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.dto.OperationResultDto; import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.calendar.CalendarDisplayQueryParamDto;
import pwc.taxtech.atms.service.ICalendarEventService; import pwc.taxtech.atms.service.ICalendarEventService;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* <p> @Description </p> * <p> @Description </p>
...@@ -112,4 +110,115 @@ public class CalendarEventServiceImpl extends BaseService implements ICalendarEv ...@@ -112,4 +110,115 @@ public class CalendarEventServiceImpl extends BaseService implements ICalendarEv
return OperationResultDto.success(); return OperationResultDto.success();
} }
public void addTriggerEvent(Long entityId, Long triggerId, Integer areaId) {
//获取对应trigger和area的action list
List<CalendarActionByAreaDto> actionList = calendarExtMapper.getActionListByTriggerAndArea(triggerId, areaId);
if(actionList == null){
logger.info("action list is null, triggerId: {}", triggerId);
return;
}
Date effectiveDate = new Date();
actionList.forEach(p -> {
//查询是否有对应actionId,且状态为未完成状态的event,正常情况下只有一条,或者没有
CalendarEvent event = calendarExtMapper.getNotCompletedEventByEntityAndAction(entityId, p.getActionId());
//计算dueDate时间
Date dueDate = calculateDueDate(effectiveDate, p.getLogicNum(), p.getLogicUnitId());
if (event == null) {
//不存在 insert
CalendarEvent newEvent = new CalendarEvent();
buildCommonEvent(newEvent, p, effectiveDate, dueDate);
newEvent.setId(idService.nextId());
newEvent.setEntityId(entityId);
newEvent.setCreatorid(authUserHelper.getCurrentUserId());
newEvent.setCreateTime(effectiveDate);
newEvent.setIsEnable(Byte.parseByte("1"));
calendarEventMapper.insert(newEvent);
} else {
//存在 update effectiveDate&dueDate
buildCommonEvent(event, p, effectiveDate, dueDate);
calendarEventMapper.updateByPrimaryKey(event);
}
});
}
private void buildCommonEvent(CalendarEvent event, CalendarActionByAreaDto dto, Date effectiveDate, Date dueDate){
event.setActionId(dto.getActionId());
event.setTaskTypeId(dto.getTaskTypeId());
event.setNotes(dto.getDescription());
event.setStaff(authUserHelper.getCurrentAuditor().get());
event.setStaffids(authUserHelper.getCurrentUserId());
event.setTaskName(dto.getActionName());
event.setOrderIndex(0);
event.setStatus(Byte.parseByte(CalendarEnum.CALENDAR_EVENT_NOT_COMPLETED.getCode()));
event.setEffectiveDate(effectiveDate);
event.setDueDate(dueDate);
event.setUpdateTime(effectiveDate);
}
/**
* 根据不同的logic计算due date
*
* @param effectiveDate
* @param logicNum
* @param logicUnitId
* @return
*/
private Date calculateDueDate(Date effectiveDate, Integer logicNum, Integer logicUnitId) {
if(!ObjectUtils.allNotNull(effectiveDate, logicNum, logicUnitId)){
return null;
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_CALENDAR_DAY.getCode()) == logicUnitId) {
return DateUtils.addDays(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_WEEK_DAY.getCode()) == logicUnitId) {
return addDaysExcludeWeekends(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_MONTH.getCode()) == logicUnitId) {
return DateUtils.addMonths(effectiveDate, logicNum);
}
if (Integer.parseInt(CalendarEnum.TRIGGER_UNIT_YEAR.getCode()) == logicUnitId) {
return DateUtils.addYears(effectiveDate, logicNum);
}
return null;
}
/**
* 排除周末的情况下,增加指定天数
*
* @param start 开始时间
* @param days 增加天数
* @return
*/
private Date addDaysExcludeWeekends(Date start, Integer days) {
Calendar c = Calendar.getInstance();
try {
c.setTime(start);
for (int i = 0; i < days; ++i) {
c.add(Calendar.DAY_OF_MONTH, 1);
//排除周六周日
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
--i;
}
}
return c.getTime();
} catch (Exception e) {
log.error("addDaysExcludeWeekends", e);
}
return null;
}
} }
...@@ -121,14 +121,16 @@ public interface CalendarExtMapper extends MyMapper { ...@@ -121,14 +121,16 @@ public interface CalendarExtMapper extends MyMapper {
"\tt1.task_type_id AS taskTypeId,\n" + "\tt1.task_type_id AS taskTypeId,\n" +
"\tdescription,\n" + "\tdescription,\n" +
"\tt3.logic_num AS logicNum,\n" + "\tt3.logic_num AS logicNum,\n" +
"\tt3.logic_unit AS logicUnit\n" + "\tt3.logic_unit AS logicUnitId\n" +
"FROM\n" + "FROM\n" +
"\tcalendar_action t1\n" + "\tcalendar_action t1\n" +
"LEFT JOIN calendar_action_jurisdiction_relationship t2 ON t1.id = t2.action_id\n" + "LEFT JOIN calendar_action_jurisdiction_relationship t2 ON t1.id = t2.action_id\n" +
"LEFT JOIN calendar_jurisdiction t3 ON t2.jurisdiction_id = t3.id\n" + "LEFT JOIN calendar_jurisdiction t3 ON t2.jurisdiction_id = t3.id\n" +
"WHERE\n" + "WHERE\n" +
"\tt1.trigger_id = #{triggerId}\n" + "\tt1.status = 1\n" +
"AND t1.trigger_id = #{triggerId}\n" +
"AND t3.area = #{areaId}\n" + "AND t3.area = #{areaId}\n" +
"AND t3.status = 1\n" +
"AND logic_unit > 0") "AND logic_unit > 0")
List<CalendarActionByAreaDto> getActionListByTriggerAndArea(@Param("triggerId") Long triggerId, @Param("areaId") Integer areaId); List<CalendarActionByAreaDto> getActionListByTriggerAndArea(@Param("triggerId") Long triggerId, @Param("areaId") Integer areaId);
......
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