ソースを参照

feat(server): 学员查询

Go 4 年 前
コミット
660674de30
21 ファイル変更341 行追加97 行削除
  1. 0 2
      front/project/admin/routes/subject/question/page.js
  2. 30 39
      front/project/admin/routes/user/student/page.js
  3. 9 0
      front/project/admin/stores/class.js
  4. 2 1
      front/project/admin/stores/index.js
  5. 4 0
      front/project/admin/stores/user.js
  6. 16 16
      server/data/src/main/java/com/qxgmat/data/dao/entity/UserClass.java
  7. 2 2
      server/data/src/main/java/com/qxgmat/data/dao/mapping/UserClassMapper.xml
  8. 6 0
      server/data/src/main/java/com/qxgmat/data/relation/UserRelationMapper.java
  9. 23 0
      server/data/src/main/java/com/qxgmat/data/relation/mapping/UserRelationMapper.xml
  10. 3 2
      server/gateway-api/src/main/java/com/qxgmat/Application.java
  11. 28 0
      server/gateway-api/src/main/java/com/qxgmat/controller/admin/ClassController.java
  12. 6 6
      server/gateway-api/src/main/java/com/qxgmat/controller/admin/UserController.java
  13. 3 5
      server/gateway-api/src/main/java/com/qxgmat/controller/api/MyController.java
  14. 27 0
      server/gateway-api/src/main/java/com/qxgmat/dto/admin/extend/ClassCourseExtendDto.java
  15. 9 9
      server/gateway-api/src/main/java/com/qxgmat/dto/admin/extend/UserClassExtendDto.java
  16. 27 0
      server/gateway-api/src/main/java/com/qxgmat/dto/admin/response/ClassCourseListDto.java
  17. 36 5
      server/gateway-api/src/main/java/com/qxgmat/dto/request/UserFeedbackErrorDto.java
  18. 22 0
      server/gateway-api/src/main/java/com/qxgmat/service/UsersService.java
  19. 1 1
      server/gateway-api/src/main/java/com/qxgmat/service/inline/AdService.java
  20. 77 0
      server/gateway-api/src/main/java/com/qxgmat/service/inline/ClassCourseService.java
  21. 10 9
      server/gateway-api/src/main/java/com/qxgmat/service/inline/UserClassService.java

+ 0 - 2
front/project/admin/routes/subject/question/page.js

@@ -39,7 +39,6 @@ export default class extends Page {
         return { value: 'examination', key: 'examination', label: '模考', title: '模考', children: formatTreeData(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; }), 'id', 'title', 'parentId') };
       }),
     ]).then(result => {
-      console.log(result);
       this.setState({ moduleStructData: result });
     });
   }
