@ -6,6 +6,7 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.json.JSONUtil ;
import cn.hutool.json.JSONUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils ;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
@ -43,13 +44,12 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService ;
import me.chanjar.weixin.mp.api.WxMpService ;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket ;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.web.bind.annotation.* ;
import org.springframework.web.bind.annotation.* ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletRequest ;
import javax.validation.constraints.NotBlank ;
import javax.validation.constraints.NotBlank ;
import java.util.Date ;
import java.util.* ;
import java.util.List ;
import java.util.Set ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
/ * *
/ * *
@ -65,6 +65,8 @@ public class UserProjectController {
private final UserProjectService projectService ;
private final UserProjectService projectService ;
private final UserProjectItemService projectItemService ;
private final UserProjectItemService projectItemService ;
private final UserProjectResultService projectResultService ;
private final UserProjectResultService projectResultService ;
private final UserProjectLogicService projectLogicService ;
private final ProjectTemplateLogicService templateLogicService ;
private final SortUtils sortUtils ;
private final SortUtils sortUtils ;
private final UserProjectThemeService userProjectThemeService ;
private final UserProjectThemeService userProjectThemeService ;
private final UserProjectSettingService userProjectSettingService ;
private final UserProjectSettingService userProjectSettingService ;
@ -96,11 +98,15 @@ public class UserProjectController {
* 从模板创建项目
* 从模板创建项目
* /
* /
@Login
@Login
@Transactional ( rollbackFor = Exception . class )
@PostMapping ( "/user/project/use-template/create" )
@PostMapping ( "/user/project/use-template/create" )
public Result createProjectByTemplate ( @RequestBody ProjectTemplateEntity request , @RequestAttribute String userId ) {
public Result createProjectByTemplate ( @RequestBody ProjectTemplateEntity request , @RequestAttribute String userId ) {
String templateKey = request . getKey ( ) ;
String templateKey = request . getKey ( ) ;
ProjectTemplateEntity projectTemplateEntity = projectTemplateService . getByKey ( templateKey ) ;
ProjectTemplateEntity projectTemplateEntity = projectTemplateService . getByKey ( templateKey ) ;
List < ProjectTemplateItemEntity > projectTemplateItemEntities = projectTemplateItemService . listByTemplateKey ( templateKey ) ;
List < ProjectTemplateItemEntity > projectTemplateItemEntities = projectTemplateItemService . listByTemplateKey ( templateKey ) ;
// 生成项目主信息
UserProjectEntity userProjectEntity = new UserProjectEntity ( ) ;
UserProjectEntity userProjectEntity = new UserProjectEntity ( ) ;
BeanUtil . copyProperties ( projectTemplateEntity , userProjectEntity , UserProjectEntity . Fields . status ) ;
BeanUtil . copyProperties ( projectTemplateEntity , userProjectEntity , UserProjectEntity . Fields . status ) ;
userProjectEntity . setId ( null ) ;
userProjectEntity . setId ( null ) ;
@ -112,11 +118,40 @@ public class UserProjectController {
// 名称后面追加一个时间
// 名称后面追加一个时间
userProjectEntity . setName ( userProjectEntity . getName ( ) . concat ( String . format ( "(%s)" , DateUtil . format ( new Date ( ) , "yyyy-MM-dd" ) ) ) ) ;
userProjectEntity . setName ( userProjectEntity . getName ( ) . concat ( String . format ( "(%s)" , DateUtil . format ( new Date ( ) , "yyyy-MM-dd" ) ) ) ) ;
projectService . save ( userProjectEntity ) ;
projectService . save ( userProjectEntity ) ;
// 生成项目题目信息
List < UserProjectItemEntity > userProjectItemEntityList = JsonUtils . jsonToList ( JsonUtils . objToJson ( projectTemplateItemEntities ) , UserProjectItemEntity . class ) ;
List < UserProjectItemEntity > userProjectItemEntityList = JsonUtils . jsonToList ( JsonUtils . objToJson ( projectTemplateItemEntities ) , UserProjectItemEntity . class ) ;
userProjectItemEntityList . forEach ( item - > {
userProjectItemEntityList . forEach ( item - > {
item . setId ( null ) ;
item . setId ( null ) ;
item . setProjectKey ( userProjectEntity . getKey ( ) ) ; } ) ;
item . setProjectKey ( userProjectEntity . getKey ( ) ) ; } ) ;
projectItemService . saveBatch ( userProjectItemEntityList ) ;
projectItemService . saveBatch ( userProjectItemEntityList ) ;
// 生成逻辑信息
List < ProjectTemplateLogicEntity > templateLogics =
templateLogicService . list ( new LambdaQueryWrapper < ProjectTemplateLogicEntity > ( ) . eq ( ProjectTemplateLogicEntity : : getProjectKey , request . getKey ( ) ) ) ;
List < UserProjectLogicEntity > logics = templateLogics . stream ( ) . map ( l - > {
// 转化condition
HashSet < UserProjectLogicEntity . Condition > conditions = new HashSet < > ( ) ;
Set < ProjectTemplateLogicEntity . Condition > conditionSource = l . getConditionList ( ) ;
for ( Object e : conditionSource ) {
UserProjectLogicEntity . Condition userProjectCondition = JsonUtils . mapToObj ( ( LinkedHashMap ) e , UserProjectLogicEntity . Condition . class ) ;
conditions . add ( userProjectCondition ) ;
}
UserProjectLogicEntity userLogicEntity = new UserProjectLogicEntity ( ) ;
userLogicEntity . setProjectKey ( userProjectEntity . getKey ( ) ) ;
userLogicEntity . setExpression ( l . getExpression ( ) ) ;
userLogicEntity . setConditionList ( conditions ) ;
userLogicEntity . setFormItemId ( l . getFormItemId ( ) ) ;
return userLogicEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
projectLogicService . saveBatch ( logics ) ;
return Result . success ( userProjectEntity . getKey ( ) ) ;
return Result . success ( userProjectEntity . getKey ( ) ) ;
}
}
@ -130,21 +165,53 @@ public class UserProjectController {
* /
* /
@Login
@Login
@PostMapping ( "/user/project/template/save" )
@PostMapping ( "/user/project/template/save" )
@Transactional ( rollbackFor = Exception . class )
public Result saveAsProjectTemplate ( @RequestBody UserProjectEntity request , @RequestAttribute String userId ) {
public Result saveAsProjectTemplate ( @RequestBody UserProjectEntity request , @RequestAttribute String userId ) {
UserProjectEntity projectEntity = projectService . getByKey ( request . getKey ( ) ) ;
UserProjectEntity projectEntity = projectService . getByKey ( request . getKey ( ) ) ;
List < UserProjectItemEntity > itemEntityList = projectItemService . listByProjectKey ( request . getKey ( ) ) ;
List < UserProjectItemEntity > itemEntityList = projectItemService . listByProjectKey ( request . getKey ( ) ) ;
/** ==================== 保存模板信息 ================================= */
ProjectTemplateEntity projectTemplateEntity = new ProjectTemplateEntity ( ) ;
ProjectTemplateEntity projectTemplateEntity = new ProjectTemplateEntity ( ) ;
BeanUtil . copyProperties ( projectEntity , projectTemplateEntity , UserProjectEntity . Fields . status ) ;
BeanUtil . copyProperties ( projectEntity , projectTemplateEntity , UserProjectEntity . Fields . status ) ;
projectTemplateEntity . setId ( null ) ;
projectTemplateEntity . setId ( null ) ;
projectTemplateEntity . setKey ( IdUtil . fastSimpleUUID ( ) ) ;
projectTemplateEntity . setKey ( IdUtil . fastSimpleUUID ( ) ) ;
projectTemplateEntity . setCategoryId ( CommonConstants . ConstantNumber . FOUR . longValue ( ) ) ;
projectTemplateEntity . setCategoryId ( CommonConstants . ConstantNumber . FOUR . longValue ( ) ) ;
projectTemplateService . save ( projectTemplateEntity ) ;
projectTemplateService . save ( projectTemplateEntity ) ;
/** ==================== 保存问题列表 ================================= */
List < ProjectTemplateItemEntity > projectTemplateItemList = JsonUtils . jsonToList ( JsonUtils . objToJson ( itemEntityList ) , ProjectTemplateItemEntity . class ) ;
List < ProjectTemplateItemEntity > projectTemplateItemList = JsonUtils . jsonToList ( JsonUtils . objToJson ( itemEntityList ) , ProjectTemplateItemEntity . class ) ;
projectTemplateItemList . forEach ( item - > {
projectTemplateItemList . forEach ( item - > {
item . setId ( null ) ;
item . setId ( null ) ;
item . setProjectKey ( projectTemplateEntity . getKey ( ) ) ;
item . setProjectKey ( projectTemplateEntity . getKey ( ) ) ;
} ) ;
} ) ;
projectTemplateItemService . saveBatch ( projectTemplateItemList ) ;
projectTemplateItemService . saveBatch ( projectTemplateItemList ) ;
/** ==================== 保存逻辑.将project逻辑转化为template逻辑,然后存入 ================================= */
List < UserProjectLogicEntity > projectLogics =
projectLogicService . list ( new LambdaQueryWrapper < UserProjectLogicEntity > ( ) . eq ( UserProjectLogicEntity : : getProjectKey , request . getKey ( ) ) ) ;
List < ProjectTemplateLogicEntity > logics = projectLogics . stream ( ) . map ( l - > {
// 转化condition
HashSet < ProjectTemplateLogicEntity . Condition > conditions = new HashSet < > ( ) ;
Set < UserProjectLogicEntity . Condition > conditionSource = l . getConditionList ( ) ;
for ( Object e : conditionSource ) {
ProjectTemplateLogicEntity . Condition templateCondition = JsonUtils . mapToObj ( ( LinkedHashMap ) e , ProjectTemplateLogicEntity . Condition . class ) ;
conditions . add ( templateCondition ) ;
}
ProjectTemplateLogicEntity templateLogEntity = new ProjectTemplateLogicEntity ( ) ;
templateLogEntity . setProjectKey ( projectTemplateEntity . getKey ( ) ) ;
templateLogEntity . setExpression ( l . getExpression ( ) ) ;
templateLogEntity . setConditionList ( conditions ) ;
templateLogEntity . setFormItemId ( l . getFormItemId ( ) ) ;
return templateLogEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
templateLogicService . saveBatch ( logics ) ;
return Result . success ( projectTemplateEntity . getKey ( ) ) ;
return Result . success ( projectTemplateEntity . getKey ( ) ) ;
}
}