lrf 2 months ago
parent
commit
3abc4f87d5

+ 1 - 1
src/config/config.prod.ts

@@ -42,7 +42,7 @@ export default {
         username: dbv2,
         password: dbv2Pwd,
         entities: ['./entityV2'],
-        synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
         logging: false,
       }
     },

+ 2 - 1
src/controller/jtjs.controller.ts

@@ -45,7 +45,8 @@ export class JtjsController {
       if (data) {
         const newData = {
           channel_id,
-          title: get(data, 'title'),
+          id: channel_id,
+          title: get(data, 'channel_name'),
           txt: get(data, 'txt.txt')
         }
         returnData.push(newData);

+ 21 - 3
src/controller/jtxw.controller.ts

@@ -2,11 +2,15 @@ import { Controller, Get, Inject, Param } from "@midwayjs/core";
 import { PartsService } from "../service/parts.service";
 import { Page, Query } from "../decorator/page.decorator";
 import { RF } from "../response/CustomerResponse";
+import { get } from "lodash";
+import { PageViewService } from "../service/v2/pageView.service";
 
 @Controller('/jtxw', { tagName: '集团新闻' })
 export class JtxwController {
   @Inject()
   service: PartsService;
+  @Inject()
+  pageViewService: PageViewService;
   @Get('/list/:type', { routerName: '集团新闻列表' })
   async list(@Param('type') type: string, @Query() query: object, @Page() page: object) {
     const configList = [
@@ -22,14 +26,28 @@ export class JtxwController {
     const config = configList.find(f => f.type === type)
     if (!config) return { data: null, total: 0 }
     const { channel_id } = config
-    const data = await this.service.contentList(channel_id, query, page)
-    return RF.success(data);
+    const { data, total } = await this.service.contentList(channel_id, query, page)
+    const newList = []
+    for (const i of data) {
+      const newData = {
+        content_id: get(i, 'content_id'),
+        id: get(i, 'content_id'),
+        title: get(i, 'ext.title'),
+        brief: get(i, 'txt.txt'),
+        date: get(i, 'ext.release_date'),
+        url: get(i, 'ext.title_img')
+      }
+      newList.push(newData)
+    }
+    return RF.success({ data: newList, total });
   }
 
   @Get('/detail/:content_id', { routerName: '集团新闻详情' })
   async detail(@Param('content_id') content_id: string) {
-    const data = await this.service.contentDetail(content_id)
+    const data: any = await this.service.contentDetail(content_id)
     // TODO:增加浏览量,然后将浏览量放到返回数据中
+    const views = await this.pageViewService.fetch(content_id)
+    data.views = views;
     return RF.success(data);
   }
 }

+ 20 - 2
src/controller/myzj.controller.ts

@@ -3,6 +3,8 @@ import { Page, Query } from "../decorator/page.decorator";
 import { PartsService } from "../service/parts.service";
 import { RF } from "../response/CustomerResponse";
 import { QuestionService } from "../service/v2/question.service";
+import { get } from "lodash";
+import { PageViewService } from "../service/v2/pageView.service";
 
 @Controller('/myzj', { tagName: '民意征集' })
 export class MyzjController {
@@ -10,6 +12,9 @@ export class MyzjController {
   service: PartsService;
   @Inject()
   questionService: QuestionService;
+  @Inject()
+  pageViewService: PageViewService
+
   @Get('/question', { routerName: '投诉与建议-查询' })
   async queryQuestion(@Query() query: object, @Page() page: object) {
     let where = {}
@@ -44,8 +49,21 @@ export class MyzjController {
   @Get('/list/rdhy', { routerName: '热点回应列表' })
   async list(@Query() query: object, @Page() page: object) {
     const channel_id = 197
-    const data = await this.service.contentList(channel_id, query, page)
-    return RF.success(data)
+    const { data, total } = await this.service.contentList(channel_id, query, page)
+    const newList = []
+    for (const i of newList) {
+      const newObject: any = {
+        content_id: get(i, 'content_id'),
+        id: get(i, 'content_id'),
+        title: get(i, 'ext.title'),
+        release_date: get(i, 'ext.release_date'),
+        url: get(i, 'ext.type_img')
+      }
+      const views = await this.pageViewService.fetch(newObject.content_id, true)
+      newObject.views = views
+      newList.push(newObject)
+    }
+    return RF.success({ data: newList, total })
   }
 
   @Get('/detail/:content_id', { routerName: '热点回应详情' })

+ 72 - 23
src/controller/xxgk.controller.ts

@@ -1,11 +1,15 @@
-import { Controller, Get, Inject } from "@midwayjs/core";
+import { Controller, Get, Inject, Param } from "@midwayjs/core";
 import { PartsService } from "../service/parts.service";
 import { RF } from "../response/CustomerResponse";
+import { get } from "lodash";
+import { PageViewService } from "../service/v2/pageView.service";
 
 @Controller('/xxgk', { tagName: '信息公开' })
 export class XxgkController {
   @Inject()
   service: PartsService;
+  @Inject()
+  pageViewService: PageViewService;
 
   @Get('/jgsz', { routerName: '机构设置' })
   async jgsz() {
@@ -17,42 +21,48 @@ export class XxgkController {
   async psgsxxgk() {
     const channel_id = 212;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
 
   @Get('/schjxxgk', { routerName: '水厂环境信息公开' })
   async schjxxgk() {
     const channel_id = 213;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
 
   @Get('/xyzl', { routerName: '行业自律' })
   async xyzl() {
     const channel_id = 214;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
 
-  @Get('/ccswjt2018nzfxxgkndgzbg', { routerName: '长春水务集团2018年政府信息公开年度工作报告' })
+  @Get('/sw2018', { routerName: '长春水务集团2018年政府信息公开年度工作报告' })
   async ccswjt2018nzfxxgkndgzbg() {
     const channel_id = 215;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
 
-  @Get('/ccswjt2019ngz', { routerName: '长春水务集团2019年工作' })
+  @Get('/sw2019', { routerName: '长春水务集团2019年工作' })
   async ccswjt2019ngz() {
     const channel_id = 216;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
 
   @Get('/zhswfw', { routerName: '智慧水务(互联网+供水服务)' })
   async zhswfw() {
     const channel_id = 217;
     const data = await this.service.channelDetail(channel_id)
-    return RF.success(data);
+    const newData = this.getViewContent(data)
+    return RF.success(newData);
   }
   /**
    * 只有获得用水是channel的数据,剩下的几个都显示的是content列表
@@ -61,7 +71,8 @@ export class XxgkController {
   async hdysz() {
     const channel_id = await this.service.searchChannelIdByCode('hdysz')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/zhswz', { routerName: '智慧水务' })
@@ -81,78 +92,116 @@ export class XxgkController {
   @Get('/yscsz', { routerName: '用水常识' })
   async yscsz() {
     const channel_id = await this.service.searchChannelIdByCode('yscsz')
-    const contentList = await this.service.contentList(channel_id)
-    return RF.success(contentList)
+    const { data, total } = await this.service.contentList(channel_id)
+    const newList = this.getViewListContent(data)
+    return RF.success({ data: newList, total })
   }
 
   @Get('/xqyshj', { routerName: '新区营商环境' })
   async xqyshj() {
     const channel_id = await this.service.searchChannelIdByCode('xqyshj')
-    const contentList = await this.service.contentList(channel_id)
-    return RF.success(contentList)
+    const { data, total } = await this.service.contentList(channel_id)
+    const newList = this.getViewListContent(data)
+    return RF.success({ data: newList, total })
   }
 
   @Get('/fwxx', { routerName: '服务信息' })
   async fwxx() {
     const channel_id = await this.service.searchChannelIdByCode('fwxx')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/fwxm', { routerName: '服务项目' })
   async fwxm() {
     const channel_id = await this.service.searchChannelIdByCode('fwxm')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/fwsf', { routerName: '服务收费' })
   async fwsf() {
     const channel_id = await this.service.searchChannelIdByCode('fwsf')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/fwjd', { routerName: '服务监督' })
   async fwjd() {
     const channel_id = await this.service.searchChannelIdByCode('fwjd')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/yjfwya', { routerName: '应急服务预案' })
   async yjfwya() {
     const channel_id = await this.service.searchChannelIdByCode('yjfwya')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/jcxxgk', { routerName: '决策信息公开' })
   async jcxxgk() {
     const channel_id = await this.service.searchChannelIdByCode('jcxxgk')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/zyzclsqk', { routerName: '重要政策落实情况' })
   async zyzclsqk() {
     const channel_id = await this.service.searchChannelIdByCode('zyzclsqk')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/qyscjyqk', { routerName: '企业生产经营情况' })
   async qyscjyqk() {
     const channel_id = await this.service.searchChannelIdByCode('qyscjyqk')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
   }
 
   @Get('/qyyxdrdzyjjfs', { routerName: '企业与相对人的争议解决方式' })
   async qyyxdrdzyjjfs() {
     const channel_id = await this.service.searchChannelIdByCode('qyyxdrdzyjjfs')
     const channelData = await this.service.channelDetail(channel_id);
-    return RF.success(channelData)
+    const newData = this.getViewContent(channelData);
+    return RF.success(newData)
+  }
+  @Get('/detail/:content_id', { routerName: '信息公开详情' })
+  async detail(@Param('content_id') content_id: string) {
+    const data: any = await this.service.contentDetail(content_id)
+    // TODO:增加浏览量,然后将浏览量放到返回数据中
+    const views = await this.pageViewService.fetch(content_id)
+    data.views = views;
+    return RF.success(data);
   }
 
+  getViewContent(data: object) {
+    return {
+      channel_id: get(data, 'channel_id'),
+      title: get(data, 'channel_name'),
+      txt: get(data, 'txt.txt')
+    }
+  }
+  getViewListContent(list: Array<any>) {
+    const newList = []
+    for (const i of list) {
+      const obj = {
+        content_id: get(i, 'content_id'),
+        title: get(i, 'ext.title'),
+        date: get(i, 'ext.release_date')
+      }
+      newList.push(obj)
+    }
+    return newList
+  }
 }

+ 3 - 0
src/filter/Default.filter.ts

@@ -5,6 +5,9 @@ import { Context } from '@midwayjs/koa';
 export class DefaultErrorFilter {
   async catch(err: Error, ctx: Context) {
     // 所有的未分类错误会到这里
+    ctx.logger.error(err.name)
+    ctx.logger.error(err.message)
+    ctx.logger.error(err.stack)
     return {
       success: false,
       message: err.message,

+ 20 - 3
src/service/frame/common.service.ts

@@ -1,6 +1,6 @@
 import { Provide } from "@midwayjs/core";
 import { InjectDataSource } from "@midwayjs/typeorm";
-import { lowerCase, replace } from "lodash";
+import { get, lowerCase, replace } from "lodash";
 import { DataSource, ObjectLiteral, Repository } from "typeorm";
 import { ServiceError } from "../../error/CustomerError.error";
 import { ErrorCode } from "../../error/Codes";
@@ -19,8 +19,25 @@ export class CommonService {
    * @returns total 总数
    */
   async search(model: Repository<ObjectLiteral>, query: object = {}, page: object = {}, others: object = {}) {
-    const data = await model.find({ where: query, ...page, ...others })
-    const total = await model.count(query)
+    const searchObject: any = {}
+    const countObject: any = {}
+    if (Object.keys(query).length > 0) {
+      searchObject.where = query
+      countObject.where = query
+    }
+    if (Object.keys(page).length > 0) {
+      const skip = get(page, 'skip', 0)
+      if (skip >= 0) searchObject.skip = skip
+      const take = get(page, 'limit', 0)
+      if (take > 0) searchObject.take = take
+    }
+    if (Object.keys(others).length > 0) {
+      for (const key in others) {
+        searchObject[key] = others[key]
+      }
+    }
+    const data = await model.find(searchObject)
+    const total = await model.count(countObject)
     return { data, total };
   }
   /**

+ 5 - 5
src/service/parts.service.ts

@@ -17,8 +17,8 @@ export class PartsService {
    * @param code channel编码
    */
   async searchChannelIdByCode(code) {
-    const channel = this.service.getModel('channel')
-    const channelData = await this.service.getOne(channel, { where: { channel_path: code } })
+    const channel = this.service.getModel('jc_channel')
+    const channelData = await this.service.getOne(channel, { channel_path: code })
     if (!channelData) return
     const channel_id = get(channelData, 'channel_id')
     return channel_id;
@@ -43,7 +43,7 @@ export class PartsService {
 
 
   /**channel列表查询 */
-  async channelList(channel_id, query = {}, page = {}, others = {}) {
+  async channelList(channel_id, query = {}, page = {}, others = { order: { channel_id: 'DESC' } }) {
     const extModel = this.service.getModel("jc_channel_ext")
     const txtModel = this.service.getModel("jc_channel_txt")
     let { data, total } = await this.service.search(extModel, { channel_id, status: '2', ...query }, page, others)
@@ -66,11 +66,11 @@ export class PartsService {
   }
 
   /**content列表查询 */
-  async contentList(channel_id, query = {}, page = {}, others = {}) {
+  async contentList(channel_id, query = {}, page = {}, others = { order: { content_id: 'DESC' } }) {
     const contentModel = this.service.getModel('jc_content')
     const extModel = this.service.getModel("jc_content_ext")
     const txtModel = this.service.getModel("jc_content_txt")
-    let { data, total } = await this.service.search(contentModel, { channel_id, ...query }, page, others)
+    let { data, total } = await this.service.search(contentModel, { channel_id, status: '2', ...query }, page, others)
     for (const i of data) {
       const content_id = get(i, 'content_id')
       const ext = await this.service.getOne(extModel, { content_id })

+ 5 - 3
src/service/v2/pageView.service.ts

@@ -9,7 +9,7 @@ export class PageViewService {
   @InjectEntityModel(PageView, 'v2')
   model: Repository<PageView>;
   /**查询浏览量,直接把当前的添加上 */
-  async fetch(content_id) {
+  async fetch(content_id, getNum = false) {
     const data = await this.model.createQueryBuilder().where(`content_id=:content_id`, { content_id }).getOne()
     let num = 1;
     if (!data) {
@@ -18,8 +18,10 @@ export class PageViewService {
     } else {
       const id = get(data, 'id')
       num = get(data, 'num', 1);
-      num = num + 1
-      await this.model.update({ id }, { num })
+      if (!getNum) {
+        num = num + 1
+        await this.model.update({ id }, { num })
+      }
     }
     return num
   }