Browse Source

科目代码

guq 6 years ago
parent
commit
ffe4fe92a4

+ 46 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/controller/SubjectController.java

@@ -0,0 +1,46 @@
+package com.usoftchina.smartschool.school.basic.controller;
+
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.page.PageDefault;
+import com.usoftchina.smartschool.page.PageRequest;
+import com.usoftchina.smartschool.school.basic.service.SubjectService;
+import com.usoftchina.smartschool.school.dto.BatchDealBaseDTO;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
+import com.usoftchina.smartschool.school.dto.ListReqDTO;
+import com.usoftchina.smartschool.school.po.Subject;
+import com.usoftchina.smartschool.school.po.SysTeacher;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author: guq
+ * @create: 2019-02-27 10:09
+ **/
+@RestController
+@RequestMapping("subject")
+public class SubjectController {
+
+
+    @Autowired
+    private SubjectService subjectService;
+
+    @GetMapping("/list")
+    public Result getList(@PageDefault PageRequest page, ListReqDTO listReqDTO) {
+        PageInfo<Subject> student = subjectService.getListData(page, listReqDTO);
+        return Result.success(student);
+    }
+
+    @PostMapping("/save")
+    public Result getFormData(@RequestBody Subject data) {
+        DocBaseDTO formData = subjectService.saveFormData(data);
+        return Result.success(formData);
+    }
+
+    @PostMapping("/batchDelete")
+    public Result batchDelete(@RequestBody BatchDealBaseDTO baseDTOs) {
+        subjectService.batchDelete(baseDTOs);
+        return Result.success();
+    }
+
+}

+ 16 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/SubjectService.java

@@ -0,0 +1,16 @@
+package com.usoftchina.smartschool.school.basic.service;
+
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.smartschool.page.PageRequest;
+import com.usoftchina.smartschool.school.dto.BatchDealBaseDTO;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
+import com.usoftchina.smartschool.school.dto.ListReqDTO;
+import com.usoftchina.smartschool.school.po.Subject;
+
+public interface SubjectService {
+    PageInfo<Subject> getListData(PageRequest page, ListReqDTO listReqDTO);
+
+    DocBaseDTO saveFormData(Subject teacher);
+
+    void batchDelete(BatchDealBaseDTO baseDTOs);
+}

+ 87 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/impl/SubjectServiceImpl.java

@@ -0,0 +1,87 @@
+package com.usoftchina.smartschool.school.basic.service.impl;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.smartschool.context.BaseContextHolder;
+import com.usoftchina.smartschool.exception.BizException;
+import com.usoftchina.smartschool.page.PageRequest;
+import com.usoftchina.smartschool.school.basic.service.SubjectService;
+import com.usoftchina.smartschool.school.dto.BatchDealBaseDTO;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
+import com.usoftchina.smartschool.school.dto.ListReqDTO;
+import com.usoftchina.smartschool.school.exception.BizExceptionCode;
+import com.usoftchina.smartschool.school.mapper.SubjectMapper;
+import com.usoftchina.smartschool.school.po.Subject;
+import com.usoftchina.smartschool.school.po.SysStudent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+
+/**
+ * @author: guq
+ * @create: 2019-02-27 10:10
+ **/
+@Service
+public class SubjectServiceImpl implements SubjectService {
+
+    @Autowired
+    private SubjectMapper subjectMapper;
+
+
+    @Override
+    public PageInfo<Subject> getListData(PageRequest page, ListReqDTO listReqDTO) {
+        PageHelper.startPage(page.getNumber(), page.getSize());
+        Long schoolId = BaseContextHolder.getSchoolId();
+        schoolId = 1l;
+        //condition语句
+        String condition = listReqDTO.getFinalCondition();
+        if(condition == null){
+            condition = "1=1";
+        }
+        List<Subject> data = subjectMapper.selectByConditon(condition, schoolId);
+        PageInfo<Subject> list = new PageInfo<>(data);
+        return list;
+    }
+
+    @Override
+    public DocBaseDTO saveFormData(Subject formdata) {
+        if (null == formdata){
+            throw new BizException(BizExceptionCode.EMPTY_DATA);
+        }
+        Long id = formdata.getSubject_id();
+        Long school = BaseContextHolder.getSchoolId();
+        school = 1l;
+        if (StringUtils.isEmpty(id) || "0".equals(id.toString())) {
+            formdata.setSchool_id(school);
+            formdata.setSubject_status(1);
+            subjectMapper.insertSelective(formdata);
+           id = formdata.getSubject_id();
+        } else {
+            //更新
+            subjectMapper.updateByPrimaryKeySelective(formdata);
+        }
+        return new DocBaseDTO(formdata.getSubject_id());
+    }
+
+    @Override
+    public void batchDelete(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return;
+        }
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            delete(base.getId());
+        }
+    }
+
+
+
+    private void delete(Long id) {
+        if (null == id || "0".equals(id)) {
+            return;
+        }
+        subjectMapper.deleteByPrimaryKey(id);
+    }
+}

