Browse Source

初始化客户表单配置

master
jianjun 4 years ago
parent
commit
befacc4edd
  1. 4
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/IcFormController.java
  2. 33
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/dao/IcFormQueryBuilderDao.java
  3. 63
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/entity/IcFormQueryBuilderEntity.java
  4. 2
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/IcFormService.java
  5. 136
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcFormServiceImpl.java
  6. 22
      epmet-module/oper-customize/oper-customize-server/src/main/resources/mapper/IcFormQueryBuilderDao.xml

4
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/IcFormController.java

@ -60,12 +60,12 @@ public class IcFormController {
* @date 2021/12/8 4:28 下午
*/
@GetMapping("initCustomerForm/{formCode}")
public Result<String> initCustomerFormByCode(@RequestParam String customerId,
public Result<String> initCustomerFormByCode(@RequestParam String customerId,@RequestParam String areaCode,
@PathVariable(value = "formCode") String formCode){
if (StringUtils.isBlank(customerId)){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"参数错误");
}
return new Result<String>().ok(icFormService.initCustomerFormByCode(customerId,formCode));
return new Result<String>().ok(icFormService.initCustomerFormByCode(customerId, areaCode, formCode));
}
/**

33
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/dao/IcFormQueryBuilderDao.java

@ -0,0 +1,33 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.IcFormQueryBuilderEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 表单查询项
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-12-08
*/
@Mapper
public interface IcFormQueryBuilderDao extends BaseDao<IcFormQueryBuilderEntity> {
}

63
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/entity/IcFormQueryBuilderEntity.java

@ -0,0 +1,63 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 表单查询项
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-12-08
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("ic_form_query_builder")
public class IcFormQueryBuilderEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
* 客户id
*/
private String customerId;
/**
* ic_form_item.id
*/
private String formItemId;
/**
* ic_form.form_code举例resi_base_info
*/
private String formCode;
/**
* 查询类型: equal, like,daterange....
*/
private String queryType;
/**
* 排序
*/
private Integer sort;
}

2
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/IcFormService.java

@ -53,5 +53,5 @@ public interface IcFormService extends BaseService<IcFormEntity> {
*/
List<FormItemResult> listItems(String customerId, String formCode);
String initCustomerFormByCode(String customerId, String formCode);
String initCustomerFormByCode(String customerId, String areaCode, String formCode);
}

136
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcFormServiceImpl.java

