增加版本管理

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2019-06-22 21:49:20 +08:00
parent c5e88307bd
commit 488cc3c24e
5 changed files with 480 additions and 0 deletions

@ -0,0 +1,72 @@
<?php
namespace app\common\Model;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
/**
* 版本库
* Class ProjectFeatures
* @package app\common\Model
*/
class ProjectFeatures extends CommonModel
{
protected $append = [];
/**
* 创建版本库
* @param $name
* @param $description
* @param $projectCode
* @param $organizationCode
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function createData($name, $description, $projectCode, $organizationCode)
{
if (!$name) {
return error(1, '请填写版本库名称');
}
$project = Project::where(['code' => $projectCode, 'deleted' => 0])->field('id')->find();
if (!$project) {
return error(3, '该项目已失效');
}
$features = self::where(['name' => $name, 'project_code' => $projectCode])->find();
if ($features) {
return error(2, '该版本库已名称存在');
}
$data = [
'create_time' => nowTime(),
'code' => createUniqueCode('ProjectFeatures'),
'project_code' => $projectCode,
'description' => $description,
'organization_code' => $organizationCode,
'name' => trim($name),
];
$result = self::create($data)->toArray();
return $result;
}
/**
* 删除版本库
* @param $featuresCode
* @return array|bool
* @throws Exception
* @throws PDOException
*/
public function deleteProjectFeatures($featuresCode)
{
if (!$featuresCode) {
return error(1, '请选择一个版本库');
}
self::where(['code' => $featuresCode])->delete();
Task::update(['features_code' => '', 'version_code' => ''], ['features_code' => $featuresCode]);
return true;
}
}

@ -0,0 +1,111 @@
<?php
namespace app\common\Model;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
/**
* 版本
* Class ProjectFeatures
* @package app\common\Model
*/
class ProjectVersion extends CommonModel
{
protected $append = ['statusText'];
/**
* 创建版本
* @param $featuresCode
* @param $name
* @param $description
* @param $projectCode
* @param $organizationCode
* @param $startTime
* @param string $planPublishTime
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function createData($featuresCode, $name, $description, $organizationCode, $startTime, $planPublishTime = '')
{
if (!$name) {
return error(1, '请填写版本名称');
}
$projectFeatures = ProjectFeatures::where(['code' => $featuresCode])->field('id')->find();
if (!$projectFeatures) {
return error(3, '该版本库已失效');
}
$version = self::where(['name' => $name, 'features_code' => $featuresCode])->find();
if ($version) {
return error(2, '该版本已名称存在');
}
$data = [
'create_time' => nowTime(),
'code' => createUniqueCode('ProjectVersion'),
'features_code' => $featuresCode,
'start_time' => $startTime,
'plan_publish_time' => $planPublishTime,
'description' => $description,
'organization_code' => $organizationCode,
'name' => trim($name),
];
$result = self::create($data)->toArray();
return $result;
}
/**
* 删除版本
* @param $featuresCode
* @return array|bool
* @throws Exception
* @throws PDOException
*/
public function deleteProjectVersion($versionCode)
{
if (!$versionCode) {
return error(1, '请选择一个版本');
}
self::where(['code' => $versionCode])->delete();
Task::update(['features_code' => '', 'version_code' => ''], ['version_code' => $versionCode]);
return true;
}
public function changeStatus($versionCode, $status, $publishTime = '')
{
if (!$versionCode) {
return error(1, '请选择一个版本');
}
$updateData = ['status' => $status];
if ($status == 3) {
$updateData['publish_time'] = $publishTime;
}
self::update($updateData, ['code' => $versionCode]);
return true;
}
public function getStatusTextAttr($value, $data)
{
//状态。0未开始1进行中2延期发布3已发布
if (!isset($data['status'])) {
return '-';
}
switch ($data['status']) {
case 0:
return '未开始';
case 1:
return '进行中';
case 2:
return '延期发布';
case 3:
return '已发布';
}
}
}

@ -0,0 +1,8 @@
<?php
namespace app\common\Model;
class ProjectVersionLog extends CommonModel
{
protected $pk = 'id';
}

