From fd120e70c697726df3e4d7d05713cc2e7c6e0776 Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 19 Jun 2020 00:23:08 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BD=BF=E7=94=A8?= =?UTF-8?q?DimRobot=202.=E4=BF=AE=E6=94=B9=EF=BC=9AMetaObjectField?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/FieldMetaObjectHandler.java | 37 +++++++-- .../epmet/commons/tools/utils/DateUtils.java | 8 +- .../com/epmet/constant/RobotConstant.java | 5 ++ .../com/epmet/controller/DemoController.java | 5 -- .../com/epmet/controller/DimController.java | 13 ++++ .../com/epmet/service/StatsDemoService.java | 1 - .../service/impl/StatsDemoServiceImpl.java | 11 --- .../service/impl/StatsDimServiceImpl.java | 10 +-- .../epmet/service/stats/DimWeekService.java | 2 + .../stats/impl/DimAgencyServiceImpl.java | 14 ++-- .../stats/impl/DimCustomerServiceImpl.java | 14 ++-- .../stats/impl/DimDateServiceImpl.java | 13 ++-- .../stats/impl/DimDepartmentServiceImpl.java | 11 +-- .../stats/impl/DimGridServiceImpl.java | 2 +- .../stats/impl/DimMonthServiceImpl.java | 11 +-- .../stats/impl/DimQuarterServiceImpl.java | 12 +-- .../stats/impl/DimWeekServiceImpl.java | 77 +++++++++++++++++++ .../stats/impl/DimYearServiceImpl.java | 11 +-- .../stats/impl/LastExecRecordServiceImpl.java | 9 +-- 19 files changed, 171 insertions(+), 95 deletions(-) create mode 100644 epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java index 1b9215e22a..1015ade75d 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java @@ -48,14 +48,11 @@ public class FieldMetaObjectHandler implements MetaObjectHandler { public void insertFill(MetaObject metaObject) { Date date = new Date(); if (metaObject.getOriginalObject() instanceof BaseEpmetEntity) { - String loginUserId = loginUserUtil.getLoginUserId(); // epmet项目新增的 - loginUserId = StringUtils.isBlank(loginUserId) ? Constant.APP_USER_FLAG : loginUserId; - //Long deptId = user == null ? null : user.getDeptId(); setFieldValByName(FieldConstant.CREATED_TIME_HUMP, date, metaObject); - setFieldValByName(FieldConstant.CREATED_BY_HUMP, loginUserId, metaObject); + setFieldValByName(FieldConstant.CREATED_BY_HUMP, getCreatedByFieldValue(metaObject), metaObject); setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, date, metaObject); - setFieldValByName(FieldConstant.UPDATED_BY_HUMP, loginUserId, metaObject); + setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject); setFieldValByName(FieldConstant.REVISION_HUMP, NumConstant.ZERO, metaObject); //删除标识 setFieldValByName(FieldConstant.DEL_FLAG_HUMP, EpmetDelFlagEnum.NORMAL.value(), metaObject); @@ -82,6 +79,32 @@ public class FieldMetaObjectHandler implements MetaObjectHandler { } } + public Object getCreatedByFieldValue(MetaObject metaObject) { + Object value = loginUserUtil.getLoginUserId(); + if (value == null) { + if (metaObject.hasGetter(FieldConstant.CREATED_BY_HUMP)) { + value = metaObject.getValue(FieldConstant.CREATED_BY_HUMP); + } + if (value == null) { + value = Constant.APP_USER_FLAG; + } + } + return value; + } + + public Object getUpdatedByFieldValue(MetaObject metaObject) { + Object value = loginUserUtil.getLoginUserId(); + if (value == null) { + if (metaObject.hasGetter(FieldConstant.UPDATED_BY_HUMP)) { + value = metaObject.getValue(FieldConstant.UPDATED_BY_HUMP); + } + if (value == null) { + value = Constant.APP_USER_FLAG; + } + } + return value; + } + @Override public void updateFill(MetaObject metaObject) { @@ -111,9 +134,7 @@ public class FieldMetaObjectHandler implements MetaObjectHandler { //更新时间 setFieldValByName(UPDATE_DATE, new Date(), metaObject); } else if (fillEsuaEntity) { - String loginUserId = loginUserUtil.getLoginUserId(); - String userId = StringUtils.isBlank(loginUserId) ? Constant.APP_USER_FLAG : loginUserId; - setFieldValByName(FieldConstant.UPDATED_BY_HUMP, userId, metaObject); + setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject); setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, new Date(), metaObject); } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java index 2db20b4501..9864888cf5 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java @@ -123,7 +123,13 @@ public class DateUtils { * @return */ public static Date[] getWeekStartAndEnd(Date date) { - return getWeekStartAndEnd(getWeekOfYear(date)); + DateTime dateTime = new DateTime(date); + LocalDate localDate = new LocalDate(dateTime); + + localDate = localDate.dayOfWeek().withMinimumValue(); + Date beginDate = localDate.toDate(); + Date endDate = localDate.plusDays(6).toDate(); + return new Date[]{beginDate, endDate}; } /** diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java new file mode 100644 index 0000000000..e548b35a1a --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java @@ -0,0 +1,5 @@ +package com.epmet.constant; + +public interface RobotConstant { + String DIMENSION_ROBOT = "DimensionRobot"; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java index 85dcc1ae04..2f6e7ac226 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java @@ -24,11 +24,6 @@ public class DemoController { @Autowired private ExecutorService executorService; - @GetMapping("testlist") - public void testList() { - demoService.testList(); - } - @GetMapping("testtx") public void testTx() { demoService.testTx(); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java index 0964efb49f..8a4e4833f3 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java @@ -28,6 +28,9 @@ public class DimController { @Autowired private DimYearService dimYearService; + @Autowired + private DimWeekService dimWeekService; + @Autowired private StatsDimService statsDimService; @@ -114,6 +117,16 @@ public class DimController { return new Result(); } + /** + * 按周维度 + * @return + */ + @PostMapping("/week/init") + public Result initWeekDim() { + dimWeekService.initWeekDim(); + return new Result(); + } + /** * @Description 所有机构 * @param diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java index 0f5524072c..e03d5844ab 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java @@ -6,7 +6,6 @@ import java.util.List; public interface StatsDemoService { - void testList(); void testTx(); Boolean testThreadPool(); void testThreadPoolAsync(); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java index b29ca1c98a..6c662d9760 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java @@ -3,7 +3,6 @@ package com.epmet.service.impl; import com.epmet.dto.AgencySubTreeDto; import com.epmet.entity.issue.IssueEntity; import com.epmet.entity.org.CustomerAgencyEntity; -import com.epmet.service.Issue.DemoIssueService; import com.epmet.service.StatsDemoService; import com.epmet.service.org.DemoGovOrgService; import com.epmet.service.stats.DemoDataStatsService; @@ -23,19 +22,9 @@ public class StatsDemoServiceImpl implements StatsDemoService { @Autowired private DemoGovOrgService demoGovOrgService; - @Autowired - private DemoIssueService demoIssueService; - @Autowired private DemoDataStatsService demoDataStatsService; - @Override - public void testList() { - List agencies = demoGovOrgService.listAllEntities(); - List issues = demoIssueService.listAllEntities(); - System.out.println(666); - } - //该service不加事务 //@Transactional(rollbackFor = Exception.class) @Override diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java index d4b435a6d8..c435ec4720 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java @@ -1,6 +1,7 @@ package com.epmet.service.impl; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.RobotConstant; import com.epmet.constant.StatsSubject; import com.epmet.entity.crm.CustomerEntity; import com.epmet.entity.org.CustomerAgencyEntity; @@ -87,20 +88,15 @@ public class StatsDimServiceImpl implements StatsDimService { * @return */ private List convertCustomerGrid2GridDim(List grids) { - Date now = new Date(); return grids.stream().map(grid -> { DimGridEntity dimGrid = new DimGridEntity(); dimGrid.setAgencyId(grid.getPid()); dimGrid.setAreaCode(grid.getAreaCode()); dimGrid.setCustomerId(grid.getCustomerId()); dimGrid.setGridName(grid.getGridName()); - dimGrid.setCreatedBy("APP_USER"); - dimGrid.setCreatedTime(now); - dimGrid.setDelFlag("0"); + dimGrid.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dimGrid.setId(grid.getId()); - dimGrid.setRevision(0); - dimGrid.setUpdatedBy("APP_USER"); - dimGrid.setUpdatedTime(now); + dimGrid.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); return dimGrid; }).collect(Collectors.toList()); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java index 1cd1f4fc41..1737b3354b 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java @@ -92,4 +92,6 @@ public interface DimWeekService extends BaseService { * @date 2020-06-16 */ void delete(String[] ids); + + void initWeekDim(); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java index bab14194e3..6f0c1b3046 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java @@ -23,6 +23,7 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.constant.RobotConstant; import com.epmet.dao.stats.DimAgencyDao; import com.epmet.dto.AgencySubTreeDto; import com.epmet.dto.stats.DimAgencyDTO; @@ -112,10 +113,9 @@ public class DimAgencyServiceImpl extends BaseServiceImpl agencies) { - Date now = new Date(); for (CustomerAgencyEntity agency : agencies) { DimAgencyEntity dimAgencyEntity = new DimAgencyEntity(); dimAgencyEntity.setAgencyName(agency.getOrganizationName()); @@ -124,14 +124,10 @@ public class DimAgencyServiceImpl extends BaseServiceImpl customers) { - Date now = new Date(); for (CustomerEntity customer : customers) { DimCustomerEntity dim = new DimCustomerEntity(); dim.setCustomerName(customer.getCustomerName()); - dim.setCreatedBy("APP_USER"); - dim.setCreatedTime(now); - dim.setUpdatedBy("APP_USER"); - dim.setUpdatedTime(now); - dim.setDelFlag("0"); - dim.setRevision(0); + dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT); + dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dim.setId(customer.getId()); - baseDao.insertOne(dim); + baseDao.insert(dim); } } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java index 8462972e2d..f6f0d9ee55 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java @@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.RobotConstant; import com.epmet.constant.StatsSubject; import com.epmet.dao.stats.DimDateDao; import com.epmet.dto.stats.DimDateDTO; @@ -104,6 +105,7 @@ public class DimDateServiceImpl extends BaseServiceImpl gridDims) { for (DimGridEntity gridDim : gridDims) { diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java index 1f09b868e9..d732bb5c47 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java @@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.RobotConstant; import com.epmet.constant.StatsSubject; import com.epmet.dao.stats.DimMonthDao; import com.epmet.dto.stats.DimMonthDTO; @@ -108,7 +109,7 @@ public class DimMonthServiceImpl extends BaseServiceImpl implements DimWeekService { + @Autowired + private LastExecRecordService lastExecRecordService; + @Override public PageData page(Map params) { IPage page = baseDao.selectPage( @@ -97,4 +107,71 @@ public class DimWeekServiceImpl extends BaseServiceImpl