|
|
@@ -1,8 +1,11 @@
|
|
|
package contractSumScore
|
|
|
|
|
|
import (
|
|
|
+ "dashoo.cn/backend/api/controllers"
|
|
|
. "dashoo.cn/backend/api/mydb"
|
|
|
+ "dashoo.cn/utils"
|
|
|
"github.com/go-xorm/xorm"
|
|
|
+ "strconv"
|
|
|
)
|
|
|
|
|
|
type OilContractSumScoreService struct {
|
|
|
@@ -14,3 +17,54 @@ func GetOilContractSumScoreService(xormEngine *xorm.Engine) *OilContractSumScore
|
|
|
s.DBE = xormEngine
|
|
|
return s
|
|
|
}
|
|
|
+
|
|
|
+func (s *OilContractSumScoreService) GetPagingComputeEntitiesWithOrderBytbl(pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
|
|
|
+ var resultsSlice []map[string][]byte
|
|
|
+ //获取总记录数
|
|
|
+ sqlCount := ` select count(*) from ( `
|
|
|
+ sqlCount += ` select contract.SupplierId from ` + controllers.OilContractReviewName + ` review `
|
|
|
+ sqlCount += ` left join ` + controllers.OilContractName + ` contract on review.ContractId=contract.id `
|
|
|
+ sqlCount += ` left join ` + controllers.OilContractEvaluationItemsName + ` items on items.ContentReviewId=review.id and items.LevelCode=1 `
|
|
|
+ sqlCount += ` where ` + where
|
|
|
+ sqlCount += ` group by contract.SupplierId,contract.SupplierName `
|
|
|
+ sqlCount += ` ) t `
|
|
|
+
|
|
|
+ var sql string
|
|
|
+ sql = `select contract.SupplierId,contract.SupplierName,sum(items.Score) as Score, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('1') then items.Score else 0 end) Score1, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('2') then items.Score else 0 end) Score2, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('3') then items.Score else 0 end) Score3, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('4') then items.Score else 0 end) Score4, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('5') then items.Score else 0 end) Score5, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('6') then items.Score else 0 end) Score6, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('7') then items.Score else 0 end) Score7, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('8') then items.Score else 0 end) Score8, `
|
|
|
+ sql += ` sum(case when items.SequenceNo in ('9') then items.Score else 0 end) Score9, `
|
|
|
+ sql += ` case when sum(items.Score) <60 then '不合格' when sum(items.Score) <80 then '合格' else '优秀' end as Evaluate `
|
|
|
+ sql += ` from ` + controllers.OilContractReviewName + ` review `
|
|
|
+ sql += ` left join ` + controllers.OilContractName + ` contract on review.ContractId=contract.id `
|
|
|
+ sql += ` left join ` + controllers.OilContractEvaluationItemsName + ` items on items.ContentReviewId=review.id and items.LevelCode=1 `
|
|
|
+ sql += ` where ` + where
|
|
|
+ sql += ` group by contract.SupplierId,contract.SupplierName `
|
|
|
+
|
|
|
+ if asc {
|
|
|
+ sql += ` order by ` + orderby + ` ASC `
|
|
|
+ } else {
|
|
|
+ sql += ` order by ` + orderby + ` DESC `
|
|
|
+ }
|
|
|
+ if (pageIndex != 0 && itemsPerPage !=0) {
|
|
|
+ sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
|
|
|
+ }
|
|
|
+
|
|
|
+ s.DBE.SQL(sql).Find(entitiesPtr)
|
|
|
+ resultsSlice, _ = s.DBE.Query(sqlCount)
|
|
|
+ if len(resultsSlice) > 0 {
|
|
|
+ results := resultsSlice[0]
|
|
|
+ for _, value := range results {
|
|
|
+ total, _ = strconv.ParseInt(string(value), 10, 64)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return total
|
|
|
+}
|
|
|
+
|