@@ -95,7 +94,6 @@ export default class extends Page {
     })
       .then((result) => {
         this.setState({ associationContentIds: result.associationContent || [] });
-        console.log(result.questionNoIds);
         if (result.questionNoIds && result.questionNoIds.length > 0) {
           return Question.listNo({ ids: result.questionNoIds }).then(list => {
             this.setState({ questionNos: list });

+ 30 - 39
front/project/admin/routes/user/student/page.js

@@ -6,16 +6,16 @@ import Block from '@src/components/Block';
 import FilterLayout from '@src/layouts/FilterLayout';
 // import ActionLayout from '@src/layouts/ActionLayout';
 import TableLayout from '@src/layouts/TableLayout';
-import { getMap, formatMoney } from '@src/services/Tools';
-import { SwitchSelect, ServiceKey } from '../../../../Constant';
+import { getMap, formatDate } from '@src/services/Tools';
+// import { SwitchSelect, ServiceKey } from '../../../../Constant';
 import { User } from '../../../stores/user';
+import { Class } from '../../../stores/class';
 
-const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
-const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
 export default class extends Page {
   constructor(props) {
     super(props);
     this.filterF = null;
+    this.courseMap = {};
   }
 
   init() {
@@ -27,58 +27,40 @@ export default class extends Page {
         placeholder: '请输入',
       },
       {
-        key: 'real',
+        key: 'courseId',
         type: 'select',
         allowClear: true,
-        name: '实名认证',
-        select: SwitchSelect,
+        name: '课程',
+        select: [],
         placeholder: '请选择',
         number: true,
       },
     ];
     this.columns = [
       {
-        title: 'ID',
-        dataIndex: 'id',
-      },
-      {
         title: '手机号',
         dataIndex: 'mobile',
       },
       {
-        title: '注册时间',
-        dataIndex: 'createTime',
+        title: '用户姓名',
+        dataIndex: 'realName',
       },
       {
-        title: '实名认证',
-        dataIndex: 'realStatus',
-        render: (text) => {
-          return SwitchSelectMap[text ? 1 : 0];
+        title: '开通科目',
+        dataIndex: 'classes',
+        render: (text, record) => {
+          return (record.classes || []).map(row => {
+            return this.courseMap[row.courseId];
+          }).join(<br />);
         },
       },
       {
-        title: '备考信息',
-        dataIndex: 'prepareStatus',
-        render: (text) => {
-          return SwitchSelectMap[text ? 1 : 0];
-        },
-      }, {
-        title: '邀请人数',
-        dataIndex: 'inviteNumber',
-      }, {
-        title: '学习时长',
+        title: '开通时间',
         dataIndex: 'time',
-      }, {
-        title: '服务中',
-        dataIndex: 'services',
-        render: (text) => {
-          return (text || []).map(row => ServiceKeyMap[row.service]).join(', ');
-        },
-      }, {
-        title: '消费金额',
-        dataIndex: 'totalMoney',
-        render: (text) => {
-          return formatMoney(text);
+        render: (text, record) => {
+          return (record.classes || []).map(row => {
+            return `${formatDate(row.startTime)} - ${formatDate(row.expireTime)}`;
+          }).join(<br />);
         },
       }, {
         title: '操作',
@@ -92,10 +74,19 @@ export default class extends Page {
         },
       },
     ];
+    Class.listCourse({ size: 100 }).then(result => {
+      this.filterForm[1].select = result.list.map(row => {
+        return {
+          title: row.title,
+          value: row.id,
+        };
+      });
+      this.courseMap = getMap(result.list, 'id');
+    });
   }
 
   initData() {
-    User.list(this.state.search).then(result => {
+    User.listStudent(this.state.search).then(result => {
       this.setTableData(result.list, result.total);
     });
   }

+ 9 - 0
front/project/admin/stores/class.js

@@ -0,0 +1,9 @@
+import BaseStore from '@src/stores/base';
+
+export default class ClassStore extends BaseStore {
+  listCourse(params) {
+    return this.apiGet('/class/course/list', params);
+  }
+}
+
+export const Class = new ClassStore({ key: 'class' });

+ 2 - 1
front/project/admin/stores/index.js

@@ -5,6 +5,7 @@ import { Preview } from './preview';
 import { User } from './user';
 import { Sentence } from './sentence';
 import { Question } from './question';
+import { Class } from './class';
 import { Slient } from './slient';
 
-export default [System, Examination, Exercise, Preview, User, Sentence, Question, Slient];
+export default [System, Examination, Exercise, Preview, User, Sentence, Question, Class, Slient];

+ 4 - 0
front/project/admin/stores/user.js

@@ -5,6 +5,10 @@ export default class UserStore extends BaseStore {
     return this.apiGet('/user/list', params);
   }
 
+  listStudent(params) {
+    return this.apiGet('/user/student/list', params);
+  }
+
   token(params) {
     return this.apiGet('/user/token', params);
   }

+ 16 - 16
server/data/src/main/java/com/qxgmat/data/dao/entity/UserClass.java

@@ -18,10 +18,10 @@ public class UserClass implements Serializable {
     private Integer userId;
 
     /**
-     * 科目id:读取struct
+     * 课程id
      */
-    @Column(name = "`category`")
-    private Integer category;
+    @Column(name = "`course_id`")
+    private Integer courseId;
 
     /**
      * 开通时间
@@ -70,21 +70,21 @@ public class UserClass implements Serializable {
     }
 
     /**
-     * 获取科目id:读取struct
+     * 获取课程id
      *
-     * @return category - 科目id:读取struct
+     * @return course_id - 课程id
      */
-    public Integer getCategory() {
-        return category;
+    public Integer getCourseId() {
+        return courseId;
     }
 
     /**
-     * 设置科目id:读取struct
+     * 设置课程id
      *
-     * @param category 科目id:读取struct
+     * @param courseId 课程id
      */
-    public void setCategory(Integer category) {
-        this.category = category;
+    public void setCourseId(Integer courseId) {
+        this.courseId = courseId;
     }
 
     /**
@@ -131,7 +131,7 @@ public class UserClass implements Serializable {
         sb.append("Hash = ").append(hashCode());
         sb.append(", id=").append(id);
         sb.append(", userId=").append(userId);
-        sb.append(", category=").append(category);
+        sb.append(", courseId=").append(courseId);
         sb.append(", startTime=").append(startTime);
         sb.append(", expireTime=").append(expireTime);
         sb.append("]");
@@ -168,12 +168,12 @@ public class UserClass implements Serializable {
         }
 
         /**
-         * 设置科目id:读取struct
+         * 设置课程id
          *
-         * @param category 科目id:读取struct
+         * @param courseId 课程id
          */
-        public Builder category(Integer category) {
-            obj.setCategory(category);
+        public Builder courseId(Integer courseId) {
+            obj.setCourseId(courseId);
             return this;
         }
 

+ 2 - 2
server/data/src/main/java/com/qxgmat/data/dao/mapping/UserClassMapper.xml

@@ -7,7 +7,7 @@
     -->
     <id column="id" jdbcType="INTEGER" property="id" />
     <result column="user_id" jdbcType="INTEGER" property="userId" />
-    <result column="category" jdbcType="INTEGER" property="category" />
+    <result column="course_id" jdbcType="INTEGER" property="courseId" />
     <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
     <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
   </resultMap>
@@ -15,6 +15,6 @@
     <!--
       WARNING - @mbg.generated
     -->
-    `id`, `user_id`, `category`, `start_time`, `expire_time`
+    `id`, `user_id`, `course_id`, `start_time`, `expire_time`
   </sql>
 </mapper>

+ 6 - 0
server/data/src/main/java/com/qxgmat/data/relation/UserRelationMapper.java

@@ -1,5 +1,6 @@
 package com.qxgmat.data.relation;
 
+import com.qxgmat.data.dao.entity.User;
 import com.qxgmat.data.dao.entity.UserReport;
 import com.qxgmat.data.relation.entity.UserPrepareRelation;
 import org.apache.ibatis.annotations.Param;
@@ -19,4 +20,9 @@ public interface UserRelationMapper {
             @Param("field") String field
     );
 
+    List<User> listByCourse(
+            @Param("keyword") String keyword,
+            @Param("courseId") Number courseId
+    );
+
 }

+ 23 - 0
server/data/src/main/java/com/qxgmat/data/relation/mapping/UserRelationMapper.xml

@@ -1,6 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qxgmat.data.relation.UserRelationMapper">
+  <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.User">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="id" jdbcType="INTEGER" property="id" />
+  </resultMap>
   <resultMap id="Prepare" type="com.qxgmat.data.relation.entity.UserPrepareRelation">
     <!--
       WARNING - @mbg.generated
@@ -42,4 +48,21 @@
     group by `${field}`
   </select>
 
+  <!--
+    购买过课程的用户
+  -->
+  <select id="listByCourse" resultMap="IdMap">
+    <bind name="keywordLike" value="'%' + keyword + '%'" />
+    select
+    <include refid="Id_Column_List" />
+    from `user` u
+    left join `user_class` uc on uc.`user_id` = u.`id`
+    <if test="courseId != null">
+      and uc.`course_id` = #{courseId,jdbcType=VARCHAR}
+    </if>
+    where uc.`id` != null
+    <if test="keyword != null">
+      and (u.`mobile` like #{keywordLike,jdbcType=VARCHAR} or u.`id` like #{keywordLike,jdbcType=VARCHAR})
+    </if>
+  </select>
 </mapper>

+ 3 - 2
server/gateway-api/src/main/java/com/qxgmat/Application.java

@@ -26,7 +26,8 @@ public class Application {
     }
 }
 
-// 练习结构扩展 - 后台限定编辑功能,不同层级设定不同,第一第二层固定存在,写入数据库
-// 模考时间设定 - 读取练习结构
+// 每日数据统计
+// 模考报告生成
+// 服务权限验证
 // 预习作业添加模式:用于主动发送用户
 // 课程与预习作业关系,分册进度

+ 28 - 0
server/gateway-api/src/main/java/com/qxgmat/controller/admin/ClassController.java

@@ -1,11 +1,39 @@
 package com.qxgmat.controller.admin;
 
+import com.github.pagehelper.Page;
+import com.nuliji.tools.PageMessage;
+import com.nuliji.tools.Response;
+import com.nuliji.tools.ResponseHelp;
+import com.nuliji.tools.Transform;
+import com.qxgmat.data.dao.entity.ClassCourse;
+import com.qxgmat.dto.admin.response.ClassCourseListDto;
+import com.qxgmat.service.inline.ClassCourseService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpSession;
+import java.util.List;
+
 @RestController("AdminClassController")
 @RequestMapping("/admin/class")
 public class ClassController {
 
+    @Autowired
+    private ClassCourseService classCourseService;
+
+    @RequestMapping(value = "/course/list", method = RequestMethod.GET)
+    @ApiOperation(value = "课程列表", httpMethod = "GET")
+    public Response<PageMessage<ClassCourseListDto>> list(
+            @RequestParam(required = false, defaultValue = "1") int page,
+            @RequestParam(required = false, defaultValue = "100") int size,
+            HttpSession session) {
+        Page<ClassCourse> p = classCourseService.select(page, size);
+        List<ClassCourseListDto> pr = Transform.convert(p, ClassCourseListDto.class);
 
+        return ResponseHelp.success(pr, page, size, p.getTotal());
+    }
 }

+ 6 - 6
server/gateway-api/src/main/java/com/qxgmat/controller/admin/UserController.java

@@ -106,30 +106,30 @@ public class UserController {
         Transform.combine(pr, serviceByUser, UserListDto.class, "id", "services", UserServiceExtendDto.class);
 
         // 绑定用户课程
-        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds);
+        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds, true);
         Transform.combine(pr, classByUser, UserListDto.class, "id", "classes", UserClassExtendDto.class);
 
         return ResponseHelp.success(pr, page, size, p.getTotal());
     }
 
-    @RequestMapping(value = "/members", method = RequestMethod.GET)
+    @RequestMapping(value = "/student/list", method = RequestMethod.GET)
     @ApiOperation(value = "会员列表", httpMethod = "GET")
     public Response<PageMessage<UserListDto>> members(
             @RequestParam(required = false, defaultValue = "1") int page,
             @RequestParam(required = false, defaultValue = "100") int size,
             @RequestParam(required = false, defaultValue = "") String keyword,
-            @RequestParam(required = false) Boolean real,
+            @RequestParam(required = false) Integer courseId,
             @RequestParam(required = false) String order,
             @RequestParam(required = false, defaultValue = "desc") String direction,
             HttpSession session) {
         // 已经购买过课程的用户
-        Page<User> p = usersService.select(page, size, keyword, real, order, DirectionStatus.ValueOf(direction));
+        Page<User> p = usersService.listByCourse(page, size, keyword, courseId);
         List<UserListDto> pr = Transform.convert(p, UserListDto.class);
 
         Collection userIds = Transform.getIds(p, User.class, "id");
 
         // 绑定用户课程
-        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds);
+        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds, false);
         Transform.combine(pr, classByUser, UserListDto.class, "id", "classes", UserClassExtendDto.class);
 
         return ResponseHelp.success(pr, page, size, p.getTotal());
@@ -153,7 +153,7 @@ public class UserController {
         Transform.combine(pr, serviceByUser, UserListDto.class, "id", "services", UserServiceExtendDto.class);
 
         // 绑定用户课程
-        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds);
+        Map<Object, Collection<UserClass>> classByUser = userClassService.mapByUser(userIds, false);
         Transform.combine(pr, classByUser, UserListDto.class, "id", "classes", UserClassExtendDto.class);
 
         return ResponseHelp.success(pr, page, size, p.getTotal());

+ 3 - 5
server/gateway-api/src/main/java/com/qxgmat/controller/api/MyController.java

@@ -7,6 +7,7 @@ import com.nuliji.tools.exception.ParameterException;
 import com.nuliji.tools.exception.SystemException;
 import com.qxgmat.data.constants.enums.QuestionType;
 import com.qxgmat.data.constants.enums.SettingKey;
+import com.qxgmat.data.constants.enums.module.FeedbackModule;
 import com.qxgmat.data.constants.enums.module.PaperModule;
 import com.qxgmat.data.constants.enums.module.QuestionModule;
 import com.qxgmat.data.constants.enums.status.DirectionStatus;
@@ -416,15 +417,12 @@ public class MyController {
         return ResponseHelp.success(true);
     }
 
-    @RequestMapping(value = "/feedback/error", method = RequestMethod.POST)
-    @ApiOperation(value = "添加勘误", notes = "添加勘误", httpMethod = "POST")
+    @RequestMapping(value = "/feedback/question/error", method = RequestMethod.POST)
+    @ApiOperation(value = "添加题目勘误", notes = "添加勘误", httpMethod = "POST")
     public Response<Boolean> addFeedbackError(@RequestBody @Validated UserFeedbackErrorDto dto)  {
         UserFeedbackError entity = Transform.dtoToEntity(dto);
         User user = (User) shiroHelp.getLoginUser();
         entity.setUserId(user.getId());
-        QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
-        entity.setQuestionId(questionNo.getQuestionId());
-        entity.setModule(questionNo.getModule());
         userFeedbackErrorService.add(entity);
 
         return ResponseHelp.success(true);

+ 27 - 0
server/gateway-api/src/main/java/com/qxgmat/dto/admin/extend/ClassCourseExtendDto.java

@@ -0,0 +1,27 @@
+package com.qxgmat.dto.admin.extend;
+
+import com.nuliji.tools.annotation.Dto;
+import com.qxgmat.data.dao.entity.ClassCourse;
+
+@Dto(entity = ClassCourse.class)
+public class ClassCourseExtendDto {
+    private Integer id;
+
+    private String title;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+}

+ 9 - 9
server/gateway-api/src/main/java/com/qxgmat/dto/admin/extend/UserClassExtendDto.java

@@ -9,7 +9,7 @@ import java.util.Date;
 public class UserClassExtendDto {
 
     private Integer id;
-    private Integer category;
+    private Integer courseId;
     private Date startTime;
     private Date expireTime;
 
@@ -21,14 +21,6 @@ public class UserClassExtendDto {
         this.id = id;
     }
 
-    public Integer getCategory() {
-        return category;
-    }
-
-    public void setCategory(Integer category) {
-        this.category = category;
-    }
-
     public Date getStartTime() {
         return startTime;
     }
@@ -44,4 +36,12 @@ public class UserClassExtendDto {
     public void setExpireTime(Date expireTime) {
         this.expireTime = expireTime;
     }
+
+    public Integer getCourseId() {
+        return courseId;
+    }
+
+    public void setCourseId(Integer courseId) {
+        this.courseId = courseId;
+    }
 }

+ 27 - 0
server/gateway-api/src/main/java/com/qxgmat/dto/admin/response/ClassCourseListDto.java

@@ -0,0 +1,27 @@
+package com.qxgmat.dto.admin.response;
+
+import com.nuliji.tools.annotation.Dto;
+import com.qxgmat.data.dao.entity.ClassCourse;
+
+@Dto(entity = ClassCourse.class)
+public class ClassCourseListDto {
+    private Integer id;
+
+    private String title;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+}

+ 36 - 5
server/gateway-api/src/main/java/com/qxgmat/dto/request/UserFeedbackErrorDto.java

@@ -5,16 +5,47 @@ import com.qxgmat.data.dao.entity.UserFeedbackError;
 
 @Dto(entity = UserFeedbackError.class)
 public class UserFeedbackErrorDto {
-    private Integer questionNoId;
+
+    private String module;
+
+    private Integer moduleId;
+
+    private String position;
+
+    private String originContent;
 
     private String content;
 
-    public Integer getQuestionNoId() {
-        return questionNoId;
+    public String getModule() {
+        return module;
+    }
+
+    public void setModule(String module) {
+        this.module = module;
+    }
+
+    public Integer getModuleId() {
+        return moduleId;
+    }
+
+    public void setModuleId(Integer moduleId) {
+        this.moduleId = moduleId;
+    }
+
+    public String getPosition() {
+        return position;
+    }
+
+    public void setPosition(String position) {
+        this.position = position;
+    }
+
+    public String getOriginContent() {
+        return originContent;
     }
 
-    public void setQuestionNoId(Integer questionNoId) {
-        this.questionNoId = questionNoId;
+    public void setOriginContent(String originContent) {
+        this.originContent = originContent;
     }
 
     public String getContent() {

+ 22 - 0
server/gateway-api/src/main/java/com/qxgmat/service/UsersService.java

@@ -4,6 +4,7 @@ import com.github.pagehelper.Page;
 import com.nuliji.tools.AbstractService;
 import com.nuliji.tools.CipherHelp;
 import com.nuliji.tools.Tools;
+import com.nuliji.tools.Transform;
 import com.nuliji.tools.exception.AuthException;
 import com.nuliji.tools.exception.ParameterException;
 import com.nuliji.tools.exception.SystemException;
@@ -403,6 +404,27 @@ public class UsersService extends AbstractService {
         return userPrepareRelationList;
     }
 
+    /**
+     * 获取购买过课程的用户
+     * @param page
+     * @param pageSize
+     * @param keyword
+     * @param courseId
+     * @return
+     */
+    public Page<User> listByCourse(int page, int pageSize, String keyword, Integer courseId){
+        Page<User> p = page(()->{
+            userRelationMapper.listByCourse(keyword, courseId);
+        }, page, pageSize);
+
+        Collection ids = Transform.getIds(p, User.class, "id");
+
+        // 获取详细数据
+        List<User> list = select(ids);
+        Transform.replace(p, list, User.class, "id");
+        return p;
+    }
+
     public boolean equalsPassword(User user, String password){
         return Objects.equals(user.getPassword(), Tools.stringMD5(Tools.stringMD5(password)));
     }

+ 1 - 1
server/gateway-api/src/main/java/com/qxgmat/service/inline/AdService.java

@@ -39,7 +39,7 @@ public class AdService extends AbstractService {
                         .orIsNull("endTime")
         );
         example.orderBy("position").asc();
-        return select(adMapper);
+        return select(adMapper, example);
     }
 
     public Ad add(Ad ad){

+ 77 - 0
server/gateway-api/src/main/java/com/qxgmat/service/inline/ClassCourseService.java

@@ -0,0 +1,77 @@
+package com.qxgmat.service.inline;
+
+import com.github.pagehelper.Page;
+import com.nuliji.tools.AbstractService;
+import com.nuliji.tools.exception.ParameterException;
+import com.nuliji.tools.exception.SystemException;
+import com.nuliji.tools.mybatis.Example;
+import com.qxgmat.data.dao.AdMapper;
+import com.qxgmat.data.dao.ClassCourseMapper;
+import com.qxgmat.data.dao.entity.Ad;
+import com.qxgmat.data.dao.entity.ClassCourse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class ClassCourseService extends AbstractService {
+    private static final Logger logger = LoggerFactory.getLogger(ClassCourseService.class);
+
+    @Resource
+    private ClassCourseMapper classCourseMapper;
+
+    public List<ClassCourse> all(){
+        Example example = new Example(ClassCourse.class);
+        return select(classCourseMapper, example);
+    }
+
+    public ClassCourse add(ClassCourse course){
+        int result = insert(classCourseMapper, course);
+        course = one(classCourseMapper, course.getId());
+        if(course == null){
+            throw new SystemException("课程添加失败");
+        }
+        return course;
+    }
+
+    public ClassCourse edit(ClassCourse course){
+        ClassCourse in = one(classCourseMapper, course.getId());
+        if(in == null){
+            throw new ParameterException("课程不存在");
+        }
+        int result = update(classCourseMapper, course);
+        return course;
+    }
+
+    public boolean delete(Number id){
+        ClassCourse in = one(classCourseMapper, id);
+        if(in == null){
+            throw new ParameterException("课程不存在");
+        }
+        int result = delete(classCourseMapper, id);
+        return result > 0;
+    }
+
+    public ClassCourse get(Number id){
+        ClassCourse in = one(classCourseMapper, id);
+
+        if(in == null){
+            throw new ParameterException("课程不存在");
+        }
+        return in;
+    }
+
+    public Page<ClassCourse> select(int page, int pageSize){
+        return select(classCourseMapper, page, pageSize);
+    }
+
+    public List<ClassCourse> select(Collection ids){
+        return select(classCourseMapper, ids);
+    }
+
+}

+ 10 - 9
server/gateway-api/src/main/java/com/qxgmat/service/inline/UserClassService.java

@@ -6,11 +6,7 @@ import com.nuliji.tools.exception.ParameterException;
 import com.nuliji.tools.exception.SystemException;
 import com.nuliji.tools.mybatis.Example;
 import com.qxgmat.data.dao.UserClassMapper;
-import com.qxgmat.data.dao.UserServiceMapper;
-import com.qxgmat.data.dao.entity.Pay;
-import com.qxgmat.data.dao.entity.UserClass;
-import com.qxgmat.data.dao.entity.UserPay;
-import com.qxgmat.data.dao.entity.UserService;
+import com.qxgmat.data.dao.entity.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -31,7 +27,7 @@ public class UserClassService extends AbstractService {
     // 开通服务
     public boolean used(UserPay pay){
         // todo 分析时长
-        add(UserClass.builder().userId(pay.getUserId()).category(Integer.valueOf(pay.getModuleExtend())).build());
+        add(UserClass.builder().userId(pay.getUserId()).courseId(Integer.valueOf(pay.getModuleExtend())).build());
         return true;
     }
 
@@ -64,16 +60,21 @@ public class UserClassService extends AbstractService {
         return select(userClassMapper, example);
     }
 
-    public Map<Object, Collection<UserClass>> mapByUser(Collection userIds){
+    public Map<Object, Collection<UserClass>> mapByUser(Collection userIds, Boolean time){
         Map<Object, Collection<UserClass>> relationMap = new HashMap<>();
         if(userIds.size() == 0) return relationMap;
         Example example = new Example(UserService.class);
         example.and(
                 example.createCriteria()
                         .andIn("userId", userIds)
-                        .andGreaterThanOrEqualTo("startTime", new Date())
-                        .andLessThan("expireTime", new Date())
         );
+        if (time){
+            example.and(
+                    example.createCriteria()
+                            .andGreaterThanOrEqualTo("startTime", new Date())
+                            .andLessThan("expireTime", new Date())
+            );
+        }
         List<UserClass> userClassList = select(userClassMapper, example);
         if(userClassList.size() == 0) return relationMap;
         for(UserClass row: userClassList){