@ -0,0 +1,116 @@
<?php
namespace app\project\controller;
use controller\BasicApi;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\facade\Request;
/**
*/
class ProjectFeatures extends BasicApi
{
public function __construct()
{
parent::__construct();
if (!$this->model) {
$this->model = new \app\common\Model\ProjectFeatures();
}
}
/**
* 显示资源版本库
* @return void
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function index()
{
$where = [];
$code = Request::post('projectCode');
if (!$code) {
$this->error("请选择一个项目");
}
$where[] = ['project_code', '=', $code];
// $list = $this->model->_list($where, 'sort asc,id asc');
$list = $this->model->where($where)->order('id desc')->select()->toArray();
$this->success('', $list);
}
/**
* 新增
* @param Request $request
* @return void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function save(Request $request)
{
$data = $request::only('name,projectCode,description');
if (!$request::post('name')) {
$this->error("请填写版本库名称");
}
$result = $this->model->createData($data['name'], $data['description'], $data['projectCode'], getCurrentOrganizationCode());
if (!isError($result)) {
$this->success('添加成功', $result);
}
$this->error($result['msg']);
}
/**
* 保存
* @param Request $request
* @return void
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function edit(Request $request)
{
$data = $request::only('name,description,featuresCode');
if (!$request::post('name')) {
$this->error("请填写版本库名称");
}
if (!$data['featuresCode']) {
$this->error("请选择一个版本库");
}
$features = $this->model->where(['code' => $data['featuresCode']])->field('id,project_code')->find();
if (!$features) {
$this->error("该版本库已失效");
}
$has = $this->model->where(['name' => $data['name'], 'project_code' => $features['project_code']])->field('id')->find();
if ($has && $has['id'] != $features['id']) {
$this->error("该版本库名称已存在");
}
$result = $this->model->_edit(['name' => $data['name'], 'description' => $data['description']], ['code' => $data['featuresCode']]);
if ($result) {
$this->success('');
}
$this->error("操作失败,请稍候再试!");
}
/**
* 删除版本库
* @return void
* @throws Exception
* @throws PDOException
*/
public function delete()
{
$code = Request::post('featuresCode');
if (!$code) {
$this->error("请选择一个版本库");
}
$result = $this->model->deleteProjectFeatures($code);
if (isError($result)) {
$this->error($result['msg'], $result['errno']);
}
$this->success();
}
}

@ -0,0 +1,173 @@
<?php
namespace app\project\controller;
use app\common\Model\Member;
use app\common\Model\ProjectVersionLog;
use controller\BasicApi;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\facade\Request;
/**
*/
class ProjectVersion extends BasicApi
{
public function __construct()
{
parent::__construct();
if (!$this->model) {
$this->model = new \app\common\Model\ProjectVersion();
}
}
/**
* 显示资源版本
* @return void
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function index()
{
$where = [];
$code = Request::post('projectFeaturesCode');
if (!$code) {
$this->error("请选择一个版本库");
}
$where[] = ['features_code', '=', $code];
$list = $this->model->where($where)->order('id asc')->select()->toArray();
$this->success('', $list);
}
/**
* 新增
* @param Request $request
* @return void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function save(Request $request)
{
$data = $request::only('featuresCode,name,description,projectCode,startTime,planPublishTime');
if (!$request::post('name')) {
$this->error("请填写版本名称");
}
$result = $this->model->createData($data['featuresCode'], $data['name'], $data['description'], getCurrentOrganizationCode(), $data['startTime'], $data['planPublishTime']);
if (!isError($result)) {
$this->success('添加成功', $result);
}
$this->error($result['msg']);
}
/**
* 保存
* @param Request $request
* @return void
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function edit(Request $request)
{
$data = $request::only('name,description,start_time,plan_publish_time');
$versionCode = $request::param('versionCode');
if (isset($data['name']) && !$data['name']) {
$this->error("请填写版本名称");
}
if (!$versionCode) {
$this->error("请选择一个版本");
}
$version = $this->model->where(['code' => $versionCode])->field('id,features_code')->find();
if (!$version) {
$this->error("该版本已失效");
}
if (isset($data['name'])) {
$has = $this->model->where(['name' => $data['name'], 'features_code' => $version['features_code']])->field('id')->find();
if ($has && $has['id'] != $version['id']) {
$this->error("该版本名称已存在");
}
}
$result = $this->model->_edit($data, ['code' => $versionCode]);
if ($result) {
$this->success('');
}
$this->error("操作失败,请稍候再试!");
}
/**
* 更改状态
*/
public function changeStatus()
{
$code = Request::post('versionCode');
$status = Request::post('status', '');
$publishTime = Request::post('publishTime', '');
$result = $this->model->changeStatus($code, $status, $publishTime);
if (isError($result)) {
$this->error($result['msg'], $result['errno']);
}
$this->success();
}
/**
* 详情
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function read()
{
$code = Request::post('versionCode');
$version = $this->model->where(['code' => $code])->field('id', true)->find();
if ($version) {
$version['featureName'] = \app\common\Model\ProjectFeatures::where(['code' => $version['features_code']])->find();
$version['featureName'] && $version['featureName'] = $version['featureName']['name'];
}
$this->success('', $version);
}
public function _getVersionTask()
{
$code = Request::post('versionCode');
$taskList = \app\common\Model\Task::where(['version_code' => $code, 'deleted' => 0])->field('id', true)->select();
$this->success('', $taskList);
}
public function _getVersionLog()
{
$code = Request::post('versionCode');
$logList = ProjectVersionLog::where(['source_code' => $code])->field('id', true)->select();
if ($logList) {
foreach ($logList as &$item) {
$member = Member::where(['code' => $item['member_code']])->field('id,name,avatar,code')->find();
!$member && $member = [];
$item['member'] = $member;
}
}
$this->success('', $logList);
}
/**
* 删除版本
* @return void
* @throws Exception
* @throws PDOException
*/
public function delete()
{
$code = Request::post('versionCode');
if (!$code) {
$this->error("请选择一个版本");
}
$result = $this->model->deleteProjectVersion($code);
if (isError($result)) {
$this->error($result['msg'], $result['errno']);
}
$this->success();
}
}