Ver Fonte

前后:hse成绩模块

wd há 4 anos atrás
pai
commit
4e7174ad70

+ 3 - 2
src/dashoo.cn/backend/api/business/oilsupplier/hsescore/hsescore.go

@@ -12,8 +12,9 @@ type HSEScore struct {
 	IdNumber       string    `xorm:"comment('身份证号') VARCHAR(50)"`
 	Score   	   int       `xorm:"comment('成绩') VARCHAR(50)"`
 	TestNumber     int       `xorm:"comment('考号') VARCHAR(50)"`
-	TrainTime      time.Time `xorm:"comment('培训时间') DATE"`
-	ApplyTime      time.Time `xorm:"comment('有效期') DATE"`
+	StartTime      time.Time `xorm:"comment('培训开始时间') DATE"`
+	EndTime        time.Time `xorm:"comment('培训结束时间') DATE"`
+	ApplyTime      time.Time `xorm:"comment('有效期(上半年为加三年的6.30,下半年为加三年的12.31)') DATE"`
 	Remark   	   string    `xorm:"comment('备注') VARCHAR(50)"`
 	CreateOn       time.Time `xorm:"comment('创建时间') DATETIME"`
 	CreateUserId   int       `xorm:"comment('创建者编号') INT(11)"`

+ 51 - 2
src/dashoo.cn/backend/api/controllers/oilsupplier/hsescore.go

@@ -62,6 +62,12 @@ func (this *HSEScoreController) GetList() {
 		if Prop == "ApplyTime" {
 			orderby = "a.ApplyTime"
 		}
+		if Prop == "StartTime" {
+			orderby = "a.StartTime"
+		}
+		if Prop == "EndTime" {
+			orderby = "a.EndTime"
+		}
 		if Prop == "Name" {
 			orderby = "a.Name"
 		}
@@ -136,6 +142,7 @@ func (this *HSEScoreController) ImportExcel() {
 	dateStr := ""
 	supplierNameStr := ""
 	supplierName := ""
+	var hseTime hsescore.HSEScore
 
 	svc := hsescore.GetHSEScoreService(utils.DBE) //获得数据库引擎
 	for i := 1; i < len(sheet.Rows); i++ {
@@ -144,9 +151,27 @@ func (this *HSEScoreController) ImportExcel() {
 		}
 		if i == 1 {
 			dateStr = sheet.Rows[i].Cells[0].String()
+			dateStr = strings.Replace(dateStr, "年", "-", -1)
+			dateStr = strings.Replace(dateStr, "月", "-", -1)
+			dateArr := strings.Split(dateStr, ":")
+			if dateArr[1] == "" || dateArr[3] == "" {
+				errinfo.Message = "时间格式不正确"
+				errinfo.Code = -2
+				this.Data["json"] = &errinfo
+				this.ServeJSON()
+				return
+			}
+			trainTime := strings.Split(dateArr[1], "至")
+			applyTimeArr := strings.Split(dateArr[3], "至")
+			endTime := strings.Split(trainTime[1], "日")
+			hseTime.EndTime, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(strings.TrimLeft(endTime[0], " ")), time.Local)
+			startTime := strings.TrimLeft(strings.TrimRight(trainTime[0], "日"), " ")
+			hseTime.StartTime, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(startTime), time.Local)
+			applyTime := strings.TrimRight(applyTimeArr[1], "日")
+			hseTime.ApplyTime, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(applyTime), time.Local)
 			continue
 		}
-		fmt.Println(dateStr)
+
 		var hse hsescore.HSEScore
 		var hseUpdate hsescore.HSEScore
 		var supplier supplier.OilSupplier
@@ -166,6 +191,9 @@ func (this *HSEScoreController) ImportExcel() {
 		if supplierName1 != "" {
 			svc.GetEntityByWhere(HSEScoreName, "SupplierName = '" + supplierName1 + "' and TestNumber = " + sheet.Rows[i].Cells[2].String(), &hseUpdate)
 			if hseUpdate.Id > 0 {
+				hseUpdate.EndTime = hseTime.EndTime
+				hseUpdate.ApplyTime = hseTime.ApplyTime
+				hseUpdate.StartTime = hseTime.StartTime
 				hseUpdate.SupplierId = supplier.Id
 				hseUpdate.Name = sheet.Rows[i].Cells[3].String()
 				hseUpdate.IdNumber = sheet.Rows[i].Cells[4].String()
@@ -178,6 +206,9 @@ func (this *HSEScoreController) ImportExcel() {
 			}
 		}
 		hse.SupplierName = supplierName1
+		hse.EndTime = hseTime.EndTime
+		hse.ApplyTime = hseTime.ApplyTime
+		hse.StartTime = hseTime.StartTime
 		hse.SupplierId = supplier.Id
 		hse.TestNumber,_ = strconv.Atoi(sheet.Rows[i].Cells[2].String())
 		hse.SupplierId = supplier.Id
@@ -197,11 +228,29 @@ func (this *HSEScoreController) ImportExcel() {
 	log.Println(elapsed)
 
 	errinfo.Code = 0
-	errinfo.Message = "导入成功,其中" + strings.TrimRight(supplierNameStr, ",") + "这些公司找不到对应,请手动新增!"
+	errinfo.Message = "导入成功,其中" + supplierNameStr + "这些公司找不到对应,请手动新增!"
 	this.Data["json"] = &errinfo
 	this.ServeJSON()
 }
 
+// excel日期字段格式化 yyyy-mm-dd
+func convertToFormatDay(excelDaysString string) string {
+	if strings.Index(excelDaysString, "-") != -1 {
+		arr := strings.Split(excelDaysString, "-")
+		if len(arr) == 3 {
+			if len(arr[1]) == 1 {
+				arr[1] = "0" + arr[1]
+			}
+			if len(arr[2]) == 1 {
+				arr[2] = "0" + arr[2]
+			}
+			excelDaysString = strings.Join(arr, "-")
+		}
+		return excelDaysString
+	}
+	return ""
+}
+
 // @Title 获取企业列表
 // @Description GetList
 // @Success 200 {object}

+ 64 - 21
src/dashoo.cn/frontend_web/src/pages/select/hsescore/index.vue

@@ -94,9 +94,14 @@
           </template>
         </el-table-column>
         <el-table-column label="考试成绩" width="120px" prop="Score" sortable align="center"></el-table-column>
-        <el-table-column label="培训日期" width="120px" prop="TrainTime" sortable align="center">
+        <el-table-column label="培训开始日期" width="120px" prop="StartTime" sortable align="center">
           <template slot-scope="scope">
-            {{ jstimehandle(scope.row.TrainTime+'') }}
+            {{ jstimehandle(scope.row.StartTime+'') }}
+          </template>
+        </el-table-column>
+        <el-table-column label="培训结束日期" width="120px" prop="EndTime" sortable align="center">
+          <template slot-scope="scope">
+            {{ jstimehandle(scope.row.EndTime+'') }}
           </template>
         </el-table-column>
       </el-table>
@@ -141,9 +146,21 @@
             </el-form-item>
           </el-col>
           <el-col :span="24">
-            <el-form-item label="培训日期" prop="TrainTime">
+            <el-form-item label="开始日期" prop="StartTime">
+              <el-date-picker
+                v-model="updateData.StartTime"
+                type="date"
+                format="yyyy 年 MM 月 dd 日"
+                value-format="yyyy-MM-dd"
+                placeholder="选择培训日期"
+                style="width: 100%"
+              ></el-date-picker>
+            </el-form-item>
+          </el-col>
+          <el-col :span="24">
+            <el-form-item label="结束日期" prop="EndTime">
               <el-date-picker
-                v-model="updateData.TrainTime"
+                v-model="updateData.EndTime"
                 type="date"
                 format="yyyy 年 MM 月 dd 日"
                 value-format="yyyy-MM-dd"
@@ -159,7 +176,7 @@
         <el-button type="primary" @click="addOrUpdate()" :loading="addLoading">确 定</el-button>
       </span>
     </el-dialog>
-    <el-dialog title="上传文件" :close-on-click-modal="false" width="600px" :visible.sync="uploadshow">
+    <el-dialog title="上传文件" :close-on-click-modal="false" width="600px" :visible.sync="uploadShow">
       <el-form label-width="100px">
         <el-row>
           <el-col :span="24">
@@ -214,7 +231,14 @@ export default {
     }
     const validDate = (rule, value, callback) => {
       if (!value || !value[0] || !value[1]) {
-        callback(new Error('请选择培训日期'))
+        callback(new Error('请选择培训开始日期'))
+      } else {
+        callback()
+      }
+    }
+    const validStartDate = (rule, value, callback) => {
+      if (!value || !value[0] || !value[1]) {
+        callback(new Error('请选择培训结束日期'))
       } else {
         callback()
       }
@@ -222,7 +246,7 @@ export default {
     return {
       title: '',
       disabled: false,
-      uploadshow: false,
+      uploadShow: false,
       id: 0,
       addDialog: false,
       tableLoading: false,
@@ -241,9 +265,12 @@ export default {
         Name: [
           {required: true, message: '请填写姓名', trigger: 'blur'}
         ],
-        TrainTime: [
+        StartTime: [
           {required: true, validator: validDate, trigger: 'blur'}
         ],
+        EndTime: [
+          {required: true, validator: validStartDate, trigger: 'blur'}
+        ],
         IdNumber: [
           {required: true, validator: checkIdNumber, trigger: 'change'}
         ]
@@ -264,7 +291,8 @@ export default {
         Name: '',
         IdNumber: '',
         Score: 0,
-        TrainTime: '',
+        StartTime: '',
+        EndTime: '',
         ApplyTime: ''
       },
       // 列表排序
@@ -290,12 +318,27 @@ export default {
       this.$refs['EntityForm'].validate((valid) => {
         if (valid) {
           console.log(this.updateData, 'this.updateData----')
-          if (this.updateData.TrainTime.length === 10) {
-            this.updateData.TrainTime += 'T00:00:00+08:00'
+          if (this.updateData.EndTime <=  this.updateData.StartTime) {
+            this.$message({
+              duration: 10000,
+              type: 'warning',
+              message: '培训结束日期需要大于开始日期'
+            })
+            return
+          }
+          if (this.updateData.StartTime.length === 10) {
+            this.updateData.StartTime += 'T00:00:00+08:00'
           }
-          const timeArr = this.updateData.TrainTime.split('T')
+          if (this.updateData.EndTime.length === 10) {
+            this.updateData.EndTime += 'T00:00:00+08:00'
+          }
+          const timeArr = this.updateData.EndTime.split('T')
           const timeArr1 = timeArr[0].split('-')
-          this.updateData.ApplyTime = timeArr1[0] + '-12-31T' + timeArr[1]
+          if (parseInt(timeArr1[1]) >= 6) {
+            this.updateData.ApplyTime = timeArr1[0] + '-12-31T' + timeArr[1]
+          } else {
+            this.updateData.ApplyTime = timeArr1[0] + '-06-30T' + timeArr[1]
+          }
           this.addLoading = true
           if (this.status) {
             hseApi.updateHSE(this.id, this.updateData, this.$axios).then(res => {
@@ -320,8 +363,7 @@ export default {
                 console.error(err)
               })
           } else {
-            hseApi.addHSE(this.updateData, this.$axios)
-              .then(res => {
+            hseApi.addHSE(this.updateData, this.$axios).then(res => {
                 if (res.data.code === 0) {
                   // 刷新列表
                   this.initDatas()
@@ -339,8 +381,7 @@ export default {
                   })
                 }
                 this.addLoading = false
-              })
-              .catch(err => {
+              }).catch(err => {
                 console.error(err)
               })
           }
@@ -350,12 +391,12 @@ export default {
       })
     },
     importExcel() {
-      this.uploadshow = true
+      this.uploadShow = true
     },
     // 导入
     uploadExcel () {
       this.importLoading = true
-      this.uploadshow = false
+      this.uploadShow = false
       let params = {
         ExcelUrl: this.Excelurl
       }
@@ -377,13 +418,15 @@ export default {
       this.updateData.Name = ''
       this.updateData.Score = 0
       this.updateData.SupplierId = ''
-      this.updateData.TrainTime = ''
+      this.updateData.StartTime = ''
+      this.updateData.EndTime = ''
     },
     update(row) {
       this.title = '修改'
       this.addDialog = true
       this.status = true
-      this.updateData.TrainTime = row.TrainTime
+      this.updateData.StartTime = row.StartTime
+      this.updateData.EndTime = row.EndTime
       this.updateData.SupplierId = row.SupplierId
       this.updateData.Score = row.Score
       this.updateData.IdNumber = row.IdNumber