123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- package service
-
- import (
- "XT_New/models"
- "XT_New/utils"
- "fmt"
- "github.com/jinzhu/gorm"
- "math/rand"
- "time"
- )
-
- //生成编号,规则为:"SH-"+4位随机数
- func CreateCode() string {
- s := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000))
- code := "SH-" + s
- return code
- }
-
- //查询编号是否重复
- func FindStorehouseCode(orgid int64, code string) bool {
- var total int
- XTReadDB().Model(&models.Storehouse{}).Where(" storehouse_code = ? and user_org_id = ? and status = 1", code, orgid).Count(&total)
- if total > 0 {
- return true
- } else {
- return false
- }
- }
-
- //判断仓库的库存是否为零 true为零,false不为零
- func IsStorehouseNil(id, orgid int64) bool { //根据 id gro_id 查为零的库存
- var h, y int
- //判断耗材是否为零
- XTReadDB().Model(&models.WarehousingInfo{}).Where("stock_count > 0 and status = 1 and org_id = ? and storehouse_id = ?", orgid, id).Count(&h)
- if h > 0 {
- return false
- }
- //判断药品是否为零
- XTReadDB().Model(&models.XtDrugWarehouseInfo{}).Where("stock_max_number > 0 or stock_min_number > 0 ").Where(" org_id = ? and storehouse_id = ?", orgid, id).Count(&y)
- if y > 0 {
- return false
- }
- return true
- }
-
- //修改仓库状态
- func UpdateStorehouseStatus(id int64) error {
- err := XTWriteDB().Exec("UPDATE xt_storehouse,(SELECT CASE storehouse_status WHEN 1 THEN 0 WHEN 0 THEN 1 END AS tt FROM xt_storehouse WHERE id=?)tmp SET storehouse_status = tmp.tt where id=?", id, id).Error
- return err
- }
-
- //删除仓库
- func DeleteStorehouse(id int64) error {
- err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ?", id).Update("status", 0).Error
- return err
- }
-
- //查询仓库名称是否重复
- func IsStorehouseName(orgid int64, storehouse_name string) (bool, error) {
- var total int
- var tmp bool
- err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1", storehouse_name, orgid).Count(&total).Error
- if total > 0 {
- tmp = true //有重复的
- } else {
- tmp = false
- }
- return tmp, err
- }
-
- //查询仓库地址是否重复
- func IsStorehouseAddress(orgid int64, storehouse_address string) (bool, error) {
- var total int
- var tmp bool
- err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1", storehouse_address, orgid).Count(&total).Error
- if total > 0 {
- tmp = true //有重复的
- } else {
- tmp = false
- }
- return tmp, err
- }
-
- //新增仓库
- func AddStroehouse(storehouse models.Storehouse) error {
- tx := XTWriteDB().Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- //创建仓库
- err := tx.Create(&storehouse).Error
- if err != nil {
- return err
- }
- var id models.Storehouse
- //获取创建仓库的id
- err = tx.Model(&models.Storehouse{}).Select("id").Where("status = 1 and user_org_id = ?", storehouse.UserOrgId).Order("id desc").First(&id).Error
- if err != nil {
- return err
- }
- //判断是否存在仓库配置
- boolean := IsStorehouseconfigXT(storehouse.UserOrgId, tx)
- if boolean == false {
- //创建仓库配置
- err = CreateStorehouseConfigXT(storehouse.UserOrgId, id.ID, tx)
- } else {
- utils.ErrorLog("仓库配置已存在")
- }
-
- return err
- }
-
- //修改仓库
- func UpdateStroehouse(storehouse models.Storehouse) error {
- err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ? and status = 1", storehouse.ID).Updates(
- map[string]interface{}{
- "storehouse_name": storehouse.StorehouseName,
- "storehouse_address": storehouse.StorehouseAddress,
- "storehouse_status": storehouse.StorehouseStatus,
- "mtime": storehouse.Mtime,
- }).Error
- return err
- }
-
- //查询一条仓库的信息
- func GetOneStorehouse(id, orgid int64) (storehouse models.Storehouse, err error) {
- err = XTReadDB().Model(&models.Storehouse{}).Where("id = ? and user_org_id = ?", id, orgid).Find(&storehouse).Error
- return
- }
-
- //分页
- func StorehouseList(page, limit, orgid int64, keyword string) (storehouse []models.Storehouse, total int64, err error) {
- db := XTReadDB().Model(&storehouse).Where("status = 1 and user_org_id = ?", orgid)
- offset := (page - 1) * limit
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Where("storehouse_code like ? or storehouse_name like ? or storehouse_address like ? or storehouse_admin_name like ?", keyword, keyword, keyword, keyword)
- }
- err = db.Count(&total).Offset(offset).Order("id").Limit(limit).Find(&storehouse).Error
- return storehouse, total, err
- }
-
- //获取当前机构所有可用的仓库名字
- func GetAllStorehouseName(orgid int64) (storehouse []models.Storehouse, err error) {
- err = XTReadDB().Model(&models.Storehouse{}).Where("storehouse_status = 1 and status = 1 and user_org_id = ?", orgid).Find(&storehouse).Error
- return
- }
-
- //根据机构id,生成一个默认仓库
- func GetDefaultStorehouse(orgid int64) error {
- var code string
- for a := true; a == true; {
- code = CreateCode()
- tmp := FindStorehouseCode(orgid, code)
- //如果没有重复的编码结束循环
- if tmp == false {
- a = false
- }
- }
- storehouse := models.Storehouse{
- StorehouseCode: code,
- StorehouseName: "默认仓库",
- StorehouseAddress: "",
- StorehouseStatus: 1,
- UserOrgId: orgid,
- StorehouseAdminName: "admin",
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- err := AddStroehouse(storehouse)
- return err
- }
-
- //查找该机构id是否有仓库存在,ture存在,false不存在
- func IsStorehouse(orgid int64) bool {
- var total int
- XTReadDB().Model(&models.Storehouse{}).Where("user_org_id = ?", orgid).Count(&total)
- if total > 0 {
- return true
- } else {
- return false
- }
- }
-
- //查找该机构id是否有仓库配置存在,ture存在,false不存在
- func IsStorehouseconfigXT(orgid int64, tx *gorm.DB) bool {
- var total int
- tx.Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Count(&total)
- if total > 0 {
- return true
- } else {
- return false
- }
- }
-
- // 根据机构id查询仓库配置
- //storehouse_info:耗材 自动入库 的仓库id
- //storehouse_out_info:耗材 自动出库 的仓库id
- //drug_storehouse_info:药品 自动入库 的仓库id
- //drug_storehouse_out:药品 自动出库 的仓库id
- func FindStorehouseConfig(orgid int64) (storehouse_config models.StorehouseConfig, err error) {
- err = XTReadDB().Model(&models.StorehouseConfig{}).Where("status = 1 and user_org_id = ?", orgid).Find(&storehouse_config).Error
- return
- }
-
- //根据机构id,仓库id新建一个仓库配置
- func CreateStorehouseConfig(orgid, id int64) (err error) {
- storeconfig := models.StorehouseConfig{
- UserOrgId: orgid,
- StorehouseInfo: id,
- StorehouseOutInfo: id,
- DrugStorehouseInfo: id,
- DrugStorehouseOut: id,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- err = XTWriteDB().Create(&storeconfig).Error
- return
- }
-
- //根据机构id,仓库id新建一个仓库配置,带事务
- func CreateStorehouseConfigXT(orgid, id int64, tx *gorm.DB) (err error) {
- storeconfig := models.StorehouseConfig{
- UserOrgId: orgid,
- StorehouseInfo: id,
- StorehouseOutInfo: id,
- DrugStorehouseInfo: id,
- DrugStorehouseOut: id,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- err = tx.Create(&storeconfig).Error
- return
- }
-
- //更改耗材自动入库仓库
- func UpdateInfo(orgid, id int64) (err error) {
- mtime := time.Now().Unix()
- err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_info": id, "mtime": mtime}).Error
- return
- }
-
- //更改耗材自动出库仓库
- func UpdateOutInfo(orgid, id int64) (err error) {
- mtime := time.Now().Unix()
- err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_out_info": id, "mtime": mtime}).Error
- return
- }
-
- //更改药品自动入库仓库
- func UpdateDrugInfo2(orgid, id int64) (err error) {
- mtime := time.Now().Unix()
- err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_info": id, "mtime": mtime}).Error
- return
- }
-
- //更改药品自动出库仓库
- func UpdateDrugOut(orgid, id int64) (err error) {
- mtime := time.Now().Unix()
- err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_out": id, "mtime": mtime}).Error
- return
- }
-
- //根据id查询仓库名称
- func FindStorehouseName(id int64) (storehouse models.Storehouse, err error) {
- err = XTReadDB().Model(&models.Storehouse{}).Where("id = ?", id).Find(&storehouse).Error
- return
- }
-
- //判断该仓库是否在仓库配置表中
- func IsInConfig(orgid, id int64) bool {
- var total int
- XTReadDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Where(
- "storehouse_info = ? or storehouse_out_info = ? or drug_storehouse_info = ? or drug_storehouse_out = ?", id, id, id, id).Count(&total)
- if total > 0 {
- return true //存在
- } else {
- return false
- }
- }
-
- //兼容旧数据
- func Byliinit() (err error) {
- tx := XTWriteDB().Begin()
- defer func() {
- if err != nil && err.Error() != "record not found" {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- err = StoreReduceOrg(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = StoreReduceConfig(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_stock_flow(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_flow(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initdialysis_before_prepare(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_automatic_reduce_detail(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_automatic_reduce_detail(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_warehouse(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_warehouse_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_warehouse_out(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_warehouse_out_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_warehouse(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_warehouse_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_warehouse_out(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_warehouse_out_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_cancel_stock(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_cancel_stock_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_cancel_stock(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_drug_cancel_stock_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehouse_info(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehousing_info_order(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehouse_out(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehousing_out_order(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehouse_cancel(tx)
- if err != nil && err.Error() != "record not found" {
- return
- }
- err = initxt_supplier_warehousing_cancel_order(tx)
-
- return
- }
-
- //根据xt_gobal_template 获取的机构id减去仓库表存在的机构id,把结果插入到仓库表
- func StoreReduceOrg(tx *gorm.DB) (err error) {
- err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
- "SELECT CONCAT(\"SH-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
- "FROM" +
- "(select t1.org_id as id FROM sgj_xt.xt_gobal_template as t1 LEFT JOIN " +
- "(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
- //err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
- // "SELECT CONCAT(\"sh-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
- // "FROM" +
- // "(select t1.id FROM sgj_users.sgj_user_org as t1 LEFT JOIN " +
- // "(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.id = t2.i WHERE t2.i is null and t1.status != 0 and t1.import = 0)tmp").Error
- return
- }
-
- //查找仓库表的orgid 减去仓库配置表的orgid,把结果插入到仓库配置表
- func StoreReduceConfig(tx *gorm.DB) (err error) {
- err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse_config(user_org_id,storehouse_info,storehouse_out_info,drug_storehouse_info,drug_storehouse_out,ctime)" +
- "SELECT tmp.user_org_id,tmp.id,tmp.id,tmp.id,tmp.id,UNIX_TIMESTAMP()" +
- "FROM(select t1.id,t1.user_org_id FROM sgj_xt.xt_storehouse as t1 LEFT JOIN " +
- "(SELECT user_org_id as i FROM sgj_xt.xt_storehouse_config) as t2 on t1.user_org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
- return
- }
-
- //初始化 xt_stock_flow(完成)
- func initxt_stock_flow(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_stock_flow as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_stock_flow WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_flow(完成)
- func initxt_drug_flow(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_flow as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_drug_flow WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 dialysis_before_prepare(完成)
- func initdialysis_before_prepare(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.dialysis_before_prepare as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.dialysis_before_prepare WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_automatic_reduce_detail(完成)
- func initxt_automatic_reduce_detail(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_automatic_reduce_detail as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_automatic_reduce_detail WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_automatic_reduce_detail(完成)
- func initxt_drug_automatic_reduce_detail(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_automatic_reduce_detail as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_automatic_reduce_detail WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_warehouse(完成)
- func initxt_warehouse(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_warehouse as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_warehouse_info(完成)
- func initxt_warehouse_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_warehouse_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_warehouse_out(完成)
- func initxt_warehouse_out(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_warehouse_out_info(完成)
- func initxt_warehouse_out_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_warehouse(完成)
- func initxt_drug_warehouse(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_warehouse_info(完成)
- func initxt_drug_warehouse_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_warehouse_out(完成)
- func initxt_drug_warehouse_out(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_warehouse_out_info(完成)
- func initxt_drug_warehouse_out_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_cancel_stock(完成)
- func initxt_cancel_stock(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_cancel_stock_info(完成)
- func initxt_cancel_stock_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_cancel_stock(完成)
- func initxt_drug_cancel_stock(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_drug_cancel_stock_info(完成)
- func initxt_drug_cancel_stock_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehouse_info(完成)
- func initxt_supplier_warehouse_info(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_info as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_info WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehousing_info_order(完成)
- func initxt_supplier_warehousing_info_order(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_info_order as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_info_order WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehouse_out(完成)
- func initxt_supplier_warehouse_out(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_out as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_out WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehousing_out_order(完成)
- func initxt_supplier_warehousing_out_order(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_out_order as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_out_order WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehouse_cancel(完成)
- func initxt_supplier_warehouse_cancel(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_cancel as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_cancel WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
-
- //初始化 xt_supplier_warehousing_cancel_order(完成)
- func initxt_supplier_warehousing_cancel_order(tx *gorm.DB) (err error) {
- err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_cancel_order as t," +
- "(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
- "(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_cancel_order WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- "WHERE t1.user_org_id = t2.orgid)tmp " +
- "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
- return
- }
|