+ 23 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/mapper/SubjectMapper.java

@@ -0,0 +1,23 @@
+package com.usoftchina.smartschool.school.mapper;
+
+import com.usoftchina.smartschool.school.po.Subject;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+@Mapper
+public interface SubjectMapper {
+    int deleteByPrimaryKey(Long subject_id);
+
+    int insert(Subject record);
+
+    int insertSelective(Subject record);
+
+    Subject selectByPrimaryKey(Long subject_id);
+
+    int updateByPrimaryKeySelective(Subject record);
+
+    int updateByPrimaryKey(Subject record);
+
+    List<Subject> selectByConditon(@Param("con") String con, @Param("school_id") Long school_id);
+}

+ 48 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/po/Subject.java

@@ -0,0 +1,48 @@
+package com.usoftchina.smartschool.school.po;
+
+/**
+ * @author: guq
+ * @create: 2019-02-27 11:49
+ **/
+public class Subject {
+
+    private Long subject_id;
+
+    private String subject_name;
+
+    private Integer subject_status;
+
+    private Long school_id;
+
+    public Long getSubject_id() {
+        return subject_id;
+    }
+
+    public void setSubject_id(Long subject_id) {
+        this.subject_id = subject_id;
+    }
+
+    public String getSubject_name() {
+        return subject_name;
+    }
+
+    public void setSubject_name(String subject_name) {
+        this.subject_name = subject_name == null ? null : subject_name.trim();
+    }
+
+    public Integer getSubject_status() {
+        return subject_status;
+    }
+
+    public void setSubject_status(Integer subject_status) {
+        this.subject_status = subject_status;
+    }
+
+    public Long getSchool_id() {
+        return school_id;
+    }
+
+    public void setSchool_id(Long school_id) {
+        this.school_id = school_id;
+    }
+}

+ 91 - 0
applications/school/school-server/src/main/resources/mapper/SubjectMapper.xml

@@ -0,0 +1,91 @@
+<?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.usoftchina.smartschool.school.mapper.SubjectMapper" >
+  <resultMap id="BaseResultMap" type="com.usoftchina.smartschool.school.po.Subject" >
+    <id column="subject_id" property="subject_id" jdbcType="BIGINT" />
+    <result column="subject_name" property="subject_name" jdbcType="VARCHAR" />
+    <result column="subject_status" property="subject_status" jdbcType="INTEGER" />
+    <result column="school_id" property="school_id" jdbcType="BIGINT" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    subject_id, subject_name, subject_status, school_id
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
+    select 
+    <include refid="Base_Column_List" />
+    from subject
+    where subject_id = #{subject_id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
+    delete from subject
+    where subject_id = #{subject_id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" parameterType="com.usoftchina.smartschool.school.po.Subject" >
+    insert into subject (subject_id, subject_name, subject_status, 
+      school_id)
+    values (#{subject_id,jdbcType=BIGINT}, #{subject_name,jdbcType=VARCHAR}, #{subject_status,jdbcType=INTEGER}, 
+      #{school_id,jdbcType=BIGINT})
+  </insert>
+  <insert id="insertSelective" parameterType="com.usoftchina.smartschool.school.po.Subject" >
+    <selectKey  resultType="java.lang.Long" keyProperty="subject_id">
+      SELECT LAST_INSERT_ID() AS ID
+    </selectKey>
+    insert into subject
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="subject_name != null" >
+        subject_name,
+      </if>
+      <if test="subject_status != null" >
+        subject_status,
+      </if>
+      <if test="school_id != null" >
+        school_id,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="subject_name != null" >
+        #{subject_name,jdbcType=VARCHAR},
+      </if>
+      <if test="subject_status != null" >
+        #{subject_status,jdbcType=INTEGER},
+      </if>
+      <if test="school_id != null" >
+        #{school_id,jdbcType=BIGINT},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.smartschool.school.po.Subject" >
+    update subject
+    <set >
+      <if test="subject_name != null" >
+        subject_name = #{subject_name,jdbcType=VARCHAR},
+      </if>
+      <if test="subject_status != null" >
+        subject_status = #{subject_status,jdbcType=INTEGER},
+      </if>
+      <if test="school_id != null" >
+        school_id = #{school_id,jdbcType=BIGINT},
+      </if>
+    </set>
+    where subject_id = #{subject_id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.usoftchina.smartschool.school.po.Subject" >
+    update subject
+    set subject_name = #{subject_name,jdbcType=VARCHAR},
+      subject_status = #{subject_status,jdbcType=INTEGER},
+      school_id = #{school_id,jdbcType=BIGINT}
+    where subject_id = #{subject_id,jdbcType=BIGINT}
+  </update>
+
+  <select id="selectByConditon" resultMap="BaseResultMap">
+    select * from subject <where>
+    <if test="con != null">
+      ${con}
+    </if>
+    <if test="school_id != null">
+      and  school_id = #{school_id}
+    </if>
+  </where>
+    order by subject_id DESC
+  </select>
+</mapper>