@ -17,23 +17,33 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dao.IcFormDao;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.dao.*;
import com.epmet.dto.form.CustomerFormQueryDTO;
import com.epmet.dto.result.CustomerFormResultDTO;
import com.epmet.dto.result.FormGroupDTO;
import com.epmet.dto.result.FormItemResult;
import com.epmet.entity.IcFormEntity;
import com.epmet.entity.*;
import com.epmet.redis.CustomerFootBarRedis;
import com.epmet.service.IcFormService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
/**
@ -42,13 +52,22 @@ import java.util.List;
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
@Slf4j
@Service
public class IcFormServiceImpl extends BaseServiceImpl<IcFormDao, IcFormEntity> implements IcFormService {
@Autowired
private CustomerFootBarRedis customerFootBarRedis;
@Autowired
private CustomerFootBarRedis customerFootBarRedis;
@Autowired
private RedisUtils redisUtils;
@Autowired
private RedisUtils redisUtils;
@Autowired
private IcFormItemDao icFormItemDao;
@Autowired
private IcFormItemOptionsDao icFormItemOptionsDao;
@Autowired
private IcFormItemGroupDao icFormItemGroupDao;
@Autowired
private IcFormQueryBuilderDao icFormQueryBuilderDao;
/**
* 获取居民信息表单
@ -60,19 +79,19 @@ public class IcFormServiceImpl extends BaseServiceImpl<IcFormDao, IcFormEntity>
*/
@Override
public CustomerFormResultDTO getCustomerForm(CustomerFormQueryDTO formDto) {
CustomerFormResultDTO customerFormResultDTO = customerFootBarRedis.getCustomerFormResultDTO(formDto.getFormCode(), formDto.getCustomerId(),formDto.getDynamic());
CustomerFormResultDTO customerFormResultDTO = customerFootBarRedis.getCustomerFormResultDTO(formDto.getFormCode(), formDto.getCustomerId(), formDto.getDynamic());
if (null != customerFormResultDTO) {
return customerFormResultDTO;
}
CustomerFormResultDTO resultDTO=baseDao.selectByCode(formDto.getCustomerId(),formDto.getFormCode());
CustomerFormResultDTO resultDTO = baseDao.selectByCode(formDto.getCustomerId(), formDto.getFormCode());
if (null == resultDTO) {
throw new RenException(EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getCode(),EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getMsg());
throw new RenException(EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getCode(), EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getMsg());
}
List<FormItemResult> itemList=baseDao.selectItemList(resultDTO.getFormId(),formDto.getDynamic());
List<FormGroupDTO> groupList=baseDao.selectListGroup(resultDTO.getFormId());
List<FormItemResult> itemList = baseDao.selectItemList(resultDTO.getFormId(), formDto.getDynamic());
List<FormGroupDTO> groupList = baseDao.selectListGroup(resultDTO.getFormId());
resultDTO.setItemList(itemList);
resultDTO.setGroupList(groupList);
customerFootBarRedis.setCustomerFormResultDTO(formDto.getFormCode(),formDto.getCustomerId(),resultDTO,formDto.getDynamic());
customerFootBarRedis.setCustomerFormResultDTO(formDto.getFormCode(), formDto.getCustomerId(), resultDTO, formDto.getDynamic());
return resultDTO;
}
@ -88,9 +107,9 @@ public class IcFormServiceImpl extends BaseServiceImpl<IcFormDao, IcFormEntity>
}
// 从db取
CustomerFormResultDTO formResultDto=baseDao.selectByCode(customerId, formCode);
CustomerFormResultDTO formResultDto = baseDao.selectByCode(customerId, formCode);
if (null == formResultDto) {
throw new RenException(EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getCode(),EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getMsg());
throw new RenException(EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getCode(), EpmetErrorCode.CUSTOMER_FORM_NOT_EXITS.getMsg());
}
List<FormItemResult> formItemResults = baseDao.listItems(formResultDto.getFormId());
@ -104,15 +123,96 @@ public class IcFormServiceImpl extends BaseServiceImpl<IcFormDao, IcFormEntity>
return formItemResults;
}
@Transactional(rollbackFor = Exception.class)
@Override
public String initCustomerFormByCode(String customerId, String formCode) {
public String initCustomerFormByCode(String customerId, String areaCode, String formCode) {
CustomerFormResultDTO formResultDTO = baseDao.selectByCode(customerId, formCode);
if (formResultDTO == null){
if (formResultDTO != null) {
return "该客户已经存在了表单的数据";
}
CustomerFormResultDTO defaultIcForm = baseDao.selectByCode("default", formCode);
String defaultCustomerId = "default";
LambdaQueryWrapper<IcFormEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IcFormEntity::getCustomerId, defaultCustomerId);
wrapper.eq(IcFormEntity::getFormCode, formCode);
IcFormEntity defaultIcForm = baseDao.selectOne(wrapper);
if (defaultIcForm == null) {
return "默认配置错误";
}
//统一前缀
String newPrefixed = DateUtils.format(new Date(), DateUtils.DATE_TIME_NO_SPLIT) + StrConstant.UNDER_LINE;
String newFormId = newPrefixed + defaultIcForm.getId();
defaultIcForm.setId(newFormId);
defaultIcForm.setAreaCode(areaCode);
int insert = baseDao.insert(defaultIcForm);
log.info("insert icForm:" + insert);
LambdaQueryWrapper<IcFormItemEntity> wrapperItem = new LambdaQueryWrapper<>();
wrapperItem.eq(IcFormItemEntity::getCustomerId, defaultCustomerId);
wrapperItem.eq(IcFormItemEntity::getFormCode, formCode);
List<IcFormItemEntity> itemList = icFormItemDao.selectList(wrapperItem);
if (CollectionUtils.isEmpty(itemList)) {
return "默认配置错误";
}
//设置item
itemList.forEach(item -> {
item.setId(newPrefixed + item.getId());
item.setCustomerId(customerId);
item.setFormId(newFormId);
item.setAreaCode(areaCode);
item.setParentItemId(newPrefixed + item.getParentItemId());
item.setItemGroupId(newPrefixed + item.getItemGroupId());
String optionSourceValue = item.getOptionSourceValue();
if (StringUtils.isNotBlank(optionSourceValue) && optionSourceValue.contains(StrConstant.QUESTION_MARK)){
//多个参数
String[] paramArr = optionSourceValue.split(StrConstant.QUESTION_MARK_TRANSFER)[NumConstant.ONE].split(StrConstant.AND_MARK);
for (String o : paramArr) {
optionSourceValue = optionSourceValue.replace(o, newPrefixed + o);
}
item.setOptionSourceValue(optionSourceValue);
}
log.debug("item:"+ JSON.toJSONString(item));
icFormItemDao.insert(item);
});
LambdaQueryWrapper<IcFormItemOptionsEntity> wrapperOptions = new LambdaQueryWrapper<>();
wrapperOptions.eq(IcFormItemOptionsEntity::getCustomerId, defaultCustomerId);
wrapperOptions.eq(IcFormItemOptionsEntity::getFormCode, formCode);
List<IcFormItemOptionsEntity> optionsList = icFormItemOptionsDao.selectList(wrapperOptions);
optionsList.forEach(item -> {
item.setId(newPrefixed + item.getId());
item.setCustomerId(customerId);
item.setFormId(newFormId);
item.setItemId(newPrefixed + item.getItemId());
log.debug("option:"+ JSON.toJSONString(item));
icFormItemOptionsDao.insert(item);
});
LambdaQueryWrapper<IcFormItemGroupEntity> wrapperGroup = new LambdaQueryWrapper<>();
wrapperGroup.eq(IcFormItemGroupEntity::getCustomerId, defaultCustomerId);
wrapperGroup.eq(IcFormItemGroupEntity::getFormCode, formCode);
List<IcFormItemGroupEntity> groupList = icFormItemGroupDao.selectList(wrapperGroup);
groupList.forEach(item -> {
item.setId(newPrefixed + item.getId());
item.setCustomerId(customerId);
item.setFormId(newFormId);
log.debug("group:"+ JSON.toJSONString(item));
icFormItemGroupDao.insert(item);
});
LambdaQueryWrapper<IcFormQueryBuilderEntity> wrapperQuery = new LambdaQueryWrapper<>();
wrapperQuery.eq(IcFormQueryBuilderEntity::getCustomerId, defaultCustomerId);
wrapperQuery.eq(IcFormQueryBuilderEntity::getFormCode, formCode);
List<IcFormQueryBuilderEntity> queryList = icFormQueryBuilderDao.selectList(wrapperQuery);
queryList.forEach(item -> {
item.setId(newPrefixed + item.getId());
item.setCustomerId(customerId);
item.setFormItemId(newPrefixed + item.getFormItemId());
log.debug("query:"+ JSON.toJSONString(item));
icFormQueryBuilderDao.insert(item);
});
return null;
return "初始化成功!客户ID:" + customerId + " formCode:" + formCode;
}
}

22
epmet-module/oper-customize/oper-customize-server/src/main/resources/mapper/IcFormQueryBuilderDao.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.IcFormQueryBuilderDao">
<resultMap type="com.epmet.entity.IcFormQueryBuilderEntity" id="icFormQueryBuilderMap">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="formItemId" column="FORM_ITEM_ID"/>
<result property="formCode" column="FORM_CODE"/>
<result property="queryType" column="QUERY_TYPE"/>
<result property="sort" column="SORT"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
</mapper>
Loading…
Cancel
Save