您的位置:首页 > 编程语言 > Java开发

Java开发快递物流项目(5)

2017-12-02 21:21 232 查看
4.定区管理功能

1)   定区添加功能

2)   定区列表分页条件查询

public class FixedAreaAction extends BaseAction<FixedArea> {

// 注入service
@Autowired
private FixedAreaService fixedAreaService;

// 定区添加功能
@Action(value = "fixedArea_save", results = {
@Result(name = "success", type = "redirect", location = "/pages/base/fixed_area.html") })
public String save() {
fixedAreaService.save(model);
return SUCCESS;
}

// 分页查询
@Action(value = "fixedArea_pageQuery", results = {
@Result(name = "success", type = "json") })
public String pageQuery() {
// 构造pageable
Pageable pageable = new PageRequest(page - 1, rows);
// 构造条件查询对象
Specification<FixedArea> specification = new Specification<FixedArea>() {

@Override
public Predicate toPredicate(Root<FixedArea> root,
CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> list = new ArrayList<>();
// 构造查询条件
if (StringUtils.isNotBlank(model.getId())) {
// 根据定去编号查询等值
Predicate p1 = cb.equal(root.get("id").as(String.class),
model.getId());
list.add(p1);
}
if (StringUtils.isNotBlank(model.getCompany())) {
// 根据公司查询 模糊
Predicate p2 = cb.like(root.get("company").as(String.class),
"%" + model.getCompany() + "%");
list.add(p2);
}

return cb.and(list.toArray(new Predicate[0]));
}
};
// 调用业务层 查询数据
Page<FixedArea> pageData = fixedAreaService.findPageData(specification,
pageable);

// 压入值栈
pushPageDataToValueStack(pageData);

return SUCCESS;

}

}

3)   定区管理客户



4)  定区关联客户

public interface CustomerService {

// 查询所有未关联客户列表
@Path("/noassociationcustomers")
@GET
@Produces({ "application/xml", "application/json" })
public List<Customer> findNoAssociationCustomers();

// 已经关联到指定定区的客户列表
@Path("/associationfixedareacustomers/{fixedareaid}")
@GET
@Produces({ "application/xml", "application/json" })
public List<Customer> findHasAssociationFixedAreaCustomers(
@PathParam("fixedareaid") String fixedAreaId);

// 将客户关联到定区上 , 将所有客户id 拼成字符串 1,2,3
@Path("/associationcustomerstofixedarea")
@PUT
public void associationCustomersToFixedArea(
@QueryParam("customerIdStr") String customerIdStr,
@QueryParam("fixedAreaId") String fixedAreaId);

}
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {

// 注入dao
@Autowired
private CustomerRepository customerRepository;

@Override
public List<Customer> findNoAssociationCustomers() {
return customerRepository.findByFixedAreaIdIsNull();
}

@Override
public List<Customer> findHasAssociationFixedAreaCustomers(
String fixedAreaId) {
return customerRepository.findByFixedAreaId(fixedAreaId);
}

@Override
public void associationCustomersToFixedArea(String customerIdStr,
String fixedAreaId) {
// 解除关联动作
customerRepository.clearFixedAreaId(fixedAreaId);

// 切割字符串 1, 2 ,3
if (StringUtils.isNotBlank(customerIdStr)) {
return;
}
String[] customerIdArray = customerIdStr.split(",");
for (String idStr : customerIdArray) {
Integer id = Integer.parseInt(idStr);
customerRepository.updateFixedAreaId(fixedAreaId, id);
}
}

}
WebService小结点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: