Search in sources :

Example 1 with TestCustomFieldOption

use of com.ngtesting.platform.entity.TestCustomFieldOption in project ngtesting-platform by aaronchen2k.

the class CustomFieldOptionServiceImpl method genVos.

@Override
public List<CustomFieldOptionVo> genVos(List<TestCustomFieldOption> pos) {
    List<CustomFieldOptionVo> vos = new LinkedList<>();
    for (TestCustomFieldOption po : pos) {
        CustomFieldOptionVo vo = genVo(po);
        vos.add(vo);
    }
    return vos;
}
Also used : CustomFieldOptionVo(com.ngtesting.platform.vo.CustomFieldOptionVo) TestCustomFieldOption(com.ngtesting.platform.entity.TestCustomFieldOption) LinkedList(java.util.LinkedList)

Example 2 with TestCustomFieldOption

use of com.ngtesting.platform.entity.TestCustomFieldOption in project ngtesting-platform by aaronchen2k.

the class CustomFieldOptionAction method save.

@AuthPassport(validate = true)
@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> save(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    CustomFieldOptionVo option = JSON.parseObject(JSON.toJSONString(json.getJSONObject("model")), CustomFieldOptionVo.class);
    TestCustomFieldOption po = customFieldOptionService.save(option);
    List<CustomFieldOptionVo> vos = customFieldOptionService.listVos(po.getFieldId());
    ret.put("data", vos);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : CustomFieldOptionVo(com.ngtesting.platform.vo.CustomFieldOptionVo) UserVo(com.ngtesting.platform.vo.UserVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) TestCustomFieldOption(com.ngtesting.platform.entity.TestCustomFieldOption) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with TestCustomFieldOption

use of com.ngtesting.platform.entity.TestCustomFieldOption in project ngtesting-platform by aaronchen2k.

the class CustomFieldOptionServiceImpl method changeOrderPers.

@Override
public boolean changeOrderPers(Long id, String act, Long fieldId) {
    TestCustomFieldOption opt = (TestCustomFieldOption) get(TestCustomFieldOption.class, id);
    String hql = "from TestCustomFieldOption opt where opt.fieldId=? and opt.deleted = false and opt.disabled = false ";
    if ("up".equals(act)) {
        hql += "and opt.ordr < ? order by ordr desc";
    } else if ("down".equals(act)) {
        hql += "and opt.ordr > ? order by ordr asc";
    } else {
        return false;
    }
    TestCustomFieldOption neighbor = (TestCustomFieldOption) getDao().findFirstByHQL(hql, fieldId, opt.getOrdr());
    Integer order = opt.getOrdr();
    opt.setOrdr(neighbor.getOrdr());
    neighbor.setOrdr(order);
    saveOrUpdate(opt);
    saveOrUpdate(neighbor);
    return true;
}
Also used : TestCustomFieldOption(com.ngtesting.platform.entity.TestCustomFieldOption)

Example 4 with TestCustomFieldOption

use of com.ngtesting.platform.entity.TestCustomFieldOption in project ngtesting-platform by aaronchen2k.

the class CustomFieldOptionServiceImpl method save.

@Override
public TestCustomFieldOption save(CustomFieldOptionVo vo) {
    if (vo == null) {
        return null;
    }
    TestCustomFieldOption po;
    if (vo.getId() != null) {
        po = (TestCustomFieldOption) get(TestCustomFieldOption.class, vo.getId());
    } else {
        po = new TestCustomFieldOption();
    }
    BeanUtilEx.copyProperties(po, vo);
    if (vo.getId() == null) {
        String hql = "select max(ordr) from TestCustomFieldOption opt where opt.fieldId = ?";
        Object obj = getByHQL(hql, vo.getFieldId());
        Integer maxOrder = obj != null ? (Integer) getByHQL(hql, vo.getFieldId()) : 10;
        po.setOrdr(maxOrder + 10);
    }
    saveOrUpdate(po);
    return po;
}
Also used : TestCustomFieldOption(com.ngtesting.platform.entity.TestCustomFieldOption)

Aggregations

TestCustomFieldOption (com.ngtesting.platform.entity.TestCustomFieldOption)4 CustomFieldOptionVo (com.ngtesting.platform.vo.CustomFieldOptionVo)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AuthPassport (com.ngtesting.platform.util.AuthPassport)1 UserVo (com.ngtesting.platform.vo.UserVo)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1